palmt5.c 13 KB

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