palmz72.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. static int palmz72_mci_init(struct device *dev,
  119. irq_handler_t palmz72_detect_int, void *data)
  120. {
  121. int err = 0;
  122. /* Setup an interrupt for detecting card insert/remove events */
  123. err = gpio_request(GPIO_NR_PALMZ72_SD_DETECT_N, "SD IRQ");
  124. if (err)
  125. goto err;
  126. err = gpio_direction_input(GPIO_NR_PALMZ72_SD_DETECT_N);
  127. if (err)
  128. goto err2;
  129. err = request_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N),
  130. palmz72_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  131. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  132. "SD/MMC card detect", data);
  133. if (err) {
  134. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  135. __func__);
  136. goto err2;
  137. }
  138. /* SD_POWER is not actually power, but it is more like chip
  139. * select, i.e. it is inverted */
  140. err = gpio_request(GPIO_NR_PALMZ72_SD_POWER_N, "SD_POWER");
  141. if (err)
  142. goto err3;
  143. err = gpio_direction_output(GPIO_NR_PALMZ72_SD_POWER_N, 0);
  144. if (err)
  145. goto err4;
  146. err = gpio_request(GPIO_NR_PALMZ72_SD_RO, "SD_RO");
  147. if (err)
  148. goto err4;
  149. err = gpio_direction_input(GPIO_NR_PALMZ72_SD_RO);
  150. if (err)
  151. goto err5;
  152. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  153. return 0;
  154. err5:
  155. gpio_free(GPIO_NR_PALMZ72_SD_RO);
  156. err4:
  157. gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
  158. err3:
  159. free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
  160. err2:
  161. gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
  162. err:
  163. return err;
  164. }
  165. static void palmz72_mci_exit(struct device *dev, void *data)
  166. {
  167. gpio_free(GPIO_NR_PALMZ72_SD_POWER_N);
  168. free_irq(gpio_to_irq(GPIO_NR_PALMZ72_SD_DETECT_N), data);
  169. gpio_free(GPIO_NR_PALMZ72_SD_DETECT_N);
  170. gpio_free(GPIO_NR_PALMZ72_SD_RO);
  171. }
  172. static void palmz72_mci_power(struct device *dev, unsigned int vdd)
  173. {
  174. struct pxamci_platform_data *p_d = dev->platform_data;
  175. if (p_d->ocr_mask & (1 << vdd))
  176. gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 0);
  177. else
  178. gpio_set_value(GPIO_NR_PALMZ72_SD_POWER_N, 1);
  179. }
  180. static int palmz72_mci_ro(struct device *dev)
  181. {
  182. return gpio_get_value(GPIO_NR_PALMZ72_SD_RO);
  183. }
  184. static struct pxamci_platform_data palmz72_mci_platform_data = {
  185. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  186. .setpower = palmz72_mci_power,
  187. .get_ro = palmz72_mci_ro,
  188. .init = palmz72_mci_init,
  189. .exit = palmz72_mci_exit,
  190. };
  191. /******************************************************************************
  192. * GPIO keyboard
  193. ******************************************************************************/
  194. static unsigned int palmz72_matrix_keys[] = {
  195. KEY(0, 0, KEY_POWER),
  196. KEY(0, 1, KEY_F1),
  197. KEY(0, 2, KEY_ENTER),
  198. KEY(1, 0, KEY_F2),
  199. KEY(1, 1, KEY_F3),
  200. KEY(1, 2, KEY_F4),
  201. KEY(2, 0, KEY_UP),
  202. KEY(2, 2, KEY_DOWN),
  203. KEY(3, 0, KEY_RIGHT),
  204. KEY(3, 2, KEY_LEFT),
  205. };
  206. static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
  207. .matrix_key_rows = 4,
  208. .matrix_key_cols = 3,
  209. .matrix_key_map = palmz72_matrix_keys,
  210. .matrix_key_map_size = ARRAY_SIZE(palmz72_matrix_keys),
  211. .debounce_interval = 30,
  212. };
  213. /******************************************************************************
  214. * Backlight
  215. ******************************************************************************/
  216. static int palmz72_backlight_init(struct device *dev)
  217. {
  218. int ret;
  219. ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
  220. if (ret)
  221. goto err;
  222. ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
  223. if (ret)
  224. goto err2;
  225. ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
  226. if (ret)
  227. goto err2;
  228. ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
  229. if (ret)
  230. goto err3;
  231. return 0;
  232. err3:
  233. gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
  234. err2:
  235. gpio_free(GPIO_NR_PALMZ72_BL_POWER);
  236. err:
  237. return ret;
  238. }
  239. static int palmz72_backlight_notify(int brightness)
  240. {
  241. gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
  242. gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
  243. return brightness;
  244. }
  245. static void palmz72_backlight_exit(struct device *dev)
  246. {
  247. gpio_free(GPIO_NR_PALMZ72_BL_POWER);
  248. gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
  249. }
  250. static struct platform_pwm_backlight_data palmz72_backlight_data = {
  251. .pwm_id = 0,
  252. .max_brightness = PALMZ72_MAX_INTENSITY,
  253. .dft_brightness = PALMZ72_MAX_INTENSITY,
  254. .pwm_period_ns = PALMZ72_PERIOD_NS,
  255. .init = palmz72_backlight_init,
  256. .notify = palmz72_backlight_notify,
  257. .exit = palmz72_backlight_exit,
  258. };
  259. static struct platform_device palmz72_backlight = {
  260. .name = "pwm-backlight",
  261. .dev = {
  262. .parent = &pxa27x_device_pwm0.dev,
  263. .platform_data = &palmz72_backlight_data,
  264. },
  265. };
  266. /******************************************************************************
  267. * IrDA
  268. ******************************************************************************/
  269. static int palmz72_irda_startup(struct device *dev)
  270. {
  271. int err;
  272. err = gpio_request(GPIO_NR_PALMZ72_IR_DISABLE, "IR DISABLE");
  273. if (err)
  274. goto err;
  275. err = gpio_direction_output(GPIO_NR_PALMZ72_IR_DISABLE, 1);
  276. if (err)
  277. gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
  278. err:
  279. return err;
  280. }
  281. static void palmz72_irda_shutdown(struct device *dev)
  282. {
  283. gpio_free(GPIO_NR_PALMZ72_IR_DISABLE);
  284. }
  285. static void palmz72_irda_transceiver_mode(struct device *dev, int mode)
  286. {
  287. gpio_set_value(GPIO_NR_PALMZ72_IR_DISABLE, mode & IR_OFF);
  288. pxa2xx_transceiver_mode(dev, mode);
  289. }
  290. static struct pxaficp_platform_data palmz72_ficp_platform_data = {
  291. .startup = palmz72_irda_startup,
  292. .shutdown = palmz72_irda_shutdown,
  293. .transceiver_cap = IR_SIRMODE | IR_OFF,
  294. .transceiver_mode = palmz72_irda_transceiver_mode,
  295. };
  296. /******************************************************************************
  297. * LEDs
  298. ******************************************************************************/
  299. static struct gpio_led gpio_leds[] = {
  300. {
  301. .name = "palmz72:green:led",
  302. .default_trigger = "none",
  303. .gpio = GPIO_NR_PALMZ72_LED_GREEN,
  304. },
  305. };
  306. static struct gpio_led_platform_data gpio_led_info = {
  307. .leds = gpio_leds,
  308. .num_leds = ARRAY_SIZE(gpio_leds),
  309. };
  310. static struct platform_device palmz72_leds = {
  311. .name = "leds-gpio",
  312. .id = -1,
  313. .dev = {
  314. .platform_data = &gpio_led_info,
  315. }
  316. };
  317. /******************************************************************************
  318. * UDC
  319. ******************************************************************************/
  320. static struct gpio_vbus_mach_info palmz72_udc_info = {
  321. .gpio_vbus = GPIO_NR_PALMZ72_USB_DETECT_N,
  322. .gpio_pullup = GPIO_NR_PALMZ72_USB_PULLUP,
  323. };
  324. static struct platform_device palmz72_gpio_vbus = {
  325. .name = "gpio-vbus",
  326. .id = -1,
  327. .dev = {
  328. .platform_data = &palmz72_udc_info,
  329. },
  330. };
  331. /******************************************************************************
  332. * Power supply
  333. ******************************************************************************/
  334. static int power_supply_init(struct device *dev)
  335. {
  336. int ret;
  337. ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
  338. if (ret)
  339. goto err1;
  340. ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
  341. if (ret)
  342. goto err2;
  343. ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
  344. if (ret)
  345. goto err2;
  346. ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
  347. if (ret)
  348. goto err3;
  349. return 0;
  350. err3:
  351. gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
  352. err2:
  353. gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
  354. err1:
  355. return ret;
  356. }
  357. static int palmz72_is_ac_online(void)
  358. {
  359. return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
  360. }
  361. static int palmz72_is_usb_online(void)
  362. {
  363. return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
  364. }
  365. static void power_supply_exit(struct device *dev)
  366. {
  367. gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
  368. gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
  369. }
  370. static char *palmz72_supplicants[] = {
  371. "main-battery",
  372. };
  373. static struct pda_power_pdata power_supply_info = {
  374. .init = power_supply_init,
  375. .is_ac_online = palmz72_is_ac_online,
  376. .is_usb_online = palmz72_is_usb_online,
  377. .exit = power_supply_exit,
  378. .supplied_to = palmz72_supplicants,
  379. .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
  380. };
  381. static struct platform_device power_supply = {
  382. .name = "pda-power",
  383. .id = -1,
  384. .dev = {
  385. .platform_data = &power_supply_info,
  386. },
  387. };
  388. /******************************************************************************
  389. * WM97xx battery
  390. ******************************************************************************/
  391. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  392. .batt_aux = WM97XX_AUX_ID3,
  393. .temp_aux = WM97XX_AUX_ID2,
  394. .charge_gpio = -1,
  395. .max_voltage = PALMZ72_BAT_MAX_VOLTAGE,
  396. .min_voltage = PALMZ72_BAT_MIN_VOLTAGE,
  397. .batt_mult = 1000,
  398. .batt_div = 414,
  399. .temp_mult = 1,
  400. .temp_div = 1,
  401. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  402. .batt_name = "main-batt",
  403. };
  404. /******************************************************************************
  405. * aSoC audio
  406. ******************************************************************************/
  407. static struct platform_device palmz72_asoc = {
  408. .name = "palm27x-asoc",
  409. .id = -1,
  410. };
  411. /******************************************************************************
  412. * Framebuffer
  413. ******************************************************************************/
  414. static struct pxafb_mode_info palmz72_lcd_modes[] = {
  415. {
  416. .pixclock = 115384,
  417. .xres = 320,
  418. .yres = 320,
  419. .bpp = 16,
  420. .left_margin = 27,
  421. .right_margin = 7,
  422. .upper_margin = 7,
  423. .lower_margin = 8,
  424. .hsync_len = 6,
  425. .vsync_len = 1,
  426. },
  427. };
  428. static struct pxafb_mach_info palmz72_lcd_screen = {
  429. .modes = palmz72_lcd_modes,
  430. .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
  431. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  432. };
  433. #ifdef CONFIG_PM
  434. /* We have some black magic here
  435. * PalmOS ROM on recover expects special struct physical address
  436. * to be transferred via PSPR. Using this struct PalmOS restores
  437. * its state after sleep. As for Linux, we need to setup it the
  438. * same way. More than that, PalmOS ROM changes some values in memory.
  439. * For now only one location is found, which needs special treatment.
  440. * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
  441. * for reading backtraces for me :)
  442. */
  443. #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
  444. static struct palmz72_resume_info palmz72_resume_info = {
  445. .magic0 = 0xb4e6,
  446. .magic1 = 1,
  447. /* reset state, MMU off etc */
  448. .arm_control = 0,
  449. .aux_control = 0,
  450. .ttb = 0,
  451. .domain_access = 0,
  452. .process_id = 0,
  453. };
  454. static unsigned long store_ptr;
  455. /* sys_device for Palm Zire 72 PM */
  456. static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
  457. {
  458. /* setup the resume_info struct for the original bootloader */
  459. palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
  460. /* Storing memory touched by ROM */
  461. store_ptr = *PALMZ72_SAVE_DWORD;
  462. /* Setting PSPR to a proper value */
  463. PSPR = virt_to_phys(&palmz72_resume_info);
  464. return 0;
  465. }
  466. static int palmz72_pm_resume(struct sys_device *dev)
  467. {
  468. *PALMZ72_SAVE_DWORD = store_ptr;
  469. return 0;
  470. }
  471. static struct sysdev_class palmz72_pm_sysclass = {
  472. .name = "palmz72_pm",
  473. .suspend = palmz72_pm_suspend,
  474. .resume = palmz72_pm_resume,
  475. };
  476. static struct sys_device palmz72_pm_device = {
  477. .cls = &palmz72_pm_sysclass,
  478. };
  479. static int __init palmz72_pm_init(void)
  480. {
  481. int ret = -ENODEV;
  482. if (machine_is_palmz72()) {
  483. ret = sysdev_class_register(&palmz72_pm_sysclass);
  484. if (ret == 0)
  485. ret = sysdev_register(&palmz72_pm_device);
  486. }
  487. return ret;
  488. }
  489. device_initcall(palmz72_pm_init);
  490. #endif
  491. /******************************************************************************
  492. * Machine init
  493. ******************************************************************************/
  494. static struct platform_device *devices[] __initdata = {
  495. &palmz72_backlight,
  496. &palmz72_leds,
  497. &palmz72_asoc,
  498. &power_supply,
  499. &palmz72_gpio_vbus,
  500. };
  501. /* setup udc GPIOs initial state */
  502. static void __init palmz72_udc_init(void)
  503. {
  504. if (!gpio_request(GPIO_NR_PALMZ72_USB_PULLUP, "USB Pullup")) {
  505. gpio_direction_output(GPIO_NR_PALMZ72_USB_PULLUP, 0);
  506. gpio_free(GPIO_NR_PALMZ72_USB_PULLUP);
  507. }
  508. }
  509. static void __init palmz72_init(void)
  510. {
  511. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
  512. set_pxa_fb_info(&palmz72_lcd_screen);
  513. pxa_set_mci_info(&palmz72_mci_platform_data);
  514. palmz72_udc_init();
  515. pxa_set_ac97_info(NULL);
  516. pxa_set_ficp_info(&palmz72_ficp_platform_data);
  517. pxa_set_keypad_info(&palmz72_keypad_platform_data);
  518. wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
  519. platform_add_devices(devices, ARRAY_SIZE(devices));
  520. }
  521. MACHINE_START(PALMZ72, "Palm Zire72")
  522. .phys_io = 0x40000000,
  523. .io_pg_offst = io_p2v(0x40000000),
  524. .boot_params = 0xa0000100,
  525. .map_io = pxa_map_io,
  526. .init_irq = pxa27x_init_irq,
  527. .timer = &pxa_timer,
  528. .init_machine = palmz72_init
  529. MACHINE_END