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