board-omap3beagle.c 14 KB

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