treo680.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * Hardware definitions for Palm Treo 680
  3. *
  4. * Author: Tomas Cech <sleep_walker@suse.cz>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * (find more info at www.hackndev.com)
  11. *
  12. */
  13. #include <linux/platform_device.h>
  14. #include <linux/delay.h>
  15. #include <linux/irq.h>
  16. #include <linux/gpio_keys.h>
  17. #include <linux/input.h>
  18. #include <linux/pda_power.h>
  19. #include <linux/pwm_backlight.h>
  20. #include <linux/gpio.h>
  21. #include <linux/wm97xx_batt.h>
  22. #include <linux/power_supply.h>
  23. #include <linux/sysdev.h>
  24. #include <linux/w1-gpio.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/map.h>
  28. #include <mach/pxa27x.h>
  29. #include <mach/pxa27x-udc.h>
  30. #include <mach/audio.h>
  31. #include <mach/treo680.h>
  32. #include <mach/mmc.h>
  33. #include <mach/pxafb.h>
  34. #include <mach/irda.h>
  35. #include <mach/pxa27x_keypad.h>
  36. #include <mach/udc.h>
  37. #include <mach/ohci.h>
  38. #include <mach/pxa2xx-regs.h>
  39. #include <mach/palmasoc.h>
  40. #include <mach/camera.h>
  41. #include <sound/pxa2xx-lib.h>
  42. #include "generic.h"
  43. #include "devices.h"
  44. /******************************************************************************
  45. * Pin configuration
  46. ******************************************************************************/
  47. static unsigned long treo680_pin_config[] __initdata = {
  48. /* MMC */
  49. GPIO32_MMC_CLK,
  50. GPIO92_MMC_DAT_0,
  51. GPIO109_MMC_DAT_1,
  52. GPIO110_MMC_DAT_2,
  53. GPIO111_MMC_DAT_3,
  54. GPIO112_MMC_CMD,
  55. GPIO33_GPIO, /* SD read only */
  56. GPIO113_GPIO, /* SD detect */
  57. /* AC97 */
  58. GPIO28_AC97_BITCLK,
  59. GPIO29_AC97_SDATA_IN_0,
  60. GPIO30_AC97_SDATA_OUT,
  61. GPIO31_AC97_SYNC,
  62. GPIO89_AC97_SYSCLK,
  63. GPIO95_AC97_nRESET,
  64. /* IrDA */
  65. GPIO46_FICP_RXD,
  66. GPIO47_FICP_TXD,
  67. /* PWM */
  68. GPIO16_PWM0_OUT,
  69. /* USB */
  70. GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH, /* usb detect */
  71. /* MATRIX KEYPAD */
  72. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  73. GPIO101_KP_MKIN_1,
  74. GPIO102_KP_MKIN_2,
  75. GPIO97_KP_MKIN_3,
  76. GPIO98_KP_MKIN_4,
  77. GPIO99_KP_MKIN_5,
  78. GPIO91_KP_MKIN_6,
  79. GPIO13_KP_MKIN_7,
  80. GPIO103_KP_MKOUT_0 | MFP_LPM_DRIVE_HIGH,
  81. GPIO104_KP_MKOUT_1,
  82. GPIO105_KP_MKOUT_2,
  83. GPIO106_KP_MKOUT_3,
  84. GPIO107_KP_MKOUT_4,
  85. GPIO108_KP_MKOUT_5,
  86. GPIO96_KP_MKOUT_6,
  87. GPIO93_KP_DKIN_0 | WAKEUP_ON_LEVEL_HIGH, /* Hotsync button */
  88. /* LCD */
  89. GPIO58_LCD_LDD_0,
  90. GPIO59_LCD_LDD_1,
  91. GPIO60_LCD_LDD_2,
  92. GPIO61_LCD_LDD_3,
  93. GPIO62_LCD_LDD_4,
  94. GPIO63_LCD_LDD_5,
  95. GPIO64_LCD_LDD_6,
  96. GPIO65_LCD_LDD_7,
  97. GPIO66_LCD_LDD_8,
  98. GPIO67_LCD_LDD_9,
  99. GPIO68_LCD_LDD_10,
  100. GPIO69_LCD_LDD_11,
  101. GPIO70_LCD_LDD_12,
  102. GPIO71_LCD_LDD_13,
  103. GPIO72_LCD_LDD_14,
  104. GPIO73_LCD_LDD_15,
  105. GPIO74_LCD_FCLK,
  106. GPIO75_LCD_LCLK,
  107. GPIO76_LCD_PCLK,
  108. /* Quick Capture Interface */
  109. GPIO84_CIF_FV,
  110. GPIO85_CIF_LV,
  111. GPIO53_CIF_MCLK,
  112. GPIO54_CIF_PCLK,
  113. GPIO81_CIF_DD_0,
  114. GPIO55_CIF_DD_1,
  115. GPIO51_CIF_DD_2,
  116. GPIO50_CIF_DD_3,
  117. GPIO52_CIF_DD_4,
  118. GPIO48_CIF_DD_5,
  119. GPIO17_CIF_DD_6,
  120. GPIO12_CIF_DD_7,
  121. /* I2C */
  122. GPIO117_I2C_SCL,
  123. GPIO118_I2C_SDA,
  124. /* GSM */
  125. GPIO14_GPIO | WAKEUP_ON_EDGE_BOTH, /* GSM host wake up */
  126. GPIO34_FFUART_RXD,
  127. GPIO35_FFUART_CTS,
  128. GPIO39_FFUART_TXD,
  129. GPIO41_FFUART_RTS,
  130. /* MISC. */
  131. GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH, /* external power detect */
  132. GPIO15_GPIO | WAKEUP_ON_EDGE_BOTH, /* silent switch */
  133. GPIO116_GPIO, /* headphone detect */
  134. GPIO11_GPIO | WAKEUP_ON_EDGE_BOTH, /* bluetooth host wake up */
  135. };
  136. /******************************************************************************
  137. * SD/MMC card controller
  138. ******************************************************************************/
  139. static int treo680_mci_init(struct device *dev,
  140. irq_handler_t treo680_detect_int, void *data)
  141. {
  142. int err = 0;
  143. /* Setup an interrupt for detecting card insert/remove events */
  144. err = gpio_request(GPIO_NR_TREO680_SD_DETECT_N, "SD IRQ");
  145. if (err)
  146. goto err;
  147. err = gpio_direction_input(GPIO_NR_TREO680_SD_DETECT_N);
  148. if (err)
  149. goto err2;
  150. err = request_irq(gpio_to_irq(GPIO_NR_TREO680_SD_DETECT_N),
  151. treo680_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  152. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  153. "SD/MMC card detect", data);
  154. if (err) {
  155. dev_err(dev, "%s: cannot request SD/MMC card detect IRQ\n",
  156. __func__);
  157. goto err2;
  158. }
  159. err = gpio_request(GPIO_NR_TREO680_SD_POWER, "SD_POWER");
  160. if (err)
  161. goto err3;
  162. err = gpio_direction_output(GPIO_NR_TREO680_SD_POWER, 1);
  163. if (err)
  164. goto err4;
  165. err = gpio_request(GPIO_NR_TREO680_SD_READONLY, "SD_READONLY");
  166. if (err)
  167. goto err4;
  168. err = gpio_direction_input(GPIO_NR_TREO680_SD_READONLY);
  169. if (err)
  170. goto err5;
  171. return 0;
  172. err5:
  173. gpio_free(GPIO_NR_TREO680_SD_READONLY);
  174. err4:
  175. gpio_free(GPIO_NR_TREO680_SD_POWER);
  176. err3:
  177. free_irq(gpio_to_irq(GPIO_NR_TREO680_SD_DETECT_N), data);
  178. err2:
  179. gpio_free(GPIO_NR_TREO680_SD_DETECT_N);
  180. err:
  181. return err;
  182. }
  183. static void treo680_mci_exit(struct device *dev, void *data)
  184. {
  185. gpio_free(GPIO_NR_TREO680_SD_READONLY);
  186. gpio_free(GPIO_NR_TREO680_SD_POWER);
  187. free_irq(gpio_to_irq(GPIO_NR_TREO680_SD_DETECT_N), data);
  188. gpio_free(GPIO_NR_TREO680_SD_DETECT_N);
  189. }
  190. static void treo680_mci_power(struct device *dev, unsigned int vdd)
  191. {
  192. struct pxamci_platform_data *p_d = dev->platform_data;
  193. gpio_set_value(GPIO_NR_TREO680_SD_POWER, p_d->ocr_mask & (1 << vdd));
  194. }
  195. static int treo680_mci_get_ro(struct device *dev)
  196. {
  197. return gpio_get_value(GPIO_NR_TREO680_SD_READONLY);
  198. }
  199. static struct pxamci_platform_data treo680_mci_platform_data = {
  200. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  201. .setpower = treo680_mci_power,
  202. .get_ro = treo680_mci_get_ro,
  203. .init = treo680_mci_init,
  204. .exit = treo680_mci_exit,
  205. };
  206. /******************************************************************************
  207. * GPIO keyboard
  208. ******************************************************************************/
  209. static unsigned int treo680_matrix_keys[] = {
  210. KEY(0, 0, KEY_F8), /* Red/Off/Power */
  211. KEY(0, 1, KEY_LEFT),
  212. KEY(0, 2, KEY_LEFTCTRL), /* Alternate */
  213. KEY(0, 3, KEY_L),
  214. KEY(0, 4, KEY_A),
  215. KEY(0, 5, KEY_Q),
  216. KEY(0, 6, KEY_P),
  217. KEY(1, 0, KEY_RIGHTCTRL), /* Menu */
  218. KEY(1, 1, KEY_RIGHT),
  219. KEY(1, 2, KEY_LEFTSHIFT), /* Left shift */
  220. KEY(1, 3, KEY_Z),
  221. KEY(1, 4, KEY_S),
  222. KEY(1, 5, KEY_W),
  223. KEY(2, 0, KEY_F1), /* Phone */
  224. KEY(2, 1, KEY_UP),
  225. KEY(2, 2, KEY_0),
  226. KEY(2, 3, KEY_X),
  227. KEY(2, 4, KEY_D),
  228. KEY(2, 5, KEY_E),
  229. KEY(3, 0, KEY_F10), /* Calendar */
  230. KEY(3, 1, KEY_DOWN),
  231. KEY(3, 2, KEY_SPACE),
  232. KEY(3, 3, KEY_C),
  233. KEY(3, 4, KEY_F),
  234. KEY(3, 5, KEY_R),
  235. KEY(4, 0, KEY_F12), /* Mail */
  236. KEY(4, 1, KEY_KPENTER),
  237. KEY(4, 2, KEY_RIGHTALT), /* Alt */
  238. KEY(4, 3, KEY_V),
  239. KEY(4, 4, KEY_G),
  240. KEY(4, 5, KEY_T),
  241. KEY(5, 0, KEY_F9), /* Home */
  242. KEY(5, 1, KEY_PAGEUP), /* Side up */
  243. KEY(5, 2, KEY_DOT),
  244. KEY(5, 3, KEY_B),
  245. KEY(5, 4, KEY_H),
  246. KEY(5, 5, KEY_Y),
  247. KEY(6, 0, KEY_TAB), /* Side Activate */
  248. KEY(6, 1, KEY_PAGEDOWN), /* Side down */
  249. KEY(6, 2, KEY_ENTER),
  250. KEY(6, 3, KEY_N),
  251. KEY(6, 4, KEY_J),
  252. KEY(6, 5, KEY_U),
  253. KEY(7, 0, KEY_F6), /* Green/Call */
  254. KEY(7, 1, KEY_O),
  255. KEY(7, 2, KEY_BACKSPACE),
  256. KEY(7, 3, KEY_M),
  257. KEY(7, 4, KEY_K),
  258. KEY(7, 5, KEY_I),
  259. };
  260. static struct pxa27x_keypad_platform_data treo680_keypad_platform_data = {
  261. .matrix_key_rows = 8,
  262. .matrix_key_cols = 7,
  263. .matrix_key_map = treo680_matrix_keys,
  264. .matrix_key_map_size = ARRAY_SIZE(treo680_matrix_keys),
  265. .direct_key_map = { KEY_CONNECT },
  266. .direct_key_num = 1,
  267. .debounce_interval = 30,
  268. };
  269. /******************************************************************************
  270. * aSoC audio
  271. ******************************************************************************/
  272. static pxa2xx_audio_ops_t treo680_ac97_pdata = {
  273. .reset_gpio = 95,
  274. };
  275. /******************************************************************************
  276. * Backlight
  277. ******************************************************************************/
  278. static int treo680_backlight_init(struct device *dev)
  279. {
  280. int ret;
  281. ret = gpio_request(GPIO_NR_TREO680_BL_POWER, "BL POWER");
  282. if (ret)
  283. goto err;
  284. ret = gpio_direction_output(GPIO_NR_TREO680_BL_POWER, 0);
  285. if (ret)
  286. goto err2;
  287. ret = gpio_request(GPIO_NR_TREO680_LCD_POWER, "LCD POWER");
  288. if (ret)
  289. goto err2;
  290. ret = gpio_direction_output(GPIO_NR_TREO680_LCD_POWER, 0);
  291. if (ret)
  292. goto err3;
  293. return 0;
  294. err3:
  295. gpio_free(GPIO_NR_TREO680_LCD_POWER);
  296. err2:
  297. gpio_free(GPIO_NR_TREO680_BL_POWER);
  298. err:
  299. return ret;
  300. }
  301. static int treo680_backlight_notify(int brightness)
  302. {
  303. gpio_set_value(GPIO_NR_TREO680_BL_POWER, brightness);
  304. return TREO680_MAX_INTENSITY - brightness;
  305. };
  306. static void treo680_backlight_exit(struct device *dev)
  307. {
  308. gpio_free(GPIO_NR_TREO680_BL_POWER);
  309. gpio_free(GPIO_NR_TREO680_LCD_POWER);
  310. }
  311. static struct platform_pwm_backlight_data treo680_backlight_data = {
  312. .pwm_id = 0,
  313. .max_brightness = TREO680_MAX_INTENSITY,
  314. .dft_brightness = TREO680_DEFAULT_INTENSITY,
  315. .pwm_period_ns = TREO680_PERIOD_NS,
  316. .init = treo680_backlight_init,
  317. .notify = treo680_backlight_notify,
  318. .exit = treo680_backlight_exit,
  319. };
  320. static struct platform_device treo680_backlight = {
  321. .name = "pwm-backlight",
  322. .dev = {
  323. .parent = &pxa27x_device_pwm0.dev,
  324. .platform_data = &treo680_backlight_data,
  325. },
  326. };
  327. /******************************************************************************
  328. * IrDA
  329. ******************************************************************************/
  330. static void treo680_transceiver_mode(struct device *dev, int mode)
  331. {
  332. gpio_set_value(GPIO_NR_TREO680_IR_EN, mode & IR_OFF);
  333. pxa2xx_transceiver_mode(dev, mode);
  334. }
  335. static int treo680_irda_startup(struct device *dev)
  336. {
  337. int err;
  338. err = gpio_request(GPIO_NR_TREO680_IR_EN, "Ir port disable");
  339. if (err)
  340. goto err1;
  341. err = gpio_direction_output(GPIO_NR_TREO680_IR_EN, 1);
  342. if (err)
  343. goto err2;
  344. return 0;
  345. err2:
  346. dev_err(dev, "treo680_irda: cannot change IR gpio direction\n");
  347. gpio_free(GPIO_NR_TREO680_IR_EN);
  348. err1:
  349. dev_err(dev, "treo680_irda: cannot allocate IR gpio\n");
  350. return err;
  351. }
  352. static void treo680_irda_shutdown(struct device *dev)
  353. {
  354. gpio_free(GPIO_NR_TREO680_AMP_EN);
  355. }
  356. static struct pxaficp_platform_data treo680_ficp_info = {
  357. .transceiver_cap = IR_FIRMODE | IR_SIRMODE | IR_OFF,
  358. .startup = treo680_irda_startup,
  359. .shutdown = treo680_irda_shutdown,
  360. .transceiver_mode = treo680_transceiver_mode,
  361. };
  362. /******************************************************************************
  363. * UDC
  364. ******************************************************************************/
  365. static struct pxa2xx_udc_mach_info treo680_udc_info __initdata = {
  366. .gpio_vbus = GPIO_NR_TREO680_USB_DETECT,
  367. .gpio_vbus_inverted = 1,
  368. .gpio_pullup = GPIO_NR_TREO680_USB_PULLUP,
  369. };
  370. /******************************************************************************
  371. * USB host
  372. ******************************************************************************/
  373. static struct pxaohci_platform_data treo680_ohci_info = {
  374. .port_mode = PMM_PERPORT_MODE,
  375. .flags = ENABLE_PORT1 | ENABLE_PORT3,
  376. .power_budget = 0,
  377. };
  378. /******************************************************************************
  379. * Power supply
  380. ******************************************************************************/
  381. static int power_supply_init(struct device *dev)
  382. {
  383. int ret;
  384. ret = gpio_request(GPIO_NR_TREO680_POWER_DETECT, "CABLE_STATE_AC");
  385. if (ret)
  386. goto err1;
  387. ret = gpio_direction_input(GPIO_NR_TREO680_POWER_DETECT);
  388. if (ret)
  389. goto err2;
  390. return 0;
  391. err2:
  392. gpio_free(GPIO_NR_TREO680_POWER_DETECT);
  393. err1:
  394. return ret;
  395. }
  396. static int treo680_is_ac_online(void)
  397. {
  398. return gpio_get_value(GPIO_NR_TREO680_POWER_DETECT);
  399. }
  400. static void power_supply_exit(struct device *dev)
  401. {
  402. gpio_free(GPIO_NR_TREO680_POWER_DETECT);
  403. }
  404. static char *treo680_supplicants[] = {
  405. "main-battery",
  406. };
  407. static struct pda_power_pdata power_supply_info = {
  408. .init = power_supply_init,
  409. .is_ac_online = treo680_is_ac_online,
  410. .exit = power_supply_exit,
  411. .supplied_to = treo680_supplicants,
  412. .num_supplicants = ARRAY_SIZE(treo680_supplicants),
  413. };
  414. static struct platform_device power_supply = {
  415. .name = "pda-power",
  416. .id = -1,
  417. .dev = {
  418. .platform_data = &power_supply_info,
  419. },
  420. };
  421. /******************************************************************************
  422. * Vibra and LEDs
  423. ******************************************************************************/
  424. static struct gpio_led gpio_leds[] = {
  425. {
  426. .name = "treo680:vibra:vibra",
  427. .default_trigger = "none",
  428. .gpio = GPIO_NR_TREO680_VIBRATE_EN,
  429. },
  430. {
  431. .name = "treo680:green:led",
  432. .default_trigger = "mmc0",
  433. .gpio = GPIO_NR_TREO680_GREEN_LED,
  434. },
  435. {
  436. .name = "treo680:keybbl:keybbl",
  437. .default_trigger = "none",
  438. .gpio = GPIO_NR_TREO680_KEYB_BL,
  439. },
  440. };
  441. static struct gpio_led_platform_data gpio_led_info = {
  442. .leds = gpio_leds,
  443. .num_leds = ARRAY_SIZE(gpio_leds),
  444. };
  445. static struct platform_device treo680_leds = {
  446. .name = "leds-gpio",
  447. .id = -1,
  448. .dev = {
  449. .platform_data = &gpio_led_info,
  450. }
  451. };
  452. /******************************************************************************
  453. * Framebuffer
  454. ******************************************************************************/
  455. /* TODO: add support for 324x324 */
  456. static struct pxafb_mode_info treo680_lcd_modes[] = {
  457. {
  458. .pixclock = 86538,
  459. .xres = 320,
  460. .yres = 320,
  461. .bpp = 16,
  462. .left_margin = 20,
  463. .right_margin = 8,
  464. .upper_margin = 8,
  465. .lower_margin = 5,
  466. .hsync_len = 4,
  467. .vsync_len = 1,
  468. },
  469. };
  470. static struct pxafb_mach_info treo680_lcd_screen = {
  471. .modes = treo680_lcd_modes,
  472. .num_modes = ARRAY_SIZE(treo680_lcd_modes),
  473. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  474. };
  475. /******************************************************************************
  476. * Power management - standby
  477. ******************************************************************************/
  478. static void __init treo680_pm_init(void)
  479. {
  480. static u32 resume[] = {
  481. 0xe3a00101, /* mov r0, #0x40000000 */
  482. 0xe380060f, /* orr r0, r0, #0x00f00000 */
  483. 0xe590f008, /* ldr pc, [r0, #0x08] */
  484. };
  485. /* this is where the bootloader jumps */
  486. memcpy(phys_to_virt(TREO680_STR_BASE), resume, sizeof(resume));
  487. }
  488. /******************************************************************************
  489. * Machine init
  490. ******************************************************************************/
  491. static struct platform_device *devices[] __initdata = {
  492. &treo680_backlight,
  493. &treo680_leds,
  494. &power_supply,
  495. };
  496. /* setup udc GPIOs initial state */
  497. static void __init treo680_udc_init(void)
  498. {
  499. if (!gpio_request(GPIO_NR_TREO680_USB_PULLUP, "UDC Vbus")) {
  500. gpio_direction_output(GPIO_NR_TREO680_USB_PULLUP, 1);
  501. gpio_free(GPIO_NR_TREO680_USB_PULLUP);
  502. }
  503. }
  504. static void __init treo680_init(void)
  505. {
  506. treo680_pm_init();
  507. pxa2xx_mfp_config(ARRAY_AND_SIZE(treo680_pin_config));
  508. pxa_set_keypad_info(&treo680_keypad_platform_data);
  509. set_pxa_fb_info(&treo680_lcd_screen);
  510. pxa_set_mci_info(&treo680_mci_platform_data);
  511. treo680_udc_init();
  512. pxa_set_udc_info(&treo680_udc_info);
  513. pxa_set_ac97_info(&treo680_ac97_pdata);
  514. pxa_set_ficp_info(&treo680_ficp_info);
  515. pxa_set_ohci_info(&treo680_ohci_info);
  516. platform_add_devices(devices, ARRAY_SIZE(devices));
  517. }
  518. MACHINE_START(TREO680, "Palm Treo 680")
  519. .phys_io = TREO680_PHYS_IO_START,
  520. .io_pg_offst = io_p2v(0x40000000),
  521. .boot_params = 0xa0000100,
  522. .map_io = pxa_map_io,
  523. .init_irq = pxa27x_init_irq,
  524. .timer = &pxa_timer,
  525. .init_machine = treo680_init,
  526. MACHINE_END