palmtreo.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Hardware definitions for Palm Treo smartphones
  4. *
  5. * currently supported:
  6. * Palm Treo 680 (GSM)
  7. * Palm Centro 685 (GSM)
  8. *
  9. * Author: Tomas Cech <[email protected]>
  10. *
  11. * (find more info at www.hackndev.com)
  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/memblock.h>
  19. #include <linux/pda_power.h>
  20. #include <linux/pwm_backlight.h>
  21. #include <linux/gpio.h>
  22. #include <linux/power_supply.h>
  23. #include <linux/w1-gpio.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/map.h>
  27. #include "pxa27x.h"
  28. #include "pxa27x-udc.h"
  29. #include <linux/platform_data/asoc-pxa.h>
  30. #include "palmtreo.h"
  31. #include <linux/platform_data/mmc-pxamci.h>
  32. #include <linux/platform_data/video-pxafb.h>
  33. #include <linux/platform_data/irda-pxaficp.h>
  34. #include <linux/platform_data/keypad-pxa27x.h>
  35. #include "udc.h"
  36. #include <linux/platform_data/usb-ohci-pxa27x.h>
  37. #include "pxa2xx-regs.h"
  38. #include <linux/platform_data/asoc-palm27x.h>
  39. #include <linux/platform_data/media/camera-pxa.h>
  40. #include "palm27x.h"
  41. #include <sound/pxa2xx-lib.h>
  42. #include "generic.h"
  43. #include "devices.h"
  44. /******************************************************************************
  45. * Pin configuration
  46. ******************************************************************************/
  47. static unsigned long treo_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. GPIO113_GPIO, /* SD detect */
  56. /* AC97 */
  57. GPIO28_AC97_BITCLK,
  58. GPIO29_AC97_SDATA_IN_0,
  59. GPIO30_AC97_SDATA_OUT,
  60. GPIO31_AC97_SYNC,
  61. GPIO89_AC97_SYSCLK,
  62. GPIO95_AC97_nRESET,
  63. /* IrDA */
  64. GPIO46_FICP_RXD,
  65. GPIO47_FICP_TXD,
  66. /* PWM */
  67. GPIO16_PWM0_OUT,
  68. /* USB */
  69. GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH, /* usb detect */
  70. /* MATRIX KEYPAD */
  71. GPIO101_KP_MKIN_1,
  72. GPIO102_KP_MKIN_2,
  73. GPIO97_KP_MKIN_3,
  74. GPIO98_KP_MKIN_4,
  75. GPIO91_KP_MKIN_6,
  76. GPIO13_KP_MKIN_7,
  77. GPIO103_KP_MKOUT_0 | MFP_LPM_DRIVE_HIGH,
  78. GPIO104_KP_MKOUT_1,
  79. GPIO105_KP_MKOUT_2,
  80. GPIO106_KP_MKOUT_3,
  81. GPIO107_KP_MKOUT_4,
  82. GPIO108_KP_MKOUT_5,
  83. GPIO96_KP_MKOUT_6,
  84. GPIO93_KP_DKIN_0 | WAKEUP_ON_LEVEL_HIGH, /* Hotsync button */
  85. /* Quick Capture Interface */
  86. GPIO84_CIF_FV,
  87. GPIO85_CIF_LV,
  88. GPIO53_CIF_MCLK,
  89. GPIO54_CIF_PCLK,
  90. GPIO81_CIF_DD_0,
  91. GPIO55_CIF_DD_1,
  92. GPIO51_CIF_DD_2,
  93. GPIO50_CIF_DD_3,
  94. GPIO52_CIF_DD_4,
  95. GPIO48_CIF_DD_5,
  96. GPIO17_CIF_DD_6,
  97. GPIO12_CIF_DD_7,
  98. /* I2C */
  99. GPIO117_I2C_SCL,
  100. GPIO118_I2C_SDA,
  101. /* GSM */
  102. GPIO14_GPIO | WAKEUP_ON_EDGE_BOTH, /* GSM host wake up */
  103. GPIO34_FFUART_RXD,
  104. GPIO35_FFUART_CTS,
  105. GPIO39_FFUART_TXD,
  106. GPIO41_FFUART_RTS,
  107. /* MISC. */
  108. GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH, /* external power detect */
  109. GPIO15_GPIO | WAKEUP_ON_EDGE_BOTH, /* silent switch */
  110. GPIO116_GPIO, /* headphone detect */
  111. GPIO11_GPIO | WAKEUP_ON_EDGE_BOTH, /* bluetooth host wake up */
  112. };
  113. #ifdef CONFIG_MACH_TREO680
  114. static unsigned long treo680_pin_config[] __initdata = {
  115. GPIO33_GPIO, /* SD read only */
  116. /* MATRIX KEYPAD - different wake up source */
  117. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  118. GPIO99_KP_MKIN_5,
  119. /* LCD... L_BIAS alt fn not configured on Treo680; is GPIO instead */
  120. GPIOxx_LCD_16BPP,
  121. GPIO74_LCD_FCLK,
  122. GPIO75_LCD_LCLK,
  123. GPIO76_LCD_PCLK,
  124. };
  125. #endif /* CONFIG_MACH_TREO680 */
  126. #ifdef CONFIG_MACH_CENTRO
  127. static unsigned long centro685_pin_config[] __initdata = {
  128. /* Bluetooth attached to BT UART*/
  129. MFP_CFG_OUT(GPIO80, AF0, DRIVE_LOW), /* power: LOW = off */
  130. GPIO42_BTUART_RXD,
  131. GPIO43_BTUART_TXD,
  132. GPIO44_BTUART_CTS,
  133. GPIO45_BTUART_RTS,
  134. /* MATRIX KEYPAD - different wake up source */
  135. GPIO100_KP_MKIN_0,
  136. GPIO99_KP_MKIN_5 | WAKEUP_ON_LEVEL_HIGH,
  137. /* LCD */
  138. GPIOxx_LCD_TFT_16BPP,
  139. };
  140. #endif /* CONFIG_MACH_CENTRO */
  141. /******************************************************************************
  142. * GPIO keyboard
  143. ******************************************************************************/
  144. #if IS_ENABLED(CONFIG_KEYBOARD_PXA27x)
  145. static const unsigned int treo680_matrix_keys[] = {
  146. KEY(0, 0, KEY_F8), /* Red/Off/Power */
  147. KEY(0, 1, KEY_LEFT),
  148. KEY(0, 2, KEY_LEFTCTRL), /* Alternate */
  149. KEY(0, 3, KEY_L),
  150. KEY(0, 4, KEY_A),
  151. KEY(0, 5, KEY_Q),
  152. KEY(0, 6, KEY_P),
  153. KEY(1, 0, KEY_RIGHTCTRL), /* Menu */
  154. KEY(1, 1, KEY_RIGHT),
  155. KEY(1, 2, KEY_LEFTSHIFT), /* Left shift */
  156. KEY(1, 3, KEY_Z),
  157. KEY(1, 4, KEY_S),
  158. KEY(1, 5, KEY_W),
  159. KEY(2, 0, KEY_F1), /* Phone */
  160. KEY(2, 1, KEY_UP),
  161. KEY(2, 2, KEY_0),
  162. KEY(2, 3, KEY_X),
  163. KEY(2, 4, KEY_D),
  164. KEY(2, 5, KEY_E),
  165. KEY(3, 0, KEY_F10), /* Calendar */
  166. KEY(3, 1, KEY_DOWN),
  167. KEY(3, 2, KEY_SPACE),
  168. KEY(3, 3, KEY_C),
  169. KEY(3, 4, KEY_F),
  170. KEY(3, 5, KEY_R),
  171. KEY(4, 0, KEY_F12), /* Mail */
  172. KEY(4, 1, KEY_KPENTER),
  173. KEY(4, 2, KEY_RIGHTALT), /* Alt */
  174. KEY(4, 3, KEY_V),
  175. KEY(4, 4, KEY_G),
  176. KEY(4, 5, KEY_T),
  177. KEY(5, 0, KEY_F9), /* Home */
  178. KEY(5, 1, KEY_PAGEUP), /* Side up */
  179. KEY(5, 2, KEY_DOT),
  180. KEY(5, 3, KEY_B),
  181. KEY(5, 4, KEY_H),
  182. KEY(5, 5, KEY_Y),
  183. KEY(6, 0, KEY_TAB), /* Side Activate */
  184. KEY(6, 1, KEY_PAGEDOWN), /* Side down */
  185. KEY(6, 2, KEY_ENTER),
  186. KEY(6, 3, KEY_N),
  187. KEY(6, 4, KEY_J),
  188. KEY(6, 5, KEY_U),
  189. KEY(7, 0, KEY_F6), /* Green/Call */
  190. KEY(7, 1, KEY_O),
  191. KEY(7, 2, KEY_BACKSPACE),
  192. KEY(7, 3, KEY_M),
  193. KEY(7, 4, KEY_K),
  194. KEY(7, 5, KEY_I),
  195. };
  196. static const unsigned int centro_matrix_keys[] = {
  197. KEY(0, 0, KEY_F9), /* Home */
  198. KEY(0, 1, KEY_LEFT),
  199. KEY(0, 2, KEY_LEFTCTRL), /* Alternate */
  200. KEY(0, 3, KEY_L),
  201. KEY(0, 4, KEY_A),
  202. KEY(0, 5, KEY_Q),
  203. KEY(0, 6, KEY_P),
  204. KEY(1, 0, KEY_RIGHTCTRL), /* Menu */
  205. KEY(1, 1, KEY_RIGHT),
  206. KEY(1, 2, KEY_LEFTSHIFT), /* Left shift */
  207. KEY(1, 3, KEY_Z),
  208. KEY(1, 4, KEY_S),
  209. KEY(1, 5, KEY_W),
  210. KEY(2, 0, KEY_F1), /* Phone */
  211. KEY(2, 1, KEY_UP),
  212. KEY(2, 2, KEY_0),
  213. KEY(2, 3, KEY_X),
  214. KEY(2, 4, KEY_D),
  215. KEY(2, 5, KEY_E),
  216. KEY(3, 0, KEY_F10), /* Calendar */
  217. KEY(3, 1, KEY_DOWN),
  218. KEY(3, 2, KEY_SPACE),
  219. KEY(3, 3, KEY_C),
  220. KEY(3, 4, KEY_F),
  221. KEY(3, 5, KEY_R),
  222. KEY(4, 0, KEY_F12), /* Mail */
  223. KEY(4, 1, KEY_KPENTER),
  224. KEY(4, 2, KEY_RIGHTALT), /* Alt */
  225. KEY(4, 3, KEY_V),
  226. KEY(4, 4, KEY_G),
  227. KEY(4, 5, KEY_T),
  228. KEY(5, 0, KEY_F8), /* Red/Off/Power */
  229. KEY(5, 1, KEY_PAGEUP), /* Side up */
  230. KEY(5, 2, KEY_DOT),
  231. KEY(5, 3, KEY_B),
  232. KEY(5, 4, KEY_H),
  233. KEY(5, 5, KEY_Y),
  234. KEY(6, 0, KEY_TAB), /* Side Activate */
  235. KEY(6, 1, KEY_PAGEDOWN), /* Side down */
  236. KEY(6, 2, KEY_ENTER),
  237. KEY(6, 3, KEY_N),
  238. KEY(6, 4, KEY_J),
  239. KEY(6, 5, KEY_U),
  240. KEY(7, 0, KEY_F6), /* Green/Call */
  241. KEY(7, 1, KEY_O),
  242. KEY(7, 2, KEY_BACKSPACE),
  243. KEY(7, 3, KEY_M),
  244. KEY(7, 4, KEY_K),
  245. KEY(7, 5, KEY_I),
  246. };
  247. static struct matrix_keymap_data treo680_matrix_keymap_data = {
  248. .keymap = treo680_matrix_keys,
  249. .keymap_size = ARRAY_SIZE(treo680_matrix_keys),
  250. };
  251. static struct matrix_keymap_data centro_matrix_keymap_data = {
  252. .keymap = centro_matrix_keys,
  253. .keymap_size = ARRAY_SIZE(centro_matrix_keys),
  254. };
  255. static struct pxa27x_keypad_platform_data treo680_keypad_pdata = {
  256. .matrix_key_rows = 8,
  257. .matrix_key_cols = 7,
  258. .matrix_keymap_data = &treo680_matrix_keymap_data,
  259. .direct_key_map = { KEY_CONNECT },
  260. .direct_key_num = 1,
  261. .debounce_interval = 30,
  262. };
  263. static void __init palmtreo_kpc_init(void)
  264. {
  265. static struct pxa27x_keypad_platform_data *data = &treo680_keypad_pdata;
  266. if (machine_is_centro())
  267. data->matrix_keymap_data = &centro_matrix_keymap_data;
  268. pxa_set_keypad_info(&treo680_keypad_pdata);
  269. }
  270. #else
  271. static inline void palmtreo_kpc_init(void) {}
  272. #endif
  273. /******************************************************************************
  274. * USB host
  275. ******************************************************************************/
  276. #if IS_ENABLED(CONFIG_USB_OHCI_HCD)
  277. static struct pxaohci_platform_data treo680_ohci_info = {
  278. .port_mode = PMM_PERPORT_MODE,
  279. .flags = ENABLE_PORT1 | ENABLE_PORT3,
  280. .power_budget = 0,
  281. };
  282. static void __init palmtreo_uhc_init(void)
  283. {
  284. if (machine_is_treo680())
  285. pxa_set_ohci_info(&treo680_ohci_info);
  286. }
  287. #else
  288. static inline void palmtreo_uhc_init(void) {}
  289. #endif
  290. /******************************************************************************
  291. * Vibra and LEDs
  292. ******************************************************************************/
  293. static struct gpio_led treo680_gpio_leds[] = {
  294. {
  295. .name = "treo680:vibra:vibra",
  296. .default_trigger = "none",
  297. .gpio = GPIO_NR_TREO680_VIBRATE_EN,
  298. },
  299. {
  300. .name = "treo680:green:led",
  301. .default_trigger = "mmc0",
  302. .gpio = GPIO_NR_TREO_GREEN_LED,
  303. },
  304. {
  305. .name = "treo680:white:keybbl",
  306. .default_trigger = "none",
  307. .gpio = GPIO_NR_TREO680_KEYB_BL,
  308. },
  309. };
  310. static struct gpio_led_platform_data treo680_gpio_led_info = {
  311. .leds = treo680_gpio_leds,
  312. .num_leds = ARRAY_SIZE(treo680_gpio_leds),
  313. };
  314. static struct gpio_led centro_gpio_leds[] = {
  315. {
  316. .name = "centro:vibra:vibra",
  317. .default_trigger = "none",
  318. .gpio = GPIO_NR_CENTRO_VIBRATE_EN,
  319. },
  320. {
  321. .name = "centro:green:led",
  322. .default_trigger = "mmc0",
  323. .gpio = GPIO_NR_TREO_GREEN_LED,
  324. },
  325. {
  326. .name = "centro:white:keybbl",
  327. .default_trigger = "none",
  328. .active_low = 1,
  329. .gpio = GPIO_NR_CENTRO_KEYB_BL,
  330. },
  331. };
  332. static struct gpio_led_platform_data centro_gpio_led_info = {
  333. .leds = centro_gpio_leds,
  334. .num_leds = ARRAY_SIZE(centro_gpio_leds),
  335. };
  336. static struct platform_device palmtreo_leds = {
  337. .name = "leds-gpio",
  338. .id = -1,
  339. };
  340. static void __init palmtreo_leds_init(void)
  341. {
  342. if (machine_is_centro())
  343. palmtreo_leds.dev.platform_data = &centro_gpio_led_info;
  344. else if (machine_is_treo680())
  345. palmtreo_leds.dev.platform_data = &treo680_gpio_led_info;
  346. platform_device_register(&palmtreo_leds);
  347. }
  348. /******************************************************************************
  349. * Machine init
  350. ******************************************************************************/
  351. static void __init treo_reserve(void)
  352. {
  353. memblock_reserve(0xa0000000, 0x1000);
  354. memblock_reserve(0xa2000000, 0x1000);
  355. }
  356. static void __init palmphone_common_init(void)
  357. {
  358. pxa2xx_mfp_config(ARRAY_AND_SIZE(treo_pin_config));
  359. pxa_set_ffuart_info(NULL);
  360. pxa_set_btuart_info(NULL);
  361. pxa_set_stuart_info(NULL);
  362. palm27x_pm_init(TREO_STR_BASE);
  363. palm27x_lcd_init(GPIO_NR_TREO_BL_POWER, &palm_320x320_new_lcd_mode);
  364. palm27x_udc_init(GPIO_NR_TREO_USB_DETECT, GPIO_NR_TREO_USB_PULLUP, 1);
  365. palm27x_irda_init(GPIO_NR_TREO_IR_EN);
  366. palm27x_ac97_init(-1, -1, -1, 95);
  367. palm27x_pwm_init(GPIO_NR_TREO_BL_POWER, -1);
  368. palm27x_power_init(GPIO_NR_TREO_POWER_DETECT, -1);
  369. palm27x_pmic_init();
  370. palmtreo_kpc_init();
  371. palmtreo_uhc_init();
  372. palmtreo_leds_init();
  373. }
  374. #ifdef CONFIG_MACH_TREO680
  375. void __init treo680_gpio_init(void)
  376. {
  377. unsigned int gpio;
  378. /* drive all three lcd gpios high initially */
  379. const unsigned long lcd_flags = GPIOF_INIT_HIGH | GPIOF_DIR_OUT;
  380. /*
  381. * LCD GPIO initialization...
  382. */
  383. /*
  384. * This is likely the power to the lcd. Toggling it low/high appears to
  385. * turn the lcd off/on. Can be toggled after lcd is initialized without
  386. * any apparent adverse effects to the lcd operation. Note that this
  387. * gpio line is used by the lcd controller as the L_BIAS signal, but
  388. * treo680 configures it as gpio.
  389. */
  390. gpio = GPIO_NR_TREO680_LCD_POWER;
  391. if (gpio_request_one(gpio, lcd_flags, "LCD power") < 0)
  392. goto fail;
  393. /*
  394. * These two are called "enables", for lack of a better understanding.
  395. * If either of these are toggled after the lcd is initialized, the
  396. * image becomes degraded. N.B. The IPL shipped with the treo
  397. * configures GPIO_NR_TREO680_LCD_EN_N as output and drives it high. If
  398. * the IPL is ever reprogrammed, this initialization may be need to be
  399. * revisited.
  400. */
  401. gpio = GPIO_NR_TREO680_LCD_EN;
  402. if (gpio_request_one(gpio, lcd_flags, "LCD enable") < 0)
  403. goto fail;
  404. gpio = GPIO_NR_TREO680_LCD_EN_N;
  405. if (gpio_request_one(gpio, lcd_flags, "LCD enable_n") < 0)
  406. goto fail;
  407. /* driving this low turns LCD on */
  408. gpio_set_value(GPIO_NR_TREO680_LCD_EN_N, 0);
  409. return;
  410. fail:
  411. pr_err("gpio %d initialization failed\n", gpio);
  412. gpio_free(GPIO_NR_TREO680_LCD_POWER);
  413. gpio_free(GPIO_NR_TREO680_LCD_EN);
  414. gpio_free(GPIO_NR_TREO680_LCD_EN_N);
  415. }
  416. static struct gpiod_lookup_table treo680_mci_gpio_table = {
  417. .dev_id = "pxa2xx-mci.0",
  418. .table = {
  419. GPIO_LOOKUP("gpio-pxa", GPIO_NR_TREO_SD_DETECT_N,
  420. "cd", GPIO_ACTIVE_LOW),
  421. GPIO_LOOKUP("gpio-pxa", GPIO_NR_TREO680_SD_READONLY,
  422. "wp", GPIO_ACTIVE_LOW),
  423. GPIO_LOOKUP("gpio-pxa", GPIO_NR_TREO680_SD_POWER,
  424. "power", GPIO_ACTIVE_HIGH),
  425. { },
  426. },
  427. };
  428. static void __init treo680_init(void)
  429. {
  430. pxa2xx_mfp_config(ARRAY_AND_SIZE(treo680_pin_config));
  431. palmphone_common_init();
  432. treo680_gpio_init();
  433. palm27x_mmc_init(&treo680_mci_gpio_table);
  434. }
  435. #endif
  436. #ifdef CONFIG_MACH_CENTRO
  437. static struct gpiod_lookup_table centro685_mci_gpio_table = {
  438. .dev_id = "pxa2xx-mci.0",
  439. .table = {
  440. GPIO_LOOKUP("gpio-pxa", GPIO_NR_TREO_SD_DETECT_N,
  441. "cd", GPIO_ACTIVE_LOW),
  442. GPIO_LOOKUP("gpio-pxa", GPIO_NR_CENTRO_SD_POWER,
  443. "power", GPIO_ACTIVE_LOW),
  444. { },
  445. },
  446. };
  447. static void __init centro_init(void)
  448. {
  449. pxa2xx_mfp_config(ARRAY_AND_SIZE(centro685_pin_config));
  450. palmphone_common_init();
  451. palm27x_mmc_init(&centro685_mci_gpio_table);
  452. }
  453. #endif
  454. #ifdef CONFIG_MACH_TREO680
  455. MACHINE_START(TREO680, "Palm Treo 680")
  456. .atag_offset = 0x100,
  457. .map_io = pxa27x_map_io,
  458. .reserve = treo_reserve,
  459. .nr_irqs = PXA_NR_IRQS,
  460. .init_irq = pxa27x_init_irq,
  461. .handle_irq = pxa27x_handle_irq,
  462. .init_time = pxa_timer_init,
  463. .init_machine = treo680_init,
  464. .restart = pxa_restart,
  465. MACHINE_END
  466. #endif
  467. #ifdef CONFIG_MACH_CENTRO
  468. MACHINE_START(CENTRO, "Palm Centro 685")
  469. .atag_offset = 0x100,
  470. .map_io = pxa27x_map_io,
  471. .reserve = treo_reserve,
  472. .nr_irqs = PXA_NR_IRQS,
  473. .init_irq = pxa27x_init_irq,
  474. .handle_irq = pxa27x_handle_irq,
  475. .init_time = pxa_timer_init,
  476. .init_machine = centro_init,
  477. .restart = pxa_restart,
  478. MACHINE_END
  479. #endif