palmz72.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*
  2. * Hardware definitions for Palm Zire72
  3. *
  4. * Authors:
  5. * Vladimir "Farcaller" Pouzanov <farcaller@gmail.com>
  6. * Sergey Lapin <slapin@ossfans.org>
  7. * Alex Osborne <bobofdoom@gmail.com>
  8. * Jan Herman <2hp@seznam.cz>
  9. *
  10. * Rewrite for mainline:
  11. * Marek Vasut <marek.vasut@gmail.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. *
  17. * (find more info at www.hackndev.com)
  18. *
  19. */
  20. #include <linux/platform_device.h>
  21. #include <linux/sysdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/irq.h>
  24. #include <linux/gpio_keys.h>
  25. #include <linux/input.h>
  26. #include <linux/pda_power.h>
  27. #include <linux/pwm_backlight.h>
  28. #include <linux/gpio.h>
  29. #include <linux/wm97xx_batt.h>
  30. #include <linux/power_supply.h>
  31. #include <linux/usb/gpio_vbus.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/map.h>
  35. #include <mach/pxa27x.h>
  36. #include <mach/audio.h>
  37. #include <mach/palmz72.h>
  38. #include <mach/mmc.h>
  39. #include <mach/pxafb.h>
  40. #include <mach/irda.h>
  41. #include <mach/pxa27x_keypad.h>
  42. #include <mach/udc.h>
  43. #include <mach/palmasoc.h>
  44. #include <mach/pm.h>
  45. #include "generic.h"
  46. #include "devices.h"
  47. /******************************************************************************
  48. * Pin configuration
  49. ******************************************************************************/
  50. static unsigned long palmz72_pin_config[] __initdata = {
  51. /* MMC */
  52. GPIO32_MMC_CLK,
  53. GPIO92_MMC_DAT_0,
  54. GPIO109_MMC_DAT_1,
  55. GPIO110_MMC_DAT_2,
  56. GPIO111_MMC_DAT_3,
  57. GPIO112_MMC_CMD,
  58. GPIO14_GPIO, /* SD detect */
  59. GPIO115_GPIO, /* SD RO */
  60. GPIO98_GPIO, /* SD power */
  61. /* AC97 */
  62. GPIO28_AC97_BITCLK,
  63. GPIO29_AC97_SDATA_IN_0,
  64. GPIO30_AC97_SDATA_OUT,
  65. GPIO31_AC97_SYNC,
  66. GPIO89_AC97_SYSCLK,
  67. GPIO113_AC97_nRESET,
  68. /* IrDA */
  69. GPIO49_GPIO, /* ir disable */
  70. GPIO46_FICP_RXD,
  71. GPIO47_FICP_TXD,
  72. /* PWM */
  73. GPIO16_PWM0_OUT,
  74. /* USB */
  75. GPIO15_GPIO, /* usb detect */
  76. GPIO95_GPIO, /* usb pullup */
  77. /* Matrix keypad */
  78. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  79. GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
  80. GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
  81. GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
  82. GPIO103_KP_MKOUT_0,
  83. GPIO104_KP_MKOUT_1,
  84. GPIO105_KP_MKOUT_2,
  85. /* LCD */
  86. GPIOxx_LCD_TFT_16BPP,
  87. GPIO20_GPIO, /* bl power */
  88. GPIO21_GPIO, /* LCD border switch */
  89. GPIO22_GPIO, /* LCD border color */
  90. GPIO96_GPIO, /* lcd power */
  91. /* Misc. */
  92. GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */
  93. GPIO88_GPIO, /* green led */
  94. GPIO27_GPIO, /* WM9712 IRQ */
  95. };
  96. /******************************************************************************
  97. * SD/MMC card controller
  98. ******************************************************************************/
  99. /* SD_POWER is not actually power, but it is more like chip
  100. * select, i.e. it is inverted */
  101. static struct pxamci_platform_data palmz72_mci_platform_data = {
  102. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  103. .gpio_card_detect = GPIO_NR_PALMZ72_SD_DETECT_N,
  104. .gpio_card_ro = GPIO_NR_PALMZ72_SD_RO,
  105. .gpio_power = GPIO_NR_PALMZ72_SD_POWER_N,
  106. .gpio_power_invert = 1,
  107. };
  108. /******************************************************************************
  109. * GPIO keyboard
  110. ******************************************************************************/
  111. static unsigned int palmz72_matrix_keys[] = {
  112. KEY(0, 0, KEY_POWER),
  113. KEY(0, 1, KEY_F1),
  114. KEY(0, 2, KEY_ENTER),
  115. KEY(1, 0, KEY_F2),
  116. KEY(1, 1, KEY_F3),
  117. KEY(1, 2, KEY_F4),
  118. KEY(2, 0, KEY_UP),
  119. KEY(2, 2, KEY_DOWN),
  120. KEY(3, 0, KEY_RIGHT),
  121. KEY(3, 2, KEY_LEFT),
  122. };
  123. static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
  124. .matrix_key_rows = 4,
  125. .matrix_key_cols = 3,
  126. .matrix_key_map = palmz72_matrix_keys,
  127. .matrix_key_map_size = ARRAY_SIZE(palmz72_matrix_keys),
  128. .debounce_interval = 30,
  129. };
  130. /******************************************************************************
  131. * Backlight
  132. ******************************************************************************/
  133. static int palmz72_backlight_init(struct device *dev)
  134. {
  135. int ret;
  136. ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
  137. if (ret)
  138. goto err;
  139. ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
  140. if (ret)
  141. goto err2;
  142. ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
  143. if (ret)
  144. goto err2;
  145. ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
  146. if (ret)
  147. goto err3;
  148. return 0;
  149. err3:
  150. gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
  151. err2:
  152. gpio_free(GPIO_NR_PALMZ72_BL_POWER);
  153. err:
  154. return ret;
  155. }
  156. static int palmz72_backlight_notify(struct device *dev, int brightness)
  157. {
  158. gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
  159. gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
  160. return brightness;
  161. }
  162. static void palmz72_backlight_exit(struct device *dev)
  163. {
  164. gpio_free(GPIO_NR_PALMZ72_BL_POWER);
  165. gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
  166. }
  167. static struct platform_pwm_backlight_data palmz72_backlight_data = {
  168. .pwm_id = 0,
  169. .max_brightness = PALMZ72_MAX_INTENSITY,
  170. .dft_brightness = PALMZ72_MAX_INTENSITY,
  171. .pwm_period_ns = PALMZ72_PERIOD_NS,
  172. .init = palmz72_backlight_init,
  173. .notify = palmz72_backlight_notify,
  174. .exit = palmz72_backlight_exit,
  175. };
  176. static struct platform_device palmz72_backlight = {
  177. .name = "pwm-backlight",
  178. .dev = {
  179. .parent = &pxa27x_device_pwm0.dev,
  180. .platform_data = &palmz72_backlight_data,
  181. },
  182. };
  183. /******************************************************************************
  184. * IrDA
  185. ******************************************************************************/
  186. static struct pxaficp_platform_data palmz72_ficp_platform_data = {
  187. .gpio_pwdown = GPIO_NR_PALMZ72_IR_DISABLE,
  188. .transceiver_cap = IR_SIRMODE | IR_OFF,
  189. };
  190. /******************************************************************************
  191. * LEDs
  192. ******************************************************************************/
  193. static struct gpio_led gpio_leds[] = {
  194. {
  195. .name = "palmz72:green:led",
  196. .default_trigger = "none",
  197. .gpio = GPIO_NR_PALMZ72_LED_GREEN,
  198. },
  199. };
  200. static struct gpio_led_platform_data gpio_led_info = {
  201. .leds = gpio_leds,
  202. .num_leds = ARRAY_SIZE(gpio_leds),
  203. };
  204. static struct platform_device palmz72_leds = {
  205. .name = "leds-gpio",
  206. .id = -1,
  207. .dev = {
  208. .platform_data = &gpio_led_info,
  209. }
  210. };
  211. /******************************************************************************
  212. * UDC
  213. ******************************************************************************/
  214. static struct gpio_vbus_mach_info palmz72_udc_info = {
  215. .gpio_vbus = GPIO_NR_PALMZ72_USB_DETECT_N,
  216. .gpio_pullup = GPIO_NR_PALMZ72_USB_PULLUP,
  217. };
  218. static struct platform_device palmz72_gpio_vbus = {
  219. .name = "gpio-vbus",
  220. .id = -1,
  221. .dev = {
  222. .platform_data = &palmz72_udc_info,
  223. },
  224. };
  225. /******************************************************************************
  226. * Power supply
  227. ******************************************************************************/
  228. static int power_supply_init(struct device *dev)
  229. {
  230. int ret;
  231. ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
  232. if (ret)
  233. goto err1;
  234. ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
  235. if (ret)
  236. goto err2;
  237. ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
  238. if (ret)
  239. goto err2;
  240. ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
  241. if (ret)
  242. goto err3;
  243. return 0;
  244. err3:
  245. gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
  246. err2:
  247. gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
  248. err1:
  249. return ret;
  250. }
  251. static int palmz72_is_ac_online(void)
  252. {
  253. return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
  254. }
  255. static int palmz72_is_usb_online(void)
  256. {
  257. return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
  258. }
  259. static void power_supply_exit(struct device *dev)
  260. {
  261. gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
  262. gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
  263. }
  264. static char *palmz72_supplicants[] = {
  265. "main-battery",
  266. };
  267. static struct pda_power_pdata power_supply_info = {
  268. .init = power_supply_init,
  269. .is_ac_online = palmz72_is_ac_online,
  270. .is_usb_online = palmz72_is_usb_online,
  271. .exit = power_supply_exit,
  272. .supplied_to = palmz72_supplicants,
  273. .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
  274. };
  275. static struct platform_device power_supply = {
  276. .name = "pda-power",
  277. .id = -1,
  278. .dev = {
  279. .platform_data = &power_supply_info,
  280. },
  281. };
  282. /******************************************************************************
  283. * WM97xx battery
  284. ******************************************************************************/
  285. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  286. .batt_aux = WM97XX_AUX_ID3,
  287. .temp_aux = WM97XX_AUX_ID2,
  288. .charge_gpio = -1,
  289. .max_voltage = PALMZ72_BAT_MAX_VOLTAGE,
  290. .min_voltage = PALMZ72_BAT_MIN_VOLTAGE,
  291. .batt_mult = 1000,
  292. .batt_div = 414,
  293. .temp_mult = 1,
  294. .temp_div = 1,
  295. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  296. .batt_name = "main-batt",
  297. };
  298. /******************************************************************************
  299. * aSoC audio
  300. ******************************************************************************/
  301. static struct platform_device palmz72_asoc = {
  302. .name = "palm27x-asoc",
  303. .id = -1,
  304. };
  305. /******************************************************************************
  306. * Framebuffer
  307. ******************************************************************************/
  308. static struct pxafb_mode_info palmz72_lcd_modes[] = {
  309. {
  310. .pixclock = 115384,
  311. .xres = 320,
  312. .yres = 320,
  313. .bpp = 16,
  314. .left_margin = 27,
  315. .right_margin = 7,
  316. .upper_margin = 7,
  317. .lower_margin = 8,
  318. .hsync_len = 6,
  319. .vsync_len = 1,
  320. },
  321. };
  322. static struct pxafb_mach_info palmz72_lcd_screen = {
  323. .modes = palmz72_lcd_modes,
  324. .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
  325. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  326. };
  327. #ifdef CONFIG_PM
  328. /* We have some black magic here
  329. * PalmOS ROM on recover expects special struct physical address
  330. * to be transferred via PSPR. Using this struct PalmOS restores
  331. * its state after sleep. As for Linux, we need to setup it the
  332. * same way. More than that, PalmOS ROM changes some values in memory.
  333. * For now only one location is found, which needs special treatment.
  334. * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
  335. * for reading backtraces for me :)
  336. */
  337. #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
  338. static struct palmz72_resume_info palmz72_resume_info = {
  339. .magic0 = 0xb4e6,
  340. .magic1 = 1,
  341. /* reset state, MMU off etc */
  342. .arm_control = 0,
  343. .aux_control = 0,
  344. .ttb = 0,
  345. .domain_access = 0,
  346. .process_id = 0,
  347. };
  348. static unsigned long store_ptr;
  349. /* sys_device for Palm Zire 72 PM */
  350. static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
  351. {
  352. /* setup the resume_info struct for the original bootloader */
  353. palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
  354. /* Storing memory touched by ROM */
  355. store_ptr = *PALMZ72_SAVE_DWORD;
  356. /* Setting PSPR to a proper value */
  357. PSPR = virt_to_phys(&palmz72_resume_info);
  358. return 0;
  359. }
  360. static int palmz72_pm_resume(struct sys_device *dev)
  361. {
  362. *PALMZ72_SAVE_DWORD = store_ptr;
  363. return 0;
  364. }
  365. static struct sysdev_class palmz72_pm_sysclass = {
  366. .name = "palmz72_pm",
  367. .suspend = palmz72_pm_suspend,
  368. .resume = palmz72_pm_resume,
  369. };
  370. static struct sys_device palmz72_pm_device = {
  371. .cls = &palmz72_pm_sysclass,
  372. };
  373. static int __init palmz72_pm_init(void)
  374. {
  375. int ret = -ENODEV;
  376. if (machine_is_palmz72()) {
  377. ret = sysdev_class_register(&palmz72_pm_sysclass);
  378. if (ret == 0)
  379. ret = sysdev_register(&palmz72_pm_device);
  380. }
  381. return ret;
  382. }
  383. device_initcall(palmz72_pm_init);
  384. #endif
  385. /******************************************************************************
  386. * Machine init
  387. ******************************************************************************/
  388. static struct platform_device *devices[] __initdata = {
  389. &palmz72_backlight,
  390. &palmz72_leds,
  391. &palmz72_asoc,
  392. &power_supply,
  393. &palmz72_gpio_vbus,
  394. };
  395. /* setup udc GPIOs initial state */
  396. static void __init palmz72_udc_init(void)
  397. {
  398. if (!gpio_request(GPIO_NR_PALMZ72_USB_PULLUP, "USB Pullup")) {
  399. gpio_direction_output(GPIO_NR_PALMZ72_USB_PULLUP, 0);
  400. gpio_free(GPIO_NR_PALMZ72_USB_PULLUP);
  401. }
  402. }
  403. static void __init palmz72_init(void)
  404. {
  405. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
  406. pxa_set_ffuart_info(NULL);
  407. pxa_set_btuart_info(NULL);
  408. pxa_set_stuart_info(NULL);
  409. set_pxa_fb_info(&palmz72_lcd_screen);
  410. pxa_set_mci_info(&palmz72_mci_platform_data);
  411. palmz72_udc_init();
  412. pxa_set_ac97_info(NULL);
  413. pxa_set_ficp_info(&palmz72_ficp_platform_data);
  414. pxa_set_keypad_info(&palmz72_keypad_platform_data);
  415. wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
  416. platform_add_devices(devices, ARRAY_SIZE(devices));
  417. }
  418. MACHINE_START(PALMZ72, "Palm Zire72")
  419. .phys_io = 0x40000000,
  420. .io_pg_offst = io_p2v(0x40000000),
  421. .boot_params = 0xa0000100,
  422. .map_io = pxa_map_io,
  423. .init_irq = pxa27x_init_irq,
  424. .timer = &pxa_timer,
  425. .init_machine = palmz72_init
  426. MACHINE_END