board-omap3beagle.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/delay.h>
  18. #include <linux/err.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/leds.h>
  22. #include <linux/gpio.h>
  23. #include <linux/input.h>
  24. #include <linux/gpio_keys.h>
  25. #include <linux/opp.h>
  26. #include <linux/cpu.h>
  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. #include <linux/regulator/machine.h>
  32. #include <linux/i2c/twl.h>
  33. #include <asm/mach-types.h>
  34. #include <asm/mach/arch.h>
  35. #include <asm/mach/map.h>
  36. #include <asm/mach/flash.h>
  37. #include "common.h"
  38. #include <video/omapdss.h>
  39. #include <video/omap-panel-tfp410.h>
  40. #include <plat/gpmc.h>
  41. #include <linux/platform_data/mtd-nand-omap2.h>
  42. #include <plat/usb.h>
  43. #include <plat/omap_device.h>
  44. #include "mux.h"
  45. #include "hsmmc.h"
  46. #include "pm.h"
  47. #include "common-board-devices.h"
  48. /*
  49. * OMAP3 Beagle revision
  50. * Run time detection of Beagle revision is done by reading GPIO.
  51. * GPIO ID -
  52. * AXBX = GPIO173, GPIO172, GPIO171: 1 1 1
  53. * C1_3 = GPIO173, GPIO172, GPIO171: 1 1 0
  54. * C4 = GPIO173, GPIO172, GPIO171: 1 0 1
  55. * XMA/XMB = GPIO173, GPIO172, GPIO171: 0 0 0
  56. * XMC = GPIO173, GPIO172, GPIO171: 0 1 0
  57. */
  58. enum {
  59. OMAP3BEAGLE_BOARD_UNKN = 0,
  60. OMAP3BEAGLE_BOARD_AXBX,
  61. OMAP3BEAGLE_BOARD_C1_3,
  62. OMAP3BEAGLE_BOARD_C4,
  63. OMAP3BEAGLE_BOARD_XM,
  64. OMAP3BEAGLE_BOARD_XMC,
  65. };
  66. static u8 omap3_beagle_version;
  67. /*
  68. * Board-specific configuration
  69. * Defaults to BeagleBoard-xMC
  70. */
  71. static struct {
  72. int mmc1_gpio_wp;
  73. int usb_pwr_level;
  74. int dvi_pd_gpio;
  75. int usr_button_gpio;
  76. int mmc_caps;
  77. } beagle_config = {
  78. .mmc1_gpio_wp = -EINVAL,
  79. .usb_pwr_level = GPIOF_OUT_INIT_LOW,
  80. .dvi_pd_gpio = -EINVAL,
  81. .usr_button_gpio = 4,
  82. .mmc_caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
  83. };
  84. static struct gpio omap3_beagle_rev_gpios[] __initdata = {
  85. { 171, GPIOF_IN, "rev_id_0" },
  86. { 172, GPIOF_IN, "rev_id_1" },
  87. { 173, GPIOF_IN, "rev_id_2" },
  88. };
  89. static void __init omap3_beagle_init_rev(void)
  90. {
  91. int ret;
  92. u16 beagle_rev = 0;
  93. omap_mux_init_gpio(171, OMAP_PIN_INPUT_PULLUP);
  94. omap_mux_init_gpio(172, OMAP_PIN_INPUT_PULLUP);
  95. omap_mux_init_gpio(173, OMAP_PIN_INPUT_PULLUP);
  96. ret = gpio_request_array(omap3_beagle_rev_gpios,
  97. ARRAY_SIZE(omap3_beagle_rev_gpios));
  98. if (ret < 0) {
  99. printk(KERN_ERR "Unable to get revision detection GPIO pins\n");
  100. omap3_beagle_version = OMAP3BEAGLE_BOARD_UNKN;
  101. return;
  102. }
  103. beagle_rev = gpio_get_value(171) | (gpio_get_value(172) << 1)
  104. | (gpio_get_value(173) << 2);
  105. gpio_free_array(omap3_beagle_rev_gpios,
  106. ARRAY_SIZE(omap3_beagle_rev_gpios));
  107. switch (beagle_rev) {
  108. case 7:
  109. printk(KERN_INFO "OMAP3 Beagle Rev: Ax/Bx\n");
  110. omap3_beagle_version = OMAP3BEAGLE_BOARD_AXBX;
  111. beagle_config.mmc1_gpio_wp = 29;
  112. beagle_config.dvi_pd_gpio = 170;
  113. beagle_config.usr_button_gpio = 7;
  114. break;
  115. case 6:
  116. printk(KERN_INFO "OMAP3 Beagle Rev: C1/C2/C3\n");
  117. omap3_beagle_version = OMAP3BEAGLE_BOARD_C1_3;
  118. beagle_config.mmc1_gpio_wp = 23;
  119. beagle_config.dvi_pd_gpio = 170;
  120. beagle_config.usr_button_gpio = 7;
  121. break;
  122. case 5:
  123. printk(KERN_INFO "OMAP3 Beagle Rev: C4\n");
  124. omap3_beagle_version = OMAP3BEAGLE_BOARD_C4;
  125. beagle_config.mmc1_gpio_wp = 23;
  126. beagle_config.dvi_pd_gpio = 170;
  127. beagle_config.usr_button_gpio = 7;
  128. break;
  129. case 0:
  130. printk(KERN_INFO "OMAP3 Beagle Rev: xM Ax/Bx\n");
  131. omap3_beagle_version = OMAP3BEAGLE_BOARD_XM;
  132. beagle_config.usb_pwr_level = GPIOF_OUT_INIT_HIGH;
  133. beagle_config.mmc_caps &= ~MMC_CAP_8_BIT_DATA;
  134. break;
  135. case 2:
  136. printk(KERN_INFO "OMAP3 Beagle Rev: xM C\n");
  137. omap3_beagle_version = OMAP3BEAGLE_BOARD_XMC;
  138. beagle_config.mmc_caps &= ~MMC_CAP_8_BIT_DATA;
  139. break;
  140. default:
  141. printk(KERN_INFO "OMAP3 Beagle Rev: unknown %hd\n", beagle_rev);
  142. omap3_beagle_version = OMAP3BEAGLE_BOARD_UNKN;
  143. }
  144. }
  145. static struct mtd_partition omap3beagle_nand_partitions[] = {
  146. /* All the partition sizes are listed in terms of NAND block size */
  147. {
  148. .name = "X-Loader",
  149. .offset = 0,
  150. .size = 4 * NAND_BLOCK_SIZE,
  151. .mask_flags = MTD_WRITEABLE, /* force read-only */
  152. },
  153. {
  154. .name = "U-Boot",
  155. .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
  156. .size = 15 * NAND_BLOCK_SIZE,
  157. .mask_flags = MTD_WRITEABLE, /* force read-only */
  158. },
  159. {
  160. .name = "U-Boot Env",
  161. .offset = MTDPART_OFS_APPEND, /* Offset = 0x260000 */
  162. .size = 1 * NAND_BLOCK_SIZE,
  163. },
  164. {
  165. .name = "Kernel",
  166. .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
  167. .size = 32 * NAND_BLOCK_SIZE,
  168. },
  169. {
  170. .name = "File System",
  171. .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
  172. .size = MTDPART_SIZ_FULL,
  173. },
  174. };
  175. /* DSS */
  176. static struct tfp410_platform_data dvi_panel = {
  177. .i2c_bus_num = 3,
  178. .power_down_gpio = -1,
  179. };
  180. static struct omap_dss_device beagle_dvi_device = {
  181. .type = OMAP_DISPLAY_TYPE_DPI,
  182. .name = "dvi",
  183. .driver_name = "tfp410",
  184. .data = &dvi_panel,
  185. .phy.dpi.data_lines = 24,
  186. };
  187. static struct omap_dss_device beagle_tv_device = {
  188. .name = "tv",
  189. .driver_name = "venc",
  190. .type = OMAP_DISPLAY_TYPE_VENC,
  191. .phy.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
  192. };
  193. static struct omap_dss_device *beagle_dss_devices[] = {
  194. &beagle_dvi_device,
  195. &beagle_tv_device,
  196. };
  197. static struct omap_dss_board_info beagle_dss_data = {
  198. .num_devices = ARRAY_SIZE(beagle_dss_devices),
  199. .devices = beagle_dss_devices,
  200. .default_device = &beagle_dvi_device,
  201. };
  202. #include "sdram-micron-mt46h32m32lf-6.h"
  203. static struct omap2_hsmmc_info mmc[] = {
  204. {
  205. .mmc = 1,
  206. .caps = MMC_CAP_4_BIT_DATA,
  207. .gpio_wp = -EINVAL,
  208. .deferred = true,
  209. },
  210. {} /* Terminator */
  211. };
  212. static struct regulator_consumer_supply beagle_vmmc1_supply[] = {
  213. REGULATOR_SUPPLY("vmmc", "omap_hsmmc.0"),
  214. };
  215. static struct regulator_consumer_supply beagle_vsim_supply[] = {
  216. REGULATOR_SUPPLY("vmmc_aux", "omap_hsmmc.0"),
  217. };
  218. static struct gpio_led gpio_leds[];
  219. static int beagle_twl_gpio_setup(struct device *dev,
  220. unsigned gpio, unsigned ngpio)
  221. {
  222. int r;
  223. mmc[0].gpio_wp = beagle_config.mmc1_gpio_wp;
  224. /* gpio + 0 is "mmc0_cd" (input/IRQ) */
  225. mmc[0].gpio_cd = gpio + 0;
  226. omap_hsmmc_late_init(mmc);
  227. /*
  228. * TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, XM active
  229. * high / others active low)
  230. * DVI reset GPIO is different between beagle revisions
  231. */
  232. /* Valid for all -xM revisions */
  233. if (cpu_is_omap3630()) {
  234. /*
  235. * gpio + 1 on Xm controls the TFP410's enable line (active low)
  236. * gpio + 2 control varies depending on the board rev as below:
  237. * P7/P8 revisions(prototype): Camera EN
  238. * A2+ revisions (production): LDO (DVI, serial, led blocks)
  239. */
  240. r = gpio_request_one(gpio + 1, GPIOF_OUT_INIT_LOW,
  241. "nDVI_PWR_EN");
  242. if (r)
  243. pr_err("%s: unable to configure nDVI_PWR_EN\n",
  244. __func__);
  245. beagle_config.dvi_pd_gpio = gpio + 2;
  246. } else {
  247. /*
  248. * REVISIT: need ehci-omap hooks for external VBUS
  249. * power switch and overcurrent detect
  250. */
  251. if (gpio_request_one(gpio + 1, GPIOF_IN, "EHCI_nOC"))
  252. pr_err("%s: unable to configure EHCI_nOC\n", __func__);
  253. }
  254. dvi_panel.power_down_gpio = beagle_config.dvi_pd_gpio;
  255. gpio_request_one(gpio + TWL4030_GPIO_MAX, beagle_config.usb_pwr_level,
  256. "nEN_USB_PWR");
  257. /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
  258. gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
  259. return 0;
  260. }
  261. static struct twl4030_gpio_platform_data beagle_gpio_data = {
  262. .use_leds = true,
  263. .pullups = BIT(1),
  264. .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
  265. | BIT(15) | BIT(16) | BIT(17),
  266. .setup = beagle_twl_gpio_setup,
  267. };
  268. /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
  269. static struct regulator_init_data beagle_vmmc1 = {
  270. .constraints = {
  271. .min_uV = 1850000,
  272. .max_uV = 3150000,
  273. .valid_modes_mask = REGULATOR_MODE_NORMAL
  274. | REGULATOR_MODE_STANDBY,
  275. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  276. | REGULATOR_CHANGE_MODE
  277. | REGULATOR_CHANGE_STATUS,
  278. },
  279. .num_consumer_supplies = ARRAY_SIZE(beagle_vmmc1_supply),
  280. .consumer_supplies = beagle_vmmc1_supply,
  281. };
  282. /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
  283. static struct regulator_init_data beagle_vsim = {
  284. .constraints = {
  285. .min_uV = 1800000,
  286. .max_uV = 3000000,
  287. .valid_modes_mask = REGULATOR_MODE_NORMAL
  288. | REGULATOR_MODE_STANDBY,
  289. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  290. | REGULATOR_CHANGE_MODE
  291. | REGULATOR_CHANGE_STATUS,
  292. },
  293. .num_consumer_supplies = ARRAY_SIZE(beagle_vsim_supply),
  294. .consumer_supplies = beagle_vsim_supply,
  295. };
  296. static struct twl4030_platform_data beagle_twldata = {
  297. /* platform_data for children goes here */
  298. .gpio = &beagle_gpio_data,
  299. .vmmc1 = &beagle_vmmc1,
  300. .vsim = &beagle_vsim,
  301. };
  302. static struct i2c_board_info __initdata beagle_i2c_eeprom[] = {
  303. {
  304. I2C_BOARD_INFO("eeprom", 0x50),
  305. },
  306. };
  307. static int __init omap3_beagle_i2c_init(void)
  308. {
  309. omap3_pmic_get_config(&beagle_twldata,
  310. TWL_COMMON_PDATA_USB | TWL_COMMON_PDATA_MADC |
  311. TWL_COMMON_PDATA_AUDIO,
  312. TWL_COMMON_REGULATOR_VDAC | TWL_COMMON_REGULATOR_VPLL2);
  313. beagle_twldata.vpll2->constraints.name = "VDVI";
  314. omap3_pmic_init("twl4030", &beagle_twldata);
  315. /* Bus 3 is attached to the DVI port where devices like the pico DLP
  316. * projector don't work reliably with 400kHz */
  317. omap_register_i2c_bus(3, 100, beagle_i2c_eeprom, ARRAY_SIZE(beagle_i2c_eeprom));
  318. return 0;
  319. }
  320. static struct gpio_led gpio_leds[] = {
  321. {
  322. .name = "beagleboard::usr0",
  323. .default_trigger = "heartbeat",
  324. .gpio = 150,
  325. },
  326. {
  327. .name = "beagleboard::usr1",
  328. .default_trigger = "mmc0",
  329. .gpio = 149,
  330. },
  331. {
  332. .name = "beagleboard::pmu_stat",
  333. .gpio = -EINVAL, /* gets replaced */
  334. .active_low = true,
  335. },
  336. };
  337. static struct gpio_led_platform_data gpio_led_info = {
  338. .leds = gpio_leds,
  339. .num_leds = ARRAY_SIZE(gpio_leds),
  340. };
  341. static struct platform_device leds_gpio = {
  342. .name = "leds-gpio",
  343. .id = -1,
  344. .dev = {
  345. .platform_data = &gpio_led_info,
  346. },
  347. };
  348. static struct gpio_keys_button gpio_buttons[] = {
  349. {
  350. .code = BTN_EXTRA,
  351. /* Dynamically assigned depending on board */
  352. .gpio = -EINVAL,
  353. .desc = "user",
  354. .wakeup = 1,
  355. },
  356. };
  357. static struct gpio_keys_platform_data gpio_key_info = {
  358. .buttons = gpio_buttons,
  359. .nbuttons = ARRAY_SIZE(gpio_buttons),
  360. };
  361. static struct platform_device keys_gpio = {
  362. .name = "gpio-keys",
  363. .id = -1,
  364. .dev = {
  365. .platform_data = &gpio_key_info,
  366. },
  367. };
  368. static struct platform_device madc_hwmon = {
  369. .name = "twl4030_madc_hwmon",
  370. .id = -1,
  371. };
  372. static struct platform_device *omap3_beagle_devices[] __initdata = {
  373. &leds_gpio,
  374. &keys_gpio,
  375. &madc_hwmon,
  376. };
  377. static const struct usbhs_omap_board_data usbhs_bdata __initconst = {
  378. .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
  379. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  380. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
  381. .phy_reset = true,
  382. .reset_gpio_port[0] = -EINVAL,
  383. .reset_gpio_port[1] = 147,
  384. .reset_gpio_port[2] = -EINVAL
  385. };
  386. #ifdef CONFIG_OMAP_MUX
  387. static struct omap_board_mux board_mux[] __initdata = {
  388. { .reg_offset = OMAP_MUX_TERMINATOR },
  389. };
  390. #endif
  391. static int __init beagle_opp_init(void)
  392. {
  393. int r = 0;
  394. if (!machine_is_omap3_beagle())
  395. return 0;
  396. /* Initialize the omap3 opp table if not already created. */
  397. r = omap3_opp_init();
  398. if (IS_ERR_VALUE(r) && (r != -EEXIST)) {
  399. pr_err("%s: opp default init failed\n", __func__);
  400. return r;
  401. }
  402. /* Custom OPP enabled for all xM versions */
  403. if (cpu_is_omap3630()) {
  404. struct device *mpu_dev, *iva_dev;
  405. mpu_dev = get_cpu_device(0);
  406. iva_dev = omap_device_get_by_hwmod_name("iva");
  407. if (IS_ERR(mpu_dev) || IS_ERR(iva_dev)) {
  408. pr_err("%s: Aiee.. no mpu/dsp devices? %p %p\n",
  409. __func__, mpu_dev, iva_dev);
  410. return -ENODEV;
  411. }
  412. /* Enable MPU 1GHz and lower opps */
  413. r = opp_enable(mpu_dev, 800000000);
  414. /* TODO: MPU 1GHz needs SR and ABB */
  415. /* Enable IVA 800MHz and lower opps */
  416. r |= opp_enable(iva_dev, 660000000);
  417. /* TODO: DSP 800MHz needs SR and ABB */
  418. if (r) {
  419. pr_err("%s: failed to enable higher opp %d\n",
  420. __func__, r);
  421. /*
  422. * Cleanup - disable the higher freqs - we dont care
  423. * about the results
  424. */
  425. opp_disable(mpu_dev, 800000000);
  426. opp_disable(iva_dev, 660000000);
  427. }
  428. }
  429. return 0;
  430. }
  431. device_initcall(beagle_opp_init);
  432. static void __init omap3_beagle_init(void)
  433. {
  434. omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
  435. omap3_beagle_init_rev();
  436. if (gpio_is_valid(beagle_config.mmc1_gpio_wp))
  437. omap_mux_init_gpio(beagle_config.mmc1_gpio_wp, OMAP_PIN_INPUT);
  438. mmc[0].caps = beagle_config.mmc_caps;
  439. omap_hsmmc_init(mmc);
  440. omap3_beagle_i2c_init();
  441. gpio_buttons[0].gpio = beagle_config.usr_button_gpio;
  442. platform_add_devices(omap3_beagle_devices,
  443. ARRAY_SIZE(omap3_beagle_devices));
  444. if (gpio_is_valid(beagle_config.dvi_pd_gpio))
  445. omap_mux_init_gpio(beagle_config.dvi_pd_gpio, OMAP_PIN_OUTPUT);
  446. omap_display_init(&beagle_dss_data);
  447. omap_serial_init();
  448. omap_sdrc_init(mt46h32m32lf6_sdrc_params,
  449. mt46h32m32lf6_sdrc_params);
  450. usb_musb_init(NULL);
  451. usbhs_init(&usbhs_bdata);
  452. omap_nand_flash_init(NAND_BUSWIDTH_16, omap3beagle_nand_partitions,
  453. ARRAY_SIZE(omap3beagle_nand_partitions));
  454. omap_twl4030_audio_init("omap3beagle");
  455. /* Ensure msecure is mux'd to be able to set the RTC. */
  456. omap_mux_init_signal("sys_drm_msecure", OMAP_PIN_OFF_OUTPUT_HIGH);
  457. /* Ensure SDRC pins are mux'd for self-refresh */
  458. omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
  459. omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
  460. }
  461. MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
  462. /* Maintainer: Syed Mohammed Khasim - http://beagleboard.org */
  463. .atag_offset = 0x100,
  464. .reserve = omap_reserve,
  465. .map_io = omap3_map_io,
  466. .init_early = omap3_init_early,
  467. .init_irq = omap3_init_irq,
  468. .handle_irq = omap3_intc_handle_irq,
  469. .init_machine = omap3_beagle_init,
  470. .init_late = omap3_init_late,
  471. .timer = &omap3_secure_timer,
  472. .restart = omap_prcm_restart,
  473. MACHINE_END