palmtx.c 13 KB

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