board-omap3touchbook.c 13 KB

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