palmtx.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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. /* MISC. */
  118. GPIO10_GPIO, /* hotsync button */
  119. GPIO12_GPIO, /* power detect */
  120. GPIO107_GPIO, /* earphone detect */
  121. };
  122. /******************************************************************************
  123. * SD/MMC card controller
  124. ******************************************************************************/
  125. static int palmtx_mci_init(struct device *dev, irq_handler_t palmtx_detect_int,
  126. void *data)
  127. {
  128. int err = 0;
  129. /* Setup an interrupt for detecting card insert/remove events */
  130. err = gpio_request(GPIO_NR_PALMTX_SD_DETECT_N, "SD IRQ");
  131. if (err)
  132. goto err;
  133. err = gpio_direction_input(GPIO_NR_PALMTX_SD_DETECT_N);
  134. if (err)
  135. goto err2;
  136. err = request_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N),
  137. palmtx_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  138. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  139. "SD/MMC card detect", data);
  140. if (err) {
  141. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  142. __func__);
  143. goto err2;
  144. }
  145. err = gpio_request(GPIO_NR_PALMTX_SD_POWER, "SD_POWER");
  146. if (err)
  147. goto err3;
  148. err = gpio_direction_output(GPIO_NR_PALMTX_SD_POWER, 0);
  149. if (err)
  150. goto err4;
  151. err = gpio_request(GPIO_NR_PALMTX_SD_READONLY, "SD_READONLY");
  152. if (err)
  153. goto err4;
  154. err = gpio_direction_input(GPIO_NR_PALMTX_SD_READONLY);
  155. if (err)
  156. goto err5;
  157. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  158. return 0;
  159. err5:
  160. gpio_free(GPIO_NR_PALMTX_SD_READONLY);
  161. err4:
  162. gpio_free(GPIO_NR_PALMTX_SD_POWER);
  163. err3:
  164. free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
  165. err2:
  166. gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
  167. err:
  168. return err;
  169. }
  170. static void palmtx_mci_exit(struct device *dev, void *data)
  171. {
  172. gpio_free(GPIO_NR_PALMTX_SD_READONLY);
  173. gpio_free(GPIO_NR_PALMTX_SD_POWER);
  174. free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
  175. gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
  176. }
  177. static void palmtx_mci_power(struct device *dev, unsigned int vdd)
  178. {
  179. struct pxamci_platform_data *p_d = dev->platform_data;
  180. gpio_set_value(GPIO_NR_PALMTX_SD_POWER, p_d->ocr_mask & (1 << vdd));
  181. }
  182. static int palmtx_mci_get_ro(struct device *dev)
  183. {
  184. return gpio_get_value(GPIO_NR_PALMTX_SD_READONLY);
  185. }
  186. static struct pxamci_platform_data palmtx_mci_platform_data = {
  187. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  188. .setpower = palmtx_mci_power,
  189. .get_ro = palmtx_mci_get_ro,
  190. .init = palmtx_mci_init,
  191. .exit = palmtx_mci_exit,
  192. };
  193. /******************************************************************************
  194. * GPIO keyboard
  195. ******************************************************************************/
  196. static unsigned int palmtx_matrix_keys[] = {
  197. KEY(0, 0, KEY_POWER),
  198. KEY(0, 1, KEY_F1),
  199. KEY(0, 2, KEY_ENTER),
  200. KEY(1, 0, KEY_F2),
  201. KEY(1, 1, KEY_F3),
  202. KEY(1, 2, KEY_F4),
  203. KEY(2, 0, KEY_UP),
  204. KEY(2, 2, KEY_DOWN),
  205. KEY(3, 0, KEY_RIGHT),
  206. KEY(3, 2, KEY_LEFT),
  207. };
  208. static struct pxa27x_keypad_platform_data palmtx_keypad_platform_data = {
  209. .matrix_key_rows = 4,
  210. .matrix_key_cols = 3,
  211. .matrix_key_map = palmtx_matrix_keys,
  212. .matrix_key_map_size = ARRAY_SIZE(palmtx_matrix_keys),
  213. .debounce_interval = 30,
  214. };
  215. /******************************************************************************
  216. * GPIO keys
  217. ******************************************************************************/
  218. static struct gpio_keys_button palmtx_pxa_buttons[] = {
  219. {KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
  220. };
  221. static struct gpio_keys_platform_data palmtx_pxa_keys_data = {
  222. .buttons = palmtx_pxa_buttons,
  223. .nbuttons = ARRAY_SIZE(palmtx_pxa_buttons),
  224. };
  225. static struct platform_device palmtx_pxa_keys = {
  226. .name = "gpio-keys",
  227. .id = -1,
  228. .dev = {
  229. .platform_data = &palmtx_pxa_keys_data,
  230. },
  231. };
  232. /******************************************************************************
  233. * Backlight
  234. ******************************************************************************/
  235. static int palmtx_backlight_init(struct device *dev)
  236. {
  237. int ret;
  238. ret = gpio_request(GPIO_NR_PALMTX_BL_POWER, "BL POWER");
  239. if (ret)
  240. goto err;
  241. ret = gpio_direction_output(GPIO_NR_PALMTX_BL_POWER, 0);
  242. if (ret)
  243. goto err2;
  244. ret = gpio_request(GPIO_NR_PALMTX_LCD_POWER, "LCD POWER");
  245. if (ret)
  246. goto err2;
  247. ret = gpio_direction_output(GPIO_NR_PALMTX_LCD_POWER, 0);
  248. if (ret)
  249. goto err3;
  250. return 0;
  251. err3:
  252. gpio_free(GPIO_NR_PALMTX_LCD_POWER);
  253. err2:
  254. gpio_free(GPIO_NR_PALMTX_BL_POWER);
  255. err:
  256. return ret;
  257. }
  258. static int palmtx_backlight_notify(int brightness)
  259. {
  260. gpio_set_value(GPIO_NR_PALMTX_BL_POWER, brightness);
  261. gpio_set_value(GPIO_NR_PALMTX_LCD_POWER, brightness);
  262. return brightness;
  263. }
  264. static void palmtx_backlight_exit(struct device *dev)
  265. {
  266. gpio_free(GPIO_NR_PALMTX_BL_POWER);
  267. gpio_free(GPIO_NR_PALMTX_LCD_POWER);
  268. }
  269. static struct platform_pwm_backlight_data palmtx_backlight_data = {
  270. .pwm_id = 0,
  271. .max_brightness = PALMTX_MAX_INTENSITY,
  272. .dft_brightness = PALMTX_MAX_INTENSITY,
  273. .pwm_period_ns = PALMTX_PERIOD_NS,
  274. .init = palmtx_backlight_init,
  275. .notify = palmtx_backlight_notify,
  276. .exit = palmtx_backlight_exit,
  277. };
  278. static struct platform_device palmtx_backlight = {
  279. .name = "pwm-backlight",
  280. .dev = {
  281. .parent = &pxa27x_device_pwm0.dev,
  282. .platform_data = &palmtx_backlight_data,
  283. },
  284. };
  285. /******************************************************************************
  286. * IrDA
  287. ******************************************************************************/
  288. static int palmtx_irda_startup(struct device *dev)
  289. {
  290. int err;
  291. err = gpio_request(GPIO_NR_PALMTX_IR_DISABLE, "IR DISABLE");
  292. if (err)
  293. goto err;
  294. err = gpio_direction_output(GPIO_NR_PALMTX_IR_DISABLE, 1);
  295. if (err)
  296. gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
  297. err:
  298. return err;
  299. }
  300. static void palmtx_irda_shutdown(struct device *dev)
  301. {
  302. gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
  303. }
  304. static void palmtx_irda_transceiver_mode(struct device *dev, int mode)
  305. {
  306. gpio_set_value(GPIO_NR_PALMTX_IR_DISABLE, mode & IR_OFF);
  307. pxa2xx_transceiver_mode(dev, mode);
  308. }
  309. static struct pxaficp_platform_data palmtx_ficp_platform_data = {
  310. .startup = palmtx_irda_startup,
  311. .shutdown = palmtx_irda_shutdown,
  312. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  313. .transceiver_mode = palmtx_irda_transceiver_mode,
  314. };
  315. /******************************************************************************
  316. * UDC
  317. ******************************************************************************/
  318. static struct gpio_vbus_mach_info palmtx_udc_info = {
  319. .gpio_vbus = GPIO_NR_PALMTX_USB_DETECT_N,
  320. .gpio_vbus_inverted = 1,
  321. .gpio_pullup = GPIO_NR_PALMTX_USB_PULLUP,
  322. };
  323. static struct platform_device palmtx_gpio_vbus = {
  324. .name = "gpio-vbus",
  325. .id = -1,
  326. .dev = {
  327. .platform_data = &palmtx_udc_info,
  328. },
  329. };
  330. /******************************************************************************
  331. * Power supply
  332. ******************************************************************************/
  333. static int power_supply_init(struct device *dev)
  334. {
  335. int ret;
  336. ret = gpio_request(GPIO_NR_PALMTX_POWER_DETECT, "CABLE_STATE_AC");
  337. if (ret)
  338. goto err1;
  339. ret = gpio_direction_input(GPIO_NR_PALMTX_POWER_DETECT);
  340. if (ret)
  341. goto err2;
  342. return 0;
  343. err2:
  344. gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
  345. err1:
  346. return ret;
  347. }
  348. static int palmtx_is_ac_online(void)
  349. {
  350. return gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT);
  351. }
  352. static void power_supply_exit(struct device *dev)
  353. {
  354. gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
  355. }
  356. static char *palmtx_supplicants[] = {
  357. "main-battery",
  358. };
  359. static struct pda_power_pdata power_supply_info = {
  360. .init = power_supply_init,
  361. .is_ac_online = palmtx_is_ac_online,
  362. .exit = power_supply_exit,
  363. .supplied_to = palmtx_supplicants,
  364. .num_supplicants = ARRAY_SIZE(palmtx_supplicants),
  365. };
  366. static struct platform_device power_supply = {
  367. .name = "pda-power",
  368. .id = -1,
  369. .dev = {
  370. .platform_data = &power_supply_info,
  371. },
  372. };
  373. /******************************************************************************
  374. * WM97xx battery
  375. ******************************************************************************/
  376. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  377. .batt_aux = WM97XX_AUX_ID3,
  378. .temp_aux = WM97XX_AUX_ID2,
  379. .charge_gpio = -1,
  380. .max_voltage = PALMTX_BAT_MAX_VOLTAGE,
  381. .min_voltage = PALMTX_BAT_MIN_VOLTAGE,
  382. .batt_mult = 1000,
  383. .batt_div = 414,
  384. .temp_mult = 1,
  385. .temp_div = 1,
  386. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  387. .batt_name = "main-batt",
  388. };
  389. /******************************************************************************
  390. * aSoC audio
  391. ******************************************************************************/
  392. static struct palm27x_asoc_info palmtx_asoc_pdata = {
  393. .jack_gpio = GPIO_NR_PALMTX_EARPHONE_DETECT,
  394. };
  395. static pxa2xx_audio_ops_t palmtx_ac97_pdata = {
  396. .reset_gpio = 95,
  397. };
  398. static struct platform_device palmtx_asoc = {
  399. .name = "palm27x-asoc",
  400. .id = -1,
  401. .dev = {
  402. .platform_data = &palmtx_asoc_pdata,
  403. },
  404. };
  405. /******************************************************************************
  406. * Framebuffer
  407. ******************************************************************************/
  408. static struct pxafb_mode_info palmtx_lcd_modes[] = {
  409. {
  410. .pixclock = 57692,
  411. .xres = 320,
  412. .yres = 480,
  413. .bpp = 16,
  414. .left_margin = 32,
  415. .right_margin = 1,
  416. .upper_margin = 7,
  417. .lower_margin = 1,
  418. .hsync_len = 4,
  419. .vsync_len = 1,
  420. },
  421. };
  422. static struct pxafb_mach_info palmtx_lcd_screen = {
  423. .modes = palmtx_lcd_modes,
  424. .num_modes = ARRAY_SIZE(palmtx_lcd_modes),
  425. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  426. };
  427. /******************************************************************************
  428. * Power management - standby
  429. ******************************************************************************/
  430. static void __init palmtx_pm_init(void)
  431. {
  432. static u32 resume[] = {
  433. 0xe3a00101, /* mov r0, #0x40000000 */
  434. 0xe380060f, /* orr r0, r0, #0x00f00000 */
  435. 0xe590f008, /* ldr pc, [r0, #0x08] */
  436. };
  437. /* copy the bootloader */
  438. memcpy(phys_to_virt(PALMTX_STR_BASE), resume, sizeof(resume));
  439. }
  440. /******************************************************************************
  441. * Machine init
  442. ******************************************************************************/
  443. static struct platform_device *devices[] __initdata = {
  444. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  445. &palmtx_pxa_keys,
  446. #endif
  447. &palmtx_backlight,
  448. &power_supply,
  449. &palmtx_asoc,
  450. &palmtx_gpio_vbus,
  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. palmtx_pm_init();
  477. set_pxa_fb_info(&palmtx_lcd_screen);
  478. pxa_set_mci_info(&palmtx_mci_platform_data);
  479. palmtx_udc_init();
  480. pxa_set_ac97_info(&palmtx_ac97_pdata);
  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