palmt5.c 14 KB

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