omap3: Add external VBUS power switch and overcurrent detect onIGEP v2 board
[sfrench/cifs-2.6.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/interrupt.h>
20
21 #include <linux/regulator/machine.h>
22 #include <linux/i2c/twl.h>
23 #include <linux/mmc/host.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_GREEN   26
43 #define IGEP2_GPIO_LED0_RED     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 static 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 static 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                 .caps           = MMC_CAP_4_BIT_DATA,
253                 .gpio_cd        = -EINVAL,
254                 .gpio_wp        = -EINVAL,
255         },
256         {
257                 .mmc            = 2,
258                 .caps           = MMC_CAP_4_BIT_DATA,
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         /*
279          * REVISIT: need ehci-omap hooks for external VBUS
280          * power switch and overcurrent detect
281          */
282         if ((gpio_request(gpio + 1, "GPIO_EHCI_NOC") < 0) ||
283             (gpio_direction_input(gpio + 1) < 0))
284                 pr_err("IGEP2: Could not obtain gpio for EHCI NOC");
285
286         /*
287          * TWL4030_GPIO_MAX + 0 == ledA, GPIO_USBH_CPEN
288          * (out, active low)
289          */
290         if ((gpio_request(gpio + TWL4030_GPIO_MAX, "GPIO_USBH_CPEN") < 0) ||
291             (gpio_direction_output(gpio + TWL4030_GPIO_MAX, 0) < 0))
292                 pr_err("IGEP2: Could not obtain gpio for USBH_CPEN");
293
294         return 0;
295 };
296
297 static struct twl4030_gpio_platform_data igep2_gpio_data = {
298         .gpio_base      = OMAP_MAX_GPIO_LINES,
299         .irq_base       = TWL4030_GPIO_IRQ_BASE,
300         .irq_end        = TWL4030_GPIO_IRQ_END,
301         .use_leds       = false,
302         .setup          = igep2_twl_gpio_setup,
303 };
304
305 static struct twl4030_usb_data igep2_usb_data = {
306         .usb_mode       = T2_USB_MODE_ULPI,
307 };
308
309 static int igep2_enable_dvi(struct omap_dss_device *dssdev)
310 {
311         gpio_direction_output(IGEP2_GPIO_DVI_PUP, 1);
312
313         return 0;
314 }
315
316 static void igep2_disable_dvi(struct omap_dss_device *dssdev)
317 {
318         gpio_direction_output(IGEP2_GPIO_DVI_PUP, 0);
319 }
320
321 static struct omap_dss_device igep2_dvi_device = {
322         .type                   = OMAP_DISPLAY_TYPE_DPI,
323         .name                   = "dvi",
324         .driver_name            = "generic_panel",
325         .phy.dpi.data_lines     = 24,
326         .platform_enable        = igep2_enable_dvi,
327         .platform_disable       = igep2_disable_dvi,
328 };
329
330 static struct omap_dss_device *igep2_dss_devices[] = {
331         &igep2_dvi_device
332 };
333
334 static struct omap_dss_board_info igep2_dss_data = {
335         .num_devices    = ARRAY_SIZE(igep2_dss_devices),
336         .devices        = igep2_dss_devices,
337         .default_device = &igep2_dvi_device,
338 };
339
340 static struct platform_device igep2_dss_device = {
341         .name   = "omapdss",
342         .id     = -1,
343         .dev    = {
344                 .platform_data = &igep2_dss_data,
345         },
346 };
347
348 static struct regulator_consumer_supply igep2_vpll2_supply = {
349         .supply = "vdds_dsi",
350         .dev    = &igep2_dss_device.dev,
351 };
352
353 static struct regulator_init_data igep2_vpll2 = {
354         .constraints = {
355                 .name                   = "VDVI",
356                 .min_uV                 = 1800000,
357                 .max_uV                 = 1800000,
358                 .apply_uV               = true,
359                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
360                                         | REGULATOR_MODE_STANDBY,
361                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
362                                         | REGULATOR_CHANGE_STATUS,
363         },
364         .num_consumer_supplies  = 1,
365         .consumer_supplies      = &igep2_vpll2_supply,
366 };
367
368 static void __init igep2_display_init(void)
369 {
370         if (gpio_request(IGEP2_GPIO_DVI_PUP, "GPIO_DVI_PUP") &&
371             gpio_direction_output(IGEP2_GPIO_DVI_PUP, 1))
372                 pr_err("IGEP v2: Could not obtain gpio GPIO_DVI_PUP\n");
373 }
374
375 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
376 #include <linux/leds.h>
377
378 static struct gpio_led igep2_gpio_leds[] = {
379         {
380                 .name = "led0:red",
381                 .gpio = IGEP2_GPIO_LED0_RED,
382         },
383         {
384                 .name = "led0:green",
385                 .default_trigger = "heartbeat",
386                 .gpio = IGEP2_GPIO_LED0_GREEN,
387         },
388         {
389                 .name = "led1:red",
390                 .gpio = IGEP2_GPIO_LED1_RED,
391         },
392 };
393
394 static struct gpio_led_platform_data igep2_led_pdata = {
395         .leds           = igep2_gpio_leds,
396         .num_leds       = ARRAY_SIZE(igep2_gpio_leds),
397 };
398
399 static struct platform_device igep2_led_device = {
400          .name   = "leds-gpio",
401          .id     = -1,
402          .dev    = {
403                  .platform_data  =  &igep2_led_pdata,
404         },
405 };
406
407 static void __init igep2_init_led(void)
408 {
409         platform_device_register(&igep2_led_device);
410 }
411
412 #else
413 static inline void igep2_init_led(void) {}
414 #endif
415
416 static struct platform_device *igep2_devices[] __initdata = {
417         &igep2_dss_device,
418 };
419
420 static void __init igep2_init_irq(void)
421 {
422         omap_board_config = igep2_config;
423         omap_board_config_size = ARRAY_SIZE(igep2_config);
424         omap2_init_common_hw(m65kxxxxam_sdrc_params, m65kxxxxam_sdrc_params);
425         omap_init_irq();
426         omap_gpio_init();
427 }
428
429 static struct twl4030_codec_audio_data igep2_audio_data = {
430         .audio_mclk = 26000000,
431 };
432
433 static struct twl4030_codec_data igep2_codec_data = {
434         .audio_mclk = 26000000,
435         .audio = &igep2_audio_data,
436 };
437
438 static struct twl4030_platform_data igep2_twldata = {
439         .irq_base       = TWL4030_IRQ_BASE,
440         .irq_end        = TWL4030_IRQ_END,
441
442         /* platform_data for children goes here */
443         .usb            = &igep2_usb_data,
444         .codec          = &igep2_codec_data,
445         .gpio           = &igep2_gpio_data,
446         .vmmc1          = &igep2_vmmc1,
447         .vmmc2          = &igep2_vmmc2,
448         .vpll2          = &igep2_vpll2,
449
450 };
451
452 static struct i2c_board_info __initdata igep2_i2c_boardinfo[] = {
453         {
454                 I2C_BOARD_INFO("twl4030", 0x48),
455                 .flags          = I2C_CLIENT_WAKE,
456                 .irq            = INT_34XX_SYS_NIRQ,
457                 .platform_data  = &igep2_twldata,
458         },
459 };
460
461 static int __init igep2_i2c_init(void)
462 {
463         omap_register_i2c_bus(1, 2600, igep2_i2c_boardinfo,
464                         ARRAY_SIZE(igep2_i2c_boardinfo));
465         /* Bus 3 is attached to the DVI port where devices like the pico DLP
466          * projector don't work reliably with 400kHz */
467         omap_register_i2c_bus(3, 100, NULL, 0);
468         return 0;
469 }
470
471 static struct omap_musb_board_data musb_board_data = {
472         .interface_type         = MUSB_INTERFACE_ULPI,
473         .mode                   = MUSB_OTG,
474         .power                  = 100,
475 };
476
477 static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
478         .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
479         .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN,
480         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
481
482         .phy_reset = true,
483         .reset_gpio_port[0] = IGEP2_GPIO_USBH_NRESET,
484         .reset_gpio_port[1] = -EINVAL,
485         .reset_gpio_port[2] = -EINVAL,
486 };
487
488 #ifdef CONFIG_OMAP_MUX
489 static struct omap_board_mux board_mux[] __initdata = {
490         { .reg_offset = OMAP_MUX_TERMINATOR },
491 };
492 #else
493 #define board_mux       NULL
494 #endif
495
496 static void __init igep2_init(void)
497 {
498         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
499         igep2_i2c_init();
500         platform_add_devices(igep2_devices, ARRAY_SIZE(igep2_devices));
501         omap_serial_init();
502         usb_musb_init(&musb_board_data);
503         usb_ehci_init(&ehci_pdata);
504
505         igep2_flash_init();
506         igep2_init_led();
507         igep2_display_init();
508         igep2_init_smsc911x();
509
510         /* GPIO userspace leds */
511 #if !defined(CONFIG_LEDS_GPIO) && !defined(CONFIG_LEDS_GPIO_MODULE)
512         if ((gpio_request(IGEP2_GPIO_LED0_RED, "led0:red") == 0) &&
513             (gpio_direction_output(IGEP2_GPIO_LED0_RED, 1) == 0)) {
514                 gpio_export(IGEP2_GPIO_LED0_RED, 0);
515                 gpio_set_value(IGEP2_GPIO_LED0_RED, 0);
516         } else
517                 pr_warning("IGEP v2: Could not obtain gpio GPIO_LED0_RED\n");
518
519         if ((gpio_request(IGEP2_GPIO_LED0_GREEN, "led0:green") == 0) &&
520             (gpio_direction_output(IGEP2_GPIO_LED0_GREEN, 1) == 0)) {
521                 gpio_export(IGEP2_GPIO_LED0_GREEN, 0);
522                 gpio_set_value(IGEP2_GPIO_LED0_GREEN, 0);
523         } else
524                 pr_warning("IGEP v2: Could not obtain gpio GPIO_LED0_GREEN\n");
525
526         if ((gpio_request(IGEP2_GPIO_LED1_RED, "led1:red") == 0) &&
527             (gpio_direction_output(IGEP2_GPIO_LED1_RED, 1) == 0)) {
528                 gpio_export(IGEP2_GPIO_LED1_RED, 0);
529                 gpio_set_value(IGEP2_GPIO_LED1_RED, 0);
530         } else
531                 pr_warning("IGEP v2: Could not obtain gpio GPIO_LED1_RED\n");
532 #endif
533
534         /* GPIO W-LAN + Bluetooth combo module */
535         if ((gpio_request(IGEP2_GPIO_WIFI_NPD, "GPIO_WIFI_NPD") == 0) &&
536             (gpio_direction_output(IGEP2_GPIO_WIFI_NPD, 1) == 0)) {
537                 gpio_export(IGEP2_GPIO_WIFI_NPD, 0);
538 /*              gpio_set_value(IGEP2_GPIO_WIFI_NPD, 0); */
539         } else
540                 pr_warning("IGEP v2: Could not obtain gpio GPIO_WIFI_NPD\n");
541
542         if ((gpio_request(IGEP2_GPIO_WIFI_NRESET, "GPIO_WIFI_NRESET") == 0) &&
543             (gpio_direction_output(IGEP2_GPIO_WIFI_NRESET, 1) == 0)) {
544                 gpio_export(IGEP2_GPIO_WIFI_NRESET, 0);
545                 gpio_set_value(IGEP2_GPIO_WIFI_NRESET, 0);
546                 udelay(10);
547                 gpio_set_value(IGEP2_GPIO_WIFI_NRESET, 1);
548         } else
549                 pr_warning("IGEP v2: Could not obtain gpio GPIO_WIFI_NRESET\n");
550 }
551
552 MACHINE_START(IGEP0020, "IGEP v2 board")
553         .phys_io        = 0x48000000,
554         .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
555         .boot_params    = 0x80000100,
556         .map_io         = omap3_map_io,
557         .reserve        = omap_reserve,
558         .init_irq       = igep2_init_irq,
559         .init_machine   = igep2_init,
560         .timer          = &omap_timer,
561 MACHINE_END