PageRenderTime 345ms CodeModel.GetById 33ms RepoModel.GetById 2ms app.codeStats 0ms

/arch/arm/mach-omap2/board-omap3touchbook.c

https://bitbucket.org/sammyz/iscream_thunderc-2.6.35-rebase
C | 577 lines | 458 code | 86 blank | 33 comment | 13 complexity | 951d8019b9acb06389a4474fa190580b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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 GPMC_CS0_BASE 0x60
  48. #define GPMC_CS_SIZE 0x30
  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. 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. static struct resource omap3touchbook_nand_resource = {
  94. .flags = IORESOURCE_MEM,
  95. };
  96. static struct platform_device omap3touchbook_nand_device = {
  97. .name = "omap2-nand",
  98. .id = -1,
  99. .dev = {
  100. .platform_data = &omap3touchbook_nand_data,
  101. },
  102. .num_resources = 1,
  103. .resource = &omap3touchbook_nand_resource,
  104. };
  105. #include "sdram-micron-mt46h32m32lf-6.h"
  106. static struct omap2_hsmmc_info mmc[] = {
  107. {
  108. .mmc = 1,
  109. .wires = 8,
  110. .gpio_wp = 29,
  111. },
  112. {} /* Terminator */
  113. };
  114. static struct platform_device omap3_touchbook_lcd_device = {
  115. .name = "omap3touchbook_lcd",
  116. .id = -1,
  117. };
  118. static struct omap_lcd_config omap3_touchbook_lcd_config __initdata = {
  119. .ctrl_name = "internal",
  120. };
  121. static struct regulator_consumer_supply touchbook_vmmc1_supply = {
  122. .supply = "vmmc",
  123. };
  124. static struct regulator_consumer_supply touchbook_vsim_supply = {
  125. .supply = "vmmc_aux",
  126. };
  127. static struct gpio_led gpio_leds[];
  128. static int touchbook_twl_gpio_setup(struct device *dev,
  129. unsigned gpio, unsigned ngpio)
  130. {
  131. if (system_rev >= 0x20 && system_rev <= 0x34301000) {
  132. omap_mux_init_gpio(23, OMAP_PIN_INPUT);
  133. mmc[0].gpio_wp = 23;
  134. } else {
  135. omap_mux_init_gpio(29, OMAP_PIN_INPUT);
  136. }
  137. /* gpio + 0 is "mmc0_cd" (input/IRQ) */
  138. mmc[0].gpio_cd = gpio + 0;
  139. omap2_hsmmc_init(mmc);
  140. /* link regulators to MMC adapters */
  141. touchbook_vmmc1_supply.dev = mmc[0].dev;
  142. touchbook_vsim_supply.dev = mmc[0].dev;
  143. /* REVISIT: need ehci-omap hooks for external VBUS
  144. * power switch and overcurrent detect
  145. */
  146. gpio_request(gpio + 1, "EHCI_nOC");
  147. gpio_direction_input(gpio + 1);
  148. /* TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, active low) */
  149. gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
  150. gpio_direction_output(gpio + TWL4030_GPIO_MAX, 0);
  151. /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
  152. gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
  153. return 0;
  154. }
  155. static struct twl4030_gpio_platform_data touchbook_gpio_data = {
  156. .gpio_base = OMAP_MAX_GPIO_LINES,
  157. .irq_base = TWL4030_GPIO_IRQ_BASE,
  158. .irq_end = TWL4030_GPIO_IRQ_END,
  159. .use_leds = true,
  160. .pullups = BIT(1),
  161. .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
  162. | BIT(15) | BIT(16) | BIT(17),
  163. .setup = touchbook_twl_gpio_setup,
  164. };
  165. static struct regulator_consumer_supply touchbook_vdac_supply = {
  166. .supply = "vdac",
  167. .dev = &omap3_touchbook_lcd_device.dev,
  168. };
  169. static struct regulator_consumer_supply touchbook_vdvi_supply = {
  170. .supply = "vdvi",
  171. .dev = &omap3_touchbook_lcd_device.dev,
  172. };
  173. /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
  174. static struct regulator_init_data touchbook_vmmc1 = {
  175. .constraints = {
  176. .min_uV = 1850000,
  177. .max_uV = 3150000,
  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_vmmc1_supply,
  186. };
  187. /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
  188. static struct regulator_init_data touchbook_vsim = {
  189. .constraints = {
  190. .min_uV = 1800000,
  191. .max_uV = 3000000,
  192. .valid_modes_mask = REGULATOR_MODE_NORMAL
  193. | REGULATOR_MODE_STANDBY,
  194. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  195. | REGULATOR_CHANGE_MODE
  196. | REGULATOR_CHANGE_STATUS,
  197. },
  198. .num_consumer_supplies = 1,
  199. .consumer_supplies = &touchbook_vsim_supply,
  200. };
  201. /* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
  202. static struct regulator_init_data touchbook_vdac = {
  203. .constraints = {
  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_vdac_supply,
  213. };
  214. /* VPLL2 for digital video outputs */
  215. static struct regulator_init_data touchbook_vpll2 = {
  216. .constraints = {
  217. .name = "VDVI",
  218. .min_uV = 1800000,
  219. .max_uV = 1800000,
  220. .valid_modes_mask = REGULATOR_MODE_NORMAL
  221. | REGULATOR_MODE_STANDBY,
  222. .valid_ops_mask = REGULATOR_CHANGE_MODE
  223. | REGULATOR_CHANGE_STATUS,
  224. },
  225. .num_consumer_supplies = 1,
  226. .consumer_supplies = &touchbook_vdvi_supply,
  227. };
  228. static struct twl4030_usb_data touchbook_usb_data = {
  229. .usb_mode = T2_USB_MODE_ULPI,
  230. };
  231. static struct twl4030_codec_audio_data touchbook_audio_data = {
  232. .audio_mclk = 26000000,
  233. };
  234. static struct twl4030_codec_data touchbook_codec_data = {
  235. .audio_mclk = 26000000,
  236. .audio = &touchbook_audio_data,
  237. };
  238. static struct twl4030_platform_data touchbook_twldata = {
  239. .irq_base = TWL4030_IRQ_BASE,
  240. .irq_end = TWL4030_IRQ_END,
  241. /* platform_data for children goes here */
  242. .usb = &touchbook_usb_data,
  243. .gpio = &touchbook_gpio_data,
  244. .codec = &touchbook_codec_data,
  245. .vmmc1 = &touchbook_vmmc1,
  246. .vsim = &touchbook_vsim,
  247. .vdac = &touchbook_vdac,
  248. .vpll2 = &touchbook_vpll2,
  249. };
  250. static struct i2c_board_info __initdata touchbook_i2c_boardinfo[] = {
  251. {
  252. I2C_BOARD_INFO("twl4030", 0x48),
  253. .flags = I2C_CLIENT_WAKE,
  254. .irq = INT_34XX_SYS_NIRQ,
  255. .platform_data = &touchbook_twldata,
  256. },
  257. };
  258. static struct i2c_board_info __initdata touchBook_i2c_boardinfo[] = {
  259. {
  260. I2C_BOARD_INFO("bq27200", 0x55),
  261. },
  262. };
  263. static int __init omap3_touchbook_i2c_init(void)
  264. {
  265. /* Standard TouchBook bus */
  266. omap_register_i2c_bus(1, 2600, touchbook_i2c_boardinfo,
  267. ARRAY_SIZE(touchbook_i2c_boardinfo));
  268. /* Additional TouchBook bus */
  269. omap_register_i2c_bus(3, 100, touchBook_i2c_boardinfo,
  270. ARRAY_SIZE(touchBook_i2c_boardinfo));
  271. return 0;
  272. }
  273. static void __init omap3_ads7846_init(void)
  274. {
  275. if (gpio_request(OMAP3_TS_GPIO, "ads7846_pen_down")) {
  276. printk(KERN_ERR "Failed to request GPIO %d for "
  277. "ads7846 pen down IRQ\n", OMAP3_TS_GPIO);
  278. return;
  279. }
  280. gpio_direction_input(OMAP3_TS_GPIO);
  281. gpio_set_debounce(OMAP3_TS_GPIO, 310);
  282. }
  283. static struct ads7846_platform_data ads7846_config = {
  284. .x_min = 100,
  285. .y_min = 265,
  286. .x_max = 3950,
  287. .y_max = 3750,
  288. .x_plate_ohms = 40,
  289. .pressure_max = 255,
  290. .debounce_max = 10,
  291. .debounce_tol = 5,
  292. .debounce_rep = 1,
  293. .gpio_pendown = OMAP3_TS_GPIO,
  294. .keep_vref_on = 1,
  295. };
  296. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  297. .turbo_mode = 0,
  298. .single_channel = 1, /* 0: slave, 1: master */
  299. };
  300. static struct spi_board_info omap3_ads7846_spi_board_info[] __initdata = {
  301. {
  302. .modalias = "ads7846",
  303. .bus_num = 4,
  304. .chip_select = 0,
  305. .max_speed_hz = 1500000,
  306. .controller_data = &ads7846_mcspi_config,
  307. .irq = OMAP_GPIO_IRQ(OMAP3_TS_GPIO),
  308. .platform_data = &ads7846_config,
  309. }
  310. };
  311. static struct gpio_led gpio_leds[] = {
  312. {
  313. .name = "touchbook::usr0",
  314. .default_trigger = "heartbeat",
  315. .gpio = 150,
  316. },
  317. {
  318. .name = "touchbook::usr1",
  319. .default_trigger = "mmc0",
  320. .gpio = 149,
  321. },
  322. {
  323. .name = "touchbook::pmu_stat",
  324. .gpio = -EINVAL, /* gets replaced */
  325. .active_low = true,
  326. },
  327. };
  328. static struct gpio_led_platform_data gpio_led_info = {
  329. .leds = gpio_leds,
  330. .num_leds = ARRAY_SIZE(gpio_leds),
  331. };
  332. static struct platform_device leds_gpio = {
  333. .name = "leds-gpio",
  334. .id = -1,
  335. .dev = {
  336. .platform_data = &gpio_led_info,
  337. },
  338. };
  339. static struct gpio_keys_button gpio_buttons[] = {
  340. {
  341. .code = BTN_EXTRA,
  342. .gpio = 7,
  343. .desc = "user",
  344. .wakeup = 1,
  345. },
  346. {
  347. .code = KEY_POWER,
  348. .gpio = 183,
  349. .desc = "power",
  350. .wakeup = 1,
  351. },
  352. };
  353. static struct gpio_keys_platform_data gpio_key_info = {
  354. .buttons = gpio_buttons,
  355. .nbuttons = ARRAY_SIZE(gpio_buttons),
  356. };
  357. static struct platform_device keys_gpio = {
  358. .name = "gpio-keys",
  359. .id = -1,
  360. .dev = {
  361. .platform_data = &gpio_key_info,
  362. },
  363. };
  364. static struct omap_board_config_kernel omap3_touchbook_config[] __initdata = {
  365. { OMAP_TAG_LCD, &omap3_touchbook_lcd_config },
  366. };
  367. #ifdef CONFIG_OMAP_MUX
  368. static struct omap_board_mux board_mux[] __initdata = {
  369. { .reg_offset = OMAP_MUX_TERMINATOR },
  370. };
  371. #else
  372. #define board_mux NULL
  373. #endif
  374. static void __init omap3_touchbook_init_irq(void)
  375. {
  376. omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
  377. omap_board_config = omap3_touchbook_config;
  378. omap_board_config_size = ARRAY_SIZE(omap3_touchbook_config);
  379. omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
  380. mt46h32m32lf6_sdrc_params);
  381. omap_init_irq();
  382. #ifdef CONFIG_OMAP_32K_TIMER
  383. omap2_gp_clockevent_set_gptimer(12);
  384. #endif
  385. omap_gpio_init();
  386. }
  387. static struct platform_device *omap3_touchbook_devices[] __initdata = {
  388. &omap3_touchbook_lcd_device,
  389. &leds_gpio,
  390. &keys_gpio,
  391. };
  392. static void __init omap3touchbook_flash_init(void)
  393. {
  394. u8 cs = 0;
  395. u8 nandcs = GPMC_CS_NUM + 1;
  396. u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
  397. /* find out the chip-select on which NAND exists */
  398. while (cs < GPMC_CS_NUM) {
  399. u32 ret = 0;
  400. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  401. if ((ret & 0xC00) == 0x800) {
  402. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  403. if (nandcs > GPMC_CS_NUM)
  404. nandcs = cs;
  405. }
  406. cs++;
  407. }
  408. if (nandcs > GPMC_CS_NUM) {
  409. printk(KERN_INFO "NAND: Unable to find configuration "
  410. "in GPMC\n ");
  411. return;
  412. }
  413. if (nandcs < GPMC_CS_NUM) {
  414. omap3touchbook_nand_data.cs = nandcs;
  415. omap3touchbook_nand_data.gpmc_cs_baseaddr = (void *)
  416. (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
  417. omap3touchbook_nand_data.gpmc_baseaddr =
  418. (void *) (gpmc_base_add);
  419. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  420. if (platform_device_register(&omap3touchbook_nand_device) < 0)
  421. printk(KERN_ERR "Unable to register NAND device\n");
  422. }
  423. }
  424. static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
  425. .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
  426. .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
  427. .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
  428. .phy_reset = true,
  429. .reset_gpio_port[0] = -EINVAL,
  430. .reset_gpio_port[1] = 147,
  431. .reset_gpio_port[2] = -EINVAL
  432. };
  433. static void omap3_touchbook_poweroff(void)
  434. {
  435. int r;
  436. r = gpio_request(TB_KILL_POWER_GPIO, "DVI reset");
  437. if (r < 0) {
  438. printk(KERN_ERR "Unable to get kill power GPIO\n");
  439. return;
  440. }
  441. gpio_direction_output(TB_KILL_POWER_GPIO, 0);
  442. }
  443. static int __init early_touchbook_revision(char *p)
  444. {
  445. if (!p)
  446. return 0;
  447. return strict_strtoul(p, 10, &touchbook_revision);
  448. }
  449. early_param("tbr", early_touchbook_revision);
  450. static struct omap_musb_board_data musb_board_data = {
  451. .interface_type = MUSB_INTERFACE_ULPI,
  452. .mode = MUSB_OTG,
  453. .power = 100,
  454. };
  455. static void __init omap3_touchbook_init(void)
  456. {
  457. pm_power_off = omap3_touchbook_poweroff;
  458. omap3_touchbook_i2c_init();
  459. platform_add_devices(omap3_touchbook_devices,
  460. ARRAY_SIZE(omap3_touchbook_devices));
  461. omap_serial_init();
  462. omap_mux_init_gpio(170, OMAP_PIN_INPUT);
  463. gpio_request(176, "DVI_nPD");
  464. /* REVISIT leave DVI powered down until it's needed ... */
  465. gpio_direction_output(176, true);
  466. /* Touchscreen and accelerometer */
  467. spi_register_board_info(omap3_ads7846_spi_board_info,
  468. ARRAY_SIZE(omap3_ads7846_spi_board_info));
  469. omap3_ads7846_init();
  470. usb_musb_init(&musb_board_data);
  471. usb_ehci_init(&ehci_pdata);
  472. omap3touchbook_flash_init();
  473. /* Ensure SDRC pins are mux'd for self-refresh */
  474. omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
  475. omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
  476. }
  477. static void __init omap3_touchbook_map_io(void)
  478. {
  479. omap2_set_globals_343x();
  480. omap34xx_map_common_io();
  481. }
  482. MACHINE_START(TOUCHBOOK, "OMAP3 touchbook Board")
  483. /* Maintainer: Gregoire Gentil - http://www.alwaysinnovating.com */
  484. .phys_io = 0x48000000,
  485. .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
  486. .boot_params = 0x80000100,
  487. .map_io = omap3_touchbook_map_io,
  488. .init_irq = omap3_touchbook_init_irq,
  489. .init_machine = omap3_touchbook_init,
  490. .timer = &omap_timer,
  491. MACHINE_END