board-omap3pandora.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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/twl4030.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 <mach/board.h>
  34. #include <mach/common.h>
  35. #include <mach/gpio.h>
  36. #include <mach/hardware.h>
  37. #include <mach/mcspi.h>
  38. #include <mach/usb.h>
  39. #include <mach/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(111, BTN_A, "a"),
  89. GPIO_BUTTON_LOW(106, BTN_B, "b"),
  90. GPIO_BUTTON_LOW(109, BTN_X, "x"),
  91. GPIO_BUTTON_LOW(101, BTN_Y, "y"),
  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_platform_data omap3pandora_twldata = {
  255. .irq_base = TWL4030_IRQ_BASE,
  256. .irq_end = TWL4030_IRQ_END,
  257. .gpio = &omap3pandora_gpio_data,
  258. .usb = &omap3pandora_usb_data,
  259. .vmmc1 = &pandora_vmmc1,
  260. .vmmc2 = &pandora_vmmc2,
  261. .keypad = &pandora_kp_data,
  262. };
  263. static struct i2c_board_info __initdata omap3pandora_i2c_boardinfo[] = {
  264. {
  265. I2C_BOARD_INFO("tps65950", 0x48),
  266. .flags = I2C_CLIENT_WAKE,
  267. .irq = INT_34XX_SYS_NIRQ,
  268. .platform_data = &omap3pandora_twldata,
  269. },
  270. };
  271. static int __init omap3pandora_i2c_init(void)
  272. {
  273. omap_register_i2c_bus(1, 2600, omap3pandora_i2c_boardinfo,
  274. ARRAY_SIZE(omap3pandora_i2c_boardinfo));
  275. /* i2c2 pins are not connected */
  276. omap_register_i2c_bus(3, 400, NULL, 0);
  277. return 0;
  278. }
  279. static void __init omap3pandora_ads7846_init(void)
  280. {
  281. int gpio = OMAP3_PANDORA_TS_GPIO;
  282. int ret;
  283. ret = gpio_request(gpio, "ads7846_pen_down");
  284. if (ret < 0) {
  285. printk(KERN_ERR "Failed to request GPIO %d for "
  286. "ads7846 pen down IRQ\n", gpio);
  287. return;
  288. }
  289. gpio_direction_input(gpio);
  290. }
  291. static int ads7846_get_pendown_state(void)
  292. {
  293. return !gpio_get_value(OMAP3_PANDORA_TS_GPIO);
  294. }
  295. static struct ads7846_platform_data ads7846_config = {
  296. .x_max = 0x0fff,
  297. .y_max = 0x0fff,
  298. .x_plate_ohms = 180,
  299. .pressure_max = 255,
  300. .debounce_max = 10,
  301. .debounce_tol = 3,
  302. .debounce_rep = 1,
  303. .get_pendown_state = ads7846_get_pendown_state,
  304. .keep_vref_on = 1,
  305. };
  306. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  307. .turbo_mode = 0,
  308. .single_channel = 1, /* 0: slave, 1: master */
  309. };
  310. static struct spi_board_info omap3pandora_spi_board_info[] __initdata = {
  311. {
  312. .modalias = "ads7846",
  313. .bus_num = 1,
  314. .chip_select = 0,
  315. .max_speed_hz = 1500000,
  316. .controller_data = &ads7846_mcspi_config,
  317. .irq = OMAP_GPIO_IRQ(OMAP3_PANDORA_TS_GPIO),
  318. .platform_data = &ads7846_config,
  319. }
  320. };
  321. static struct platform_device omap3pandora_lcd_device = {
  322. .name = "pandora_lcd",
  323. .id = -1,
  324. };
  325. static struct omap_lcd_config omap3pandora_lcd_config __initdata = {
  326. .ctrl_name = "internal",
  327. };
  328. static struct omap_board_config_kernel omap3pandora_config[] __initdata = {
  329. { OMAP_TAG_LCD, &omap3pandora_lcd_config },
  330. };
  331. static void __init omap3pandora_init_irq(void)
  332. {
  333. omap_board_config = omap3pandora_config;
  334. omap_board_config_size = ARRAY_SIZE(omap3pandora_config);
  335. omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
  336. mt46h32m32lf6_sdrc_params);
  337. omap_init_irq();
  338. omap_gpio_init();
  339. }
  340. static struct platform_device *omap3pandora_devices[] __initdata = {
  341. &omap3pandora_lcd_device,
  342. &pandora_leds_gpio,
  343. &pandora_keys_gpio,
  344. };
  345. static void __init omap3pandora_init(void)
  346. {
  347. omap3pandora_i2c_init();
  348. platform_add_devices(omap3pandora_devices,
  349. ARRAY_SIZE(omap3pandora_devices));
  350. omap_serial_init();
  351. spi_register_board_info(omap3pandora_spi_board_info,
  352. ARRAY_SIZE(omap3pandora_spi_board_info));
  353. omap3pandora_ads7846_init();
  354. pandora_keys_gpio_init();
  355. usb_musb_init();
  356. /* Ensure SDRC pins are mux'd for self-refresh */
  357. omap_cfg_reg(H16_34XX_SDRC_CKE0);
  358. omap_cfg_reg(H17_34XX_SDRC_CKE1);
  359. }
  360. static void __init omap3pandora_map_io(void)
  361. {
  362. omap2_set_globals_343x();
  363. omap2_map_common_io();
  364. }
  365. MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
  366. .phys_io = 0x48000000,
  367. .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
  368. .boot_params = 0x80000100,
  369. .map_io = omap3pandora_map_io,
  370. .init_irq = omap3pandora_init_irq,
  371. .init_machine = omap3pandora_init,
  372. .timer = &omap_timer,
  373. MACHINE_END