board-omap3pandora.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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/gpio_keys.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/map.h>
  32. #include <mach/board.h>
  33. #include <mach/common.h>
  34. #include <mach/gpio.h>
  35. #include <mach/hardware.h>
  36. #include <mach/mcspi.h>
  37. #include <mach/usb.h>
  38. #include <mach/keypad.h>
  39. #include "sdram-micron-mt46h32m32lf-6.h"
  40. #include "mmc-twl4030.h"
  41. #define OMAP3_PANDORA_TS_GPIO 94
  42. /* hardware debounce: (value + 1) * 31us */
  43. #define GPIO_DEBOUNCE_TIME 127
  44. static struct gpio_led pandora_gpio_leds[] = {
  45. {
  46. .name = "pandora::sd1",
  47. .default_trigger = "mmc0",
  48. .gpio = 128,
  49. }, {
  50. .name = "pandora::sd2",
  51. .default_trigger = "mmc1",
  52. .gpio = 129,
  53. }, {
  54. .name = "pandora::bluetooth",
  55. .gpio = 158,
  56. }, {
  57. .name = "pandora::wifi",
  58. .gpio = 159,
  59. },
  60. };
  61. static struct gpio_led_platform_data pandora_gpio_led_data = {
  62. .leds = pandora_gpio_leds,
  63. .num_leds = ARRAY_SIZE(pandora_gpio_leds),
  64. };
  65. static struct platform_device pandora_leds_gpio = {
  66. .name = "leds-gpio",
  67. .id = -1,
  68. .dev = {
  69. .platform_data = &pandora_gpio_led_data,
  70. },
  71. };
  72. #define GPIO_BUTTON(gpio_num, ev_type, ev_code, act_low, descr) \
  73. { \
  74. .gpio = gpio_num, \
  75. .type = ev_type, \
  76. .code = ev_code, \
  77. .active_low = act_low, \
  78. .desc = "btn " descr, \
  79. }
  80. #define GPIO_BUTTON_LOW(gpio_num, event_code, description) \
  81. GPIO_BUTTON(gpio_num, EV_KEY, event_code, 1, description)
  82. static struct gpio_keys_button pandora_gpio_keys[] = {
  83. GPIO_BUTTON_LOW(110, KEY_UP, "up"),
  84. GPIO_BUTTON_LOW(103, KEY_DOWN, "down"),
  85. GPIO_BUTTON_LOW(96, KEY_LEFT, "left"),
  86. GPIO_BUTTON_LOW(98, KEY_RIGHT, "right"),
  87. GPIO_BUTTON_LOW(111, BTN_A, "a"),
  88. GPIO_BUTTON_LOW(106, BTN_B, "b"),
  89. GPIO_BUTTON_LOW(109, BTN_X, "x"),
  90. GPIO_BUTTON_LOW(101, BTN_Y, "y"),
  91. GPIO_BUTTON_LOW(102, BTN_TL, "l"),
  92. GPIO_BUTTON_LOW(97, BTN_TL2, "l2"),
  93. GPIO_BUTTON_LOW(105, BTN_TR, "r"),
  94. GPIO_BUTTON_LOW(107, BTN_TR2, "r2"),
  95. GPIO_BUTTON_LOW(104, KEY_LEFTCTRL, "ctrl"),
  96. GPIO_BUTTON_LOW(99, KEY_MENU, "menu"),
  97. GPIO_BUTTON_LOW(176, KEY_COFFEE, "hold"),
  98. GPIO_BUTTON(100, EV_KEY, KEY_LEFTALT, 0, "alt"),
  99. GPIO_BUTTON(108, EV_SW, SW_LID, 1, "lid"),
  100. };
  101. static struct gpio_keys_platform_data pandora_gpio_key_info = {
  102. .buttons = pandora_gpio_keys,
  103. .nbuttons = ARRAY_SIZE(pandora_gpio_keys),
  104. };
  105. static struct platform_device pandora_keys_gpio = {
  106. .name = "gpio-keys",
  107. .id = -1,
  108. .dev = {
  109. .platform_data = &pandora_gpio_key_info,
  110. },
  111. };
  112. static void __init pandora_keys_gpio_init(void)
  113. {
  114. /* set debounce time for GPIO banks 4 and 6 */
  115. omap_set_gpio_debounce_time(32 * 3, GPIO_DEBOUNCE_TIME);
  116. omap_set_gpio_debounce_time(32 * 5, GPIO_DEBOUNCE_TIME);
  117. }
  118. static int pandora_keypad_map[] = {
  119. /* col, row, code */
  120. KEY(0, 0, KEY_9),
  121. KEY(0, 1, KEY_0),
  122. KEY(0, 2, KEY_BACKSPACE),
  123. KEY(0, 3, KEY_O),
  124. KEY(0, 4, KEY_P),
  125. KEY(0, 5, KEY_K),
  126. KEY(0, 6, KEY_L),
  127. KEY(0, 7, KEY_ENTER),
  128. KEY(1, 0, KEY_8),
  129. KEY(1, 1, KEY_7),
  130. KEY(1, 2, KEY_6),
  131. KEY(1, 3, KEY_5),
  132. KEY(1, 4, KEY_4),
  133. KEY(1, 5, KEY_3),
  134. KEY(1, 6, KEY_2),
  135. KEY(1, 7, KEY_1),
  136. KEY(2, 0, KEY_I),
  137. KEY(2, 1, KEY_U),
  138. KEY(2, 2, KEY_Y),
  139. KEY(2, 3, KEY_T),
  140. KEY(2, 4, KEY_R),
  141. KEY(2, 5, KEY_E),
  142. KEY(2, 6, KEY_W),
  143. KEY(2, 7, KEY_Q),
  144. KEY(3, 0, KEY_J),
  145. KEY(3, 1, KEY_H),
  146. KEY(3, 2, KEY_G),
  147. KEY(3, 3, KEY_F),
  148. KEY(3, 4, KEY_D),
  149. KEY(3, 5, KEY_S),
  150. KEY(3, 6, KEY_A),
  151. KEY(3, 7, KEY_LEFTSHIFT),
  152. KEY(4, 0, KEY_N),
  153. KEY(4, 1, KEY_B),
  154. KEY(4, 2, KEY_V),
  155. KEY(4, 3, KEY_C),
  156. KEY(4, 4, KEY_X),
  157. KEY(4, 5, KEY_Z),
  158. KEY(4, 6, KEY_DOT),
  159. KEY(4, 7, KEY_COMMA),
  160. KEY(5, 0, KEY_M),
  161. KEY(5, 1, KEY_SPACE),
  162. KEY(5, 2, KEY_FN),
  163. };
  164. static struct twl4030_keypad_data pandora_kp_data = {
  165. .rows = 8,
  166. .cols = 6,
  167. .keymap = pandora_keypad_map,
  168. .keymapsize = ARRAY_SIZE(pandora_keypad_map),
  169. .rep = 1,
  170. };
  171. static struct twl4030_hsmmc_info omap3pandora_mmc[] = {
  172. {
  173. .mmc = 1,
  174. .wires = 4,
  175. .gpio_cd = -EINVAL,
  176. .gpio_wp = 126,
  177. .ext_clock = 0,
  178. },
  179. {
  180. .mmc = 2,
  181. .wires = 4,
  182. .gpio_cd = -EINVAL,
  183. .gpio_wp = 127,
  184. .ext_clock = 1,
  185. .transceiver = true,
  186. },
  187. {
  188. .mmc = 3,
  189. .wires = 4,
  190. .gpio_cd = -EINVAL,
  191. .gpio_wp = -EINVAL,
  192. },
  193. {} /* Terminator */
  194. };
  195. static struct omap_uart_config omap3pandora_uart_config __initdata = {
  196. .enabled_uarts = (1 << 2), /* UART3 */
  197. };
  198. static struct regulator_consumer_supply pandora_vmmc1_supply = {
  199. .supply = "vmmc",
  200. };
  201. static struct regulator_consumer_supply pandora_vmmc2_supply = {
  202. .supply = "vmmc",
  203. };
  204. static int omap3pandora_twl_gpio_setup(struct device *dev,
  205. unsigned gpio, unsigned ngpio)
  206. {
  207. /* gpio + {0,1} is "mmc{0,1}_cd" (input/IRQ) */
  208. omap3pandora_mmc[0].gpio_cd = gpio + 0;
  209. omap3pandora_mmc[1].gpio_cd = gpio + 1;
  210. twl4030_mmc_init(omap3pandora_mmc);
  211. /* link regulators to MMC adapters */
  212. pandora_vmmc1_supply.dev = omap3pandora_mmc[0].dev;
  213. pandora_vmmc2_supply.dev = omap3pandora_mmc[1].dev;
  214. return 0;
  215. }
  216. static struct twl4030_gpio_platform_data omap3pandora_gpio_data = {
  217. .gpio_base = OMAP_MAX_GPIO_LINES,
  218. .irq_base = TWL4030_GPIO_IRQ_BASE,
  219. .irq_end = TWL4030_GPIO_IRQ_END,
  220. .setup = omap3pandora_twl_gpio_setup,
  221. };
  222. /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
  223. static struct regulator_init_data pandora_vmmc1 = {
  224. .constraints = {
  225. .min_uV = 1850000,
  226. .max_uV = 3150000,
  227. .valid_modes_mask = REGULATOR_MODE_NORMAL
  228. | REGULATOR_MODE_STANDBY,
  229. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  230. | REGULATOR_CHANGE_MODE
  231. | REGULATOR_CHANGE_STATUS,
  232. },
  233. .num_consumer_supplies = 1,
  234. .consumer_supplies = &pandora_vmmc1_supply,
  235. };
  236. /* VMMC2 for MMC2 pins CMD, CLK, DAT0..DAT3 (max 100 mA) */
  237. static struct regulator_init_data pandora_vmmc2 = {
  238. .constraints = {
  239. .min_uV = 1850000,
  240. .max_uV = 3150000,
  241. .valid_modes_mask = REGULATOR_MODE_NORMAL
  242. | REGULATOR_MODE_STANDBY,
  243. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  244. | REGULATOR_CHANGE_MODE
  245. | REGULATOR_CHANGE_STATUS,
  246. },
  247. .num_consumer_supplies = 1,
  248. .consumer_supplies = &pandora_vmmc2_supply,
  249. };
  250. static struct twl4030_usb_data omap3pandora_usb_data = {
  251. .usb_mode = T2_USB_MODE_ULPI,
  252. };
  253. static struct twl4030_platform_data omap3pandora_twldata = {
  254. .irq_base = TWL4030_IRQ_BASE,
  255. .irq_end = TWL4030_IRQ_END,
  256. .gpio = &omap3pandora_gpio_data,
  257. .usb = &omap3pandora_usb_data,
  258. .vmmc1 = &pandora_vmmc1,
  259. .vmmc2 = &pandora_vmmc2,
  260. .keypad = &pandora_kp_data,
  261. };
  262. static struct i2c_board_info __initdata omap3pandora_i2c_boardinfo[] = {
  263. {
  264. I2C_BOARD_INFO("tps65950", 0x48),
  265. .flags = I2C_CLIENT_WAKE,
  266. .irq = INT_34XX_SYS_NIRQ,
  267. .platform_data = &omap3pandora_twldata,
  268. },
  269. };
  270. static int __init omap3pandora_i2c_init(void)
  271. {
  272. omap_register_i2c_bus(1, 2600, omap3pandora_i2c_boardinfo,
  273. ARRAY_SIZE(omap3pandora_i2c_boardinfo));
  274. /* i2c2 pins are not connected */
  275. omap_register_i2c_bus(3, 400, NULL, 0);
  276. return 0;
  277. }
  278. static void __init omap3pandora_init_irq(void)
  279. {
  280. omap2_init_common_hw(mt46h32m32lf6_sdrc_params);
  281. omap_init_irq();
  282. omap_gpio_init();
  283. }
  284. static void __init omap3pandora_ads7846_init(void)
  285. {
  286. int gpio = OMAP3_PANDORA_TS_GPIO;
  287. int ret;
  288. ret = gpio_request(gpio, "ads7846_pen_down");
  289. if (ret < 0) {
  290. printk(KERN_ERR "Failed to request GPIO %d for "
  291. "ads7846 pen down IRQ\n", gpio);
  292. return;
  293. }
  294. gpio_direction_input(gpio);
  295. }
  296. static int ads7846_get_pendown_state(void)
  297. {
  298. return !gpio_get_value(OMAP3_PANDORA_TS_GPIO);
  299. }
  300. static struct ads7846_platform_data ads7846_config = {
  301. .x_max = 0x0fff,
  302. .y_max = 0x0fff,
  303. .x_plate_ohms = 180,
  304. .pressure_max = 255,
  305. .debounce_max = 10,
  306. .debounce_tol = 3,
  307. .debounce_rep = 1,
  308. .get_pendown_state = ads7846_get_pendown_state,
  309. .keep_vref_on = 1,
  310. };
  311. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  312. .turbo_mode = 0,
  313. .single_channel = 1, /* 0: slave, 1: master */
  314. };
  315. static struct spi_board_info omap3pandora_spi_board_info[] __initdata = {
  316. {
  317. .modalias = "ads7846",
  318. .bus_num = 1,
  319. .chip_select = 0,
  320. .max_speed_hz = 1500000,
  321. .controller_data = &ads7846_mcspi_config,
  322. .irq = OMAP_GPIO_IRQ(OMAP3_PANDORA_TS_GPIO),
  323. .platform_data = &ads7846_config,
  324. }
  325. };
  326. static struct platform_device omap3pandora_lcd_device = {
  327. .name = "pandora_lcd",
  328. .id = -1,
  329. };
  330. static struct omap_lcd_config omap3pandora_lcd_config __initdata = {
  331. .ctrl_name = "internal",
  332. };
  333. static struct omap_board_config_kernel omap3pandora_config[] __initdata = {
  334. { OMAP_TAG_UART, &omap3pandora_uart_config },
  335. { OMAP_TAG_LCD, &omap3pandora_lcd_config },
  336. };
  337. static struct platform_device *omap3pandora_devices[] __initdata = {
  338. &omap3pandora_lcd_device,
  339. &pandora_leds_gpio,
  340. &pandora_keys_gpio,
  341. };
  342. static void __init omap3pandora_init(void)
  343. {
  344. omap3pandora_i2c_init();
  345. platform_add_devices(omap3pandora_devices,
  346. ARRAY_SIZE(omap3pandora_devices));
  347. omap_board_config = omap3pandora_config;
  348. omap_board_config_size = ARRAY_SIZE(omap3pandora_config);
  349. omap_serial_init();
  350. spi_register_board_info(omap3pandora_spi_board_info,
  351. ARRAY_SIZE(omap3pandora_spi_board_info));
  352. omap3pandora_ads7846_init();
  353. pandora_keys_gpio_init();
  354. usb_musb_init();
  355. }
  356. static void __init omap3pandora_map_io(void)
  357. {
  358. omap2_set_globals_343x();
  359. omap2_map_common_io();
  360. }
  361. MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
  362. .phys_io = 0x48000000,
  363. .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
  364. .boot_params = 0x80000100,
  365. .map_io = omap3pandora_map_io,
  366. .init_irq = omap3pandora_init_irq,
  367. .init_machine = omap3pandora_init,
  368. .timer = &omap_timer,
  369. MACHINE_END