Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[pandora-kernel.git] / arch / arm / mach-omap2 / board-igep0020.c
1 /*
2  * Copyright (C) 2009 Integration Software and Electronic Engineering.
3  *
4  * Modified from mach-omap2/board-generic.c
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/delay.h>
15 #include <linux/err.h>
16 #include <linux/clk.h>
17 #include <linux/io.h>
18 #include <linux/gpio.h>
19 #include <linux/leds.h>
20 #include <linux/interrupt.h>
21
22 #include <linux/regulator/machine.h>
23 #include <linux/i2c/twl.h>
24
25 #include <asm/mach-types.h>
26 #include <asm/mach/arch.h>
27
28 #include <plat/board.h>
29 #include <plat/common.h>
30 #include <plat/gpmc.h>
31 #include <plat/usb.h>
32 #include <plat/display.h>
33 #include <plat/onenand.h>
34
35 #include "mux.h"
36 #include "hsmmc.h"
37 #include "sdram-numonyx-m65kxxxxam.h"
38
39 #define IGEP2_SMSC911X_CS       5
40 #define IGEP2_SMSC911X_GPIO     176
41 #define IGEP2_GPIO_USBH_NRESET  24
42 #define IGEP2_GPIO_LED0_RED     26
43 #define IGEP2_GPIO_LED0_GREEN   27
44 #define IGEP2_GPIO_LED1_RED     28
45 #define IGEP2_GPIO_DVI_PUP      170
46 #define IGEP2_GPIO_WIFI_NPD     94
47 #define IGEP2_GPIO_WIFI_NRESET  95
48
49 #if defined(CONFIG_MTD_ONENAND_OMAP2) || \
50         defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)
51
52 #define ONENAND_MAP             0x20000000
53
54 /* NAND04GR4E1A ( x2 Flash built-in COMBO POP MEMORY )
55  * Since the device is equipped with two DataRAMs, and two-plane NAND
56  * Flash memory array, these two component enables simultaneous program
57  * of 4KiB. Plane1 has only even blocks such as block0, block2, block4
58  * while Plane2 has only odd blocks such as block1, block3, block5.
59  * So MTD regards it as 4KiB page size and 256KiB block size 64*(2*2048)
60  */
61
62 static struct mtd_partition igep2_onenand_partitions[] = {
63         {
64                 .name           = "X-Loader",
65                 .offset         = 0,
66                 .size           = 2 * (64*(2*2048))
67         },
68         {
69                 .name           = "U-Boot",
70                 .offset         = MTDPART_OFS_APPEND,
71                 .size           = 6 * (64*(2*2048)),
72         },
73         {
74                 .name           = "Environment",
75                 .offset         = MTDPART_OFS_APPEND,
76                 .size           = 2 * (64*(2*2048)),
77         },
78         {
79                 .name           = "Kernel",
80                 .offset         = MTDPART_OFS_APPEND,
81                 .size           = 12 * (64*(2*2048)),
82         },
83         {
84                 .name           = "File System",
85                 .offset         = MTDPART_OFS_APPEND,
86                 .size           = MTDPART_SIZ_FULL,
87         },
88 };
89
90 static int igep2_onenand_setup(void __iomem *onenand_base, int freq)
91 {
92        /* nothing is required to be setup for onenand as of now */
93        return 0;
94 }
95
96 static struct omap_onenand_platform_data igep2_onenand_data = {
97         .parts = igep2_onenand_partitions,
98         .nr_parts = ARRAY_SIZE(igep2_onenand_partitions),
99         .onenand_setup = igep2_onenand_setup,
100         .dma_channel    = -1,   /* disable DMA in OMAP OneNAND driver */
101 };
102
103 static struct platform_device igep2_onenand_device = {
104         .name           = "omap2-onenand",
105         .id             = -1,
106         .dev = {
107                 .platform_data = &igep2_onenand_data,
108         },
109 };
110
111 void __init igep2_flash_init(void)
112 {
113         u8              cs = 0;
114         u8              onenandcs = GPMC_CS_NUM + 1;
115
116         while (cs < GPMC_CS_NUM) {
117                 u32 ret = 0;
118                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
119
120                 /* Check if NAND/oneNAND is configured */
121                 if ((ret & 0xC00) == 0x800)
122                         /* NAND found */
123                         pr_err("IGEP v2: Unsupported NAND found\n");
124                 else {
125                         ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7);
126                         if ((ret & 0x3F) == (ONENAND_MAP >> 24))
127                                 /* ONENAND found */
128                                 onenandcs = cs;
129                 }
130                 cs++;
131         }
132         if (onenandcs > GPMC_CS_NUM) {
133                 pr_err("IGEP v2: Unable to find configuration in GPMC\n");
134                 return;
135         }
136
137         if (onenandcs < GPMC_CS_NUM) {
138                 igep2_onenand_data.cs = onenandcs;
139                 if (platform_device_register(&igep2_onenand_device) < 0)
140                         pr_err("IGEP v2: Unable to register OneNAND device\n");
141         }
142 }
143
144 #else
145 void __init igep2_flash_init(void) {}
146 #endif
147
148 #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
149
150 #include <linux/smsc911x.h>
151
152 static struct smsc911x_platform_config igep2_smsc911x_config = {
153         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
154         .irq_type       = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
155         .flags          = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS  ,
156         .phy_interface  = PHY_INTERFACE_MODE_MII,
157 };
158
159 static struct resource igep2_smsc911x_resources[] = {
160         {
161                 .flags  = IORESOURCE_MEM,
162         },
163         {
164                 .start  = OMAP_GPIO_IRQ(IGEP2_SMSC911X_GPIO),
165                 .end    = OMAP_GPIO_IRQ(IGEP2_SMSC911X_GPIO),
166                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
167         },
168 };
169
170 static struct platform_device igep2_smsc911x_device = {
171         .name           = "smsc911x",
172         .id             = 0,
173         .num_resources  = ARRAY_SIZE(igep2_smsc911x_resources),
174         .resource       = igep2_smsc911x_resources,
175         .dev            = {
176                 .platform_data = &igep2_smsc911x_config,
177         },
178 };
179
180 static inline void __init igep2_init_smsc911x(void)
181 {
182         unsigned long cs_mem_base;
183
184         if (gpmc_cs_request(IGEP2_SMSC911X_CS, SZ_16M, &cs_mem_base) < 0) {
185                 pr_err("IGEP v2: Failed request for GPMC mem for smsc911x\n");
186                 gpmc_cs_free(IGEP2_SMSC911X_CS);
187                 return;
188         }
189
190         igep2_smsc911x_resources[0].start = cs_mem_base + 0x0;
191         igep2_smsc911x_resources[0].end   = cs_mem_base + 0xff;
192
193         if ((gpio_request(IGEP2_SMSC911X_GPIO, "SMSC911X IRQ") == 0) &&
194             (gpio_direction_input(IGEP2_SMSC911X_GPIO) == 0)) {
195                 gpio_export(IGEP2_SMSC911X_GPIO, 0);
196         } else {
197                 pr_err("IGEP v2: Could not obtain gpio for for SMSC911X IRQ\n");
198                 return;
199         }
200
201         platform_device_register(&igep2_smsc911x_device);
202 }
203
204 #else
205 static inline void __init igep2_init_smsc911x(void) { }
206 #endif
207
208 static struct omap_board_config_kernel igep2_config[] __initdata = {
209 };
210
211 static struct regulator_consumer_supply igep2_vmmc1_supply = {
212         .supply         = "vmmc",
213 };
214
215 static struct regulator_consumer_supply igep2_vmmc2_supply = {
216         .supply         = "vmmc",
217 };
218
219 /* VMMC1 for OMAP VDD_MMC1 (i/o) and MMC1 card */
220 static struct regulator_init_data igep2_vmmc1 = {
221         .constraints = {
222                 .min_uV                 = 1850000,
223                 .max_uV                 = 3150000,
224                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
225                                         | REGULATOR_MODE_STANDBY,
226                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
227                                         | REGULATOR_CHANGE_MODE
228                                         | REGULATOR_CHANGE_STATUS,
229         },
230         .num_consumer_supplies  = 1,
231         .consumer_supplies      = &igep2_vmmc1_supply,
232 };
233
234 /* VMMC2 for OMAP VDD_MMC2 (i/o) and MMC2 WIFI */
235 static struct regulator_init_data igep2_vmmc2 = {
236         .constraints = {
237                 .min_uV                 = 1850000,
238                 .max_uV                 = 3150000,
239                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
240                                         | REGULATOR_MODE_STANDBY,
241                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
242                                         | REGULATOR_CHANGE_MODE
243                                         | REGULATOR_CHANGE_STATUS,
244         },
245         .num_consumer_supplies  = 1,
246         .consumer_supplies      = &igep2_vmmc2_supply,
247 };
248
249 static struct omap2_hsmmc_info mmc[] = {
250         {
251                 .mmc            = 1,
252                 .wires          = 4,
253                 .gpio_cd        = -EINVAL,
254                 .gpio_wp        = -EINVAL,
255         },
256         {
257                 .mmc            = 2,
258                 .wires          = 4,
259                 .gpio_cd        = -EINVAL,
260                 .gpio_wp        = -EINVAL,
261         },
262         {}      /* Terminator */
263 };
264
265 static int igep2_twl_gpio_setup(struct device *dev,
266                 unsigned gpio, unsigned ngpio)
267 {
268         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
269         mmc[0].gpio_cd = gpio + 0;
270         omap2_hsmmc_init(mmc);
271
272         /* link regulators to MMC adapters ... we "know" the
273          * regulators will be set up only *after* we return.
274         */
275         igep2_vmmc1_supply.dev = mmc[0].dev;
276         igep2_vmmc2_supply.dev = mmc[1].dev;
277
278         return 0;
279 };
280
281 static struct twl4030_gpio_platform_data igep2_gpio_data = {
282         .gpio_base      = OMAP_MAX_GPIO_LINES,
283         .irq_base       = TWL4030_GPIO_IRQ_BASE,
284         .irq_end        = TWL4030_GPIO_IRQ_END,
285         .use_leds       = false,
286         .setup          = igep2_twl_gpio_setup,
287 };
288
289 static struct twl4030_usb_data igep2_usb_data = {
290         .usb_mode       = T2_USB_MODE_ULPI,
291 };
292
293 static int igep2_enable_dvi(struct omap_dss_device *dssdev)
294 {
295         gpio_direction_output(IGEP2_GPIO_DVI_PUP, 1);
296
297         return 0;
298 }
299
300 static void igep2_disable_dvi(struct omap_dss_device *dssdev)
301 {
302         gpio_direction_output(IGEP2_GPIO_DVI_PUP, 0);
303 }
304
305 static struct omap_dss_device igep2_dvi_device = {
306         .type                   = OMAP_DISPLAY_TYPE_DPI,
307         .name                   = "dvi",
308         .driver_name            = "generic_panel",
309         .phy.dpi.data_lines     = 24,
310         .platform_enable        = igep2_enable_dvi,
311         .platform_disable       = igep2_disable_dvi,
312 };
313
314 static struct omap_dss_device *igep2_dss_devices[] = {
315         &igep2_dvi_device
316 };
317
318 static struct omap_dss_board_info igep2_dss_data = {
319         .num_devices    = ARRAY_SIZE(igep2_dss_devices),
320         .devices        = igep2_dss_devices,
321         .default_device = &igep2_dvi_device,
322 };
323
324 static struct platform_device igep2_dss_device = {
325         .name   = "omapdss",
326         .id     = -1,
327         .dev    = {
328                 .platform_data = &igep2_dss_data,
329         },
330 };
331
332 static struct regulator_consumer_supply igep2_vpll2_supply = {
333         .supply = "vdds_dsi",
334         .dev    = &igep2_dss_device.dev,
335 };
336
337 static struct regulator_init_data igep2_vpll2 = {
338         .constraints = {
339                 .name                   = "VDVI",
340                 .min_uV                 = 1800000,
341                 .max_uV                 = 1800000,
342                 .apply_uV               = true,
343                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
344                                         | REGULATOR_MODE_STANDBY,
345                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
346                                         | REGULATOR_CHANGE_STATUS,
347         },
348         .num_consumer_supplies  = 1,
349         .consumer_supplies      = &igep2_vpll2_supply,
350 };
351
352 static void __init igep2_display_init(void)
353 {
354         if (gpio_request(IGEP2_GPIO_DVI_PUP, "GPIO_DVI_PUP") &&
355             gpio_direction_output(IGEP2_GPIO_DVI_PUP, 1))
356                 pr_err("IGEP v2: Could not obtain gpio GPIO_DVI_PUP\n");
357 }
358 #ifdef CONFIG_LEDS_TRIGGERS
359 static struct gpio_led gpio_leds[] = {
360         {
361                 .name = "GPIO_LED1_RED",
362                 .default_trigger = "heartbeat",
363                 .gpio = IGEP2_GPIO_LED1_RED,
364         },
365 };
366
367 static struct gpio_led_platform_data gpio_leds_info = {
368         .leds           = gpio_leds,
369         .num_leds       = ARRAY_SIZE(gpio_leds),
370 };
371
372 static struct platform_device leds_gpio = {
373          .name   = "leds-gpio",
374          .id     = -1,
375          .dev    = {
376                  .platform_data  =  &gpio_leds_info,
377         },
378 };
379 #endif
380
381 static struct platform_device *igep2_devices[] __initdata = {
382         &igep2_dss_device,
383 #ifdef CONFIG_LEDS_TRIGGERS
384         &leds_gpio,
385 #endif
386 };
387
388 static void __init igep2_init_irq(void)
389 {
390         omap_board_config = igep2_config;
391         omap_board_config_size = ARRAY_SIZE(igep2_config);
392         omap2_init_common_hw(m65kxxxxam_sdrc_params, m65kxxxxam_sdrc_params);
393         omap_init_irq();
394         omap_gpio_init();
395 }
396
397 static struct twl4030_codec_audio_data igep2_audio_data = {
398         .audio_mclk = 26000000,
399 };
400
401 static struct twl4030_codec_data igep2_codec_data = {
402         .audio_mclk = 26000000,
403         .audio = &igep2_audio_data,
404 };
405
406 static struct twl4030_platform_data igep2_twldata = {
407         .irq_base       = TWL4030_IRQ_BASE,
408         .irq_end        = TWL4030_IRQ_END,
409
410         /* platform_data for children goes here */
411         .usb            = &igep2_usb_data,
412         .codec          = &igep2_codec_data,
413         .gpio           = &igep2_gpio_data,
414         .vmmc1          = &igep2_vmmc1,
415         .vmmc2          = &igep2_vmmc2,
416         .vpll2          = &igep2_vpll2,
417
418 };
419
420 static struct i2c_board_info __initdata igep2_i2c_boardinfo[] = {
421         {
422                 I2C_BOARD_INFO("twl4030", 0x48),
423                 .flags          = I2C_CLIENT_WAKE,
424                 .irq            = INT_34XX_SYS_NIRQ,
425                 .platform_data  = &igep2_twldata,
426         },
427 };
428
429 static int __init igep2_i2c_init(void)
430 {
431         omap_register_i2c_bus(1, 2600, igep2_i2c_boardinfo,
432                         ARRAY_SIZE(igep2_i2c_boardinfo));
433         /* Bus 3 is attached to the DVI port where devices like the pico DLP
434          * projector don't work reliably with 400kHz */
435         omap_register_i2c_bus(3, 100, NULL, 0);
436         return 0;
437 }
438
439 static struct omap_musb_board_data musb_board_data = {
440         .interface_type         = MUSB_INTERFACE_ULPI,
441         .mode                   = MUSB_OTG,
442         .power                  = 100,
443 };
444
445 static struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
446         .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN,
447         .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
448         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
449
450         .phy_reset = true,
451         .reset_gpio_port[0] = -EINVAL,
452         .reset_gpio_port[1] = IGEP2_GPIO_USBH_NRESET,
453         .reset_gpio_port[2] = -EINVAL,
454 };
455
456 #ifdef CONFIG_OMAP_MUX
457 static struct omap_board_mux board_mux[] __initdata = {
458         { .reg_offset = OMAP_MUX_TERMINATOR },
459 };
460 #else
461 #define board_mux       NULL
462 #endif
463
464 static void __init igep2_init(void)
465 {
466         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
467         igep2_i2c_init();
468         platform_add_devices(igep2_devices, ARRAY_SIZE(igep2_devices));
469         omap_serial_init();
470         usb_musb_init(&musb_board_data);
471         usb_ehci_init(&ehci_pdata);
472
473         igep2_flash_init();
474         igep2_display_init();
475         igep2_init_smsc911x();
476
477         /* GPIO userspace leds */
478         if ((gpio_request(IGEP2_GPIO_LED0_RED, "GPIO_LED0_RED") == 0) &&
479             (gpio_direction_output(IGEP2_GPIO_LED0_RED, 1) == 0)) {
480                 gpio_export(IGEP2_GPIO_LED0_RED, 0);
481                 gpio_set_value(IGEP2_GPIO_LED0_RED, 0);
482         } else
483                 pr_warning("IGEP v2: Could not obtain gpio GPIO_LED0_RED\n");
484
485         if ((gpio_request(IGEP2_GPIO_LED0_GREEN, "GPIO_LED0_GREEN") == 0) &&
486             (gpio_direction_output(IGEP2_GPIO_LED0_GREEN, 1) == 0)) {
487                 gpio_export(IGEP2_GPIO_LED0_GREEN, 0);
488                 gpio_set_value(IGEP2_GPIO_LED0_GREEN, 0);
489         } else
490                 pr_warning("IGEP v2: Could not obtain gpio GPIO_LED0_GREEN\n");
491 #ifndef CONFIG_LEDS_TRIGGERS
492         if ((gpio_request(IGEP2_GPIO_LED1_RED, "GPIO_LED1_RED") == 0) &&
493             (gpio_direction_output(IGEP2_GPIO_LED1_RED, 1) == 0)) {
494                 gpio_export(IGEP2_GPIO_LED1_RED, 0);
495                 gpio_set_value(IGEP2_GPIO_LED1_RED, 0);
496         } else
497                 pr_warning("IGEP v2: Could not obtain gpio GPIO_LED1_RED\n");
498 #endif
499         /* GPIO W-LAN + Bluetooth combo module */
500         if ((gpio_request(IGEP2_GPIO_WIFI_NPD, "GPIO_WIFI_NPD") == 0) &&
501             (gpio_direction_output(IGEP2_GPIO_WIFI_NPD, 1) == 0)) {
502                 gpio_export(IGEP2_GPIO_WIFI_NPD, 0);
503 /*              gpio_set_value(IGEP2_GPIO_WIFI_NPD, 0); */
504         } else
505                 pr_warning("IGEP v2: Could not obtain gpio GPIO_WIFI_NPD\n");
506
507         if ((gpio_request(IGEP2_GPIO_WIFI_NRESET, "GPIO_WIFI_NRESET") == 0) &&
508             (gpio_direction_output(IGEP2_GPIO_WIFI_NRESET, 1) == 0)) {
509                 gpio_export(IGEP2_GPIO_WIFI_NRESET, 0);
510                 gpio_set_value(IGEP2_GPIO_WIFI_NRESET, 0);
511                 udelay(10);
512                 gpio_set_value(IGEP2_GPIO_WIFI_NRESET, 1);
513         } else
514                 pr_warning("IGEP v2: Could not obtain gpio GPIO_WIFI_NRESET\n");
515 }
516
517 static void __init igep2_map_io(void)
518 {
519         omap2_set_globals_343x();
520         omap34xx_map_common_io();
521 }
522
523 MACHINE_START(IGEP0020, "IGEP v2 board")
524         .phys_io        = 0x48000000,
525         .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
526         .boot_params    = 0x80000100,
527         .map_io         = igep2_map_io,
528         .init_irq       = igep2_init_irq,
529         .init_machine   = igep2_init,
530         .timer          = &omap_timer,
531 MACHINE_END