palmz72.c 14 KB

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