palmt5.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. /* MISC */
  103. GPIO10_GPIO, /* hotsync button */
  104. GPIO90_GPIO, /* power detect */
  105. GPIO107_GPIO, /* earphone detect */
  106. };
  107. /******************************************************************************
  108. * SD/MMC card controller
  109. ******************************************************************************/
  110. static int palmt5_mci_init(struct device *dev, irq_handler_t palmt5_detect_int,
  111. void *data)
  112. {
  113. int err = 0;
  114. /* Setup an interrupt for detecting card insert/remove events */
  115. err = gpio_request(GPIO_NR_PALMT5_SD_DETECT_N, "SD IRQ");
  116. if (err)
  117. goto err;
  118. err = gpio_direction_input(GPIO_NR_PALMT5_SD_DETECT_N);
  119. if (err)
  120. goto err2;
  121. err = request_irq(gpio_to_irq(GPIO_NR_PALMT5_SD_DETECT_N),
  122. palmt5_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  123. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  124. "SD/MMC card detect", data);
  125. if (err) {
  126. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  127. __func__);
  128. goto err2;
  129. }
  130. err = gpio_request(GPIO_NR_PALMT5_SD_POWER, "SD_POWER");
  131. if (err)
  132. goto err3;
  133. err = gpio_direction_output(GPIO_NR_PALMT5_SD_POWER, 0);
  134. if (err)
  135. goto err4;
  136. err = gpio_request(GPIO_NR_PALMT5_SD_READONLY, "SD_READONLY");
  137. if (err)
  138. goto err4;
  139. err = gpio_direction_input(GPIO_NR_PALMT5_SD_READONLY);
  140. if (err)
  141. goto err5;
  142. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  143. return 0;
  144. err5:
  145. gpio_free(GPIO_NR_PALMT5_SD_READONLY);
  146. err4:
  147. gpio_free(GPIO_NR_PALMT5_SD_POWER);
  148. err3:
  149. free_irq(gpio_to_irq(GPIO_NR_PALMT5_SD_DETECT_N), data);
  150. err2:
  151. gpio_free(GPIO_NR_PALMT5_SD_DETECT_N);
  152. err:
  153. return err;
  154. }
  155. static void palmt5_mci_exit(struct device *dev, void *data)
  156. {
  157. gpio_free(GPIO_NR_PALMT5_SD_READONLY);
  158. gpio_free(GPIO_NR_PALMT5_SD_POWER);
  159. free_irq(IRQ_GPIO_PALMT5_SD_DETECT_N, data);
  160. gpio_free(GPIO_NR_PALMT5_SD_DETECT_N);
  161. }
  162. static void palmt5_mci_power(struct device *dev, unsigned int vdd)
  163. {
  164. struct pxamci_platform_data *p_d = dev->platform_data;
  165. gpio_set_value(GPIO_NR_PALMT5_SD_POWER, p_d->ocr_mask & (1 << vdd));
  166. }
  167. static int palmt5_mci_get_ro(struct device *dev)
  168. {
  169. return gpio_get_value(GPIO_NR_PALMT5_SD_READONLY);
  170. }
  171. static struct pxamci_platform_data palmt5_mci_platform_data = {
  172. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  173. .setpower = palmt5_mci_power,
  174. .get_ro = palmt5_mci_get_ro,
  175. .init = palmt5_mci_init,
  176. .exit = palmt5_mci_exit,
  177. };
  178. /******************************************************************************
  179. * GPIO keyboard
  180. ******************************************************************************/
  181. static unsigned int palmt5_matrix_keys[] = {
  182. KEY(0, 0, KEY_POWER),
  183. KEY(0, 1, KEY_F1),
  184. KEY(0, 2, KEY_ENTER),
  185. KEY(1, 0, KEY_F2),
  186. KEY(1, 1, KEY_F3),
  187. KEY(1, 2, KEY_F4),
  188. KEY(2, 0, KEY_UP),
  189. KEY(2, 2, KEY_DOWN),
  190. KEY(3, 0, KEY_RIGHT),
  191. KEY(3, 2, KEY_LEFT),
  192. };
  193. static struct pxa27x_keypad_platform_data palmt5_keypad_platform_data = {
  194. .matrix_key_rows = 4,
  195. .matrix_key_cols = 3,
  196. .matrix_key_map = palmt5_matrix_keys,
  197. .matrix_key_map_size = ARRAY_SIZE(palmt5_matrix_keys),
  198. .debounce_interval = 30,
  199. };
  200. /******************************************************************************
  201. * GPIO keys
  202. ******************************************************************************/
  203. static struct gpio_keys_button palmt5_pxa_buttons[] = {
  204. {KEY_F8, GPIO_NR_PALMT5_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
  205. };
  206. static struct gpio_keys_platform_data palmt5_pxa_keys_data = {
  207. .buttons = palmt5_pxa_buttons,
  208. .nbuttons = ARRAY_SIZE(palmt5_pxa_buttons),
  209. };
  210. static struct platform_device palmt5_pxa_keys = {
  211. .name = "gpio-keys",
  212. .id = -1,
  213. .dev = {
  214. .platform_data = &palmt5_pxa_keys_data,
  215. },
  216. };
  217. /******************************************************************************
  218. * Backlight
  219. ******************************************************************************/
  220. static int palmt5_backlight_init(struct device *dev)
  221. {
  222. int ret;
  223. ret = gpio_request(GPIO_NR_PALMT5_BL_POWER, "BL POWER");
  224. if (ret)
  225. goto err;
  226. ret = gpio_direction_output(GPIO_NR_PALMT5_BL_POWER, 0);
  227. if (ret)
  228. goto err2;
  229. ret = gpio_request(GPIO_NR_PALMT5_LCD_POWER, "LCD POWER");
  230. if (ret)
  231. goto err2;
  232. ret = gpio_direction_output(GPIO_NR_PALMT5_LCD_POWER, 0);
  233. if (ret)
  234. goto err3;
  235. return 0;
  236. err3:
  237. gpio_free(GPIO_NR_PALMT5_LCD_POWER);
  238. err2:
  239. gpio_free(GPIO_NR_PALMT5_BL_POWER);
  240. err:
  241. return ret;
  242. }
  243. static int palmt5_backlight_notify(int brightness)
  244. {
  245. gpio_set_value(GPIO_NR_PALMT5_BL_POWER, brightness);
  246. gpio_set_value(GPIO_NR_PALMT5_LCD_POWER, brightness);
  247. return brightness;
  248. }
  249. static void palmt5_backlight_exit(struct device *dev)
  250. {
  251. gpio_free(GPIO_NR_PALMT5_BL_POWER);
  252. gpio_free(GPIO_NR_PALMT5_LCD_POWER);
  253. }
  254. static struct platform_pwm_backlight_data palmt5_backlight_data = {
  255. .pwm_id = 0,
  256. .max_brightness = PALMT5_MAX_INTENSITY,
  257. .dft_brightness = PALMT5_MAX_INTENSITY,
  258. .pwm_period_ns = PALMT5_PERIOD_NS,
  259. .init = palmt5_backlight_init,
  260. .notify = palmt5_backlight_notify,
  261. .exit = palmt5_backlight_exit,
  262. };
  263. static struct platform_device palmt5_backlight = {
  264. .name = "pwm-backlight",
  265. .dev = {
  266. .parent = &pxa27x_device_pwm0.dev,
  267. .platform_data = &palmt5_backlight_data,
  268. },
  269. };
  270. /******************************************************************************
  271. * IrDA
  272. ******************************************************************************/
  273. static int palmt5_irda_startup(struct device *dev)
  274. {
  275. int err;
  276. err = gpio_request(GPIO_NR_PALMT5_IR_DISABLE, "IR DISABLE");
  277. if (err)
  278. goto err;
  279. err = gpio_direction_output(GPIO_NR_PALMT5_IR_DISABLE, 1);
  280. if (err)
  281. gpio_free(GPIO_NR_PALMT5_IR_DISABLE);
  282. err:
  283. return err;
  284. }
  285. static void palmt5_irda_shutdown(struct device *dev)
  286. {
  287. gpio_free(GPIO_NR_PALMT5_IR_DISABLE);
  288. }
  289. static void palmt5_irda_transceiver_mode(struct device *dev, int mode)
  290. {
  291. gpio_set_value(GPIO_NR_PALMT5_IR_DISABLE, mode & IR_OFF);
  292. pxa2xx_transceiver_mode(dev, mode);
  293. }
  294. static struct pxaficp_platform_data palmt5_ficp_platform_data = {
  295. .startup = palmt5_irda_startup,
  296. .shutdown = palmt5_irda_shutdown,
  297. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  298. .transceiver_mode = palmt5_irda_transceiver_mode,
  299. };
  300. /******************************************************************************
  301. * UDC
  302. ******************************************************************************/
  303. static struct gpio_vbus_mach_info palmt5_udc_info = {
  304. .gpio_vbus = GPIO_NR_PALMT5_USB_DETECT_N,
  305. .gpio_vbus_inverted = 1,
  306. .gpio_pullup = GPIO_NR_PALMT5_USB_PULLUP,
  307. };
  308. static struct platform_device palmt5_gpio_vbus = {
  309. .name = "gpio-vbus",
  310. .id = -1,
  311. .dev = {
  312. .platform_data = &palmt5_udc_info,
  313. },
  314. };
  315. /******************************************************************************
  316. * Power supply
  317. ******************************************************************************/
  318. static int power_supply_init(struct device *dev)
  319. {
  320. int ret;
  321. ret = gpio_request(GPIO_NR_PALMT5_POWER_DETECT, "CABLE_STATE_AC");
  322. if (ret)
  323. goto err1;
  324. ret = gpio_direction_input(GPIO_NR_PALMT5_POWER_DETECT);
  325. if (ret)
  326. goto err2;
  327. return 0;
  328. err2:
  329. gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
  330. err1:
  331. return ret;
  332. }
  333. static int palmt5_is_ac_online(void)
  334. {
  335. return gpio_get_value(GPIO_NR_PALMT5_POWER_DETECT);
  336. }
  337. static void power_supply_exit(struct device *dev)
  338. {
  339. gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
  340. }
  341. static char *palmt5_supplicants[] = {
  342. "main-battery",
  343. };
  344. static struct pda_power_pdata power_supply_info = {
  345. .init = power_supply_init,
  346. .is_ac_online = palmt5_is_ac_online,
  347. .exit = power_supply_exit,
  348. .supplied_to = palmt5_supplicants,
  349. .num_supplicants = ARRAY_SIZE(palmt5_supplicants),
  350. };
  351. static struct platform_device power_supply = {
  352. .name = "pda-power",
  353. .id = -1,
  354. .dev = {
  355. .platform_data = &power_supply_info,
  356. },
  357. };
  358. /******************************************************************************
  359. * WM97xx battery
  360. ******************************************************************************/
  361. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  362. .batt_aux = WM97XX_AUX_ID3,
  363. .temp_aux = WM97XX_AUX_ID2,
  364. .charge_gpio = -1,
  365. .max_voltage = PALMT5_BAT_MAX_VOLTAGE,
  366. .min_voltage = PALMT5_BAT_MIN_VOLTAGE,
  367. .batt_mult = 1000,
  368. .batt_div = 414,
  369. .temp_mult = 1,
  370. .temp_div = 1,
  371. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  372. .batt_name = "main-batt",
  373. };
  374. /******************************************************************************
  375. * aSoC audio
  376. ******************************************************************************/
  377. static struct palm27x_asoc_info palmt5_asoc_pdata = {
  378. .jack_gpio = GPIO_NR_PALMT5_EARPHONE_DETECT,
  379. };
  380. static pxa2xx_audio_ops_t palmt5_ac97_pdata = {
  381. .reset_gpio = 95,
  382. };
  383. static struct platform_device palmt5_asoc = {
  384. .name = "palm27x-asoc",
  385. .id = -1,
  386. .dev = {
  387. .platform_data = &palmt5_asoc_pdata,
  388. },
  389. };
  390. /******************************************************************************
  391. * Framebuffer
  392. ******************************************************************************/
  393. static struct pxafb_mode_info palmt5_lcd_modes[] = {
  394. {
  395. .pixclock = 57692,
  396. .xres = 320,
  397. .yres = 480,
  398. .bpp = 16,
  399. .left_margin = 32,
  400. .right_margin = 1,
  401. .upper_margin = 7,
  402. .lower_margin = 1,
  403. .hsync_len = 4,
  404. .vsync_len = 1,
  405. },
  406. };
  407. static struct pxafb_mach_info palmt5_lcd_screen = {
  408. .modes = palmt5_lcd_modes,
  409. .num_modes = ARRAY_SIZE(palmt5_lcd_modes),
  410. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  411. };
  412. /******************************************************************************
  413. * Power management - standby
  414. ******************************************************************************/
  415. static void __init palmt5_pm_init(void)
  416. {
  417. static u32 resume[] = {
  418. 0xe3a00101, /* mov r0, #0x40000000 */
  419. 0xe380060f, /* orr r0, r0, #0x00f00000 */
  420. 0xe590f008, /* ldr pc, [r0, #0x08] */
  421. };
  422. /* copy the bootloader */
  423. memcpy(phys_to_virt(PALMT5_STR_BASE), resume, sizeof(resume));
  424. }
  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. &palmt5_gpio_vbus,
  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. palmt5_pm_init();
  449. set_pxa_fb_info(&palmt5_lcd_screen);
  450. pxa_set_mci_info(&palmt5_mci_platform_data);
  451. palmt5_udc_init();
  452. pxa_set_ac97_info(&palmt5_ac97_pdata);
  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