palmt5.c 13 KB

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