palmt5.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /*
  2. * Hardware definitions for Palm Tungsten|T5
  3. *
  4. * Author: Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * Based on work of:
  7. * Ales Snuparek <snuparek@atlas.cz>
  8. * Justin Kendrick <twilightsentry@gmail.com>
  9. * RichardT5 <richard_t5@users.sourceforge.net>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. * (find more info at www.hackndev.com)
  16. *
  17. */
  18. #include <linux/platform_device.h>
  19. #include <linux/delay.h>
  20. #include <linux/irq.h>
  21. #include <linux/gpio_keys.h>
  22. #include <linux/input.h>
  23. #include <linux/pda_power.h>
  24. #include <linux/pwm_backlight.h>
  25. #include <linux/gpio.h>
  26. #include <linux/wm97xx_batt.h>
  27. #include <linux/power_supply.h>
  28. #include <asm/mach-types.h>
  29. #include <asm/mach/arch.h>
  30. #include <asm/mach/map.h>
  31. #include <mach/pxa27x.h>
  32. #include <mach/audio.h>
  33. #include <mach/palmt5.h>
  34. #include <mach/mmc.h>
  35. #include <mach/pxafb.h>
  36. #include <mach/irda.h>
  37. #include <mach/pxa27x_keypad.h>
  38. #include <mach/udc.h>
  39. #include <mach/palmasoc.h>
  40. #include "generic.h"
  41. #include "devices.h"
  42. /******************************************************************************
  43. * Pin configuration
  44. ******************************************************************************/
  45. static unsigned long palmt5_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. /* USB */
  66. GPIO15_GPIO, /* usb detect */
  67. GPIO95_GPIO, /* usb power */
  68. /* MATRIX KEYPAD */
  69. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  70. GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
  71. GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
  72. GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
  73. GPIO103_KP_MKOUT_0,
  74. GPIO104_KP_MKOUT_1,
  75. GPIO105_KP_MKOUT_2,
  76. /* LCD */
  77. GPIO58_LCD_LDD_0,
  78. GPIO59_LCD_LDD_1,
  79. GPIO60_LCD_LDD_2,
  80. GPIO61_LCD_LDD_3,
  81. GPIO62_LCD_LDD_4,
  82. GPIO63_LCD_LDD_5,
  83. GPIO64_LCD_LDD_6,
  84. GPIO65_LCD_LDD_7,
  85. GPIO66_LCD_LDD_8,
  86. GPIO67_LCD_LDD_9,
  87. GPIO68_LCD_LDD_10,
  88. GPIO69_LCD_LDD_11,
  89. GPIO70_LCD_LDD_12,
  90. GPIO71_LCD_LDD_13,
  91. GPIO72_LCD_LDD_14,
  92. GPIO73_LCD_LDD_15,
  93. GPIO74_LCD_FCLK,
  94. GPIO75_LCD_LCLK,
  95. GPIO76_LCD_PCLK,
  96. GPIO77_LCD_BIAS,
  97. /* PWM */
  98. GPIO16_PWM0_OUT,
  99. /* MISC */
  100. GPIO10_GPIO, /* hotsync button */
  101. GPIO90_GPIO, /* power detect */
  102. GPIO107_GPIO, /* earphone detect */
  103. };
  104. /******************************************************************************
  105. * SD/MMC card controller
  106. ******************************************************************************/
  107. static int palmt5_mci_init(struct device *dev, irq_handler_t palmt5_detect_int,
  108. void *data)
  109. {
  110. int err = 0;
  111. /* Setup an interrupt for detecting card insert/remove events */
  112. err = gpio_request(GPIO_NR_PALMT5_SD_DETECT_N, "SD IRQ");
  113. if (err)
  114. goto err;
  115. err = gpio_direction_input(GPIO_NR_PALMT5_SD_DETECT_N);
  116. if (err)
  117. goto err2;
  118. err = request_irq(gpio_to_irq(GPIO_NR_PALMT5_SD_DETECT_N),
  119. palmt5_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  120. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  121. "SD/MMC card detect", data);
  122. if (err) {
  123. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  124. __func__);
  125. goto err2;
  126. }
  127. err = gpio_request(GPIO_NR_PALMT5_SD_POWER, "SD_POWER");
  128. if (err)
  129. goto err3;
  130. err = gpio_direction_output(GPIO_NR_PALMT5_SD_POWER, 0);
  131. if (err)
  132. goto err4;
  133. err = gpio_request(GPIO_NR_PALMT5_SD_READONLY, "SD_READONLY");
  134. if (err)
  135. goto err4;
  136. err = gpio_direction_input(GPIO_NR_PALMT5_SD_READONLY);
  137. if (err)
  138. goto err5;
  139. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  140. return 0;
  141. err5:
  142. gpio_free(GPIO_NR_PALMT5_SD_READONLY);
  143. err4:
  144. gpio_free(GPIO_NR_PALMT5_SD_POWER);
  145. err3:
  146. free_irq(gpio_to_irq(GPIO_NR_PALMT5_SD_DETECT_N), data);
  147. err2:
  148. gpio_free(GPIO_NR_PALMT5_SD_DETECT_N);
  149. err:
  150. return err;
  151. }
  152. static void palmt5_mci_exit(struct device *dev, void *data)
  153. {
  154. gpio_free(GPIO_NR_PALMT5_SD_READONLY);
  155. gpio_free(GPIO_NR_PALMT5_SD_POWER);
  156. free_irq(IRQ_GPIO_PALMT5_SD_DETECT_N, data);
  157. gpio_free(GPIO_NR_PALMT5_SD_DETECT_N);
  158. }
  159. static void palmt5_mci_power(struct device *dev, unsigned int vdd)
  160. {
  161. struct pxamci_platform_data *p_d = dev->platform_data;
  162. gpio_set_value(GPIO_NR_PALMT5_SD_POWER, p_d->ocr_mask & (1 << vdd));
  163. }
  164. static int palmt5_mci_get_ro(struct device *dev)
  165. {
  166. return gpio_get_value(GPIO_NR_PALMT5_SD_READONLY);
  167. }
  168. static struct pxamci_platform_data palmt5_mci_platform_data = {
  169. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  170. .setpower = palmt5_mci_power,
  171. .get_ro = palmt5_mci_get_ro,
  172. .init = palmt5_mci_init,
  173. .exit = palmt5_mci_exit,
  174. };
  175. /******************************************************************************
  176. * GPIO keyboard
  177. ******************************************************************************/
  178. static unsigned int palmt5_matrix_keys[] = {
  179. KEY(0, 0, KEY_POWER),
  180. KEY(0, 1, KEY_F1),
  181. KEY(0, 2, KEY_ENTER),
  182. KEY(1, 0, KEY_F2),
  183. KEY(1, 1, KEY_F3),
  184. KEY(1, 2, KEY_F4),
  185. KEY(2, 0, KEY_UP),
  186. KEY(2, 2, KEY_DOWN),
  187. KEY(3, 0, KEY_RIGHT),
  188. KEY(3, 2, KEY_LEFT),
  189. };
  190. static struct pxa27x_keypad_platform_data palmt5_keypad_platform_data = {
  191. .matrix_key_rows = 4,
  192. .matrix_key_cols = 3,
  193. .matrix_key_map = palmt5_matrix_keys,
  194. .matrix_key_map_size = ARRAY_SIZE(palmt5_matrix_keys),
  195. .debounce_interval = 30,
  196. };
  197. /******************************************************************************
  198. * GPIO keys
  199. ******************************************************************************/
  200. static struct gpio_keys_button palmt5_pxa_buttons[] = {
  201. {KEY_F8, GPIO_NR_PALMT5_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
  202. };
  203. static struct gpio_keys_platform_data palmt5_pxa_keys_data = {
  204. .buttons = palmt5_pxa_buttons,
  205. .nbuttons = ARRAY_SIZE(palmt5_pxa_buttons),
  206. };
  207. static struct platform_device palmt5_pxa_keys = {
  208. .name = "gpio-keys",
  209. .id = -1,
  210. .dev = {
  211. .platform_data = &palmt5_pxa_keys_data,
  212. },
  213. };
  214. /******************************************************************************
  215. * Backlight
  216. ******************************************************************************/
  217. static int palmt5_backlight_init(struct device *dev)
  218. {
  219. int ret;
  220. ret = gpio_request(GPIO_NR_PALMT5_BL_POWER, "BL POWER");
  221. if (ret)
  222. goto err;
  223. ret = gpio_direction_output(GPIO_NR_PALMT5_BL_POWER, 0);
  224. if (ret)
  225. goto err2;
  226. ret = gpio_request(GPIO_NR_PALMT5_LCD_POWER, "LCD POWER");
  227. if (ret)
  228. goto err2;
  229. ret = gpio_direction_output(GPIO_NR_PALMT5_LCD_POWER, 0);
  230. if (ret)
  231. goto err3;
  232. return 0;
  233. err3:
  234. gpio_free(GPIO_NR_PALMT5_LCD_POWER);
  235. err2:
  236. gpio_free(GPIO_NR_PALMT5_BL_POWER);
  237. err:
  238. return ret;
  239. }
  240. static int palmt5_backlight_notify(int brightness)
  241. {
  242. gpio_set_value(GPIO_NR_PALMT5_BL_POWER, brightness);
  243. gpio_set_value(GPIO_NR_PALMT5_LCD_POWER, brightness);
  244. return brightness;
  245. }
  246. static void palmt5_backlight_exit(struct device *dev)
  247. {
  248. gpio_free(GPIO_NR_PALMT5_BL_POWER);
  249. gpio_free(GPIO_NR_PALMT5_LCD_POWER);
  250. }
  251. static struct platform_pwm_backlight_data palmt5_backlight_data = {
  252. .pwm_id = 0,
  253. .max_brightness = PALMT5_MAX_INTENSITY,
  254. .dft_brightness = PALMT5_MAX_INTENSITY,
  255. .pwm_period_ns = PALMT5_PERIOD_NS,
  256. .init = palmt5_backlight_init,
  257. .notify = palmt5_backlight_notify,
  258. .exit = palmt5_backlight_exit,
  259. };
  260. static struct platform_device palmt5_backlight = {
  261. .name = "pwm-backlight",
  262. .dev = {
  263. .parent = &pxa27x_device_pwm0.dev,
  264. .platform_data = &palmt5_backlight_data,
  265. },
  266. };
  267. /******************************************************************************
  268. * IrDA
  269. ******************************************************************************/
  270. static int palmt5_irda_startup(struct device *dev)
  271. {
  272. int err;
  273. err = gpio_request(GPIO_NR_PALMT5_IR_DISABLE, "IR DISABLE");
  274. if (err)
  275. goto err;
  276. err = gpio_direction_output(GPIO_NR_PALMT5_IR_DISABLE, 1);
  277. if (err)
  278. gpio_free(GPIO_NR_PALMT5_IR_DISABLE);
  279. err:
  280. return err;
  281. }
  282. static void palmt5_irda_shutdown(struct device *dev)
  283. {
  284. gpio_free(GPIO_NR_PALMT5_IR_DISABLE);
  285. }
  286. static void palmt5_irda_transceiver_mode(struct device *dev, int mode)
  287. {
  288. gpio_set_value(GPIO_NR_PALMT5_IR_DISABLE, mode & IR_OFF);
  289. pxa2xx_transceiver_mode(dev, mode);
  290. }
  291. static struct pxaficp_platform_data palmt5_ficp_platform_data = {
  292. .startup = palmt5_irda_startup,
  293. .shutdown = palmt5_irda_shutdown,
  294. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  295. .transceiver_mode = palmt5_irda_transceiver_mode,
  296. };
  297. /******************************************************************************
  298. * UDC
  299. ******************************************************************************/
  300. static struct pxa2xx_udc_mach_info palmt5_udc_info __initdata = {
  301. .gpio_vbus = GPIO_NR_PALMT5_USB_DETECT_N,
  302. .gpio_vbus_inverted = 1,
  303. .gpio_pullup = GPIO_NR_PALMT5_USB_POWER,
  304. .gpio_pullup_inverted = 0,
  305. };
  306. /******************************************************************************
  307. * Power supply
  308. ******************************************************************************/
  309. static int power_supply_init(struct device *dev)
  310. {
  311. int ret;
  312. ret = gpio_request(GPIO_NR_PALMT5_POWER_DETECT, "CABLE_STATE_AC");
  313. if (ret)
  314. goto err1;
  315. ret = gpio_direction_input(GPIO_NR_PALMT5_POWER_DETECT);
  316. if (ret)
  317. goto err2;
  318. return 0;
  319. err2:
  320. gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
  321. err1:
  322. return ret;
  323. }
  324. static int palmt5_is_ac_online(void)
  325. {
  326. return gpio_get_value(GPIO_NR_PALMT5_POWER_DETECT);
  327. }
  328. static void power_supply_exit(struct device *dev)
  329. {
  330. gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
  331. }
  332. static char *palmt5_supplicants[] = {
  333. "main-battery",
  334. };
  335. static struct pda_power_pdata power_supply_info = {
  336. .init = power_supply_init,
  337. .is_ac_online = palmt5_is_ac_online,
  338. .exit = power_supply_exit,
  339. .supplied_to = palmt5_supplicants,
  340. .num_supplicants = ARRAY_SIZE(palmt5_supplicants),
  341. };
  342. static struct platform_device power_supply = {
  343. .name = "pda-power",
  344. .id = -1,
  345. .dev = {
  346. .platform_data = &power_supply_info,
  347. },
  348. };
  349. /******************************************************************************
  350. * WM97xx battery
  351. ******************************************************************************/
  352. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  353. .batt_aux = WM97XX_AUX_ID3,
  354. .temp_aux = WM97XX_AUX_ID2,
  355. .charge_gpio = -1,
  356. .max_voltage = PALMT5_BAT_MAX_VOLTAGE,
  357. .min_voltage = PALMT5_BAT_MIN_VOLTAGE,
  358. .batt_mult = 1000,
  359. .batt_div = 414,
  360. .temp_mult = 1,
  361. .temp_div = 1,
  362. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  363. .batt_name = "main-batt",
  364. };
  365. /******************************************************************************
  366. * aSoC audio
  367. ******************************************************************************/
  368. static struct palm27x_asoc_info palm27x_asoc_pdata = {
  369. .jack_gpio = GPIO_NR_PALMT5_EARPHONE_DETECT,
  370. };
  371. /******************************************************************************
  372. * Framebuffer
  373. ******************************************************************************/
  374. static struct pxafb_mode_info palmt5_lcd_modes[] = {
  375. {
  376. .pixclock = 57692,
  377. .xres = 320,
  378. .yres = 480,
  379. .bpp = 16,
  380. .left_margin = 32,
  381. .right_margin = 1,
  382. .upper_margin = 7,
  383. .lower_margin = 1,
  384. .hsync_len = 4,
  385. .vsync_len = 1,
  386. },
  387. };
  388. static struct pxafb_mach_info palmt5_lcd_screen = {
  389. .modes = palmt5_lcd_modes,
  390. .num_modes = ARRAY_SIZE(palmt5_lcd_modes),
  391. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  392. };
  393. /******************************************************************************
  394. * Power management - standby
  395. ******************************************************************************/
  396. #ifdef CONFIG_PM
  397. static u32 *addr __initdata;
  398. static u32 resume[3] __initdata = {
  399. 0xe3a00101, /* mov r0, #0x40000000 */
  400. 0xe380060f, /* orr r0, r0, #0x00f00000 */
  401. 0xe590f008, /* ldr pc, [r0, #0x08] */
  402. };
  403. static int __init palmt5_pm_init(void)
  404. {
  405. int i;
  406. /* this is where the bootloader jumps */
  407. addr = phys_to_virt(PALMT5_STR_BASE);
  408. for (i = 0; i < 3; i++)
  409. addr[i] = resume[i];
  410. return 0;
  411. }
  412. device_initcall(palmt5_pm_init);
  413. #endif
  414. /******************************************************************************
  415. * Machine init
  416. ******************************************************************************/
  417. static struct platform_device *devices[] __initdata = {
  418. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  419. &palmt5_pxa_keys,
  420. #endif
  421. &palmt5_backlight,
  422. &power_supply,
  423. };
  424. /* setup udc GPIOs initial state */
  425. static void __init palmt5_udc_init(void)
  426. {
  427. if (!gpio_request(GPIO_NR_PALMT5_USB_POWER, "UDC Vbus")) {
  428. gpio_direction_output(GPIO_NR_PALMT5_USB_POWER, 1);
  429. gpio_free(GPIO_NR_PALMT5_USB_POWER);
  430. }
  431. }
  432. static void __init palmt5_init(void)
  433. {
  434. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmt5_pin_config));
  435. set_pxa_fb_info(&palmt5_lcd_screen);
  436. pxa_set_mci_info(&palmt5_mci_platform_data);
  437. palmt5_udc_init();
  438. pxa_set_udc_info(&palmt5_udc_info);
  439. pxa_set_ac97_info(NULL);
  440. pxa_set_ficp_info(&palmt5_ficp_platform_data);
  441. pxa_set_keypad_info(&palmt5_keypad_platform_data);
  442. wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
  443. palm27x_asoc_set_pdata(&palm27x_asoc_pdata);
  444. platform_add_devices(devices, ARRAY_SIZE(devices));
  445. }
  446. MACHINE_START(PALMT5, "Palm Tungsten|T5")
  447. .phys_io = PALMT5_PHYS_IO_START,
  448. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  449. .boot_params = 0xa0000100,
  450. .map_io = pxa_map_io,
  451. .init_irq = pxa27x_init_irq,
  452. .timer = &pxa_timer,
  453. .init_machine = palmt5_init
  454. MACHINE_END