board-omap3pandora.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. * board-omap3pandora.c (Pandora Handheld Console)
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. *
  18. */
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/spi/spi.h>
  23. #include <linux/spi/ads7846.h>
  24. #include <linux/regulator/machine.h>
  25. #include <linux/i2c/twl.h>
  26. #include <linux/leds.h>
  27. #include <linux/input.h>
  28. #include <linux/input/matrix_keypad.h>
  29. #include <linux/gpio_keys.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/map.h>
  33. #include <plat/board.h>
  34. #include <plat/common.h>
  35. #include <mach/gpio.h>
  36. #include <mach/hardware.h>
  37. #include <plat/mcspi.h>
  38. #include <plat/usb.h>
  39. #include "mux.h"
  40. #include "sdram-micron-mt46h32m32lf-6.h"
  41. #include "mmc-twl4030.h"
  42. #define OMAP3_PANDORA_TS_GPIO 94
  43. /* hardware debounce: (value + 1) * 31us */
  44. #define GPIO_DEBOUNCE_TIME 127
  45. static struct gpio_led pandora_gpio_leds[] = {
  46. {
  47. .name = "pandora::sd1",
  48. .default_trigger = "mmc0",
  49. .gpio = 128,
  50. }, {
  51. .name = "pandora::sd2",
  52. .default_trigger = "mmc1",
  53. .gpio = 129,
  54. }, {
  55. .name = "pandora::bluetooth",
  56. .gpio = 158,
  57. }, {
  58. .name = "pandora::wifi",
  59. .gpio = 159,
  60. },
  61. };
  62. static struct gpio_led_platform_data pandora_gpio_led_data = {
  63. .leds = pandora_gpio_leds,
  64. .num_leds = ARRAY_SIZE(pandora_gpio_leds),
  65. };
  66. static struct platform_device pandora_leds_gpio = {
  67. .name = "leds-gpio",
  68. .id = -1,
  69. .dev = {
  70. .platform_data = &pandora_gpio_led_data,
  71. },
  72. };
  73. #define GPIO_BUTTON(gpio_num, ev_type, ev_code, act_low, descr) \
  74. { \
  75. .gpio = gpio_num, \
  76. .type = ev_type, \
  77. .code = ev_code, \
  78. .active_low = act_low, \
  79. .desc = "btn " descr, \
  80. }
  81. #define GPIO_BUTTON_LOW(gpio_num, event_code, description) \
  82. GPIO_BUTTON(gpio_num, EV_KEY, event_code, 1, description)
  83. static struct gpio_keys_button pandora_gpio_keys[] = {
  84. GPIO_BUTTON_LOW(110, KEY_UP, "up"),
  85. GPIO_BUTTON_LOW(103, KEY_DOWN, "down"),
  86. GPIO_BUTTON_LOW(96, KEY_LEFT, "left"),
  87. GPIO_BUTTON_LOW(98, KEY_RIGHT, "right"),
  88. GPIO_BUTTON_LOW(109, KEY_KP1, "game 1"),
  89. GPIO_BUTTON_LOW(111, KEY_KP2, "game 2"),
  90. GPIO_BUTTON_LOW(106, KEY_KP3, "game 3"),
  91. GPIO_BUTTON_LOW(101, KEY_KP4, "game 4"),
  92. GPIO_BUTTON_LOW(102, BTN_TL, "l"),
  93. GPIO_BUTTON_LOW(97, BTN_TL2, "l2"),
  94. GPIO_BUTTON_LOW(105, BTN_TR, "r"),
  95. GPIO_BUTTON_LOW(107, BTN_TR2, "r2"),
  96. GPIO_BUTTON_LOW(104, KEY_LEFTCTRL, "ctrl"),
  97. GPIO_BUTTON_LOW(99, KEY_MENU, "menu"),
  98. GPIO_BUTTON_LOW(176, KEY_COFFEE, "hold"),
  99. GPIO_BUTTON(100, EV_KEY, KEY_LEFTALT, 0, "alt"),
  100. GPIO_BUTTON(108, EV_SW, SW_LID, 1, "lid"),
  101. };
  102. static struct gpio_keys_platform_data pandora_gpio_key_info = {
  103. .buttons = pandora_gpio_keys,
  104. .nbuttons = ARRAY_SIZE(pandora_gpio_keys),
  105. };
  106. static struct platform_device pandora_keys_gpio = {
  107. .name = "gpio-keys",
  108. .id = -1,
  109. .dev = {
  110. .platform_data = &pandora_gpio_key_info,
  111. },
  112. };
  113. static void __init pandora_keys_gpio_init(void)
  114. {
  115. /* set debounce time for GPIO banks 4 and 6 */
  116. omap_set_gpio_debounce_time(32 * 3, GPIO_DEBOUNCE_TIME);
  117. omap_set_gpio_debounce_time(32 * 5, GPIO_DEBOUNCE_TIME);
  118. }
  119. static int board_keymap[] = {
  120. /* row, col, code */
  121. KEY(0, 0, KEY_9),
  122. KEY(0, 1, KEY_8),
  123. KEY(0, 2, KEY_I),
  124. KEY(0, 3, KEY_J),
  125. KEY(0, 4, KEY_N),
  126. KEY(0, 5, KEY_M),
  127. KEY(1, 0, KEY_0),
  128. KEY(1, 1, KEY_7),
  129. KEY(1, 2, KEY_U),
  130. KEY(1, 3, KEY_H),
  131. KEY(1, 4, KEY_B),
  132. KEY(1, 5, KEY_SPACE),
  133. KEY(2, 0, KEY_BACKSPACE),
  134. KEY(2, 1, KEY_6),
  135. KEY(2, 2, KEY_Y),
  136. KEY(2, 3, KEY_G),
  137. KEY(2, 4, KEY_V),
  138. KEY(2, 5, KEY_FN),
  139. KEY(3, 0, KEY_O),
  140. KEY(3, 1, KEY_5),
  141. KEY(3, 2, KEY_T),
  142. KEY(3, 3, KEY_F),
  143. KEY(3, 4, KEY_C),
  144. KEY(4, 0, KEY_P),
  145. KEY(4, 1, KEY_4),
  146. KEY(4, 2, KEY_R),
  147. KEY(4, 3, KEY_D),
  148. KEY(4, 4, KEY_X),
  149. KEY(5, 0, KEY_K),
  150. KEY(5, 1, KEY_3),
  151. KEY(5, 2, KEY_E),
  152. KEY(5, 3, KEY_S),
  153. KEY(5, 4, KEY_Z),
  154. KEY(6, 0, KEY_L),
  155. KEY(6, 1, KEY_2),
  156. KEY(6, 2, KEY_W),
  157. KEY(6, 3, KEY_A),
  158. KEY(6, 4, KEY_DOT),
  159. KEY(7, 0, KEY_ENTER),
  160. KEY(7, 1, KEY_1),
  161. KEY(7, 2, KEY_Q),
  162. KEY(7, 3, KEY_LEFTSHIFT),
  163. KEY(7, 4, KEY_COMMA),
  164. };
  165. static struct matrix_keymap_data board_map_data = {
  166. .keymap = board_keymap,
  167. .keymap_size = ARRAY_SIZE(board_keymap),
  168. };
  169. static struct twl4030_keypad_data pandora_kp_data = {
  170. .keymap_data = &board_map_data,
  171. .rows = 8,
  172. .cols = 6,
  173. .rep = 1,
  174. };
  175. static struct twl4030_hsmmc_info omap3pandora_mmc[] = {
  176. {
  177. .mmc = 1,
  178. .wires = 4,
  179. .gpio_cd = -EINVAL,
  180. .gpio_wp = 126,
  181. .ext_clock = 0,
  182. },
  183. {
  184. .mmc = 2,
  185. .wires = 4,
  186. .gpio_cd = -EINVAL,
  187. .gpio_wp = 127,
  188. .ext_clock = 1,
  189. .transceiver = true,
  190. },
  191. {
  192. .mmc = 3,
  193. .wires = 4,
  194. .gpio_cd = -EINVAL,
  195. .gpio_wp = -EINVAL,
  196. },
  197. {} /* Terminator */
  198. };
  199. static struct regulator_consumer_supply pandora_vmmc1_supply = {
  200. .supply = "vmmc",
  201. };
  202. static struct regulator_consumer_supply pandora_vmmc2_supply = {
  203. .supply = "vmmc",
  204. };
  205. static int omap3pandora_twl_gpio_setup(struct device *dev,
  206. unsigned gpio, unsigned ngpio)
  207. {
  208. /* gpio + {0,1} is "mmc{0,1}_cd" (input/IRQ) */
  209. omap3pandora_mmc[0].gpio_cd = gpio + 0;
  210. omap3pandora_mmc[1].gpio_cd = gpio + 1;
  211. twl4030_mmc_init(omap3pandora_mmc);
  212. /* link regulators to MMC adapters */
  213. pandora_vmmc1_supply.dev = omap3pandora_mmc[0].dev;
  214. pandora_vmmc2_supply.dev = omap3pandora_mmc[1].dev;
  215. return 0;
  216. }
  217. static struct twl4030_gpio_platform_data omap3pandora_gpio_data = {
  218. .gpio_base = OMAP_MAX_GPIO_LINES,
  219. .irq_base = TWL4030_GPIO_IRQ_BASE,
  220. .irq_end = TWL4030_GPIO_IRQ_END,
  221. .setup = omap3pandora_twl_gpio_setup,
  222. };
  223. /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
  224. static struct regulator_init_data pandora_vmmc1 = {
  225. .constraints = {
  226. .min_uV = 1850000,
  227. .max_uV = 3150000,
  228. .valid_modes_mask = REGULATOR_MODE_NORMAL
  229. | REGULATOR_MODE_STANDBY,
  230. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  231. | REGULATOR_CHANGE_MODE
  232. | REGULATOR_CHANGE_STATUS,
  233. },
  234. .num_consumer_supplies = 1,
  235. .consumer_supplies = &pandora_vmmc1_supply,
  236. };
  237. /* VMMC2 for MMC2 pins CMD, CLK, DAT0..DAT3 (max 100 mA) */
  238. static struct regulator_init_data pandora_vmmc2 = {
  239. .constraints = {
  240. .min_uV = 1850000,
  241. .max_uV = 3150000,
  242. .valid_modes_mask = REGULATOR_MODE_NORMAL
  243. | REGULATOR_MODE_STANDBY,
  244. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  245. | REGULATOR_CHANGE_MODE
  246. | REGULATOR_CHANGE_STATUS,
  247. },
  248. .num_consumer_supplies = 1,
  249. .consumer_supplies = &pandora_vmmc2_supply,
  250. };
  251. static struct twl4030_usb_data omap3pandora_usb_data = {
  252. .usb_mode = T2_USB_MODE_ULPI,
  253. };
  254. static struct twl4030_codec_audio_data omap3pandora_audio_data = {
  255. .audio_mclk = 26000000,
  256. };
  257. static struct twl4030_codec_data omap3pandora_codec_data = {
  258. .audio_mclk = 26000000,
  259. .audio = &omap3pandora_audio_data,
  260. };
  261. static struct twl4030_platform_data omap3pandora_twldata = {
  262. .irq_base = TWL4030_IRQ_BASE,
  263. .irq_end = TWL4030_IRQ_END,
  264. .gpio = &omap3pandora_gpio_data,
  265. .usb = &omap3pandora_usb_data,
  266. .codec = &omap3pandora_codec_data,
  267. .vmmc1 = &pandora_vmmc1,
  268. .vmmc2 = &pandora_vmmc2,
  269. .keypad = &pandora_kp_data,
  270. };
  271. static struct i2c_board_info __initdata omap3pandora_i2c_boardinfo[] = {
  272. {
  273. I2C_BOARD_INFO("tps65950", 0x48),
  274. .flags = I2C_CLIENT_WAKE,
  275. .irq = INT_34XX_SYS_NIRQ,
  276. .platform_data = &omap3pandora_twldata,
  277. },
  278. };
  279. static int __init omap3pandora_i2c_init(void)
  280. {
  281. omap_register_i2c_bus(1, 2600, omap3pandora_i2c_boardinfo,
  282. ARRAY_SIZE(omap3pandora_i2c_boardinfo));
  283. /* i2c2 pins are not connected */
  284. omap_register_i2c_bus(3, 100, NULL, 0);
  285. return 0;
  286. }
  287. static void __init omap3pandora_ads7846_init(void)
  288. {
  289. int gpio = OMAP3_PANDORA_TS_GPIO;
  290. int ret;
  291. ret = gpio_request(gpio, "ads7846_pen_down");
  292. if (ret < 0) {
  293. printk(KERN_ERR "Failed to request GPIO %d for "
  294. "ads7846 pen down IRQ\n", gpio);
  295. return;
  296. }
  297. gpio_direction_input(gpio);
  298. }
  299. static int ads7846_get_pendown_state(void)
  300. {
  301. return !gpio_get_value(OMAP3_PANDORA_TS_GPIO);
  302. }
  303. static struct ads7846_platform_data ads7846_config = {
  304. .x_max = 0x0fff,
  305. .y_max = 0x0fff,
  306. .x_plate_ohms = 180,
  307. .pressure_max = 255,
  308. .debounce_max = 10,
  309. .debounce_tol = 3,
  310. .debounce_rep = 1,
  311. .get_pendown_state = ads7846_get_pendown_state,
  312. .keep_vref_on = 1,
  313. };
  314. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  315. .turbo_mode = 0,
  316. .single_channel = 1, /* 0: slave, 1: master */
  317. };
  318. static struct spi_board_info omap3pandora_spi_board_info[] __initdata = {
  319. {
  320. .modalias = "ads7846",
  321. .bus_num = 1,
  322. .chip_select = 0,
  323. .max_speed_hz = 1500000,
  324. .controller_data = &ads7846_mcspi_config,
  325. .irq = OMAP_GPIO_IRQ(OMAP3_PANDORA_TS_GPIO),
  326. .platform_data = &ads7846_config,
  327. }
  328. };
  329. static void __init omap3pandora_init_irq(void)
  330. {
  331. omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
  332. mt46h32m32lf6_sdrc_params);
  333. omap_init_irq();
  334. omap_gpio_init();
  335. }
  336. static struct platform_device *omap3pandora_devices[] __initdata = {
  337. &pandora_leds_gpio,
  338. &pandora_keys_gpio,
  339. };
  340. static struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
  341. .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
  342. .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN,
  343. .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
  344. .phy_reset = true,
  345. .reset_gpio_port[0] = 16,
  346. .reset_gpio_port[1] = -EINVAL,
  347. .reset_gpio_port[2] = -EINVAL
  348. };
  349. #ifdef CONFIG_OMAP_MUX
  350. static struct omap_board_mux board_mux[] __initdata = {
  351. { .reg_offset = OMAP_MUX_TERMINATOR },
  352. };
  353. #else
  354. #define board_mux NULL
  355. #endif
  356. static void __init omap3pandora_init(void)
  357. {
  358. omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
  359. omap3pandora_i2c_init();
  360. platform_add_devices(omap3pandora_devices,
  361. ARRAY_SIZE(omap3pandora_devices));
  362. omap_serial_init();
  363. spi_register_board_info(omap3pandora_spi_board_info,
  364. ARRAY_SIZE(omap3pandora_spi_board_info));
  365. omap3pandora_ads7846_init();
  366. usb_ehci_init(&ehci_pdata);
  367. pandora_keys_gpio_init();
  368. usb_musb_init();
  369. /* Ensure SDRC pins are mux'd for self-refresh */
  370. omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
  371. omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
  372. }
  373. static void __init omap3pandora_map_io(void)
  374. {
  375. omap2_set_globals_343x();
  376. omap2_map_common_io();
  377. }
  378. MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
  379. .phys_io = 0x48000000,
  380. .io_pg_offst = ((0xfa000000) >> 18) & 0xfffc,
  381. .boot_params = 0x80000100,
  382. .map_io = omap3pandora_map_io,
  383. .init_irq = omap3pandora_init_irq,
  384. .init_machine = omap3pandora_init,
  385. .timer = &omap_timer,
  386. MACHINE_END