omap: mmc: extended to pass host capabilities from board file
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3beagle.c
1 /*
2  * linux/arch/arm/mach-omap2/board-omap3beagle.c
3  *
4  * Copyright (C) 2008 Texas Instruments
5  *
6  * Modified from mach-omap2/board-3430sdp.c
7  *
8  * Initial code: Syed Mohammed Khasim
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/clk.h>
21 #include <linux/io.h>
22 #include <linux/leds.h>
23 #include <linux/gpio.h>
24 #include <linux/input.h>
25 #include <linux/gpio_keys.h>
26
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/mtd/nand.h>
30 #include <linux/mmc/host.h>
31
32 #include <linux/regulator/machine.h>
33 #include <linux/i2c/twl.h>
34
35 #include <mach/hardware.h>
36 #include <asm/mach-types.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/map.h>
39 #include <asm/mach/flash.h>
40
41 #include <plat/board.h>
42 #include <plat/common.h>
43 #include <plat/display.h>
44 #include <plat/gpmc.h>
45 #include <plat/nand.h>
46 #include <plat/usb.h>
47 #include <plat/timer-gp.h>
48
49 #include "mux.h"
50 #include "hsmmc.h"
51
52 #define NAND_BLOCK_SIZE         SZ_128K
53
54 static struct mtd_partition omap3beagle_nand_partitions[] = {
55         /* All the partition sizes are listed in terms of NAND block size */
56         {
57                 .name           = "X-Loader",
58                 .offset         = 0,
59                 .size           = 4 * NAND_BLOCK_SIZE,
60                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
61         },
62         {
63                 .name           = "U-Boot",
64                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
65                 .size           = 15 * NAND_BLOCK_SIZE,
66                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
67         },
68         {
69                 .name           = "U-Boot Env",
70                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x260000 */
71                 .size           = 1 * NAND_BLOCK_SIZE,
72         },
73         {
74                 .name           = "Kernel",
75                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
76                 .size           = 32 * NAND_BLOCK_SIZE,
77         },
78         {
79                 .name           = "File System",
80                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
81                 .size           = MTDPART_SIZ_FULL,
82         },
83 };
84
85 static struct omap_nand_platform_data omap3beagle_nand_data = {
86         .options        = NAND_BUSWIDTH_16,
87         .parts          = omap3beagle_nand_partitions,
88         .nr_parts       = ARRAY_SIZE(omap3beagle_nand_partitions),
89         .dma_channel    = -1,           /* disable DMA in OMAP NAND driver */
90         .nand_setup     = NULL,
91         .dev_ready      = NULL,
92 };
93
94 /* DSS */
95
96 static int beagle_enable_dvi(struct omap_dss_device *dssdev)
97 {
98         if (gpio_is_valid(dssdev->reset_gpio))
99                 gpio_set_value(dssdev->reset_gpio, 1);
100
101         return 0;
102 }
103
104 static void beagle_disable_dvi(struct omap_dss_device *dssdev)
105 {
106         if (gpio_is_valid(dssdev->reset_gpio))
107                 gpio_set_value(dssdev->reset_gpio, 0);
108 }
109
110 static struct omap_dss_device beagle_dvi_device = {
111         .type = OMAP_DISPLAY_TYPE_DPI,
112         .name = "dvi",
113         .driver_name = "generic_panel",
114         .phy.dpi.data_lines = 24,
115         .reset_gpio = 170,
116         .platform_enable = beagle_enable_dvi,
117         .platform_disable = beagle_disable_dvi,
118 };
119
120 static struct omap_dss_device beagle_tv_device = {
121         .name = "tv",
122         .driver_name = "venc",
123         .type = OMAP_DISPLAY_TYPE_VENC,
124         .phy.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
125 };
126
127 static struct omap_dss_device *beagle_dss_devices[] = {
128         &beagle_dvi_device,
129         &beagle_tv_device,
130 };
131
132 static struct omap_dss_board_info beagle_dss_data = {
133         .num_devices = ARRAY_SIZE(beagle_dss_devices),
134         .devices = beagle_dss_devices,
135         .default_device = &beagle_dvi_device,
136 };
137
138 static struct platform_device beagle_dss_device = {
139         .name          = "omapdss",
140         .id            = -1,
141         .dev            = {
142                 .platform_data = &beagle_dss_data,
143         },
144 };
145
146 static struct regulator_consumer_supply beagle_vdac_supply =
147         REGULATOR_SUPPLY("vdda_dac", "omapdss");
148
149 static struct regulator_consumer_supply beagle_vdvi_supply =
150         REGULATOR_SUPPLY("vdds_dsi", "omapdss");
151
152 static void __init beagle_display_init(void)
153 {
154         int r;
155
156         r = gpio_request(beagle_dvi_device.reset_gpio, "DVI reset");
157         if (r < 0) {
158                 printk(KERN_ERR "Unable to get DVI reset GPIO\n");
159                 return;
160         }
161
162         gpio_direction_output(beagle_dvi_device.reset_gpio, 0);
163 }
164
165 #include "sdram-micron-mt46h32m32lf-6.h"
166
167 static struct omap2_hsmmc_info mmc[] = {
168         {
169                 .mmc            = 1,
170                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
171                 .gpio_wp        = 29,
172         },
173         {}      /* Terminator */
174 };
175
176 static struct regulator_consumer_supply beagle_vmmc1_supply = {
177         .supply                 = "vmmc",
178 };
179
180 static struct regulator_consumer_supply beagle_vsim_supply = {
181         .supply                 = "vmmc_aux",
182 };
183
184 static struct gpio_led gpio_leds[];
185
186 static int beagle_twl_gpio_setup(struct device *dev,
187                 unsigned gpio, unsigned ngpio)
188 {
189         if (system_rev >= 0x20 && system_rev <= 0x34301000) {
190                 omap_mux_init_gpio(23, OMAP_PIN_INPUT);
191                 mmc[0].gpio_wp = 23;
192         } else {
193                 omap_mux_init_gpio(29, OMAP_PIN_INPUT);
194         }
195         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
196         mmc[0].gpio_cd = gpio + 0;
197         omap2_hsmmc_init(mmc);
198
199         /* link regulators to MMC adapters */
200         beagle_vmmc1_supply.dev = mmc[0].dev;
201         beagle_vsim_supply.dev = mmc[0].dev;
202
203         /* REVISIT: need ehci-omap hooks for external VBUS
204          * power switch and overcurrent detect
205          */
206
207         gpio_request(gpio + 1, "EHCI_nOC");
208         gpio_direction_input(gpio + 1);
209
210         /* TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, active low) */
211         gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
212         gpio_direction_output(gpio + TWL4030_GPIO_MAX, 0);
213
214         /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
215         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
216
217         return 0;
218 }
219
220 static struct twl4030_gpio_platform_data beagle_gpio_data = {
221         .gpio_base      = OMAP_MAX_GPIO_LINES,
222         .irq_base       = TWL4030_GPIO_IRQ_BASE,
223         .irq_end        = TWL4030_GPIO_IRQ_END,
224         .use_leds       = true,
225         .pullups        = BIT(1),
226         .pulldowns      = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
227                                 | BIT(15) | BIT(16) | BIT(17),
228         .setup          = beagle_twl_gpio_setup,
229 };
230
231 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
232 static struct regulator_init_data beagle_vmmc1 = {
233         .constraints = {
234                 .min_uV                 = 1850000,
235                 .max_uV                 = 3150000,
236                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
237                                         | REGULATOR_MODE_STANDBY,
238                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
239                                         | REGULATOR_CHANGE_MODE
240                                         | REGULATOR_CHANGE_STATUS,
241         },
242         .num_consumer_supplies  = 1,
243         .consumer_supplies      = &beagle_vmmc1_supply,
244 };
245
246 /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
247 static struct regulator_init_data beagle_vsim = {
248         .constraints = {
249                 .min_uV                 = 1800000,
250                 .max_uV                 = 3000000,
251                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
252                                         | REGULATOR_MODE_STANDBY,
253                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
254                                         | REGULATOR_CHANGE_MODE
255                                         | REGULATOR_CHANGE_STATUS,
256         },
257         .num_consumer_supplies  = 1,
258         .consumer_supplies      = &beagle_vsim_supply,
259 };
260
261 /* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
262 static struct regulator_init_data beagle_vdac = {
263         .constraints = {
264                 .min_uV                 = 1800000,
265                 .max_uV                 = 1800000,
266                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
267                                         | REGULATOR_MODE_STANDBY,
268                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
269                                         | REGULATOR_CHANGE_STATUS,
270         },
271         .num_consumer_supplies  = 1,
272         .consumer_supplies      = &beagle_vdac_supply,
273 };
274
275 /* VPLL2 for digital video outputs */
276 static struct regulator_init_data beagle_vpll2 = {
277         .constraints = {
278                 .name                   = "VDVI",
279                 .min_uV                 = 1800000,
280                 .max_uV                 = 1800000,
281                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
282                                         | REGULATOR_MODE_STANDBY,
283                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
284                                         | REGULATOR_CHANGE_STATUS,
285         },
286         .num_consumer_supplies  = 1,
287         .consumer_supplies      = &beagle_vdvi_supply,
288 };
289
290 static struct twl4030_usb_data beagle_usb_data = {
291         .usb_mode       = T2_USB_MODE_ULPI,
292 };
293
294 static struct twl4030_codec_audio_data beagle_audio_data = {
295         .audio_mclk = 26000000,
296 };
297
298 static struct twl4030_codec_data beagle_codec_data = {
299         .audio_mclk = 26000000,
300         .audio = &beagle_audio_data,
301 };
302
303 static struct twl4030_platform_data beagle_twldata = {
304         .irq_base       = TWL4030_IRQ_BASE,
305         .irq_end        = TWL4030_IRQ_END,
306
307         /* platform_data for children goes here */
308         .usb            = &beagle_usb_data,
309         .gpio           = &beagle_gpio_data,
310         .codec          = &beagle_codec_data,
311         .vmmc1          = &beagle_vmmc1,
312         .vsim           = &beagle_vsim,
313         .vdac           = &beagle_vdac,
314         .vpll2          = &beagle_vpll2,
315 };
316
317 static struct i2c_board_info __initdata beagle_i2c_boardinfo[] = {
318         {
319                 I2C_BOARD_INFO("twl4030", 0x48),
320                 .flags = I2C_CLIENT_WAKE,
321                 .irq = INT_34XX_SYS_NIRQ,
322                 .platform_data = &beagle_twldata,
323         },
324 };
325
326 static int __init omap3_beagle_i2c_init(void)
327 {
328         omap_register_i2c_bus(1, 2600, beagle_i2c_boardinfo,
329                         ARRAY_SIZE(beagle_i2c_boardinfo));
330         /* Bus 3 is attached to the DVI port where devices like the pico DLP
331          * projector don't work reliably with 400kHz */
332         omap_register_i2c_bus(3, 100, NULL, 0);
333         return 0;
334 }
335
336 static struct gpio_led gpio_leds[] = {
337         {
338                 .name                   = "beagleboard::usr0",
339                 .default_trigger        = "heartbeat",
340                 .gpio                   = 150,
341         },
342         {
343                 .name                   = "beagleboard::usr1",
344                 .default_trigger        = "mmc0",
345                 .gpio                   = 149,
346         },
347         {
348                 .name                   = "beagleboard::pmu_stat",
349                 .gpio                   = -EINVAL,      /* gets replaced */
350                 .active_low             = true,
351         },
352 };
353
354 static struct gpio_led_platform_data gpio_led_info = {
355         .leds           = gpio_leds,
356         .num_leds       = ARRAY_SIZE(gpio_leds),
357 };
358
359 static struct platform_device leds_gpio = {
360         .name   = "leds-gpio",
361         .id     = -1,
362         .dev    = {
363                 .platform_data  = &gpio_led_info,
364         },
365 };
366
367 static struct gpio_keys_button gpio_buttons[] = {
368         {
369                 .code                   = BTN_EXTRA,
370                 .gpio                   = 7,
371                 .desc                   = "user",
372                 .wakeup                 = 1,
373         },
374 };
375
376 static struct gpio_keys_platform_data gpio_key_info = {
377         .buttons        = gpio_buttons,
378         .nbuttons       = ARRAY_SIZE(gpio_buttons),
379 };
380
381 static struct platform_device keys_gpio = {
382         .name   = "gpio-keys",
383         .id     = -1,
384         .dev    = {
385                 .platform_data  = &gpio_key_info,
386         },
387 };
388
389 static void __init omap3_beagle_init_irq(void)
390 {
391         omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
392                              mt46h32m32lf6_sdrc_params);
393         omap_init_irq();
394 #ifdef CONFIG_OMAP_32K_TIMER
395         omap2_gp_clockevent_set_gptimer(12);
396 #endif
397         omap_gpio_init();
398 }
399
400 static struct platform_device *omap3_beagle_devices[] __initdata = {
401         &leds_gpio,
402         &keys_gpio,
403         &beagle_dss_device,
404 };
405
406 static void __init omap3beagle_flash_init(void)
407 {
408         u8 cs = 0;
409         u8 nandcs = GPMC_CS_NUM + 1;
410
411         /* find out the chip-select on which NAND exists */
412         while (cs < GPMC_CS_NUM) {
413                 u32 ret = 0;
414                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
415
416                 if ((ret & 0xC00) == 0x800) {
417                         printk(KERN_INFO "Found NAND on CS%d\n", cs);
418                         if (nandcs > GPMC_CS_NUM)
419                                 nandcs = cs;
420                 }
421                 cs++;
422         }
423
424         if (nandcs > GPMC_CS_NUM) {
425                 printk(KERN_INFO "NAND: Unable to find configuration "
426                                  "in GPMC\n ");
427                 return;
428         }
429
430         if (nandcs < GPMC_CS_NUM) {
431                 omap3beagle_nand_data.cs = nandcs;
432
433                 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
434                 if (gpmc_nand_init(&omap3beagle_nand_data) < 0)
435                         printk(KERN_ERR "Unable to register NAND device\n");
436         }
437 }
438
439 static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
440
441         .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
442         .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
443         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
444
445         .phy_reset  = true,
446         .reset_gpio_port[0]  = -EINVAL,
447         .reset_gpio_port[1]  = 147,
448         .reset_gpio_port[2]  = -EINVAL
449 };
450
451 #ifdef CONFIG_OMAP_MUX
452 static struct omap_board_mux board_mux[] __initdata = {
453         { .reg_offset = OMAP_MUX_TERMINATOR },
454 };
455 #else
456 #define board_mux       NULL
457 #endif
458
459 static struct omap_musb_board_data musb_board_data = {
460         .interface_type         = MUSB_INTERFACE_ULPI,
461         .mode                   = MUSB_OTG,
462         .power                  = 100,
463 };
464
465 static void __init omap3_beagle_init(void)
466 {
467         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
468         omap3_beagle_i2c_init();
469         platform_add_devices(omap3_beagle_devices,
470                         ARRAY_SIZE(omap3_beagle_devices));
471         omap_serial_init();
472
473         omap_mux_init_gpio(170, OMAP_PIN_INPUT);
474         gpio_request(170, "DVI_nPD");
475         /* REVISIT leave DVI powered down until it's needed ... */
476         gpio_direction_output(170, true);
477
478         usb_musb_init(&musb_board_data);
479         usb_ehci_init(&ehci_pdata);
480         omap3beagle_flash_init();
481
482         /* Ensure SDRC pins are mux'd for self-refresh */
483         omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
484         omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
485
486         beagle_display_init();
487 }
488
489 MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
490         /* Maintainer: Syed Mohammed Khasim - http://beagleboard.org */
491         .phys_io        = 0x48000000,
492         .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
493         .boot_params    = 0x80000100,
494         .map_io         = omap3_map_io,
495         .reserve        = omap_reserve,
496         .init_irq       = omap3_beagle_init_irq,
497         .init_machine   = omap3_beagle_init,
498         .timer          = &omap_timer,
499 MACHINE_END