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 */
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 #include <linux/opp.h>
27 #include <linux/cpu.h>
29 #include <linux/mtd/mtd.h>
30 #include <linux/mtd/partitions.h>
31 #include <linux/mtd/nand.h>
32 #include <linux/mmc/host.h>
34 #include <linux/regulator/machine.h>
35 #include <linux/regulator/fixed.h>
36 #include <linux/i2c/twl.h>
37 #include <linux/usb/phy.h>
39 #include <asm/mach-types.h>
40 #include <asm/mach/arch.h>
41 #include <asm/mach/map.h>
42 #include <asm/mach/flash.h>
44 #include <video/omapdss.h>
45 #include <video/omap-panel-tfp410.h>
46 #include <linux/platform_data/mtd-nand-omap2.h>
48 #include "common.h"
49 #include "omap_device.h"
50 #include "gpmc.h"
51 #include "soc.h"
52 #include "mux.h"
53 #include "hsmmc.h"
54 #include "pm.h"
55 #include "board-flash.h"
56 #include "common-board-devices.h"
58 #define NAND_CS 0
60 /*
61 * OMAP3 Beagle revision
62 * Run time detection of Beagle revision is done by reading GPIO.
63 * GPIO ID -
64 * AXBX = GPIO173, GPIO172, GPIO171: 1 1 1
65 * C1_3 = GPIO173, GPIO172, GPIO171: 1 1 0
66 * C4 = GPIO173, GPIO172, GPIO171: 1 0 1
67 * XMA/XMB = GPIO173, GPIO172, GPIO171: 0 0 0
68 * XMC = GPIO173, GPIO172, GPIO171: 0 1 0
69 */
70 enum {
71 OMAP3BEAGLE_BOARD_UNKN = 0,
72 OMAP3BEAGLE_BOARD_AXBX,
73 OMAP3BEAGLE_BOARD_C1_3,
74 OMAP3BEAGLE_BOARD_C4,
75 OMAP3BEAGLE_BOARD_XM,
76 OMAP3BEAGLE_BOARD_XMC,
77 };
79 static u8 omap3_beagle_version;
81 /*
82 * Board-specific configuration
83 * Defaults to BeagleBoard-xMC
84 */
85 static struct {
86 int mmc1_gpio_wp;
87 bool usb_pwr_level; /* 0 - Active Low, 1 - Active High */
88 int dvi_pd_gpio;
89 int usr_button_gpio;
90 int mmc_caps;
91 } beagle_config = {
92 .mmc1_gpio_wp = -EINVAL,
93 .usb_pwr_level = 0,
94 .dvi_pd_gpio = -EINVAL,
95 .usr_button_gpio = 4,
96 .mmc_caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
97 };
99 static struct gpio omap3_beagle_rev_gpios[] __initdata = {
100 { 171, GPIOF_IN, "rev_id_0" },
101 { 172, GPIOF_IN, "rev_id_1" },
102 { 173, GPIOF_IN, "rev_id_2" },
103 };
105 static void __init omap3_beagle_init_rev(void)
106 {
107 int ret;
108 u16 beagle_rev = 0;
110 omap_mux_init_gpio(171, OMAP_PIN_INPUT_PULLUP);
111 omap_mux_init_gpio(172, OMAP_PIN_INPUT_PULLUP);
112 omap_mux_init_gpio(173, OMAP_PIN_INPUT_PULLUP);
114 ret = gpio_request_array(omap3_beagle_rev_gpios,
115 ARRAY_SIZE(omap3_beagle_rev_gpios));
116 if (ret < 0) {
117 printk(KERN_ERR "Unable to get revision detection GPIO pins\n");
118 omap3_beagle_version = OMAP3BEAGLE_BOARD_UNKN;
119 return;
120 }
122 beagle_rev = gpio_get_value(171) | (gpio_get_value(172) << 1)
123 | (gpio_get_value(173) << 2);
125 gpio_free_array(omap3_beagle_rev_gpios,
126 ARRAY_SIZE(omap3_beagle_rev_gpios));
128 switch (beagle_rev) {
129 case 7:
130 printk(KERN_INFO "OMAP3 Beagle Rev: Ax/Bx\n");
131 omap3_beagle_version = OMAP3BEAGLE_BOARD_AXBX;
132 beagle_config.mmc1_gpio_wp = 29;
133 beagle_config.dvi_pd_gpio = 170;
134 beagle_config.usr_button_gpio = 7;
135 break;
136 case 6:
137 printk(KERN_INFO "OMAP3 Beagle Rev: C1/C2/C3\n");
138 omap3_beagle_version = OMAP3BEAGLE_BOARD_C1_3;
139 beagle_config.mmc1_gpio_wp = 23;
140 beagle_config.dvi_pd_gpio = 170;
141 beagle_config.usr_button_gpio = 7;
142 break;
143 case 5:
144 printk(KERN_INFO "OMAP3 Beagle Rev: C4\n");
145 omap3_beagle_version = OMAP3BEAGLE_BOARD_C4;
146 beagle_config.mmc1_gpio_wp = 23;
147 beagle_config.dvi_pd_gpio = 170;
148 beagle_config.usr_button_gpio = 7;
149 break;
150 case 0:
151 printk(KERN_INFO "OMAP3 Beagle Rev: xM Ax/Bx\n");
152 omap3_beagle_version = OMAP3BEAGLE_BOARD_XM;
153 beagle_config.usb_pwr_level = 1;
154 beagle_config.mmc_caps &= ~MMC_CAP_8_BIT_DATA;
155 break;
156 case 2:
157 printk(KERN_INFO "OMAP3 Beagle Rev: xM C\n");
158 omap3_beagle_version = OMAP3BEAGLE_BOARD_XMC;
159 beagle_config.mmc_caps &= ~MMC_CAP_8_BIT_DATA;
160 break;
161 default:
162 printk(KERN_INFO "OMAP3 Beagle Rev: unknown %hd\n", beagle_rev);
163 omap3_beagle_version = OMAP3BEAGLE_BOARD_UNKN;
164 }
165 }
167 static struct mtd_partition omap3beagle_nand_partitions[] = {
168 /* All the partition sizes are listed in terms of NAND block size */
169 {
170 .name = "X-Loader",
171 .offset = 0,
172 .size = 4 * NAND_BLOCK_SIZE,
173 .mask_flags = MTD_WRITEABLE, /* force read-only */
174 },
175 {
176 .name = "U-Boot",
177 .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
178 .size = 15 * NAND_BLOCK_SIZE,
179 .mask_flags = MTD_WRITEABLE, /* force read-only */
180 },
181 {
182 .name = "U-Boot Env",
183 .offset = MTDPART_OFS_APPEND, /* Offset = 0x260000 */
184 .size = 1 * NAND_BLOCK_SIZE,
185 },
186 {
187 .name = "Kernel",
188 .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
189 .size = 32 * NAND_BLOCK_SIZE,
190 },
191 {
192 .name = "File System",
193 .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
194 .size = MTDPART_SIZ_FULL,
195 },
196 };
198 /* DSS */
200 static struct tfp410_platform_data dvi_panel = {
201 .i2c_bus_num = 3,
202 .power_down_gpio = -1,
203 };
205 static struct omap_dss_device beagle_dvi_device = {
206 .type = OMAP_DISPLAY_TYPE_DPI,
207 .name = "dvi",
208 .driver_name = "tfp410",
209 .data = &dvi_panel,
210 .phy.dpi.data_lines = 24,
211 };
213 static struct omap_dss_device beagle_tv_device = {
214 .name = "tv",
215 .driver_name = "venc",
216 .type = OMAP_DISPLAY_TYPE_VENC,
217 .phy.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
218 };
220 static struct omap_dss_device *beagle_dss_devices[] = {
221 &beagle_dvi_device,
222 &beagle_tv_device,
223 };
225 static struct omap_dss_board_info beagle_dss_data = {
226 .num_devices = ARRAY_SIZE(beagle_dss_devices),
227 .devices = beagle_dss_devices,
228 .default_device = &beagle_dvi_device,
229 };
231 #include "sdram-micron-mt46h32m32lf-6.h"
233 static struct omap2_hsmmc_info mmc[] = {
234 {
235 .mmc = 1,
236 .caps = MMC_CAP_4_BIT_DATA,
237 .gpio_wp = -EINVAL,
238 .deferred = true,
239 },
240 {} /* Terminator */
241 };
243 static struct regulator_consumer_supply beagle_vmmc1_supply[] = {
244 REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
245 };
247 static struct regulator_consumer_supply beagle_vsim_supply[] = {
248 REGULATOR_SUPPLY("vmmc_aux", "omap_hsmmc.0"),
249 };
251 static struct gpio_led gpio_leds[];
253 /* PHY device on HS USB Port 2 i.e. nop_usb_xceiv.2 */
254 static struct platform_device hsusb2_phy_device = {
255 .name = "nop_usb_xceiv",
256 .id = 2,
257 };
259 /* Regulator for HS USB Port 2 PHY reset */
260 static struct regulator_consumer_supply hsusb2_reset_supplies[] = {
261 /* Link PHY device to reset supply so it gets used in the PHY driver */
262 REGULATOR_SUPPLY("reset", "nop_usb_xceiv.2"),
263 };
265 static struct regulator_init_data hsusb2_reset_data = {
266 .constraints = {
267 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
268 },
269 .consumer_supplies = hsusb2_reset_supplies,
270 .num_consumer_supplies = ARRAY_SIZE(hsusb2_reset_supplies),
271 };
273 static struct fixed_voltage_config hsusb2_reset_config = {
274 .supply_name = "hsusb2_reset",
275 .microvolts = 3300000,
276 .gpio = 147,
277 .startup_delay = 70000, /* 70msec */
278 .enable_high = 1,
279 .enabled_at_boot = 0, /* keep in RESET */
280 .init_data = &hsusb2_reset_data,
281 };
283 static struct platform_device hsusb2_reset_device = {
284 .name = "reg-fixed-voltage",
285 .id = PLATFORM_DEVID_AUTO,
286 .dev = {
287 .platform_data = &hsusb2_reset_config,
288 },
289 };
291 /* Regulator for HS USB Port 2 supply */
292 static struct regulator_consumer_supply hsusb2_power_supplies[] = {
293 /* Link PHY device to power supply so it gets enabled in the PHY driver */
294 REGULATOR_SUPPLY("vcc", "nop_usb_xceiv.2"),
295 };
297 static struct regulator_init_data hsusb2_power_data = {
298 .constraints = {
299 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
300 },
301 .consumer_supplies = hsusb2_power_supplies,
302 .num_consumer_supplies = ARRAY_SIZE(hsusb2_power_supplies),
303 };
305 static struct fixed_voltage_config hsusb2_power_config = {
306 .supply_name = "hsusb2_vbus",
307 .microvolts = 5000000,
308 .gpio = -1, /* set at runtime in beagle_twl_gpio_setup */
309 .startup_delay = 70000, /* 70msec */
310 .enable_high = 0, /* updated in omap3_beagle_init_rev() */
311 .enabled_at_boot = 0,
312 .init_data = &hsusb2_power_data,
313 };
315 static struct platform_device hsusb2_power_device = {
316 .name = "reg-fixed-voltage",
317 .id = PLATFORM_DEVID_AUTO,
318 .dev = {
319 .platform_data = &hsusb2_power_config,
320 },
321 };
323 static int beagle_twl_gpio_setup(struct device *dev,
324 unsigned gpio, unsigned ngpio)
325 {
326 int r;
328 mmc[0].gpio_wp = beagle_config.mmc1_gpio_wp;
329 /* gpio + 0 is "mmc0_cd" (input/IRQ) */
330 mmc[0].gpio_cd = gpio + 0;
331 omap_hsmmc_late_init(mmc);
333 /*
334 * TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, XM active
335 * high / others active low)
336 * DVI reset GPIO is different between beagle revisions
337 */
338 /* Valid for all -xM revisions */
339 if (cpu_is_omap3630()) {
340 /*
341 * gpio + 1 on Xm controls the TFP410's enable line (active low)
342 * gpio + 2 control varies depending on the board rev as below:
343 * P7/P8 revisions(prototype): Camera EN
344 * A2+ revisions (production): LDO (DVI, serial, led blocks)
345 */
346 r = gpio_request_one(gpio + 1, GPIOF_OUT_INIT_LOW,
347 "nDVI_PWR_EN");
348 if (r)
349 pr_err("%s: unable to configure nDVI_PWR_EN\n",
350 __func__);
352 beagle_config.dvi_pd_gpio = gpio + 2;
354 } else {
355 /*
356 * REVISIT: need ehci-omap hooks for external VBUS
357 * power switch and overcurrent detect
358 */
359 if (gpio_request_one(gpio + 1, GPIOF_IN, "EHCI_nOC"))
360 pr_err("%s: unable to configure EHCI_nOC\n", __func__);
361 }
362 dvi_panel.power_down_gpio = beagle_config.dvi_pd_gpio;
364 /* TWL4030_GPIO_MAX controls HS USB Port 2 power */
365 hsusb2_power_config.gpio = gpio + TWL4030_GPIO_MAX;
366 hsusb2_power_config.enable_high = beagle_config.usb_pwr_level;
368 platform_device_register(&hsusb2_power_device);
369 platform_device_register(&hsusb2_phy_device);
371 /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
372 gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
374 return 0;
375 }
377 static struct twl4030_gpio_platform_data beagle_gpio_data = {
378 .use_leds = true,
379 .pullups = BIT(1),
380 .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
381 | BIT(15) | BIT(16) | BIT(17),
382 .setup = beagle_twl_gpio_setup,
383 };
385 /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
386 static struct regulator_init_data beagle_vmmc1 = {
387 .constraints = {
388 .min_uV = 1850000,
389 .max_uV = 3150000,
390 .valid_modes_mask = REGULATOR_MODE_NORMAL
391 | REGULATOR_MODE_STANDBY,
392 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
393 | REGULATOR_CHANGE_MODE
394 | REGULATOR_CHANGE_STATUS,
395 },
396 .num_consumer_supplies = ARRAY_SIZE(beagle_vmmc1_supply),
397 .consumer_supplies = beagle_vmmc1_supply,
398 };
400 /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
401 static struct regulator_init_data beagle_vsim = {
402 .constraints = {
403 .min_uV = 1800000,
404 .max_uV = 3000000,
405 .valid_modes_mask = REGULATOR_MODE_NORMAL
406 | REGULATOR_MODE_STANDBY,
407 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
408 | REGULATOR_CHANGE_MODE
409 | REGULATOR_CHANGE_STATUS,
410 },
411 .num_consumer_supplies = ARRAY_SIZE(beagle_vsim_supply),
412 .consumer_supplies = beagle_vsim_supply,
413 };
415 static struct twl4030_platform_data beagle_twldata = {
416 /* platform_data for children goes here */
417 .gpio = &beagle_gpio_data,
418 .vmmc1 = &beagle_vmmc1,
419 .vsim = &beagle_vsim,
420 };
422 static struct i2c_board_info __initdata beagle_i2c_eeprom[] = {
423 {
424 I2C_BOARD_INFO("eeprom", 0x50),
425 },
426 };
428 static int __init omap3_beagle_i2c_init(void)
429 {
430 omap3_pmic_get_config(&beagle_twldata,
431 TWL_COMMON_PDATA_USB | TWL_COMMON_PDATA_MADC |
432 TWL_COMMON_PDATA_AUDIO,
433 TWL_COMMON_REGULATOR_VDAC | TWL_COMMON_REGULATOR_VPLL2);
435 beagle_twldata.vpll2->constraints.name = "VDVI";
437 omap3_pmic_init("twl4030", &beagle_twldata);
438 /* Bus 3 is attached to the DVI port where devices like the pico DLP
439 * projector don't work reliably with 400kHz */
440 omap_register_i2c_bus(3, 100, beagle_i2c_eeprom, ARRAY_SIZE(beagle_i2c_eeprom));
441 return 0;
442 }
444 static struct gpio_led gpio_leds[] = {
445 {
446 .name = "beagleboard::usr0",
447 .default_trigger = "heartbeat",
448 .gpio = 150,
449 },
450 {
451 .name = "beagleboard::usr1",
452 .default_trigger = "mmc0",
453 .gpio = 149,
454 },
455 {
456 .name = "beagleboard::pmu_stat",
457 .gpio = -EINVAL, /* gets replaced */
458 .active_low = true,
459 },
460 };
462 static struct gpio_led_platform_data gpio_led_info = {
463 .leds = gpio_leds,
464 .num_leds = ARRAY_SIZE(gpio_leds),
465 };
467 static struct platform_device leds_gpio = {
468 .name = "leds-gpio",
469 .id = -1,
470 .dev = {
471 .platform_data = &gpio_led_info,
472 },
473 };
475 static struct gpio_keys_button gpio_buttons[] = {
476 {
477 .code = BTN_EXTRA,
478 /* Dynamically assigned depending on board */
479 .gpio = -EINVAL,
480 .desc = "user",
481 .wakeup = 1,
482 },
483 };
485 static struct gpio_keys_platform_data gpio_key_info = {
486 .buttons = gpio_buttons,
487 .nbuttons = ARRAY_SIZE(gpio_buttons),
488 };
490 static struct platform_device keys_gpio = {
491 .name = "gpio-keys",
492 .id = -1,
493 .dev = {
494 .platform_data = &gpio_key_info,
495 },
496 };
498 static struct platform_device madc_hwmon = {
499 .name = "twl4030_madc_hwmon",
500 .id = -1,
501 };
503 static struct platform_device *omap3_beagle_devices[] __initdata = {
504 &leds_gpio,
505 &keys_gpio,
506 &madc_hwmon,
507 &hsusb2_reset_device,
508 };
510 static struct usbhs_omap_platform_data usbhs_bdata __initdata = {
511 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
512 };
514 #ifdef CONFIG_OMAP_MUX
515 static struct omap_board_mux board_mux[] __initdata = {
516 { .reg_offset = OMAP_MUX_TERMINATOR },
517 };
518 #endif
520 static int __init beagle_opp_init(void)
521 {
522 int r = 0;
524 if (!machine_is_omap3_beagle())
525 return 0;
527 /* Initialize the omap3 opp table if not already created. */
528 r = omap3_opp_init();
529 if (IS_ERR_VALUE(r) && (r != -EEXIST)) {
530 pr_err("%s: opp default init failed\n", __func__);
531 return r;
532 }
534 /* Custom OPP enabled for all xM versions */
535 if (cpu_is_omap3630()) {
536 struct device *mpu_dev, *iva_dev;
538 mpu_dev = get_cpu_device(0);
539 iva_dev = omap_device_get_by_hwmod_name("iva");
541 if (IS_ERR(mpu_dev) || IS_ERR(iva_dev)) {
542 pr_err("%s: Aiee.. no mpu/dsp devices? %p %p\n",
543 __func__, mpu_dev, iva_dev);
544 return -ENODEV;
545 }
546 /* Enable MPU 1GHz and lower opps */
547 r = opp_enable(mpu_dev, 800000000);
548 /* TODO: MPU 1GHz needs SR and ABB */
550 /* Enable IVA 800MHz and lower opps */
551 r |= opp_enable(iva_dev, 660000000);
552 /* TODO: DSP 800MHz needs SR and ABB */
553 if (r) {
554 pr_err("%s: failed to enable higher opp %d\n",
555 __func__, r);
556 /*
557 * Cleanup - disable the higher freqs - we dont care
558 * about the results
559 */
560 opp_disable(mpu_dev, 800000000);
561 opp_disable(iva_dev, 660000000);
562 }
563 }
564 return 0;
565 }
566 device_initcall(beagle_opp_init);
568 static void __init omap3_beagle_init(void)
569 {
570 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
571 omap3_beagle_init_rev();
573 if (gpio_is_valid(beagle_config.mmc1_gpio_wp))
574 omap_mux_init_gpio(beagle_config.mmc1_gpio_wp, OMAP_PIN_INPUT);
575 mmc[0].caps = beagle_config.mmc_caps;
576 omap_hsmmc_init(mmc);
578 omap3_beagle_i2c_init();
580 gpio_buttons[0].gpio = beagle_config.usr_button_gpio;
582 platform_add_devices(omap3_beagle_devices,
583 ARRAY_SIZE(omap3_beagle_devices));
584 if (gpio_is_valid(beagle_config.dvi_pd_gpio))
585 omap_mux_init_gpio(beagle_config.dvi_pd_gpio, OMAP_PIN_OUTPUT);
586 omap_display_init(&beagle_dss_data);
587 omap_serial_init();
588 omap_sdrc_init(mt46h32m32lf6_sdrc_params,
589 mt46h32m32lf6_sdrc_params);
591 usb_bind_phy("musb-hdrc.1.auto", 0, "twl4030_usb");
592 usb_musb_init(NULL);
594 /* PHY on HSUSB Port 2 i.e. index 1 */
595 usb_bind_phy("ehci-omap.0", 1, "nop_usb_xceiv.2");
596 usbhs_init(&usbhs_bdata);
598 board_nand_init(omap3beagle_nand_partitions,
599 ARRAY_SIZE(omap3beagle_nand_partitions), NAND_CS,
600 NAND_BUSWIDTH_16, NULL);
601 omap_twl4030_audio_init("omap3beagle");
603 /* Ensure msecure is mux'd to be able to set the RTC. */
604 omap_mux_init_signal("sys_drm_msecure", OMAP_PIN_OFF_OUTPUT_HIGH);
606 /* Ensure SDRC pins are mux'd for self-refresh */
607 omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
608 omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
609 }
611 MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
612 /* Maintainer: Syed Mohammed Khasim - http://beagleboard.org */
613 .atag_offset = 0x100,
614 .reserve = omap_reserve,
615 .map_io = omap3_map_io,
616 .init_early = omap3_init_early,
617 .init_irq = omap3_init_irq,
618 .handle_irq = omap3_intc_handle_irq,
619 .init_machine = omap3_beagle_init,
620 .init_late = omap3_init_late,
621 .timer = &omap3_secure_timer,
622 .restart = omap3xxx_restart,
623 MACHINE_END