board-omap3beagle.c 14 KB

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