board-omap3touchbook.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. /*
  2. * linux/arch/arm/mach-omap2/board-omap3touchbook.c
  3. *
  4. * Copyright (C) 2009 Always Innovating
  5. *
  6. * Modified from mach-omap2/board-omap3beagleboard.c
  7. *
  8. * Initial code: Grégoire Gentil, Tim Yamin
  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 <plat/mcspi.h>
  30. #include <linux/spi/spi.h>
  31. #include <linux/spi/ads7846.h>
  32. #include <linux/regulator/machine.h>
  33. #include <linux/i2c/twl.h>
  34. #include <mach/hardware.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 <plat/board.h>
  40. #include <plat/common.h>
  41. #include <plat/gpmc.h>
  42. #include <plat/nand.h>
  43. #include <plat/usb.h>
  44. #include "mux.h"
  45. #include "hsmmc.h"
  46. #include "timer-gp.h"
  47. #include "common-board-devices.h"
  48. #include <asm/setup.h>
  49. #define NAND_BLOCK_SIZE SZ_128K
  50. #define OMAP3_AC_GPIO 136
  51. #define OMAP3_TS_GPIO 162
  52. #define TB_BL_PWM_TIMER 9
  53. #define TB_KILL_POWER_GPIO 168
  54. static unsigned long touchbook_revision;
  55. static struct mtd_partition omap3touchbook_nand_partitions[] = {
  56. /* All the partition sizes are listed in terms of NAND block size */
  57. {
  58. .name = "X-Loader",
  59. .offset = 0,
  60. .size = 4 * NAND_BLOCK_SIZE,
  61. .mask_flags = MTD_WRITEABLE, /* force read-only */
  62. },
  63. {
  64. .name = "U-Boot",
  65. .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
  66. .size = 15 * NAND_BLOCK_SIZE,
  67. .mask_flags = MTD_WRITEABLE, /* force read-only */
  68. },
  69. {
  70. .name = "U-Boot Env",
  71. .offset = MTDPART_OFS_APPEND, /* Offset = 0x260000 */
  72. .size = 1 * NAND_BLOCK_SIZE,
  73. },
  74. {
  75. .name = "Kernel",
  76. .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
  77. .size = 32 * NAND_BLOCK_SIZE,
  78. },
  79. {
  80. .name = "File System",
  81. .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
  82. .size = MTDPART_SIZ_FULL,
  83. },
  84. };
  85. static struct omap_nand_platform_data omap3touchbook_nand_data = {
  86. .options = NAND_BUSWIDTH_16,
  87. .parts = omap3touchbook_nand_partitions,
  88. .nr_parts = ARRAY_SIZE(omap3touchbook_nand_partitions),
  89. .dma_channel = -1, /* disable DMA in OMAP NAND driver */
  90. .nand_setup = NULL,
  91. .dev_ready = NULL,
  92. };
  93. #include "sdram-micron-mt46h32m32lf-6.h"
  94. static struct omap2_hsmmc_info mmc[] = {
  95. {
  96. .mmc = 1,
  97. .caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
  98. .gpio_wp = 29,
  99. },
  100. {} /* Terminator */
  101. };
  102. static struct platform_device omap3_touchbook_lcd_device = {
  103. .name = "omap3touchbook_lcd",
  104. .id = -1,
  105. };
  106. static struct omap_lcd_config omap3_touchbook_lcd_config __initdata = {
  107. .ctrl_name = "internal",
  108. };
  109. static struct regulator_consumer_supply touchbook_vmmc1_supply = {
  110. .supply = "vmmc",
  111. };
  112. static struct regulator_consumer_supply touchbook_vsim_supply = {
  113. .supply = "vmmc_aux",
  114. };
  115. static struct gpio_led gpio_leds[];
  116. static int touchbook_twl_gpio_setup(struct device *dev,
  117. unsigned gpio, unsigned ngpio)
  118. {
  119. if (system_rev >= 0x20 && system_rev <= 0x34301000) {
  120. omap_mux_init_gpio(23, OMAP_PIN_INPUT);
  121. mmc[0].gpio_wp = 23;
  122. } else {
  123. omap_mux_init_gpio(29, OMAP_PIN_INPUT);
  124. }
  125. /* gpio + 0 is "mmc0_cd" (input/IRQ) */
  126. mmc[0].gpio_cd = gpio + 0;
  127. omap2_hsmmc_init(mmc);
  128. /* link regulators to MMC adapters */
  129. touchbook_vmmc1_supply.dev = mmc[0].dev;
  130. touchbook_vsim_supply.dev = mmc[0].dev;
  131. /* REVISIT: need ehci-omap hooks for external VBUS
  132. * power switch and overcurrent detect
  133. */
  134. gpio_request(gpio + 1, "EHCI_nOC");
  135. gpio_direction_input(gpio + 1);
  136. /* TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, active low) */
  137. gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
  138. gpio_direction_output(gpio + TWL4030_GPIO_MAX, 0);
  139. /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
  140. gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
  141. return 0;
  142. }
  143. static struct twl4030_gpio_platform_data touchbook_gpio_data = {
  144. .gpio_base = OMAP_MAX_GPIO_LINES,
  145. .irq_base = TWL4030_GPIO_IRQ_BASE,
  146. .irq_end = TWL4030_GPIO_IRQ_END,
  147. .use_leds = true,
  148. .pullups = BIT(1),
  149. .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
  150. | BIT(15) | BIT(16) | BIT(17),
  151. .setup = touchbook_twl_gpio_setup,
  152. };
  153. static struct regulator_consumer_supply touchbook_vdac_supply = {
  154. .supply = "vdac",
  155. .dev = &omap3_touchbook_lcd_device.dev,
  156. };
  157. static struct regulator_consumer_supply touchbook_vdvi_supply = {
  158. .supply = "vdvi",
  159. .dev = &omap3_touchbook_lcd_device.dev,
  160. };
  161. /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
  162. static struct regulator_init_data touchbook_vmmc1 = {
  163. .constraints = {
  164. .min_uV = 1850000,
  165. .max_uV = 3150000,
  166. .valid_modes_mask = REGULATOR_MODE_NORMAL
  167. | REGULATOR_MODE_STANDBY,
  168. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  169. | REGULATOR_CHANGE_MODE
  170. | REGULATOR_CHANGE_STATUS,
  171. },
  172. .num_consumer_supplies = 1,
  173. .consumer_supplies = &touchbook_vmmc1_supply,
  174. };
  175. /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
  176. static struct regulator_init_data touchbook_vsim = {
  177. .constraints = {
  178. .min_uV = 1800000,
  179. .max_uV = 3000000,
  180. .valid_modes_mask = REGULATOR_MODE_NORMAL
  181. | REGULATOR_MODE_STANDBY,
  182. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  183. | REGULATOR_CHANGE_MODE
  184. | REGULATOR_CHANGE_STATUS,
  185. },
  186. .num_consumer_supplies = 1,
  187. .consumer_supplies = &touchbook_vsim_supply,
  188. };
  189. /* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
  190. static struct regulator_init_data touchbook_vdac = {
  191. .constraints = {
  192. .min_uV = 1800000,
  193. .max_uV = 1800000,
  194. .valid_modes_mask = REGULATOR_MODE_NORMAL
  195. | REGULATOR_MODE_STANDBY,
  196. .valid_ops_mask = REGULATOR_CHANGE_MODE
  197. | REGULATOR_CHANGE_STATUS,
  198. },
  199. .num_consumer_supplies = 1,
  200. .consumer_supplies = &touchbook_vdac_supply,
  201. };
  202. /* VPLL2 for digital video outputs */
  203. static struct regulator_init_data touchbook_vpll2 = {
  204. .constraints = {
  205. .name = "VDVI",
  206. .min_uV = 1800000,
  207. .max_uV = 1800000,
  208. .valid_modes_mask = REGULATOR_MODE_NORMAL
  209. | REGULATOR_MODE_STANDBY,
  210. .valid_ops_mask = REGULATOR_CHANGE_MODE
  211. | REGULATOR_CHANGE_STATUS,
  212. },
  213. .num_consumer_supplies = 1,
  214. .consumer_supplies = &touchbook_vdvi_supply,
  215. };
  216. static struct twl4030_usb_data touchbook_usb_data = {
  217. .usb_mode = T2_USB_MODE_ULPI,
  218. };
  219. static struct twl4030_codec_audio_data touchbook_audio_data;
  220. static struct twl4030_codec_data touchbook_codec_data = {
  221. .audio_mclk = 26000000,
  222. .audio = &touchbook_audio_data,
  223. };
  224. static struct twl4030_platform_data touchbook_twldata = {
  225. .irq_base = TWL4030_IRQ_BASE,
  226. .irq_end = TWL4030_IRQ_END,
  227. /* platform_data for children goes here */
  228. .usb = &touchbook_usb_data,
  229. .gpio = &touchbook_gpio_data,
  230. .codec = &touchbook_codec_data,
  231. .vmmc1 = &touchbook_vmmc1,
  232. .vsim = &touchbook_vsim,
  233. .vdac = &touchbook_vdac,
  234. .vpll2 = &touchbook_vpll2,
  235. };
  236. static struct i2c_board_info __initdata touchBook_i2c_boardinfo[] = {
  237. {
  238. I2C_BOARD_INFO("bq27200", 0x55),
  239. },
  240. };
  241. static int __init omap3_touchbook_i2c_init(void)
  242. {
  243. /* Standard TouchBook bus */
  244. omap3_pmic_init("twl4030", &touchbook_twldata);
  245. /* Additional TouchBook bus */
  246. omap_register_i2c_bus(3, 100, touchBook_i2c_boardinfo,
  247. ARRAY_SIZE(touchBook_i2c_boardinfo));
  248. return 0;
  249. }
  250. static struct ads7846_platform_data ads7846_pdata = {
  251. .x_min = 100,
  252. .y_min = 265,
  253. .x_max = 3950,
  254. .y_max = 3750,
  255. .x_plate_ohms = 40,
  256. .pressure_max = 255,
  257. .debounce_max = 10,
  258. .debounce_tol = 5,
  259. .debounce_rep = 1,
  260. .gpio_pendown = OMAP3_TS_GPIO,
  261. .keep_vref_on = 1,
  262. };
  263. static struct gpio_led gpio_leds[] = {
  264. {
  265. .name = "touchbook::usr0",
  266. .default_trigger = "heartbeat",
  267. .gpio = 150,
  268. },
  269. {
  270. .name = "touchbook::usr1",
  271. .default_trigger = "mmc0",
  272. .gpio = 149,
  273. },
  274. {
  275. .name = "touchbook::pmu_stat",
  276. .gpio = -EINVAL, /* gets replaced */
  277. .active_low = true,
  278. },
  279. };
  280. static struct gpio_led_platform_data gpio_led_info = {
  281. .leds = gpio_leds,
  282. .num_leds = ARRAY_SIZE(gpio_leds),
  283. };
  284. static struct platform_device leds_gpio = {
  285. .name = "leds-gpio",
  286. .id = -1,
  287. .dev = {
  288. .platform_data = &gpio_led_info,
  289. },
  290. };
  291. static struct gpio_keys_button gpio_buttons[] = {
  292. {
  293. .code = BTN_EXTRA,
  294. .gpio = 7,
  295. .desc = "user",
  296. .wakeup = 1,
  297. },
  298. {
  299. .code = KEY_POWER,
  300. .gpio = 183,
  301. .desc = "power",
  302. .wakeup = 1,
  303. },
  304. };
  305. static struct gpio_keys_platform_data gpio_key_info = {
  306. .buttons = gpio_buttons,
  307. .nbuttons = ARRAY_SIZE(gpio_buttons),
  308. };
  309. static struct platform_device keys_gpio = {
  310. .name = "gpio-keys",
  311. .id = -1,
  312. .dev = {
  313. .platform_data = &gpio_key_info,
  314. },
  315. };
  316. static struct omap_board_config_kernel omap3_touchbook_config[] __initdata = {
  317. { OMAP_TAG_LCD, &omap3_touchbook_lcd_config },
  318. };
  319. #ifdef CONFIG_OMAP_MUX
  320. static struct omap_board_mux board_mux[] __initdata = {
  321. { .reg_offset = OMAP_MUX_TERMINATOR },
  322. };
  323. #endif
  324. static void __init omap3_touchbook_init_early(void)
  325. {
  326. omap2_init_common_infrastructure();
  327. omap2_init_common_devices(mt46h32m32lf6_sdrc_params,
  328. mt46h32m32lf6_sdrc_params);
  329. }
  330. static void __init omap3_touchbook_init_irq(void)
  331. {
  332. omap_init_irq();
  333. #ifdef CONFIG_OMAP_32K_TIMER
  334. omap2_gp_clockevent_set_gptimer(12);
  335. #endif
  336. }
  337. static struct platform_device *omap3_touchbook_devices[] __initdata = {
  338. &omap3_touchbook_lcd_device,
  339. &leds_gpio,
  340. &keys_gpio,
  341. };
  342. static void __init omap3touchbook_flash_init(void)
  343. {
  344. u8 cs = 0;
  345. u8 nandcs = GPMC_CS_NUM + 1;
  346. /* find out the chip-select on which NAND exists */
  347. while (cs < GPMC_CS_NUM) {
  348. u32 ret = 0;
  349. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  350. if ((ret & 0xC00) == 0x800) {
  351. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  352. if (nandcs > GPMC_CS_NUM)
  353. nandcs = cs;
  354. }
  355. cs++;
  356. }
  357. if (nandcs > GPMC_CS_NUM) {
  358. printk(KERN_INFO "NAND: Unable to find configuration "
  359. "in GPMC\n ");
  360. return;
  361. }
  362. if (nandcs < GPMC_CS_NUM) {
  363. omap3touchbook_nand_data.cs = nandcs;
  364. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  365. if (gpmc_nand_init(&omap3touchbook_nand_data) < 0)
  366. printk(KERN_ERR "Unable to register NAND device\n");
  367. }
  368. }
  369. static const struct usbhs_omap_board_data usbhs_bdata __initconst = {
  370. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  371. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  372. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
  373. .phy_reset = true,
  374. .reset_gpio_port[0] = -EINVAL,
  375. .reset_gpio_port[1] = 147,
  376. .reset_gpio_port[2] = -EINVAL
  377. };
  378. static void omap3_touchbook_poweroff(void)
  379. {
  380. int r;
  381. r = gpio_request(TB_KILL_POWER_GPIO, "DVI reset");
  382. if (r < 0) {
  383. printk(KERN_ERR "Unable to get kill power GPIO\n");
  384. return;
  385. }
  386. gpio_direction_output(TB_KILL_POWER_GPIO, 0);
  387. }
  388. static int __init early_touchbook_revision(char *p)
  389. {
  390. if (!p)
  391. return 0;
  392. return strict_strtoul(p, 10, &touchbook_revision);
  393. }
  394. early_param("tbr", early_touchbook_revision);
  395. static struct omap_musb_board_data musb_board_data = {
  396. .interface_type = MUSB_INTERFACE_ULPI,
  397. .mode = MUSB_OTG,
  398. .power = 100,
  399. };
  400. static void __init omap3_touchbook_init(void)
  401. {
  402. omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
  403. omap_board_config = omap3_touchbook_config;
  404. omap_board_config_size = ARRAY_SIZE(omap3_touchbook_config);
  405. pm_power_off = omap3_touchbook_poweroff;
  406. omap3_touchbook_i2c_init();
  407. platform_add_devices(omap3_touchbook_devices,
  408. ARRAY_SIZE(omap3_touchbook_devices));
  409. omap_serial_init();
  410. omap_mux_init_gpio(170, OMAP_PIN_INPUT);
  411. gpio_request(176, "DVI_nPD");
  412. /* REVISIT leave DVI powered down until it's needed ... */
  413. gpio_direction_output(176, true);
  414. /* Touchscreen and accelerometer */
  415. omap_ads7846_init(4, OMAP3_TS_GPIO, 310, &ads7846_pdata);
  416. usb_musb_init(&musb_board_data);
  417. usbhs_init(&usbhs_bdata);
  418. omap3touchbook_flash_init();
  419. /* Ensure SDRC pins are mux'd for self-refresh */
  420. omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
  421. omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
  422. }
  423. MACHINE_START(TOUCHBOOK, "OMAP3 touchbook Board")
  424. /* Maintainer: Gregoire Gentil - http://www.alwaysinnovating.com */
  425. .boot_params = 0x80000100,
  426. .reserve = omap_reserve,
  427. .map_io = omap3_map_io,
  428. .init_early = omap3_touchbook_init_early,
  429. .init_irq = omap3_touchbook_init_irq,
  430. .init_machine = omap3_touchbook_init,
  431. .timer = &omap_timer,
  432. MACHINE_END