palmz72.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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/power_supply.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/map.h>
  33. #include <mach/pxa27x.h>
  34. #include <mach/audio.h>
  35. #include <mach/palmz72.h>
  36. #include <mach/mmc.h>
  37. #include <mach/pxafb.h>
  38. #include <mach/irda.h>
  39. #include <mach/pxa27x_keypad.h>
  40. #include <mach/udc.h>
  41. #include <mach/pm.h>
  42. #include "generic.h"
  43. #include "devices.h"
  44. /******************************************************************************
  45. * Pin configuration
  46. ******************************************************************************/
  47. static unsigned long palmz72_pin_config[] __initdata = {
  48. /* MMC */
  49. GPIO32_MMC_CLK,
  50. GPIO92_MMC_DAT_0,
  51. GPIO109_MMC_DAT_1,
  52. GPIO110_MMC_DAT_2,
  53. GPIO111_MMC_DAT_3,
  54. GPIO112_MMC_CMD,
  55. GPIO14_GPIO, /* SD detect */
  56. GPIO115_GPIO, /* SD RO */
  57. GPIO98_GPIO, /* SD power */
  58. /* AC97 */
  59. GPIO28_AC97_BITCLK,
  60. GPIO29_AC97_SDATA_IN_0,
  61. GPIO30_AC97_SDATA_OUT,
  62. GPIO31_AC97_SYNC,
  63. /* IrDA */
  64. GPIO49_GPIO, /* ir disable */
  65. GPIO46_FICP_RXD,
  66. GPIO47_FICP_TXD,
  67. /* PWM */
  68. GPIO16_PWM0_OUT,
  69. /* USB */
  70. GPIO15_GPIO, /* usb detect */
  71. GPIO12_GPIO, /* usb pullup */
  72. GPIO95_GPIO, /* usb power */
  73. /* Matrix keypad */
  74. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  75. GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
  76. GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
  77. GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
  78. GPIO103_KP_MKOUT_0,
  79. GPIO104_KP_MKOUT_1,
  80. GPIO105_KP_MKOUT_2,
  81. /* LCD */
  82. GPIO58_LCD_LDD_0,
  83. GPIO59_LCD_LDD_1,
  84. GPIO60_LCD_LDD_2,
  85. GPIO61_LCD_LDD_3,
  86. GPIO62_LCD_LDD_4,
  87. GPIO63_LCD_LDD_5,
  88. GPIO64_LCD_LDD_6,
  89. GPIO65_LCD_LDD_7,
  90. GPIO66_LCD_LDD_8,
  91. GPIO67_LCD_LDD_9,
  92. GPIO68_LCD_LDD_10,
  93. GPIO69_LCD_LDD_11,
  94. GPIO70_LCD_LDD_12,
  95. GPIO71_LCD_LDD_13,
  96. GPIO72_LCD_LDD_14,
  97. GPIO73_LCD_LDD_15,
  98. GPIO74_LCD_FCLK,
  99. GPIO75_LCD_LCLK,
  100. GPIO76_LCD_PCLK,
  101. GPIO77_LCD_BIAS,
  102. GPIO20_GPIO, /* bl power */
  103. GPIO21_GPIO, /* LCD border switch */
  104. GPIO22_GPIO, /* LCD border color */
  105. GPIO96_GPIO, /* lcd power */
  106. /* Misc. */
  107. GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */
  108. GPIO88_GPIO, /* green led */
  109. GPIO27_GPIO, /* WM9712 IRQ */
  110. };
  111. /******************************************************************************
  112. * SD/MMC card controller
  113. ******************************************************************************/
  114. static int palmz72_mci_init(struct device *dev,
  115. irq_handler_t palmz72_detect_int, void *data)
  116. {
  117. int err = 0;
  118. /* Setup an interrupt for detecting card insert/remove events */
  119. err = gpio_request(GPIO_NR_PALMZ72_SD_DETECT_N, "SD IRQ");
  120. if (err)
  121. goto err;
  122. err = gpio_direction_input(GPIO_NR_PALMZ72_SD_DETECT_N);
  123. if (err)
  124. goto err2;
  125. err = request_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N),
  126. palmz72_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  127. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  128. "SD/MMC card detect", data);
  129. if (err) {
  130. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  131. __func__);
  132. goto err2;
  133. }
  134. /* SD_POWER is not actually power, but it is more like chip
  135. * select, i.e. it is inverted */
  136. err = gpio_request(GPIO_NR_PALMZ72_SD_POWER_N, "SD_POWER");
  137. if (err)
  138. goto err3;
  139. err = gpio_direction_output(GPIO_NR_PALMZ72_SD_POWER_N, 0);
  140. if (err)
  141. goto err4;
  142. err = gpio_request(GPIO_NR_PALMZ72_SD_RO, "SD_RO");
  143. if (err)
  144. goto err4;
  145. err = gpio_direction_input(GPIO_NR_PALMZ72_SD_RO);
  146. if (err)
  147. goto err5;
  148. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  149. return 0;
  150. err5:
  151. gpio_free(GPIO_NR_PALMZ72_SD_RO);
  152. err4:
  153. gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
  154. err3:
  155. free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
  156. err2:
  157. gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
  158. err:
  159. return err;
  160. }
  161. static void palmz72_mci_exit(struct device *dev, void *data)
  162. {
  163. gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
  164. free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
  165. gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
  166. gpio_free(GPIO_NR_PALMZ72_SD_RO);
  167. }
  168. static void palmz72_mci_power(struct device *dev, unsigned int vdd)
  169. {
  170. struct pxamci_platform_data *p_d = dev->platform_data;
  171. if (p_d->ocr_mask & (1 << vdd))
  172. gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 0);
  173. else
  174. gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 1);
  175. }
  176. static int palmz72_mci_ro(struct device *dev)
  177. {
  178. return gpio_get_value(GPIO_NR_PALMZ72_SD_RO);
  179. }
  180. static struct pxamci_platform_data palmz72_mci_platform_data = {
  181. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  182. .setpower = palmz72_mci_power,
  183. .get_ro = palmz72_mci_ro,
  184. .init = palmz72_mci_init,
  185. .exit = palmz72_mci_exit,
  186. };
  187. /******************************************************************************
  188. * GPIO keyboard
  189. ******************************************************************************/
  190. static unsigned int palmz72_matrix_keys[] = {
  191. KEY(0, 0, KEY_POWER),
  192. KEY(0, 1, KEY_F1),
  193. KEY(0, 2, KEY_ENTER),
  194. KEY(1, 0, KEY_F2),
  195. KEY(1, 1, KEY_F3),
  196. KEY(1, 2, KEY_F4),
  197. KEY(2, 0, KEY_UP),
  198. KEY(2, 2, KEY_DOWN),
  199. KEY(3, 0, KEY_RIGHT),
  200. KEY(3, 2, KEY_LEFT),
  201. };
  202. static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
  203. .matrix_key_rows = 4,
  204. .matrix_key_cols = 3,
  205. .matrix_key_map = palmz72_matrix_keys,
  206. .matrix_key_map_size = ARRAY_SIZE(palmz72_matrix_keys),
  207. .debounce_interval = 30,
  208. };
  209. /******************************************************************************
  210. * Backlight
  211. ******************************************************************************/
  212. static int palmz72_backlight_init(struct device *dev)
  213. {
  214. int ret;
  215. ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
  216. if (ret)
  217. goto err;
  218. ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
  219. if (ret)
  220. goto err2;
  221. ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
  222. if (ret)
  223. goto err2;
  224. ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
  225. if (ret)
  226. goto err3;
  227. return 0;
  228. err3:
  229. gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
  230. err2:
  231. gpio_free(GPIO_NR_PALMZ72_BL_POWER);
  232. err:
  233. return ret;
  234. }
  235. static int palmz72_backlight_notify(int brightness)
  236. {
  237. gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
  238. gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
  239. return brightness;
  240. }
  241. static void palmz72_backlight_exit(struct device *dev)
  242. {
  243. gpio_free(GPIO_NR_PALMZ72_BL_POWER);
  244. gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
  245. }
  246. static struct platform_pwm_backlight_data palmz72_backlight_data = {
  247. .pwm_id = 0,
  248. .max_brightness = PALMZ72_MAX_INTENSITY,
  249. .dft_brightness = PALMZ72_MAX_INTENSITY,
  250. .pwm_period_ns = PALMZ72_PERIOD_NS,
  251. .init = palmz72_backlight_init,
  252. .notify = palmz72_backlight_notify,
  253. .exit = palmz72_backlight_exit,
  254. };
  255. static struct platform_device palmz72_backlight = {
  256. .name = "pwm-backlight",
  257. .dev = {
  258. .parent = &pxa27x_device_pwm0.dev,
  259. .platform_data = &palmz72_backlight_data,
  260. },
  261. };
  262. /******************************************************************************
  263. * IrDA
  264. ******************************************************************************/
  265. static int palmz72_irda_startup(struct device *dev)
  266. {
  267. int err;
  268. err = gpio_request(GPIO_NR_PALMZ72_IR_DISABLE, "IR DISABLE");
  269. if (err)
  270. goto err;
  271. err = gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE, 1);
  272. if (err)
  273. gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
  274. err:
  275. return err;
  276. }
  277. static void palmz72_irda_shutdown(struct device *dev)
  278. {
  279. gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
  280. }
  281. static void palmz72_irda_transceiver_mode(struct device *dev, int mode)
  282. {
  283. gpio_set_value(GPIO_NR_PALMZ72_IR_DISABLE, mode & IR_OFF);
  284. pxa2xx_transceiver_mode(dev, mode);
  285. }
  286. static struct pxaficp_platform_data palmz72_ficp_platform_data = {
  287. .startup = palmz72_irda_startup,
  288. .shutdown = palmz72_irda_shutdown,
  289. .transceiver_cap = IR_SIRMODE | IR_OFF,
  290. .transceiver_mode = palmz72_irda_transceiver_mode,
  291. };
  292. /******************************************************************************
  293. * LEDs
  294. ******************************************************************************/
  295. static struct gpio_led gpio_leds[] = {
  296. {
  297. .name = "palmz72:green:led",
  298. .default_trigger = "none",
  299. .gpio = GPIO_NR_PALMZ72_LED_GREEN,
  300. },
  301. };
  302. static struct gpio_led_platform_data gpio_led_info = {
  303. .leds = gpio_leds,
  304. .num_leds = ARRAY_SIZE(gpio_leds),
  305. };
  306. static struct platform_device palmz72_leds = {
  307. .name = "leds-gpio",
  308. .id = -1,
  309. .dev = {
  310. .platform_data = &gpio_led_info,
  311. }
  312. };
  313. /******************************************************************************
  314. * Power supply
  315. ******************************************************************************/
  316. static int power_supply_init(struct device *dev)
  317. {
  318. int ret;
  319. ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
  320. if (ret)
  321. goto err1;
  322. ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
  323. if (ret)
  324. goto err2;
  325. ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
  326. if (ret)
  327. goto err2;
  328. ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
  329. if (ret)
  330. goto err3;
  331. return 0;
  332. err3:
  333. gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
  334. err2:
  335. gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
  336. err1:
  337. return ret;
  338. }
  339. static int palmz72_is_ac_online(void)
  340. {
  341. return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
  342. }
  343. static int palmz72_is_usb_online(void)
  344. {
  345. return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
  346. }
  347. static void power_supply_exit(struct device *dev)
  348. {
  349. gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
  350. gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
  351. }
  352. static char *palmz72_supplicants[] = {
  353. "main-battery",
  354. };
  355. static struct pda_power_pdata power_supply_info = {
  356. .init = power_supply_init,
  357. .is_ac_online = palmz72_is_ac_online,
  358. .is_usb_online = palmz72_is_usb_online,
  359. .exit = power_supply_exit,
  360. .supplied_to = palmz72_supplicants,
  361. .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
  362. };
  363. static struct platform_device power_supply = {
  364. .name = "pda-power",
  365. .id = -1,
  366. .dev = {
  367. .platform_data = &power_supply_info,
  368. },
  369. };
  370. /******************************************************************************
  371. * Framebuffer
  372. ******************************************************************************/
  373. static struct pxafb_mode_info palmz72_lcd_modes[] = {
  374. {
  375. .pixclock = 115384,
  376. .xres = 320,
  377. .yres = 320,
  378. .bpp = 16,
  379. .left_margin = 27,
  380. .right_margin = 7,
  381. .upper_margin = 7,
  382. .lower_margin = 8,
  383. .hsync_len = 6,
  384. .vsync_len = 1,
  385. },
  386. };
  387. static struct pxafb_mach_info palmz72_lcd_screen = {
  388. .modes = palmz72_lcd_modes,
  389. .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
  390. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  391. };
  392. #ifdef CONFIG_PM
  393. /* We have some black magic here
  394. * PalmOS ROM on recover expects special struct physical address
  395. * to be transferred via PSPR. Using this struct PalmOS restores
  396. * its state after sleep. As for Linux, we need to setup it the
  397. * same way. More than that, PalmOS ROM changes some values in memory.
  398. * For now only one location is found, which needs special treatment.
  399. * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
  400. * for reading backtraces for me :)
  401. */
  402. #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
  403. static struct palmz72_resume_info palmz72_resume_info = {
  404. .magic0 = 0xb4e6,
  405. .magic1 = 1,
  406. /* reset state, MMU off etc */
  407. .arm_control = 0,
  408. .aux_control = 0,
  409. .ttb = 0,
  410. .domain_access = 0,
  411. .process_id = 0,
  412. };
  413. static unsigned long store_ptr;
  414. /* sys_device for Palm Zire 72 PM */
  415. static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
  416. {
  417. /* setup the resume_info struct for the original bootloader */
  418. palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
  419. /* Storing memory touched by ROM */
  420. store_ptr = *PALMZ72_SAVE_DWORD;
  421. /* Setting PSPR to a proper value */
  422. PSPR = virt_to_phys(&palmz72_resume_info);
  423. return 0;
  424. }
  425. static int palmz72_pm_resume(struct sys_device *dev)
  426. {
  427. *PALMZ72_SAVE_DWORD = store_ptr;
  428. return 0;
  429. }
  430. static struct sysdev_class palmz72_pm_sysclass = {
  431. .name = "palmz72_pm",
  432. .suspend = palmz72_pm_suspend,
  433. .resume = palmz72_pm_resume,
  434. };
  435. static struct sys_device palmz72_pm_device = {
  436. .cls = &palmz72_pm_sysclass,
  437. };
  438. static int __init palmz72_pm_init(void)
  439. {
  440. int ret = -ENODEV;
  441. if (machine_is_palmz72()) {
  442. ret = sysdev_class_register(&palmz72_pm_sysclass);
  443. if (ret == 0)
  444. ret = sysdev_register(&palmz72_pm_device);
  445. }
  446. return ret;
  447. }
  448. device_initcall(palmz72_pm_init);
  449. #endif
  450. /******************************************************************************
  451. * Machine init
  452. ******************************************************************************/
  453. static struct platform_device *devices[] __initdata = {
  454. &palmz72_backlight,
  455. &palmz72_leds,
  456. &power_supply,
  457. };
  458. static void __init palmz72_init(void)
  459. {
  460. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
  461. set_pxa_fb_info(&palmz72_lcd_screen);
  462. pxa_set_mci_info(&palmz72_mci_platform_data);
  463. pxa_set_ac97_info(NULL);
  464. pxa_set_ficp_info(&palmz72_ficp_platform_data);
  465. pxa_set_keypad_info(&palmz72_keypad_platform_data);
  466. platform_add_devices(devices, ARRAY_SIZE(devices));
  467. }
  468. MACHINE_START(PALMZ72, "Palm Zire72")
  469. .phys_io = 0x40000000,
  470. .io_pg_offst = io_p2v(0x40000000),
  471. .boot_params = 0xa0000100,
  472. .map_io = pxa_map_io,
  473. .init_irq = pxa27x_init_irq,
  474. .timer = &pxa_timer,
  475. .init_machine = palmz72_init
  476. MACHINE_END