HACK: OMAP3: beagle: switch to GPTIMER1
[beagleboard-validation:linux.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/irq.h>
25 #include <linux/input.h>
26 #include <linux/gpio_keys.h>
27 #include <linux/opp.h>
28
29 #include <linux/mtd/mtd.h>
30 #include <linux/mtd/partitions.h>
31 #include <linux/mtd/nand.h>
32 #include <linux/mmc/host.h>
33
34 #include <linux/regulator/machine.h>
35 #include <linux/i2c/twl.h>
36
37 #include <mach/hardware.h>
38 #include <asm/mach-types.h>
39 #include <asm/mach/arch.h>
40 #include <asm/mach/map.h>
41 #include <asm/mach/flash.h>
42
43 #include <plat/board.h>
44 #include <plat/common.h>
45 #include <video/omapdss.h>
46 #include <video/omap-panel-generic-dpi.h>
47 #include <plat/gpmc.h>
48 #include <plat/nand.h>
49 #include <plat/usb.h>
50 #include <plat/omap_device.h>
51
52 #include "mux.h"
53 #include "hsmmc.h"
54 #include "pm.h"
55 #include "common-board-devices.h"
56
57 /*
58  * OMAP3 Beagle revision
59  * Run time detection of Beagle revision is done by reading GPIO.
60  * GPIO ID -
61  *      AXBX    = GPIO173, GPIO172, GPIO171: 1 1 1
62  *      C1_3    = GPIO173, GPIO172, GPIO171: 1 1 0
63  *      C4      = GPIO173, GPIO172, GPIO171: 1 0 1
64  *      XMA/XMB = GPIO173, GPIO172, GPIO171: 0 0 0
65  *      XMC = GPIO173, GPIO172, GPIO171: 0 1 0
66  */
67 enum {
68         OMAP3BEAGLE_BOARD_UNKN = 0,
69         OMAP3BEAGLE_BOARD_AXBX,
70         OMAP3BEAGLE_BOARD_C1_3,
71         OMAP3BEAGLE_BOARD_C4,
72         OMAP3BEAGLE_BOARD_XM,
73         OMAP3BEAGLE_BOARD_XMC,
74 };
75
76 static u8 omap3_beagle_version;
77
78 /*
79  * Board-specific configuration
80  * Defaults to BeagleBoard-xMC
81  */
82 static struct {
83         int mmc1_gpio_wp;
84         int usb_pwr_level;
85         int reset_gpio;
86         int usr_button_gpio;
87 } beagle_config = {
88         .mmc1_gpio_wp = -EINVAL,
89         .usb_pwr_level = GPIOF_OUT_INIT_LOW,
90         .reset_gpio = 129,
91         .usr_button_gpio = 4,
92 };
93
94 static struct gpio omap3_beagle_rev_gpios[] __initdata = {
95         { 171, GPIOF_IN, "rev_id_0"    },
96         { 172, GPIOF_IN, "rev_id_1" },
97         { 173, GPIOF_IN, "rev_id_2"    },
98 };
99
100 static void __init omap3_beagle_init_rev(void)
101 {
102         int ret;
103         u16 beagle_rev = 0;
104
105         omap_mux_init_gpio(171, OMAP_PIN_INPUT_PULLUP);
106         omap_mux_init_gpio(172, OMAP_PIN_INPUT_PULLUP);
107         omap_mux_init_gpio(173, OMAP_PIN_INPUT_PULLUP);
108
109         ret = gpio_request_array(omap3_beagle_rev_gpios,
110                                  ARRAY_SIZE(omap3_beagle_rev_gpios));
111         if (ret < 0) {
112                 printk(KERN_ERR "Unable to get revision detection GPIO pins\n");
113                 omap3_beagle_version = OMAP3BEAGLE_BOARD_UNKN;
114                 return;
115         }
116
117         beagle_rev = gpio_get_value(171) | (gpio_get_value(172) << 1)
118                         | (gpio_get_value(173) << 2);
119
120         gpio_free_array(omap3_beagle_rev_gpios,
121                         ARRAY_SIZE(omap3_beagle_rev_gpios));
122
123         switch (beagle_rev) {
124         case 7:
125                 printk(KERN_INFO "OMAP3 Beagle Rev: Ax/Bx\n");
126                 omap3_beagle_version = OMAP3BEAGLE_BOARD_AXBX;
127                 beagle_config.mmc1_gpio_wp = 29;
128                 beagle_config.reset_gpio = 170;
129                 beagle_config.usr_button_gpio = 7;
130                 break;
131         case 6:
132                 printk(KERN_INFO "OMAP3 Beagle Rev: C1/C2/C3\n");
133                 omap3_beagle_version = OMAP3BEAGLE_BOARD_C1_3;
134                 beagle_config.mmc1_gpio_wp = 23;
135                 beagle_config.reset_gpio = 170;
136                 beagle_config.usr_button_gpio = 7;
137                 break;
138         case 5:
139                 printk(KERN_INFO "OMAP3 Beagle Rev: C4\n");
140                 omap3_beagle_version = OMAP3BEAGLE_BOARD_C4;
141                 beagle_config.mmc1_gpio_wp = 23;
142                 beagle_config.reset_gpio = 170;
143                 beagle_config.usr_button_gpio = 7;
144                 break;
145         case 0:
146                 printk(KERN_INFO "OMAP3 Beagle Rev: xM Ax/Bx\n");
147                 omap3_beagle_version = OMAP3BEAGLE_BOARD_XM;
148                 beagle_config.usb_pwr_level = GPIOF_OUT_INIT_HIGH;
149                 break;
150         case 2:
151                 printk(KERN_INFO "OMAP3 Beagle Rev: xM C\n");
152                 omap3_beagle_version = OMAP3BEAGLE_BOARD_XMC;
153                 break;
154         default:
155                 printk(KERN_INFO "OMAP3 Beagle Rev: unknown %hd\n", beagle_rev);
156                 omap3_beagle_version = OMAP3BEAGLE_BOARD_UNKN;
157         }
158 }
159
160 char expansionboard_name[16];
161
162 #if defined(CONFIG_WL12XX) || defined(CONFIG_WL12XX_MODULE)
163 #include <linux/regulator/fixed.h>
164 #include <linux/wl12xx.h>
165
166 #define OMAP_BEAGLE_WLAN_EN_GPIO    (139)
167 #define OMAP_BEAGLE_BT_EN_GPIO      (138)
168 #define OMAP_BEAGLE_WLAN_IRQ_GPIO   (137)
169 #define OMAP_BEAGLE_FM_EN_BT_WU     (136)
170
171 struct wl12xx_platform_data omap_beagle_wlan_data __initdata = {
172         .irq = OMAP_GPIO_IRQ(OMAP_BEAGLE_WLAN_IRQ_GPIO),
173         .board_ref_clock = 2, /* 38.4 MHz */
174 };
175
176 static int gpios[] = {OMAP_BEAGLE_BT_EN_GPIO, OMAP_BEAGLE_FM_EN_BT_WU, -1};
177 static struct platform_device wl12xx_device = {
178                 .name           = "kim",
179                 .id                     = -1,
180                 .dev.platform_data = &gpios,
181 };
182
183 static struct omap2_hsmmc_info mmcbbt[] = {
184         {
185                 .mmc            = 1,
186                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
187                 .gpio_wp        = 29,
188         },
189         {
190                 .name           = "wl1271",
191                 .mmc            = 2,
192                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_POWER_OFF_CARD,
193                 .gpio_wp        = -EINVAL,
194                 .gpio_cd        = -EINVAL,
195                 .ocr_mask       = MMC_VDD_165_195,
196                 .nonremovable   = true,
197         },
198         {}      /* Terminator */
199  };
200
201 static struct regulator_consumer_supply beagle_vmmc2_supply = 
202         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.1");
203
204 static struct regulator_init_data beagle_vmmc2 = {
205         .constraints = {
206                 .min_uV                 = 1850000,
207                 .max_uV                 = 1850000,
208                 .apply_uV               = true,
209                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
210                                         | REGULATOR_MODE_STANDBY,
211                 .valid_ops_mask         = REGULATOR_CHANGE_MODE
212                                         | REGULATOR_CHANGE_STATUS,
213         },
214         .num_consumer_supplies = 1,
215         .consumer_supplies = &beagle_vmmc2_supply,
216 };
217
218 static struct fixed_voltage_config beagle_vwlan = {
219         .supply_name = "vwl1271",
220         .microvolts = 1800000,  /* 1.8V */
221         .gpio = OMAP_BEAGLE_WLAN_EN_GPIO,
222         .startup_delay = 70000, /* 70ms */
223         .enable_high = 1,
224         .enabled_at_boot = 0,
225         .init_data = &beagle_vmmc2,
226 };
227
228 static struct platform_device omap_vwlan_device = {
229         .name           = "reg-fixed-voltage",
230         .id             = 1,
231         .dev = {
232                 .platform_data = &beagle_vwlan,
233         },
234 };
235 #endif
236
237 #if defined(CONFIG_ENC28J60) || defined(CONFIG_ENC28J60_MODULE)
238
239 #include <plat/mcspi.h>
240 #include <linux/spi/spi.h>
241
242 #define OMAP3BEAGLE_GPIO_ENC28J60_IRQ 157
243
244 static struct omap2_mcspi_device_config enc28j60_spi_chip_info = {
245         .turbo_mode     = 0,
246         .single_channel = 1,    /* 0: slave, 1: master */
247 };
248
249 static struct spi_board_info omap3beagle_zippy_spi_board_info[] __initdata = {
250         {
251                 .modalias               = "enc28j60",
252                 .bus_num                = 4,
253                 .chip_select            = 0,
254                 .max_speed_hz           = 20000000,
255                 .controller_data        = &enc28j60_spi_chip_info,
256         },
257 };
258
259 static void __init omap3beagle_enc28j60_init(void)
260 {
261         if ((gpio_request(OMAP3BEAGLE_GPIO_ENC28J60_IRQ, "ENC28J60_IRQ") == 0) &&
262             (gpio_direction_input(OMAP3BEAGLE_GPIO_ENC28J60_IRQ) == 0)) {
263                 gpio_export(OMAP3BEAGLE_GPIO_ENC28J60_IRQ, 0);
264                 omap3beagle_zippy_spi_board_info[0].irq = OMAP_GPIO_IRQ(OMAP3BEAGLE_GPIO_ENC28J60_IRQ);
265                 irq_set_irq_type(omap3beagle_zippy_spi_board_info[0].irq, IRQ_TYPE_EDGE_FALLING);
266         } else {
267                 printk(KERN_ERR "could not obtain gpio for ENC28J60_IRQ\n");
268                 return;
269         }
270
271         spi_register_board_info(omap3beagle_zippy_spi_board_info,
272                         ARRAY_SIZE(omap3beagle_zippy_spi_board_info));
273 }
274
275 #else
276 static inline void __init omap3beagle_enc28j60_init(void) { return; }
277 #endif
278
279 #if defined(CONFIG_KS8851) || defined(CONFIG_KS8851_MODULE)
280
281 #include <plat/mcspi.h>
282 #include <linux/spi/spi.h>
283
284 #define OMAP3BEAGLE_GPIO_KS8851_IRQ 157
285
286 static struct omap2_mcspi_device_config ks8851_spi_chip_info = {
287         .turbo_mode     = 0,
288         .single_channel = 1,    /* 0: slave, 1: master */
289 };
290
291 static struct spi_board_info omap3beagle_zippy2_spi_board_info[] __initdata = {
292         {
293                 .modalias               = "ks8851",
294                 .bus_num                = 4,
295                 .chip_select            = 0,
296                 .max_speed_hz           = 36000000,
297                 .controller_data        = &ks8851_spi_chip_info,
298         },
299 };
300
301 static void __init omap3beagle_ks8851_init(void)
302 {
303         if ((gpio_request(OMAP3BEAGLE_GPIO_KS8851_IRQ, "KS8851_IRQ") == 0) &&
304             (gpio_direction_input(OMAP3BEAGLE_GPIO_KS8851_IRQ) == 0)) {
305                 gpio_export(OMAP3BEAGLE_GPIO_KS8851_IRQ, 0);
306                 omap3beagle_zippy2_spi_board_info[0].irq        = OMAP_GPIO_IRQ(OMAP3BEAGLE_GPIO_KS8851_IRQ);
307                 irq_set_irq_type(omap3beagle_zippy2_spi_board_info[0].irq, IRQ_TYPE_EDGE_FALLING);
308         } else {
309                 printk(KERN_ERR "could not obtain gpio for KS8851_IRQ\n");
310                 return;
311         }
312         
313         spi_register_board_info(omap3beagle_zippy2_spi_board_info,
314                                                         ARRAY_SIZE(omap3beagle_zippy2_spi_board_info));
315 }
316
317 #else
318 static inline void __init omap3beagle_ks8851_init(void) { return; }
319 #endif
320
321 static struct mtd_partition omap3beagle_nand_partitions[] = {
322         /* All the partition sizes are listed in terms of NAND block size */
323         {
324                 .name           = "X-Loader",
325                 .offset         = 0,
326                 .size           = 4 * NAND_BLOCK_SIZE,
327                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
328         },
329         {
330                 .name           = "U-Boot",
331                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
332                 .size           = 15 * NAND_BLOCK_SIZE,
333                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
334         },
335         {
336                 .name           = "U-Boot Env",
337                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x260000 */
338                 .size           = 1 * NAND_BLOCK_SIZE,
339         },
340         {
341                 .name           = "Kernel",
342                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
343                 .size           = 32 * NAND_BLOCK_SIZE,
344         },
345         {
346                 .name           = "File System",
347                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
348                 .size           = MTDPART_SIZ_FULL,
349         },
350 };
351
352 /* DSS */
353
354 static int beagle_enable_dvi(struct omap_dss_device *dssdev)
355 {
356         if (gpio_is_valid(dssdev->reset_gpio))
357                 gpio_set_value(dssdev->reset_gpio, 1);
358
359         return 0;
360 }
361
362 static void beagle_disable_dvi(struct omap_dss_device *dssdev)
363 {
364         if (gpio_is_valid(dssdev->reset_gpio))
365                 gpio_set_value(dssdev->reset_gpio, 0);
366 }
367
368 static struct panel_generic_dpi_data dvi_panel = {
369         .name = "generic",
370         .platform_enable = beagle_enable_dvi,
371         .platform_disable = beagle_disable_dvi,
372 };
373
374 static struct omap_dss_device beagle_dvi_device = {
375         .type = OMAP_DISPLAY_TYPE_DPI,
376         .name = "dvi",
377         .driver_name = "generic_dpi_panel",
378         .data = &dvi_panel,
379         .phy.dpi.data_lines = 24,
380         .reset_gpio = -EINVAL,
381 };
382
383 static struct omap_dss_device beagle_tv_device = {
384         .name = "tv",
385         .driver_name = "venc",
386         .type = OMAP_DISPLAY_TYPE_VENC,
387         .phy.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
388 };
389
390 static struct omap_dss_device *beagle_dss_devices[] = {
391         &beagle_dvi_device,
392         &beagle_tv_device,
393 };
394
395 static struct omap_dss_board_info beagle_dss_data = {
396         .num_devices = ARRAY_SIZE(beagle_dss_devices),
397         .devices = beagle_dss_devices,
398         .default_device = &beagle_dvi_device,
399 };
400
401 static void __init beagle_display_init(void)
402 {
403         int r;
404
405         r = gpio_request_one(beagle_dvi_device.reset_gpio, GPIOF_OUT_INIT_LOW,
406                              "DVI reset");
407         if (r < 0)
408                 printk(KERN_ERR "Unable to get DVI reset GPIO\n");
409 }
410
411 #include "sdram-micron-mt46h32m32lf-6.h"
412
413 static struct omap2_hsmmc_info mmc[] = {
414         {
415                 .mmc            = 1,
416                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
417                 .gpio_wp        = -EINVAL,
418         },
419         {
420                 .mmc            = 2,
421                 .caps       = MMC_CAP_4_BIT_DATA,
422                 .transceiver    = true,
423                 .ocr_mask       = 0x00100000,   /* 3.3V */
424         },
425         {}      /* Terminator */
426 };
427
428 static struct regulator_consumer_supply beagle_vmmc1_supply[] = {
429         REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
430 };
431
432 static struct regulator_consumer_supply beagle_vsim_supply[] = {
433         REGULATOR_SUPPLY("vmmc_aux", "omap_hsmmc.0"),
434 };
435
436 static struct gpio_led gpio_leds[];
437
438 static int beagle_twl_gpio_setup(struct device *dev,
439                 unsigned gpio, unsigned ngpio)
440 {
441         int r;
442
443         if (beagle_config.mmc1_gpio_wp != -EINVAL)
444                 omap_mux_init_gpio(beagle_config.mmc1_gpio_wp, OMAP_PIN_INPUT);
445         mmc[0].gpio_wp = beagle_config.mmc1_gpio_wp;
446         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
447         mmc[0].gpio_cd = gpio + 0;
448 #if defined(CONFIG_WL12XX) || defined(CONFIG_WL12XX_MODULE)
449         if(!strcmp(expansionboard_name, "bbtoys-wifi")) { 
450                 omap2_hsmmc_init(mmcbbt);
451         } else {
452                 omap2_hsmmc_init(mmc);
453         }
454 #else
455         omap2_hsmmc_init(mmc);
456 #endif
457
458         /*
459          * TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, XM active
460          * high / others active low)
461          * DVI reset GPIO is different between beagle revisions
462          */
463         /* Valid for all -xM revisions */
464         if (cpu_is_omap3630()) {
465                 /*
466                  * gpio + 1 on Xm controls the TFP410's enable line (active low)
467                  * gpio + 2 control varies depending on the board rev as below:
468                  * P7/P8 revisions(prototype): Camera EN
469                  * A2+ revisions (production): LDO (DVI, serial, led blocks)
470                  */
471                 r = gpio_request_one(gpio + 1, GPIOF_OUT_INIT_LOW,
472                                      "nDVI_PWR_EN");
473                 if (r)
474                         pr_err("%s: unable to configure nDVI_PWR_EN\n",
475                                 __func__);
476                 r = gpio_request_one(gpio + 2, GPIOF_OUT_INIT_HIGH,
477                                      "DVI_LDO_EN");
478                 if (r)
479                         pr_err("%s: unable to configure DVI_LDO_EN\n",
480                                 __func__);
481         } else {
482                 /*
483                  * REVISIT: need ehci-omap hooks for external VBUS
484                  * power switch and overcurrent detect
485                  */
486                 if (gpio_request_one(gpio + 1, GPIOF_IN, "EHCI_nOC"))
487                         pr_err("%s: unable to configure EHCI_nOC\n", __func__);
488         }
489         beagle_dvi_device.reset_gpio = beagle_config.reset_gpio;
490
491         gpio_request_one(gpio + TWL4030_GPIO_MAX, beagle_config.usb_pwr_level,
492                         "nEN_USB_PWR");
493
494         /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
495         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
496
497         return 0;
498 }
499
500 static struct twl4030_gpio_platform_data beagle_gpio_data = {
501         .gpio_base      = OMAP_MAX_GPIO_LINES,
502         .irq_base       = TWL4030_GPIO_IRQ_BASE,
503         .irq_end        = TWL4030_GPIO_IRQ_END,
504         .use_leds       = true,
505         .pullups        = BIT(1),
506         .pulldowns      = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
507                                 | BIT(15) | BIT(16) | BIT(17),
508         .setup          = beagle_twl_gpio_setup,
509 };
510
511 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
512 static struct regulator_init_data beagle_vmmc1 = {
513         .constraints = {
514                 .min_uV                 = 1850000,
515                 .max_uV                 = 3150000,
516                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
517                                         | REGULATOR_MODE_STANDBY,
518                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
519                                         | REGULATOR_CHANGE_MODE
520                                         | REGULATOR_CHANGE_STATUS,
521         },
522         .num_consumer_supplies  = ARRAY_SIZE(beagle_vmmc1_supply),
523         .consumer_supplies      = beagle_vmmc1_supply,
524 };
525
526 /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
527 static struct regulator_init_data beagle_vsim = {
528         .constraints = {
529                 .min_uV                 = 1800000,
530                 .max_uV                 = 3000000,
531                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
532                                         | REGULATOR_MODE_STANDBY,
533                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
534                                         | REGULATOR_CHANGE_MODE
535                                         | REGULATOR_CHANGE_STATUS,
536         },
537         .num_consumer_supplies  = ARRAY_SIZE(beagle_vsim_supply),
538         .consumer_supplies      = beagle_vsim_supply,
539 };
540
541 static struct twl4030_platform_data beagle_twldata = {
542         /* platform_data for children goes here */
543         .gpio           = &beagle_gpio_data,
544         .vmmc1          = &beagle_vmmc1,
545         .vsim           = &beagle_vsim,
546 };
547
548 static struct i2c_board_info __initdata beagle_i2c_eeprom[] = {
549        {
550                I2C_BOARD_INFO("eeprom", 0x50),
551        },
552 };
553
554 #if defined(CONFIG_RTC_DRV_DS1307) || \
555         defined(CONFIG_RTC_DRV_DS1307_MODULE)
556
557 static struct i2c_board_info __initdata beagle_i2c2_zippy[] = {
558         {
559                 I2C_BOARD_INFO("eeprom", 0x50),
560                 I2C_BOARD_INFO("ds1307", 0x68),
561         },
562 };
563 #else
564 static struct i2c_board_info __initdata beagle_i2c2_zippy[] = {};
565 #endif
566
567 static int __init omap3_beagle_i2c_init(void)
568 {
569         omap3_pmic_get_config(&beagle_twldata,
570                         TWL_COMMON_PDATA_USB | TWL_COMMON_PDATA_AUDIO,
571                         TWL_COMMON_REGULATOR_VDAC | TWL_COMMON_REGULATOR_VPLL2);
572
573         beagle_twldata.vpll2->constraints.name = "VDVI";
574
575         omap3_pmic_init("twl4030", &beagle_twldata);
576         /* Bus 3 is attached to the DVI port where devices like the pico DLP
577          * projector don't work reliably with 400kHz */
578         omap_register_i2c_bus(3, 100, beagle_i2c_eeprom, ARRAY_SIZE(beagle_i2c_eeprom));
579         return 0;
580 }
581
582 static struct gpio_led gpio_leds[] = {
583         {
584                 .name                   = "beagleboard::usr0",
585                 .default_trigger        = "heartbeat",
586                 .gpio                   = 150,
587         },
588         {
589                 .name                   = "beagleboard::usr1",
590                 .default_trigger        = "mmc0",
591                 .gpio                   = 149,
592         },
593         {
594                 .name                   = "beagleboard::pmu_stat",
595                 .gpio                   = -EINVAL,      /* gets replaced */
596                 .active_low             = true,
597         },
598 };
599
600 static struct gpio_led_platform_data gpio_led_info = {
601         .leds           = gpio_leds,
602         .num_leds       = ARRAY_SIZE(gpio_leds),
603 };
604
605 static struct platform_device leds_gpio = {
606         .name   = "leds-gpio",
607         .id     = -1,
608         .dev    = {
609                 .platform_data  = &gpio_led_info,
610         },
611 };
612
613 static struct gpio_keys_button gpio_buttons[] = {
614         {
615                 .code                   = BTN_EXTRA,
616                 /* Dynamically assigned depending on board */
617                 .gpio                   = -EINVAL,
618                 .desc                   = "user",
619                 .wakeup                 = 1,
620         },
621 };
622
623 static struct gpio_keys_platform_data gpio_key_info = {
624         .buttons        = gpio_buttons,
625         .nbuttons       = ARRAY_SIZE(gpio_buttons),
626 };
627
628 static struct platform_device keys_gpio = {
629         .name   = "gpio-keys",
630         .id     = -1,
631         .dev    = {
632                 .platform_data  = &gpio_key_info,
633         },
634 };
635
636 static void __init omap3_beagle_init_early(void)
637 {
638         omap2_init_common_infrastructure();
639         omap2_init_common_devices(mt46h32m32lf6_sdrc_params,
640                                   mt46h32m32lf6_sdrc_params);
641 }
642
643 static void __init omap3_beagle_init_irq(void)
644 {
645         omap3_init_irq();
646 }
647
648 static struct platform_device *omap3_beagle_devices[] __initdata = {
649         &leds_gpio,
650         &keys_gpio,
651 };
652
653 static const struct usbhs_omap_board_data usbhs_bdata __initconst = {
654
655         .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
656         .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
657         .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
658
659         .phy_reset  = true,
660         .reset_gpio_port[0]  = -EINVAL,
661         .reset_gpio_port[1]  = 147,
662         .reset_gpio_port[2]  = -EINVAL
663 };
664
665 #ifdef CONFIG_OMAP_MUX
666 static struct omap_board_mux board_mux[] __initdata = {
667         { .reg_offset = OMAP_MUX_TERMINATOR },
668 };
669 #endif
670
671 static int __init expansionboard_setup(char *str)
672 {
673         if (!str)
674                 return -EINVAL;
675         strncpy(expansionboard_name, str, 16);
676         printk(KERN_INFO "Beagle expansionboard: %s\n", expansionboard_name);
677         return 0;
678 }
679
680 static void __init beagle_opp_init(void)
681 {
682         int r = 0;
683
684         /* Initialize the omap3 opp table */
685         if (omap3_opp_init()) {
686                 pr_err("%s: opp default init failed\n", __func__);
687                 return;
688         }
689
690         /* Custom OPP enabled for all xM versions */
691         if (cpu_is_omap3630()) {
692                 struct omap_hwmod *mh = omap_hwmod_lookup("mpu");
693                 struct omap_hwmod *dh = omap_hwmod_lookup("iva");
694                 struct device *dev;
695
696                 if (!mh || !dh) {
697                         pr_err("%s: Aiee.. no mpu/dsp devices? %p %p\n",
698                                 __func__, mh, dh);
699                         return;
700                 }
701                 /* Enable MPU 1GHz and lower opps */
702                 dev = &mh->od->pdev.dev;
703                 r = opp_enable(dev, 800000000);
704                 /* TODO: MPU 1GHz needs SR and ABB */
705
706                 /* Enable IVA 800MHz and lower opps */
707                 dev = &dh->od->pdev.dev;
708                 r |= opp_enable(dev, 660000000);
709                 /* TODO: DSP 800MHz needs SR and ABB */
710                 if (r) {
711                         pr_err("%s: failed to enable higher opp %d\n",
712                                 __func__, r);
713                         /*
714                          * Cleanup - disable the higher freqs - we dont care
715                          * about the results
716                          */
717                         dev = &mh->od->pdev.dev;
718                         opp_disable(dev, 800000000);
719                         dev = &dh->od->pdev.dev;
720                         opp_disable(dev, 660000000);
721                 }
722         }
723         return;
724 }
725
726 static void __init omap3_beagle_init(void)
727 {
728         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
729         omap3_beagle_init_rev();
730         omap3_beagle_i2c_init();
731
732         gpio_buttons[0].gpio = beagle_config.usr_button_gpio;
733
734         platform_add_devices(omap3_beagle_devices,
735                         ARRAY_SIZE(omap3_beagle_devices));
736         omap_display_init(&beagle_dss_data);
737         omap_serial_init();
738
739         omap_mux_init_gpio(170, OMAP_PIN_INPUT);
740         /* REVISIT leave DVI powered down until it's needed ... */
741         gpio_request_one(170, GPIOF_OUT_INIT_HIGH, "DVI_nPD");
742
743         if(!strcmp(expansionboard_name, "zippy")) 
744         {
745                 printk(KERN_INFO "Beagle expansionboard: initializing enc28j60\n");
746                 omap3beagle_enc28j60_init();
747                 printk(KERN_INFO "Beagle expansionboard: assigning GPIO 141 and 162 to MMC1\n");
748                 mmc[1].gpio_wp = 141;
749                 mmc[1].gpio_cd = 162;
750                 printk(KERN_INFO "Beagle expansionboard: registering I2C2 for zippy board\n");
751                 omap_register_i2c_bus(2, 400,  beagle_i2c2_zippy,
752                                                         ARRAY_SIZE(beagle_i2c2_zippy));
753
754         }
755         
756         if(!strcmp(expansionboard_name, "zippy2")) 
757         {
758                 printk(KERN_INFO "Beagle expansionboard: initializing ks_8851\n");
759                 omap3beagle_ks8851_init();
760                 printk(KERN_INFO "Beagle expansionboard: assigning GPIO 141 and 162 to MMC1\n");
761                 mmc[1].gpio_wp = 141;
762                 mmc[1].gpio_cd = 162;
763                 printk(KERN_INFO "Beagle expansionboard: registering I2C2 for zippy2 board\n");
764                 omap_register_i2c_bus(2, 400,  beagle_i2c2_zippy,
765                                                         ARRAY_SIZE(beagle_i2c2_zippy));         
766         }
767
768         if(!strcmp(expansionboard_name, "trainer"))
769         {
770                 printk(KERN_INFO "Beagle expansionboard: exporting GPIOs 130-141,162 to userspace\n");
771                 gpio_request(130, "sysfs");
772                 gpio_export(130, 1);
773                 gpio_request(131, "sysfs");
774                 gpio_export(131, 1);
775                 gpio_request(132, "sysfs");
776                 gpio_export(132, 1);
777                 gpio_request(133, "sysfs");
778                 gpio_export(133, 1);
779                 gpio_request(134, "sysfs");
780                 gpio_export(134, 1);
781                 gpio_request(135, "sysfs");
782                 gpio_export(135, 1);
783                 gpio_request(136, "sysfs");
784                 gpio_export(136, 1);
785                 gpio_request(137, "sysfs");
786                 gpio_export(137, 1);
787                 gpio_request(138, "sysfs");
788                 gpio_export(138, 1);
789                 gpio_request(139, "sysfs");
790                 gpio_export(139, 1);
791                 gpio_request(140, "sysfs");
792                 gpio_export(140, 1);
793                 gpio_request(141, "sysfs");
794                 gpio_export(141, 1);
795                 gpio_request(162, "sysfs");
796                 gpio_export(162, 1);
797         }
798
799         if(!strcmp(expansionboard_name, "bbtoys-wifi"))
800         {
801                 if (wl12xx_set_platform_data(&omap_beagle_wlan_data))
802                         pr_err("error setting wl12xx data\n");
803                 printk(KERN_INFO "Beagle expansionboard: registering wl12xx bt platform device\n");
804                 platform_device_register(&wl12xx_device);
805                 printk(KERN_INFO "Beagle expansionboard: registering wl12xx wifi platform device\n");
806                 platform_device_register(&omap_vwlan_device);
807         }
808
809         usb_musb_init(NULL);
810         usbhs_init(&usbhs_bdata);
811         omap_nand_flash_init(NAND_BUSWIDTH_16, omap3beagle_nand_partitions,
812                              ARRAY_SIZE(omap3beagle_nand_partitions));
813
814         /* Ensure msecure is mux'd to be able to set the RTC. */
815         omap_mux_init_signal("sys_drm_msecure", OMAP_PIN_OFF_OUTPUT_HIGH);
816
817         /* Ensure SDRC pins are mux'd for self-refresh */
818         omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
819         omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
820
821         beagle_display_init();
822         beagle_opp_init();
823 }
824
825 early_param("buddy", expansionboard_setup);
826
827 MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
828         /* Maintainer: Syed Mohammed Khasim - http://beagleboard.org */
829         .boot_params    = 0x80000100,
830         .reserve        = omap_reserve,
831         .map_io         = omap3_map_io,
832         .init_early     = omap3_beagle_init_early,
833         .init_irq       = omap3_beagle_init_irq,
834         .init_machine   = omap3_beagle_init,
835         .timer          = &omap3_timer,
836 MACHINE_END