palmz72.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. GPIO58_LCD_LDD_0,
  87. GPIO59_LCD_LDD_1,
  88. GPIO60_LCD_LDD_2,
  89. GPIO61_LCD_LDD_3,
  90. GPIO62_LCD_LDD_4,
  91. GPIO63_LCD_LDD_5,
  92. GPIO64_LCD_LDD_6,
  93. GPIO65_LCD_LDD_7,
  94. GPIO66_LCD_LDD_8,
  95. GPIO67_LCD_LDD_9,
  96. GPIO68_LCD_LDD_10,
  97. GPIO69_LCD_LDD_11,
  98. GPIO70_LCD_LDD_12,
  99. GPIO71_LCD_LDD_13,
  100. GPIO72_LCD_LDD_14,
  101. GPIO73_LCD_LDD_15,
  102. GPIO74_LCD_FCLK,
  103. GPIO75_LCD_LCLK,
  104. GPIO76_LCD_PCLK,
  105. GPIO77_LCD_BIAS,
  106. GPIO20_GPIO, /* bl power */
  107. GPIO21_GPIO, /* LCD border switch */
  108. GPIO22_GPIO, /* LCD border color */
  109. GPIO96_GPIO, /* lcd power */
  110. /* Misc. */
  111. GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */
  112. GPIO88_GPIO, /* green led */
  113. GPIO27_GPIO, /* WM9712 IRQ */
  114. };
  115. /******************************************************************************
  116. * SD/MMC card controller
  117. ******************************************************************************/
  118. /* SD_POWER is not actually power, but it is more like chip
  119. * select, i.e. it is inverted */
  120. static struct pxamci_platform_data palmz72_mci_platform_data = {
  121. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  122. .gpio_card_detect = GPIO_NR_PALMZ72_SD_DETECT_N,
  123. .gpio_card_ro = GPIO_NR_PALMZ72_SD_RO,
  124. .gpio_power = GPIO_NR_PALMZ72_SD_POWER_N,
  125. .gpio_power_invert = 1,
  126. };
  127. /******************************************************************************
  128. * GPIO keyboard
  129. ******************************************************************************/
  130. static unsigned int palmz72_matrix_keys[] = {
  131. KEY(0, 0, KEY_POWER),
  132. KEY(0, 1, KEY_F1),
  133. KEY(0, 2, KEY_ENTER),
  134. KEY(1, 0, KEY_F2),
  135. KEY(1, 1, KEY_F3),
  136. KEY(1, 2, KEY_F4),
  137. KEY(2, 0, KEY_UP),
  138. KEY(2, 2, KEY_DOWN),
  139. KEY(3, 0, KEY_RIGHT),
  140. KEY(3, 2, KEY_LEFT),
  141. };
  142. static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
  143. .matrix_key_rows = 4,
  144. .matrix_key_cols = 3,
  145. .matrix_key_map = palmz72_matrix_keys,
  146. .matrix_key_map_size = ARRAY_SIZE(palmz72_matrix_keys),
  147. .debounce_interval = 30,
  148. };
  149. /******************************************************************************
  150. * Backlight
  151. ******************************************************************************/
  152. static int palmz72_backlight_init(struct device *dev)
  153. {
  154. int ret;
  155. ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
  156. if (ret)
  157. goto err;
  158. ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
  159. if (ret)
  160. goto err2;
  161. ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
  162. if (ret)
  163. goto err2;
  164. ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
  165. if (ret)
  166. goto err3;
  167. return 0;
  168. err3:
  169. gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
  170. err2:
  171. gpio_free(GPIO_NR_PALMZ72_BL_POWER);
  172. err:
  173. return ret;
  174. }
  175. static int palmz72_backlight_notify(int brightness)
  176. {
  177. gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
  178. gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
  179. return brightness;
  180. }
  181. static void palmz72_backlight_exit(struct device *dev)
  182. {
  183. gpio_free(GPIO_NR_PALMZ72_BL_POWER);
  184. gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
  185. }
  186. static struct platform_pwm_backlight_data palmz72_backlight_data = {
  187. .pwm_id = 0,
  188. .max_brightness = PALMZ72_MAX_INTENSITY,
  189. .dft_brightness = PALMZ72_MAX_INTENSITY,
  190. .pwm_period_ns = PALMZ72_PERIOD_NS,
  191. .init = palmz72_backlight_init,
  192. .notify = palmz72_backlight_notify,
  193. .exit = palmz72_backlight_exit,
  194. };
  195. static struct platform_device palmz72_backlight = {
  196. .name = "pwm-backlight",
  197. .dev = {
  198. .parent = &pxa27x_device_pwm0.dev,
  199. .platform_data = &palmz72_backlight_data,
  200. },
  201. };
  202. /******************************************************************************
  203. * IrDA
  204. ******************************************************************************/
  205. static struct pxaficp_platform_data palmz72_ficp_platform_data = {
  206. .gpio_pwdown = GPIO_NR_PALMZ72_IR_DISABLE,
  207. .transceiver_cap = IR_SIRMODE | IR_OFF,
  208. };
  209. /******************************************************************************
  210. * LEDs
  211. ******************************************************************************/
  212. static struct gpio_led gpio_leds[] = {
  213. {
  214. .name = "palmz72:green:led",
  215. .default_trigger = "none",
  216. .gpio = GPIO_NR_PALMZ72_LED_GREEN,
  217. },
  218. };
  219. static struct gpio_led_platform_data gpio_led_info = {
  220. .leds = gpio_leds,
  221. .num_leds = ARRAY_SIZE(gpio_leds),
  222. };
  223. static struct platform_device palmz72_leds = {
  224. .name = "leds-gpio",
  225. .id = -1,
  226. .dev = {
  227. .platform_data = &gpio_led_info,
  228. }
  229. };
  230. /******************************************************************************
  231. * UDC
  232. ******************************************************************************/
  233. static struct gpio_vbus_mach_info palmz72_udc_info = {
  234. .gpio_vbus = GPIO_NR_PALMZ72_USB_DETECT_N,
  235. .gpio_pullup = GPIO_NR_PALMZ72_USB_PULLUP,
  236. };
  237. static struct platform_device palmz72_gpio_vbus = {
  238. .name = "gpio-vbus",
  239. .id = -1,
  240. .dev = {
  241. .platform_data = &palmz72_udc_info,
  242. },
  243. };
  244. /******************************************************************************
  245. * Power supply
  246. ******************************************************************************/
  247. static int power_supply_init(struct device *dev)
  248. {
  249. int ret;
  250. ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
  251. if (ret)
  252. goto err1;
  253. ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
  254. if (ret)
  255. goto err2;
  256. ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
  257. if (ret)
  258. goto err2;
  259. ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
  260. if (ret)
  261. goto err3;
  262. return 0;
  263. err3:
  264. gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
  265. err2:
  266. gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
  267. err1:
  268. return ret;
  269. }
  270. static int palmz72_is_ac_online(void)
  271. {
  272. return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
  273. }
  274. static int palmz72_is_usb_online(void)
  275. {
  276. return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
  277. }
  278. static void power_supply_exit(struct device *dev)
  279. {
  280. gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
  281. gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
  282. }
  283. static char *palmz72_supplicants[] = {
  284. "main-battery",
  285. };
  286. static struct pda_power_pdata power_supply_info = {
  287. .init = power_supply_init,
  288. .is_ac_online = palmz72_is_ac_online,
  289. .is_usb_online = palmz72_is_usb_online,
  290. .exit = power_supply_exit,
  291. .supplied_to = palmz72_supplicants,
  292. .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
  293. };
  294. static struct platform_device power_supply = {
  295. .name = "pda-power",
  296. .id = -1,
  297. .dev = {
  298. .platform_data = &power_supply_info,
  299. },
  300. };
  301. /******************************************************************************
  302. * WM97xx battery
  303. ******************************************************************************/
  304. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  305. .batt_aux = WM97XX_AUX_ID3,
  306. .temp_aux = WM97XX_AUX_ID2,
  307. .charge_gpio = -1,
  308. .max_voltage = PALMZ72_BAT_MAX_VOLTAGE,
  309. .min_voltage = PALMZ72_BAT_MIN_VOLTAGE,
  310. .batt_mult = 1000,
  311. .batt_div = 414,
  312. .temp_mult = 1,
  313. .temp_div = 1,
  314. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  315. .batt_name = "main-batt",
  316. };
  317. /******************************************************************************
  318. * aSoC audio
  319. ******************************************************************************/
  320. static struct platform_device palmz72_asoc = {
  321. .name = "palm27x-asoc",
  322. .id = -1,
  323. };
  324. /******************************************************************************
  325. * Framebuffer
  326. ******************************************************************************/
  327. static struct pxafb_mode_info palmz72_lcd_modes[] = {
  328. {
  329. .pixclock = 115384,
  330. .xres = 320,
  331. .yres = 320,
  332. .bpp = 16,
  333. .left_margin = 27,
  334. .right_margin = 7,
  335. .upper_margin = 7,
  336. .lower_margin = 8,
  337. .hsync_len = 6,
  338. .vsync_len = 1,
  339. },
  340. };
  341. static struct pxafb_mach_info palmz72_lcd_screen = {
  342. .modes = palmz72_lcd_modes,
  343. .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
  344. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  345. };
  346. #ifdef CONFIG_PM
  347. /* We have some black magic here
  348. * PalmOS ROM on recover expects special struct physical address
  349. * to be transferred via PSPR. Using this struct PalmOS restores
  350. * its state after sleep. As for Linux, we need to setup it the
  351. * same way. More than that, PalmOS ROM changes some values in memory.
  352. * For now only one location is found, which needs special treatment.
  353. * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
  354. * for reading backtraces for me :)
  355. */
  356. #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
  357. static struct palmz72_resume_info palmz72_resume_info = {
  358. .magic0 = 0xb4e6,
  359. .magic1 = 1,
  360. /* reset state, MMU off etc */
  361. .arm_control = 0,
  362. .aux_control = 0,
  363. .ttb = 0,
  364. .domain_access = 0,
  365. .process_id = 0,
  366. };
  367. static unsigned long store_ptr;
  368. /* sys_device for Palm Zire 72 PM */
  369. static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
  370. {
  371. /* setup the resume_info struct for the original bootloader */
  372. palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
  373. /* Storing memory touched by ROM */
  374. store_ptr = *PALMZ72_SAVE_DWORD;
  375. /* Setting PSPR to a proper value */
  376. PSPR = virt_to_phys(&palmz72_resume_info);
  377. return 0;
  378. }
  379. static int palmz72_pm_resume(struct sys_device *dev)
  380. {
  381. *PALMZ72_SAVE_DWORD = store_ptr;
  382. return 0;
  383. }
  384. static struct sysdev_class palmz72_pm_sysclass = {
  385. .name = "palmz72_pm",
  386. .suspend = palmz72_pm_suspend,
  387. .resume = palmz72_pm_resume,
  388. };
  389. static struct sys_device palmz72_pm_device = {
  390. .cls = &palmz72_pm_sysclass,
  391. };
  392. static int __init palmz72_pm_init(void)
  393. {
  394. int ret = -ENODEV;
  395. if (machine_is_palmz72()) {
  396. ret = sysdev_class_register(&palmz72_pm_sysclass);
  397. if (ret == 0)
  398. ret = sysdev_register(&palmz72_pm_device);
  399. }
  400. return ret;
  401. }
  402. device_initcall(palmz72_pm_init);
  403. #endif
  404. /******************************************************************************
  405. * Machine init
  406. ******************************************************************************/
  407. static struct platform_device *devices[] __initdata = {
  408. &palmz72_backlight,
  409. &palmz72_leds,
  410. &palmz72_asoc,
  411. &power_supply,
  412. &palmz72_gpio_vbus,
  413. };
  414. /* setup udc GPIOs initial state */
  415. static void __init palmz72_udc_init(void)
  416. {
  417. if (!gpio_request(GPIO_NR_PALMZ72_USB_PULLUP, "USB Pullup")) {
  418. gpio_direction_output(GPIO_NR_PALMZ72_USB_PULLUP, 0);
  419. gpio_free(GPIO_NR_PALMZ72_USB_PULLUP);
  420. }
  421. }
  422. static void __init palmz72_init(void)
  423. {
  424. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
  425. set_pxa_fb_info(&palmz72_lcd_screen);
  426. pxa_set_mci_info(&palmz72_mci_platform_data);
  427. palmz72_udc_init();
  428. pxa_set_ac97_info(NULL);
  429. pxa_set_ficp_info(&palmz72_ficp_platform_data);
  430. pxa_set_keypad_info(&palmz72_keypad_platform_data);
  431. wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
  432. platform_add_devices(devices, ARRAY_SIZE(devices));
  433. }
  434. MACHINE_START(PALMZ72, "Palm Zire72")
  435. .phys_io = 0x40000000,
  436. .io_pg_offst = io_p2v(0x40000000),
  437. .boot_params = 0xa0000100,
  438. .map_io = pxa_map_io,
  439. .init_irq = pxa27x_init_irq,
  440. .timer = &pxa_timer,
  441. .init_machine = palmz72_init
  442. MACHINE_END