palmtx.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. * Hardware definitions for PalmTX
  3. *
  4. * Author: Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * Based on work of:
  7. * Alex Osborne <ato@meshy.org>
  8. * Cristiano P. <cristianop@users.sourceforge.net>
  9. * Jan Herman <2hp@seznam.cz>
  10. * Michal Hrusecky
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * (find more info at www.hackndev.com)
  17. *
  18. */
  19. #include <linux/platform_device.h>
  20. #include <linux/delay.h>
  21. #include <linux/irq.h>
  22. #include <linux/gpio_keys.h>
  23. #include <linux/input.h>
  24. #include <linux/pda_power.h>
  25. #include <linux/pwm_backlight.h>
  26. #include <linux/gpio.h>
  27. #include <linux/wm97xx_batt.h>
  28. #include <linux/power_supply.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/map.h>
  32. #include <mach/pxa27x.h>
  33. #include <mach/audio.h>
  34. #include <mach/palmtx.h>
  35. #include <mach/mmc.h>
  36. #include <mach/pxafb.h>
  37. #include <mach/irda.h>
  38. #include <mach/pxa27x_keypad.h>
  39. #include <mach/udc.h>
  40. #include <mach/palmasoc.h>
  41. #include "generic.h"
  42. #include "devices.h"
  43. /******************************************************************************
  44. * Pin configuration
  45. ******************************************************************************/
  46. static unsigned long palmtx_pin_config[] __initdata = {
  47. /* MMC */
  48. GPIO32_MMC_CLK,
  49. GPIO92_MMC_DAT_0,
  50. GPIO109_MMC_DAT_1,
  51. GPIO110_MMC_DAT_2,
  52. GPIO111_MMC_DAT_3,
  53. GPIO112_MMC_CMD,
  54. GPIO14_GPIO, /* SD detect */
  55. GPIO114_GPIO, /* SD power */
  56. GPIO115_GPIO, /* SD r/o switch */
  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. GPIO40_GPIO, /* ir disable */
  66. GPIO46_FICP_RXD,
  67. GPIO47_FICP_TXD,
  68. /* PWM */
  69. GPIO16_PWM0_OUT,
  70. /* USB */
  71. GPIO13_GPIO, /* usb detect */
  72. GPIO93_GPIO, /* usb power */
  73. /* PCMCIA */
  74. GPIO48_nPOE,
  75. GPIO49_nPWE,
  76. GPIO50_nPIOR,
  77. GPIO51_nPIOW,
  78. GPIO85_nPCE_1,
  79. GPIO54_nPCE_2,
  80. GPIO79_PSKTSEL,
  81. GPIO55_nPREG,
  82. GPIO56_nPWAIT,
  83. GPIO57_nIOIS16,
  84. GPIO94_GPIO, /* wifi power 1 */
  85. GPIO108_GPIO, /* wifi power 2 */
  86. GPIO116_GPIO, /* wifi ready */
  87. /* MATRIX KEYPAD */
  88. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  89. GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
  90. GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
  91. GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
  92. GPIO103_KP_MKOUT_0,
  93. GPIO104_KP_MKOUT_1,
  94. GPIO105_KP_MKOUT_2,
  95. /* LCD */
  96. GPIO58_LCD_LDD_0,
  97. GPIO59_LCD_LDD_1,
  98. GPIO60_LCD_LDD_2,
  99. GPIO61_LCD_LDD_3,
  100. GPIO62_LCD_LDD_4,
  101. GPIO63_LCD_LDD_5,
  102. GPIO64_LCD_LDD_6,
  103. GPIO65_LCD_LDD_7,
  104. GPIO66_LCD_LDD_8,
  105. GPIO67_LCD_LDD_9,
  106. GPIO68_LCD_LDD_10,
  107. GPIO69_LCD_LDD_11,
  108. GPIO70_LCD_LDD_12,
  109. GPIO71_LCD_LDD_13,
  110. GPIO72_LCD_LDD_14,
  111. GPIO73_LCD_LDD_15,
  112. GPIO74_LCD_FCLK,
  113. GPIO75_LCD_LCLK,
  114. GPIO76_LCD_PCLK,
  115. GPIO77_LCD_BIAS,
  116. /* MISC. */
  117. GPIO10_GPIO, /* hotsync button */
  118. GPIO12_GPIO, /* power detect */
  119. GPIO107_GPIO, /* earphone detect */
  120. };
  121. /******************************************************************************
  122. * SD/MMC card controller
  123. ******************************************************************************/
  124. static int palmtx_mci_init(struct device *dev, irq_handler_t palmtx_detect_int,
  125. void *data)
  126. {
  127. int err = 0;
  128. /* Setup an interrupt for detecting card insert/remove events */
  129. err = gpio_request(GPIO_NR_PALMTX_SD_DETECT_N, "SD IRQ");
  130. if (err)
  131. goto err;
  132. err = gpio_direction_input(GPIO_NR_PALMTX_SD_DETECT_N);
  133. if (err)
  134. goto err2;
  135. err = request_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N),
  136. palmtx_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  137. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  138. "SD/MMC card detect", data);
  139. if (err) {
  140. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  141. __func__);
  142. goto err2;
  143. }
  144. err = gpio_request(GPIO_NR_PALMTX_SD_POWER, "SD_POWER");
  145. if (err)
  146. goto err3;
  147. err = gpio_direction_output(GPIO_NR_PALMTX_SD_POWER, 0);
  148. if (err)
  149. goto err4;
  150. err = gpio_request(GPIO_NR_PALMTX_SD_READONLY, "SD_READONLY");
  151. if (err)
  152. goto err4;
  153. err = gpio_direction_input(GPIO_NR_PALMTX_SD_READONLY);
  154. if (err)
  155. goto err5;
  156. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  157. return 0;
  158. err5:
  159. gpio_free(GPIO_NR_PALMTX_SD_READONLY);
  160. err4:
  161. gpio_free(GPIO_NR_PALMTX_SD_POWER);
  162. err3:
  163. free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
  164. err2:
  165. gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
  166. err:
  167. return err;
  168. }
  169. static void palmtx_mci_exit(struct device *dev, void *data)
  170. {
  171. gpio_free(GPIO_NR_PALMTX_SD_READONLY);
  172. gpio_free(GPIO_NR_PALMTX_SD_POWER);
  173. free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
  174. gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
  175. }
  176. static void palmtx_mci_power(struct device *dev, unsigned int vdd)
  177. {
  178. struct pxamci_platform_data *p_d = dev->platform_data;
  179. gpio_set_value(GPIO_NR_PALMTX_SD_POWER, p_d->ocr_mask & (1 << vdd));
  180. }
  181. static int palmtx_mci_get_ro(struct device *dev)
  182. {
  183. return gpio_get_value(GPIO_NR_PALMTX_SD_READONLY);
  184. }
  185. static struct pxamci_platform_data palmtx_mci_platform_data = {
  186. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  187. .setpower = palmtx_mci_power,
  188. .get_ro = palmtx_mci_get_ro,
  189. .init = palmtx_mci_init,
  190. .exit = palmtx_mci_exit,
  191. };
  192. /******************************************************************************
  193. * GPIO keyboard
  194. ******************************************************************************/
  195. static unsigned int palmtx_matrix_keys[] = {
  196. KEY(0, 0, KEY_POWER),
  197. KEY(0, 1, KEY_F1),
  198. KEY(0, 2, KEY_ENTER),
  199. KEY(1, 0, KEY_F2),
  200. KEY(1, 1, KEY_F3),
  201. KEY(1, 2, KEY_F4),
  202. KEY(2, 0, KEY_UP),
  203. KEY(2, 2, KEY_DOWN),
  204. KEY(3, 0, KEY_RIGHT),
  205. KEY(3, 2, KEY_LEFT),
  206. };
  207. static struct pxa27x_keypad_platform_data palmtx_keypad_platform_data = {
  208. .matrix_key_rows = 4,
  209. .matrix_key_cols = 3,
  210. .matrix_key_map = palmtx_matrix_keys,
  211. .matrix_key_map_size = ARRAY_SIZE(palmtx_matrix_keys),
  212. .debounce_interval = 30,
  213. };
  214. /******************************************************************************
  215. * GPIO keys
  216. ******************************************************************************/
  217. static struct gpio_keys_button palmtx_pxa_buttons[] = {
  218. {KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
  219. };
  220. static struct gpio_keys_platform_data palmtx_pxa_keys_data = {
  221. .buttons = palmtx_pxa_buttons,
  222. .nbuttons = ARRAY_SIZE(palmtx_pxa_buttons),
  223. };
  224. static struct platform_device palmtx_pxa_keys = {
  225. .name = "gpio-keys",
  226. .id = -1,
  227. .dev = {
  228. .platform_data = &palmtx_pxa_keys_data,
  229. },
  230. };
  231. /******************************************************************************
  232. * Backlight
  233. ******************************************************************************/
  234. static int palmtx_backlight_init(struct device *dev)
  235. {
  236. int ret;
  237. ret = gpio_request(GPIO_NR_PALMTX_BL_POWER, "BL POWER");
  238. if (ret)
  239. goto err;
  240. ret = gpio_direction_output(GPIO_NR_PALMTX_BL_POWER, 0);
  241. if (ret)
  242. goto err2;
  243. ret = gpio_request(GPIO_NR_PALMTX_LCD_POWER, "LCD POWER");
  244. if (ret)
  245. goto err2;
  246. ret = gpio_direction_output(GPIO_NR_PALMTX_LCD_POWER, 0);
  247. if (ret)
  248. goto err3;
  249. return 0;
  250. err3:
  251. gpio_free(GPIO_NR_PALMTX_LCD_POWER);
  252. err2:
  253. gpio_free(GPIO_NR_PALMTX_BL_POWER);
  254. err:
  255. return ret;
  256. }
  257. static int palmtx_backlight_notify(int brightness)
  258. {
  259. gpio_set_value(GPIO_NR_PALMTX_BL_POWER, brightness);
  260. gpio_set_value(GPIO_NR_PALMTX_LCD_POWER, brightness);
  261. return brightness;
  262. }
  263. static void palmtx_backlight_exit(struct device *dev)
  264. {
  265. gpio_free(GPIO_NR_PALMTX_BL_POWER);
  266. gpio_free(GPIO_NR_PALMTX_LCD_POWER);
  267. }
  268. static struct platform_pwm_backlight_data palmtx_backlight_data = {
  269. .pwm_id = 0,
  270. .max_brightness = PALMTX_MAX_INTENSITY,
  271. .dft_brightness = PALMTX_MAX_INTENSITY,
  272. .pwm_period_ns = PALMTX_PERIOD_NS,
  273. .init = palmtx_backlight_init,
  274. .notify = palmtx_backlight_notify,
  275. .exit = palmtx_backlight_exit,
  276. };
  277. static struct platform_device palmtx_backlight = {
  278. .name = "pwm-backlight",
  279. .dev = {
  280. .parent = &pxa27x_device_pwm0.dev,
  281. .platform_data = &palmtx_backlight_data,
  282. },
  283. };
  284. /******************************************************************************
  285. * IrDA
  286. ******************************************************************************/
  287. static int palmtx_irda_startup(struct device *dev)
  288. {
  289. int err;
  290. err = gpio_request(GPIO_NR_PALMTX_IR_DISABLE, "IR DISABLE");
  291. if (err)
  292. goto err;
  293. err = gpio_direction_output(GPIO_NR_PALMTX_IR_DISABLE, 1);
  294. if (err)
  295. gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
  296. err:
  297. return err;
  298. }
  299. static void palmtx_irda_shutdown(struct device *dev)
  300. {
  301. gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
  302. }
  303. static void palmtx_irda_transceiver_mode(struct device *dev, int mode)
  304. {
  305. gpio_set_value(GPIO_NR_PALMTX_IR_DISABLE, mode & IR_OFF);
  306. pxa2xx_transceiver_mode(dev, mode);
  307. }
  308. static struct pxaficp_platform_data palmtx_ficp_platform_data = {
  309. .startup = palmtx_irda_startup,
  310. .shutdown = palmtx_irda_shutdown,
  311. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  312. .transceiver_mode = palmtx_irda_transceiver_mode,
  313. };
  314. /******************************************************************************
  315. * UDC
  316. ******************************************************************************/
  317. static struct pxa2xx_udc_mach_info palmtx_udc_info __initdata = {
  318. .gpio_vbus = GPIO_NR_PALMTX_USB_DETECT_N,
  319. .gpio_vbus_inverted = 1,
  320. .gpio_pullup = GPIO_NR_PALMTX_USB_PULLUP,
  321. .gpio_pullup_inverted = 0,
  322. };
  323. /******************************************************************************
  324. * Power supply
  325. ******************************************************************************/
  326. static int power_supply_init(struct device *dev)
  327. {
  328. int ret;
  329. ret = gpio_request(GPIO_NR_PALMTX_POWER_DETECT, "CABLE_STATE_AC");
  330. if (ret)
  331. goto err1;
  332. ret = gpio_direction_input(GPIO_NR_PALMTX_POWER_DETECT);
  333. if (ret)
  334. goto err2;
  335. return 0;
  336. err2:
  337. gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
  338. err1:
  339. return ret;
  340. }
  341. static int palmtx_is_ac_online(void)
  342. {
  343. return gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT);
  344. }
  345. static void power_supply_exit(struct device *dev)
  346. {
  347. gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
  348. }
  349. static char *palmtx_supplicants[] = {
  350. "main-battery",
  351. };
  352. static struct pda_power_pdata power_supply_info = {
  353. .init = power_supply_init,
  354. .is_ac_online = palmtx_is_ac_online,
  355. .exit = power_supply_exit,
  356. .supplied_to = palmtx_supplicants,
  357. .num_supplicants = ARRAY_SIZE(palmtx_supplicants),
  358. };
  359. static struct platform_device power_supply = {
  360. .name = "pda-power",
  361. .id = -1,
  362. .dev = {
  363. .platform_data = &power_supply_info,
  364. },
  365. };
  366. /******************************************************************************
  367. * WM97xx battery
  368. ******************************************************************************/
  369. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  370. .batt_aux = WM97XX_AUX_ID3,
  371. .temp_aux = WM97XX_AUX_ID2,
  372. .charge_gpio = -1,
  373. .max_voltage = PALMTX_BAT_MAX_VOLTAGE,
  374. .min_voltage = PALMTX_BAT_MIN_VOLTAGE,
  375. .batt_mult = 1000,
  376. .batt_div = 414,
  377. .temp_mult = 1,
  378. .temp_div = 1,
  379. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  380. .batt_name = "main-batt",
  381. };
  382. /******************************************************************************
  383. * aSoC audio
  384. ******************************************************************************/
  385. static struct palm27x_asoc_info palmtx_asoc_pdata = {
  386. .jack_gpio = GPIO_NR_PALMTX_EARPHONE_DETECT,
  387. };
  388. static pxa2xx_audio_ops_t palmtx_ac97_pdata = {
  389. .reset_gpio = 95,
  390. };
  391. static struct platform_device palmtx_asoc = {
  392. .name = "palm27x-asoc",
  393. .id = -1,
  394. .dev = {
  395. .platform_data = &palmtx_asoc_pdata,
  396. },
  397. };
  398. /******************************************************************************
  399. * Framebuffer
  400. ******************************************************************************/
  401. static struct pxafb_mode_info palmtx_lcd_modes[] = {
  402. {
  403. .pixclock = 57692,
  404. .xres = 320,
  405. .yres = 480,
  406. .bpp = 16,
  407. .left_margin = 32,
  408. .right_margin = 1,
  409. .upper_margin = 7,
  410. .lower_margin = 1,
  411. .hsync_len = 4,
  412. .vsync_len = 1,
  413. },
  414. };
  415. static struct pxafb_mach_info palmtx_lcd_screen = {
  416. .modes = palmtx_lcd_modes,
  417. .num_modes = ARRAY_SIZE(palmtx_lcd_modes),
  418. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  419. };
  420. /******************************************************************************
  421. * Power management - standby
  422. ******************************************************************************/
  423. #ifdef CONFIG_PM
  424. static u32 *addr __initdata;
  425. static u32 resume[3] __initdata = {
  426. 0xe3a00101, /* mov r0, #0x40000000 */
  427. 0xe380060f, /* orr r0, r0, #0x00f00000 */
  428. 0xe590f008, /* ldr pc, [r0, #0x08] */
  429. };
  430. static int __init palmtx_pm_init(void)
  431. {
  432. int i;
  433. /* this is where the bootloader jumps */
  434. addr = phys_to_virt(PALMTX_STR_BASE);
  435. for (i = 0; i < 3; i++)
  436. addr[i] = resume[i];
  437. return 0;
  438. }
  439. device_initcall(palmtx_pm_init);
  440. #endif
  441. /******************************************************************************
  442. * Machine init
  443. ******************************************************************************/
  444. static struct platform_device *devices[] __initdata = {
  445. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  446. &palmtx_pxa_keys,
  447. #endif
  448. &palmtx_backlight,
  449. &power_supply,
  450. &palmtx_asoc,
  451. };
  452. static struct map_desc palmtx_io_desc[] __initdata = {
  453. {
  454. .virtual = PALMTX_PCMCIA_VIRT,
  455. .pfn = __phys_to_pfn(PALMTX_PCMCIA_PHYS),
  456. .length = PALMTX_PCMCIA_SIZE,
  457. .type = MT_DEVICE
  458. },
  459. };
  460. static void __init palmtx_map_io(void)
  461. {
  462. pxa_map_io();
  463. iotable_init(palmtx_io_desc, ARRAY_SIZE(palmtx_io_desc));
  464. }
  465. /* setup udc GPIOs initial state */
  466. static void __init palmtx_udc_init(void)
  467. {
  468. if (!gpio_request(GPIO_NR_PALMTX_USB_PULLUP, "UDC Vbus")) {
  469. gpio_direction_output(GPIO_NR_PALMTX_USB_PULLUP, 1);
  470. gpio_free(GPIO_NR_PALMTX_USB_PULLUP);
  471. }
  472. }
  473. static void __init palmtx_init(void)
  474. {
  475. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmtx_pin_config));
  476. set_pxa_fb_info(&palmtx_lcd_screen);
  477. pxa_set_mci_info(&palmtx_mci_platform_data);
  478. palmtx_udc_init();
  479. pxa_set_ac97_info(&palmtx_ac97_pdata);
  480. pxa_set_udc_info(&palmtx_udc_info);
  481. pxa_set_ficp_info(&palmtx_ficp_platform_data);
  482. pxa_set_keypad_info(&palmtx_keypad_platform_data);
  483. wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
  484. platform_add_devices(devices, ARRAY_SIZE(devices));
  485. }
  486. MACHINE_START(PALMTX, "Palm T|X")
  487. .phys_io = PALMTX_PHYS_IO_START,
  488. .io_pg_offst = io_p2v(0x40000000),
  489. .boot_params = 0xa0000100,
  490. .map_io = palmtx_map_io,
  491. .init_irq = pxa27x_init_irq,
  492. .timer = &pxa_timer,
  493. .init_machine = palmtx_init
  494. MACHINE_END