palmtx.c 14 KB

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