board-omap3beagle.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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/mtd/mtd.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <linux/mtd/nand.h>
  28. #include <linux/mmc/host.h>
  29. #include <linux/regulator/machine.h>
  30. #include <linux/i2c/twl.h>
  31. #include <mach/hardware.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/map.h>
  35. #include <asm/mach/flash.h>
  36. #include <plat/board.h>
  37. #include <plat/common.h>
  38. #include <plat/display.h>
  39. #include <plat/gpmc.h>
  40. #include <plat/nand.h>
  41. #include <plat/usb.h>
  42. #include "mux.h"
  43. #include "hsmmc.h"
  44. #include "timer-gp.h"
  45. #define NAND_BLOCK_SIZE SZ_128K
  46. /*
  47. * OMAP3 Beagle revision
  48. * Run time detection of Beagle revision is done by reading GPIO.
  49. * GPIO ID -
  50. * AXBX = GPIO173, GPIO172, GPIO171: 1 1 1
  51. * C1_3 = GPIO173, GPIO172, GPIO171: 1 1 0
  52. * C4 = GPIO173, GPIO172, GPIO171: 1 0 1
  53. * XM = GPIO173, GPIO172, GPIO171: 0 0 0
  54. */
  55. enum {
  56. OMAP3BEAGLE_BOARD_UNKN = 0,
  57. OMAP3BEAGLE_BOARD_AXBX,
  58. OMAP3BEAGLE_BOARD_C1_3,
  59. OMAP3BEAGLE_BOARD_C4,
  60. OMAP3BEAGLE_BOARD_XM,
  61. };
  62. static u8 omap3_beagle_version;
  63. static u8 omap3_beagle_get_rev(void)
  64. {
  65. return omap3_beagle_version;
  66. }
  67. static void __init omap3_beagle_init_rev(void)
  68. {
  69. int ret;
  70. u16 beagle_rev = 0;
  71. omap_mux_init_gpio(171, OMAP_PIN_INPUT_PULLUP);
  72. omap_mux_init_gpio(172, OMAP_PIN_INPUT_PULLUP);
  73. omap_mux_init_gpio(173, OMAP_PIN_INPUT_PULLUP);
  74. ret = gpio_request(171, "rev_id_0");
  75. if (ret < 0)
  76. goto fail0;
  77. ret = gpio_request(172, "rev_id_1");
  78. if (ret < 0)
  79. goto fail1;
  80. ret = gpio_request(173, "rev_id_2");
  81. if (ret < 0)
  82. goto fail2;
  83. gpio_direction_input(171);
  84. gpio_direction_input(172);
  85. gpio_direction_input(173);
  86. beagle_rev = gpio_get_value(171) | (gpio_get_value(172) << 1)
  87. | (gpio_get_value(173) << 2);
  88. switch (beagle_rev) {
  89. case 7:
  90. printk(KERN_INFO "OMAP3 Beagle Rev: Ax/Bx\n");
  91. omap3_beagle_version = OMAP3BEAGLE_BOARD_AXBX;
  92. break;
  93. case 6:
  94. printk(KERN_INFO "OMAP3 Beagle Rev: C1/C2/C3\n");
  95. omap3_beagle_version = OMAP3BEAGLE_BOARD_C1_3;
  96. break;
  97. case 5:
  98. printk(KERN_INFO "OMAP3 Beagle Rev: C4\n");
  99. omap3_beagle_version = OMAP3BEAGLE_BOARD_C4;
  100. break;
  101. case 0:
  102. printk(KERN_INFO "OMAP3 Beagle Rev: xM\n");
  103. omap3_beagle_version = OMAP3BEAGLE_BOARD_XM;
  104. break;
  105. default:
  106. printk(KERN_INFO "OMAP3 Beagle Rev: unknown %hd\n", beagle_rev);
  107. omap3_beagle_version = OMAP3BEAGLE_BOARD_UNKN;
  108. }
  109. return;
  110. fail2:
  111. gpio_free(172);
  112. fail1:
  113. gpio_free(171);
  114. fail0:
  115. printk(KERN_ERR "Unable to get revision detection GPIO pins\n");
  116. omap3_beagle_version = OMAP3BEAGLE_BOARD_UNKN;
  117. return;
  118. }
  119. static struct mtd_partition omap3beagle_nand_partitions[] = {
  120. /* All the partition sizes are listed in terms of NAND block size */
  121. {
  122. .name = "X-Loader",
  123. .offset = 0,
  124. .size = 4 * NAND_BLOCK_SIZE,
  125. .mask_flags = MTD_WRITEABLE, /* force read-only */
  126. },
  127. {
  128. .name = "U-Boot",
  129. .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
  130. .size = 15 * NAND_BLOCK_SIZE,
  131. .mask_flags = MTD_WRITEABLE, /* force read-only */
  132. },
  133. {
  134. .name = "U-Boot Env",
  135. .offset = MTDPART_OFS_APPEND, /* Offset = 0x260000 */
  136. .size = 1 * NAND_BLOCK_SIZE,
  137. },
  138. {
  139. .name = "Kernel",
  140. .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
  141. .size = 32 * NAND_BLOCK_SIZE,
  142. },
  143. {
  144. .name = "File System",
  145. .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
  146. .size = MTDPART_SIZ_FULL,
  147. },
  148. };
  149. static struct omap_nand_platform_data omap3beagle_nand_data = {
  150. .options = NAND_BUSWIDTH_16,
  151. .parts = omap3beagle_nand_partitions,
  152. .nr_parts = ARRAY_SIZE(omap3beagle_nand_partitions),
  153. .dma_channel = -1, /* disable DMA in OMAP NAND driver */
  154. .nand_setup = NULL,
  155. .dev_ready = NULL,
  156. };
  157. /* DSS */
  158. static int beagle_enable_dvi(struct omap_dss_device *dssdev)
  159. {
  160. if (gpio_is_valid(dssdev->reset_gpio))
  161. gpio_set_value(dssdev->reset_gpio, 1);
  162. return 0;
  163. }
  164. static void beagle_disable_dvi(struct omap_dss_device *dssdev)
  165. {
  166. if (gpio_is_valid(dssdev->reset_gpio))
  167. gpio_set_value(dssdev->reset_gpio, 0);
  168. }
  169. static struct omap_dss_device beagle_dvi_device = {
  170. .type = OMAP_DISPLAY_TYPE_DPI,
  171. .name = "dvi",
  172. .driver_name = "generic_panel",
  173. .phy.dpi.data_lines = 24,
  174. .reset_gpio = 170,
  175. .platform_enable = beagle_enable_dvi,
  176. .platform_disable = beagle_disable_dvi,
  177. };
  178. static struct omap_dss_device beagle_tv_device = {
  179. .name = "tv",
  180. .driver_name = "venc",
  181. .type = OMAP_DISPLAY_TYPE_VENC,
  182. .phy.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
  183. };
  184. static struct omap_dss_device *beagle_dss_devices[] = {
  185. &beagle_dvi_device,
  186. &beagle_tv_device,
  187. };
  188. static struct omap_dss_board_info beagle_dss_data = {
  189. .num_devices = ARRAY_SIZE(beagle_dss_devices),
  190. .devices = beagle_dss_devices,
  191. .default_device = &beagle_dvi_device,
  192. };
  193. static struct platform_device beagle_dss_device = {
  194. .name = "omapdss",
  195. .id = -1,
  196. .dev = {
  197. .platform_data = &beagle_dss_data,
  198. },
  199. };
  200. static struct regulator_consumer_supply beagle_vdac_supply =
  201. REGULATOR_SUPPLY("vdda_dac", "omapdss");
  202. static struct regulator_consumer_supply beagle_vdvi_supply =
  203. REGULATOR_SUPPLY("vdds_dsi", "omapdss");
  204. static void __init beagle_display_init(void)
  205. {
  206. int r;
  207. r = gpio_request(beagle_dvi_device.reset_gpio, "DVI reset");
  208. if (r < 0) {
  209. printk(KERN_ERR "Unable to get DVI reset GPIO\n");
  210. return;
  211. }
  212. gpio_direction_output(beagle_dvi_device.reset_gpio, 0);
  213. }
  214. #include "sdram-micron-mt46h32m32lf-6.h"
  215. static struct omap2_hsmmc_info mmc[] = {
  216. {
  217. .mmc = 1,
  218. .caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
  219. .gpio_wp = 29,
  220. },
  221. {} /* Terminator */
  222. };
  223. static struct regulator_consumer_supply beagle_vmmc1_supply = {
  224. .supply = "vmmc",
  225. };
  226. static struct regulator_consumer_supply beagle_vsim_supply = {
  227. .supply = "vmmc_aux",
  228. };
  229. static struct gpio_led gpio_leds[];
  230. static int beagle_twl_gpio_setup(struct device *dev,
  231. unsigned gpio, unsigned ngpio)
  232. {
  233. if (omap3_beagle_get_rev() == OMAP3BEAGLE_BOARD_XM) {
  234. mmc[0].gpio_wp = -EINVAL;
  235. } else if ((omap3_beagle_get_rev() == OMAP3BEAGLE_BOARD_C1_3) ||
  236. (omap3_beagle_get_rev() == OMAP3BEAGLE_BOARD_C4)) {
  237. omap_mux_init_gpio(23, OMAP_PIN_INPUT);
  238. mmc[0].gpio_wp = 23;
  239. } else {
  240. omap_mux_init_gpio(29, OMAP_PIN_INPUT);
  241. }
  242. /* gpio + 0 is "mmc0_cd" (input/IRQ) */
  243. mmc[0].gpio_cd = gpio + 0;
  244. omap2_hsmmc_init(mmc);
  245. /* link regulators to MMC adapters */
  246. beagle_vmmc1_supply.dev = mmc[0].dev;
  247. beagle_vsim_supply.dev = mmc[0].dev;
  248. /* REVISIT: need ehci-omap hooks for external VBUS
  249. * power switch and overcurrent detect
  250. */
  251. gpio_request(gpio + 1, "EHCI_nOC");
  252. gpio_direction_input(gpio + 1);
  253. /*
  254. * TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, XM active
  255. * high / others active low)
  256. */
  257. gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
  258. if (omap3_beagle_get_rev() == OMAP3BEAGLE_BOARD_XM)
  259. gpio_direction_output(gpio + TWL4030_GPIO_MAX, 1);
  260. else
  261. gpio_direction_output(gpio + TWL4030_GPIO_MAX, 0);
  262. /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
  263. gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
  264. return 0;
  265. }
  266. static struct twl4030_gpio_platform_data beagle_gpio_data = {
  267. .gpio_base = OMAP_MAX_GPIO_LINES,
  268. .irq_base = TWL4030_GPIO_IRQ_BASE,
  269. .irq_end = TWL4030_GPIO_IRQ_END,
  270. .use_leds = true,
  271. .pullups = BIT(1),
  272. .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
  273. | BIT(15) | BIT(16) | BIT(17),
  274. .setup = beagle_twl_gpio_setup,
  275. };
  276. /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
  277. static struct regulator_init_data beagle_vmmc1 = {
  278. .constraints = {
  279. .min_uV = 1850000,
  280. .max_uV = 3150000,
  281. .valid_modes_mask = REGULATOR_MODE_NORMAL
  282. | REGULATOR_MODE_STANDBY,
  283. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  284. | REGULATOR_CHANGE_MODE
  285. | REGULATOR_CHANGE_STATUS,
  286. },
  287. .num_consumer_supplies = 1,
  288. .consumer_supplies = &beagle_vmmc1_supply,
  289. };
  290. /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
  291. static struct regulator_init_data beagle_vsim = {
  292. .constraints = {
  293. .min_uV = 1800000,
  294. .max_uV = 3000000,
  295. .valid_modes_mask = REGULATOR_MODE_NORMAL
  296. | REGULATOR_MODE_STANDBY,
  297. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  298. | REGULATOR_CHANGE_MODE
  299. | REGULATOR_CHANGE_STATUS,
  300. },
  301. .num_consumer_supplies = 1,
  302. .consumer_supplies = &beagle_vsim_supply,
  303. };
  304. /* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
  305. static struct regulator_init_data beagle_vdac = {
  306. .constraints = {
  307. .min_uV = 1800000,
  308. .max_uV = 1800000,
  309. .valid_modes_mask = REGULATOR_MODE_NORMAL
  310. | REGULATOR_MODE_STANDBY,
  311. .valid_ops_mask = REGULATOR_CHANGE_MODE
  312. | REGULATOR_CHANGE_STATUS,
  313. },
  314. .num_consumer_supplies = 1,
  315. .consumer_supplies = &beagle_vdac_supply,
  316. };
  317. /* VPLL2 for digital video outputs */
  318. static struct regulator_init_data beagle_vpll2 = {
  319. .constraints = {
  320. .name = "VDVI",
  321. .min_uV = 1800000,
  322. .max_uV = 1800000,
  323. .valid_modes_mask = REGULATOR_MODE_NORMAL
  324. | REGULATOR_MODE_STANDBY,
  325. .valid_ops_mask = REGULATOR_CHANGE_MODE
  326. | REGULATOR_CHANGE_STATUS,
  327. },
  328. .num_consumer_supplies = 1,
  329. .consumer_supplies = &beagle_vdvi_supply,
  330. };
  331. static struct twl4030_usb_data beagle_usb_data = {
  332. .usb_mode = T2_USB_MODE_ULPI,
  333. };
  334. static struct twl4030_codec_audio_data beagle_audio_data = {
  335. .audio_mclk = 26000000,
  336. };
  337. static struct twl4030_codec_data beagle_codec_data = {
  338. .audio_mclk = 26000000,
  339. .audio = &beagle_audio_data,
  340. };
  341. static struct twl4030_platform_data beagle_twldata = {
  342. .irq_base = TWL4030_IRQ_BASE,
  343. .irq_end = TWL4030_IRQ_END,
  344. /* platform_data for children goes here */
  345. .usb = &beagle_usb_data,
  346. .gpio = &beagle_gpio_data,
  347. .codec = &beagle_codec_data,
  348. .vmmc1 = &beagle_vmmc1,
  349. .vsim = &beagle_vsim,
  350. .vdac = &beagle_vdac,
  351. .vpll2 = &beagle_vpll2,
  352. };
  353. static struct i2c_board_info __initdata beagle_i2c_boardinfo[] = {
  354. {
  355. I2C_BOARD_INFO("twl4030", 0x48),
  356. .flags = I2C_CLIENT_WAKE,
  357. .irq = INT_34XX_SYS_NIRQ,
  358. .platform_data = &beagle_twldata,
  359. },
  360. };
  361. static struct i2c_board_info __initdata beagle_i2c_eeprom[] = {
  362. {
  363. I2C_BOARD_INFO("eeprom", 0x50),
  364. },
  365. };
  366. static int __init omap3_beagle_i2c_init(void)
  367. {
  368. omap_register_i2c_bus(1, 2600, beagle_i2c_boardinfo,
  369. ARRAY_SIZE(beagle_i2c_boardinfo));
  370. /* Bus 3 is attached to the DVI port where devices like the pico DLP
  371. * projector don't work reliably with 400kHz */
  372. omap_register_i2c_bus(3, 100, beagle_i2c_eeprom, ARRAY_SIZE(beagle_i2c_eeprom));
  373. return 0;
  374. }
  375. static struct gpio_led gpio_leds[] = {
  376. {
  377. .name = "beagleboard::usr0",
  378. .default_trigger = "heartbeat",
  379. .gpio = 150,
  380. },
  381. {
  382. .name = "beagleboard::usr1",
  383. .default_trigger = "mmc0",
  384. .gpio = 149,
  385. },
  386. {
  387. .name = "beagleboard::pmu_stat",
  388. .gpio = -EINVAL, /* gets replaced */
  389. .active_low = true,
  390. },
  391. };
  392. static struct gpio_led_platform_data gpio_led_info = {
  393. .leds = gpio_leds,
  394. .num_leds = ARRAY_SIZE(gpio_leds),
  395. };
  396. static struct platform_device leds_gpio = {
  397. .name = "leds-gpio",
  398. .id = -1,
  399. .dev = {
  400. .platform_data = &gpio_led_info,
  401. },
  402. };
  403. static struct gpio_keys_button gpio_buttons[] = {
  404. {
  405. .code = BTN_EXTRA,
  406. .gpio = 7,
  407. .desc = "user",
  408. .wakeup = 1,
  409. },
  410. };
  411. static struct gpio_keys_platform_data gpio_key_info = {
  412. .buttons = gpio_buttons,
  413. .nbuttons = ARRAY_SIZE(gpio_buttons),
  414. };
  415. static struct platform_device keys_gpio = {
  416. .name = "gpio-keys",
  417. .id = -1,
  418. .dev = {
  419. .platform_data = &gpio_key_info,
  420. },
  421. };
  422. static void __init omap3_beagle_init_irq(void)
  423. {
  424. omap2_init_common_infrastructure();
  425. omap2_init_common_devices(mt46h32m32lf6_sdrc_params,
  426. mt46h32m32lf6_sdrc_params);
  427. omap_init_irq();
  428. #ifdef CONFIG_OMAP_32K_TIMER
  429. omap2_gp_clockevent_set_gptimer(12);
  430. #endif
  431. }
  432. static struct platform_device *omap3_beagle_devices[] __initdata = {
  433. &leds_gpio,
  434. &keys_gpio,
  435. &beagle_dss_device,
  436. };
  437. static void __init omap3beagle_flash_init(void)
  438. {
  439. u8 cs = 0;
  440. u8 nandcs = GPMC_CS_NUM + 1;
  441. /* find out the chip-select on which NAND exists */
  442. while (cs < GPMC_CS_NUM) {
  443. u32 ret = 0;
  444. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  445. if ((ret & 0xC00) == 0x800) {
  446. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  447. if (nandcs > GPMC_CS_NUM)
  448. nandcs = cs;
  449. }
  450. cs++;
  451. }
  452. if (nandcs > GPMC_CS_NUM) {
  453. printk(KERN_INFO "NAND: Unable to find configuration "
  454. "in GPMC\n ");
  455. return;
  456. }
  457. if (nandcs < GPMC_CS_NUM) {
  458. omap3beagle_nand_data.cs = nandcs;
  459. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  460. if (gpmc_nand_init(&omap3beagle_nand_data) < 0)
  461. printk(KERN_ERR "Unable to register NAND device\n");
  462. }
  463. }
  464. static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
  465. .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
  466. .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
  467. .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
  468. .phy_reset = true,
  469. .reset_gpio_port[0] = -EINVAL,
  470. .reset_gpio_port[1] = 147,
  471. .reset_gpio_port[2] = -EINVAL
  472. };
  473. #ifdef CONFIG_OMAP_MUX
  474. static struct omap_board_mux board_mux[] __initdata = {
  475. { .reg_offset = OMAP_MUX_TERMINATOR },
  476. };
  477. #endif
  478. static struct omap_musb_board_data musb_board_data = {
  479. .interface_type = MUSB_INTERFACE_ULPI,
  480. .mode = MUSB_OTG,
  481. .power = 100,
  482. };
  483. static void __init omap3_beagle_init(void)
  484. {
  485. omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
  486. omap3_beagle_init_rev();
  487. omap3_beagle_i2c_init();
  488. platform_add_devices(omap3_beagle_devices,
  489. ARRAY_SIZE(omap3_beagle_devices));
  490. omap_serial_init();
  491. omap_mux_init_gpio(170, OMAP_PIN_INPUT);
  492. gpio_request(170, "DVI_nPD");
  493. /* REVISIT leave DVI powered down until it's needed ... */
  494. gpio_direction_output(170, true);
  495. usb_musb_init(&musb_board_data);
  496. usb_ehci_init(&ehci_pdata);
  497. omap3beagle_flash_init();
  498. /* Ensure SDRC pins are mux'd for self-refresh */
  499. omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
  500. omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
  501. beagle_display_init();
  502. }
  503. MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
  504. /* Maintainer: Syed Mohammed Khasim - http://beagleboard.org */
  505. .boot_params = 0x80000100,
  506. .map_io = omap3_map_io,
  507. .reserve = omap_reserve,
  508. .init_irq = omap3_beagle_init_irq,
  509. .init_machine = omap3_beagle_init,
  510. .timer = &omap_timer,
  511. MACHINE_END