board-omap3beagle.c 14 KB

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