palmz72.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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/syscore_ops.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.h>
  30. #include <linux/power_supply.h>
  31. #include <linux/usb/gpio_vbus.h>
  32. #include <linux/platform_data/i2c-gpio.h>
  33. #include <linux/gpio/machine.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/suspend.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/map.h>
  38. #include "pxa27x.h"
  39. #include <mach/audio.h>
  40. #include "palmz72.h"
  41. #include <linux/platform_data/mmc-pxamci.h>
  42. #include <linux/platform_data/video-pxafb.h>
  43. #include <linux/platform_data/irda-pxaficp.h>
  44. #include <linux/platform_data/keypad-pxa27x.h>
  45. #include "udc.h"
  46. #include <linux/platform_data/asoc-palm27x.h>
  47. #include "palm27x.h"
  48. #include "pm.h"
  49. #include <linux/platform_data/media/camera-pxa.h>
  50. #include <media/soc_camera.h>
  51. #include "generic.h"
  52. #include "devices.h"
  53. /******************************************************************************
  54. * Pin configuration
  55. ******************************************************************************/
  56. static unsigned long palmz72_pin_config[] __initdata = {
  57. /* MMC */
  58. GPIO32_MMC_CLK,
  59. GPIO92_MMC_DAT_0,
  60. GPIO109_MMC_DAT_1,
  61. GPIO110_MMC_DAT_2,
  62. GPIO111_MMC_DAT_3,
  63. GPIO112_MMC_CMD,
  64. GPIO14_GPIO, /* SD detect */
  65. GPIO115_GPIO, /* SD RO */
  66. GPIO98_GPIO, /* SD power */
  67. /* AC97 */
  68. GPIO28_AC97_BITCLK,
  69. GPIO29_AC97_SDATA_IN_0,
  70. GPIO30_AC97_SDATA_OUT,
  71. GPIO31_AC97_SYNC,
  72. GPIO89_AC97_SYSCLK,
  73. GPIO113_AC97_nRESET,
  74. /* IrDA */
  75. GPIO49_GPIO, /* ir disable */
  76. GPIO46_FICP_RXD,
  77. GPIO47_FICP_TXD,
  78. /* PWM */
  79. GPIO16_PWM0_OUT,
  80. /* USB */
  81. GPIO15_GPIO, /* usb detect */
  82. GPIO95_GPIO, /* usb pullup */
  83. /* Matrix keypad */
  84. GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
  85. GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
  86. GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
  87. GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
  88. GPIO103_KP_MKOUT_0,
  89. GPIO104_KP_MKOUT_1,
  90. GPIO105_KP_MKOUT_2,
  91. /* LCD */
  92. GPIOxx_LCD_TFT_16BPP,
  93. GPIO20_GPIO, /* bl power */
  94. GPIO21_GPIO, /* LCD border switch */
  95. GPIO22_GPIO, /* LCD border color */
  96. GPIO96_GPIO, /* lcd power */
  97. /* PXA Camera */
  98. GPIO81_CIF_DD_0,
  99. GPIO48_CIF_DD_5,
  100. GPIO50_CIF_DD_3,
  101. GPIO51_CIF_DD_2,
  102. GPIO52_CIF_DD_4,
  103. GPIO53_CIF_MCLK,
  104. GPIO54_CIF_PCLK,
  105. GPIO55_CIF_DD_1,
  106. GPIO84_CIF_FV,
  107. GPIO85_CIF_LV,
  108. GPIO93_CIF_DD_6,
  109. GPIO108_CIF_DD_7,
  110. GPIO56_GPIO, /* OV9640 Powerdown */
  111. GPIO57_GPIO, /* OV9640 Reset */
  112. GPIO91_GPIO, /* OV9640 Power */
  113. /* I2C */
  114. GPIO117_GPIO, /* I2C_SCL */
  115. GPIO118_GPIO, /* I2C_SDA */
  116. /* Misc. */
  117. GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */
  118. GPIO88_GPIO, /* green led */
  119. GPIO27_GPIO, /* WM9712 IRQ */
  120. };
  121. /******************************************************************************
  122. * GPIO keyboard
  123. ******************************************************************************/
  124. #if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
  125. static const unsigned int palmz72_matrix_keys[] = {
  126. KEY(0, 0, KEY_POWER),
  127. KEY(0, 1, KEY_F1),
  128. KEY(0, 2, KEY_ENTER),
  129. KEY(1, 0, KEY_F2),
  130. KEY(1, 1, KEY_F3),
  131. KEY(1, 2, KEY_F4),
  132. KEY(2, 0, KEY_UP),
  133. KEY(2, 2, KEY_DOWN),
  134. KEY(3, 0, KEY_RIGHT),
  135. KEY(3, 2, KEY_LEFT),
  136. };
  137. static struct matrix_keymap_data almz72_matrix_keymap_data = {
  138. .keymap = palmz72_matrix_keys,
  139. .keymap_size = ARRAY_SIZE(palmz72_matrix_keys),
  140. };
  141. static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
  142. .matrix_key_rows = 4,
  143. .matrix_key_cols = 3,
  144. .matrix_keymap_data = &almz72_matrix_keymap_data,
  145. .debounce_interval = 30,
  146. };
  147. static void __init palmz72_kpc_init(void)
  148. {
  149. pxa_set_keypad_info(&palmz72_keypad_platform_data);
  150. }
  151. #else
  152. static inline void palmz72_kpc_init(void) {}
  153. #endif
  154. /******************************************************************************
  155. * LEDs
  156. ******************************************************************************/
  157. #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  158. static struct gpio_led gpio_leds[] = {
  159. {
  160. .name = "palmz72:green:led",
  161. .default_trigger = "none",
  162. .gpio = GPIO_NR_PALMZ72_LED_GREEN,
  163. },
  164. };
  165. static struct gpio_led_platform_data gpio_led_info = {
  166. .leds = gpio_leds,
  167. .num_leds = ARRAY_SIZE(gpio_leds),
  168. };
  169. static struct platform_device palmz72_leds = {
  170. .name = "leds-gpio",
  171. .id = -1,
  172. .dev = {
  173. .platform_data = &gpio_led_info,
  174. }
  175. };
  176. static void __init palmz72_leds_init(void)
  177. {
  178. platform_device_register(&palmz72_leds);
  179. }
  180. #else
  181. static inline void palmz72_leds_init(void) {}
  182. #endif
  183. #ifdef CONFIG_PM
  184. /* We have some black magic here
  185. * PalmOS ROM on recover expects special struct physical address
  186. * to be transferred via PSPR. Using this struct PalmOS restores
  187. * its state after sleep. As for Linux, we need to setup it the
  188. * same way. More than that, PalmOS ROM changes some values in memory.
  189. * For now only one location is found, which needs special treatment.
  190. * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
  191. * for reading backtraces for me :)
  192. */
  193. #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
  194. static struct palmz72_resume_info palmz72_resume_info = {
  195. .magic0 = 0xb4e6,
  196. .magic1 = 1,
  197. /* reset state, MMU off etc */
  198. .arm_control = 0,
  199. .aux_control = 0,
  200. .ttb = 0,
  201. .domain_access = 0,
  202. .process_id = 0,
  203. };
  204. static unsigned long store_ptr;
  205. /* syscore_ops for Palm Zire 72 PM */
  206. static int palmz72_pm_suspend(void)
  207. {
  208. /* setup the resume_info struct for the original bootloader */
  209. palmz72_resume_info.resume_addr = (u32) cpu_resume;
  210. /* Storing memory touched by ROM */
  211. store_ptr = *PALMZ72_SAVE_DWORD;
  212. /* Setting PSPR to a proper value */
  213. PSPR = __pa_symbol(&palmz72_resume_info);
  214. return 0;
  215. }
  216. static void palmz72_pm_resume(void)
  217. {
  218. *PALMZ72_SAVE_DWORD = store_ptr;
  219. }
  220. static struct syscore_ops palmz72_pm_syscore_ops = {
  221. .suspend = palmz72_pm_suspend,
  222. .resume = palmz72_pm_resume,
  223. };
  224. static int __init palmz72_pm_init(void)
  225. {
  226. if (machine_is_palmz72()) {
  227. register_syscore_ops(&palmz72_pm_syscore_ops);
  228. return 0;
  229. }
  230. return -ENODEV;
  231. }
  232. device_initcall(palmz72_pm_init);
  233. #endif
  234. /******************************************************************************
  235. * SoC Camera
  236. ******************************************************************************/
  237. #if defined(CONFIG_SOC_CAMERA_OV9640) || \
  238. defined(CONFIG_SOC_CAMERA_OV9640_MODULE)
  239. static struct pxacamera_platform_data palmz72_pxacamera_platform_data = {
  240. .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
  241. PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
  242. .mclk_10khz = 2600,
  243. };
  244. /* Board I2C devices. */
  245. static struct i2c_board_info palmz72_i2c_device[] = {
  246. {
  247. I2C_BOARD_INFO("ov9640", 0x30),
  248. }
  249. };
  250. static int palmz72_camera_power(struct device *dev, int power)
  251. {
  252. gpio_set_value(GPIO_NR_PALMZ72_CAM_PWDN, !power);
  253. mdelay(50);
  254. return 0;
  255. }
  256. static int palmz72_camera_reset(struct device *dev)
  257. {
  258. gpio_set_value(GPIO_NR_PALMZ72_CAM_RESET, 1);
  259. mdelay(50);
  260. gpio_set_value(GPIO_NR_PALMZ72_CAM_RESET, 0);
  261. mdelay(50);
  262. return 0;
  263. }
  264. static struct soc_camera_link palmz72_iclink = {
  265. .bus_id = 0, /* Match id in pxa27x_device_camera in device.c */
  266. .board_info = &palmz72_i2c_device[0],
  267. .i2c_adapter_id = 0,
  268. .module_name = "ov96xx",
  269. .power = &palmz72_camera_power,
  270. .reset = &palmz72_camera_reset,
  271. .flags = SOCAM_DATAWIDTH_8,
  272. };
  273. static struct gpiod_lookup_table palmz72_i2c_gpiod_table = {
  274. .dev_id = "i2c-gpio.0",
  275. .table = {
  276. GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0,
  277. GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  278. GPIO_LOOKUP_IDX("gpio-pxa", 117, NULL, 1,
  279. GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
  280. },
  281. };
  282. static struct i2c_gpio_platform_data palmz72_i2c_bus_data = {
  283. .udelay = 10,
  284. .timeout = 100,
  285. };
  286. static struct platform_device palmz72_i2c_bus_device = {
  287. .name = "i2c-gpio",
  288. .id = 0, /* we use this as a replacement for i2c-pxa */
  289. .dev = {
  290. .platform_data = &palmz72_i2c_bus_data,
  291. }
  292. };
  293. static struct platform_device palmz72_camera = {
  294. .name = "soc-camera-pdrv",
  295. .id = -1,
  296. .dev = {
  297. .platform_data = &palmz72_iclink,
  298. },
  299. };
  300. /* Here we request the camera GPIOs and configure them. We power up the camera
  301. * module, deassert the reset pin, but put it into powerdown (low to no power
  302. * consumption) mode. This allows us to later bring the module up fast. */
  303. static struct gpio palmz72_camera_gpios[] = {
  304. { GPIO_NR_PALMZ72_CAM_POWER, GPIOF_INIT_HIGH,"Camera DVDD" },
  305. { GPIO_NR_PALMZ72_CAM_RESET, GPIOF_INIT_LOW, "Camera RESET" },
  306. { GPIO_NR_PALMZ72_CAM_PWDN, GPIOF_INIT_LOW, "Camera PWDN" },
  307. };
  308. static inline void __init palmz72_cam_gpio_init(void)
  309. {
  310. int ret;
  311. ret = gpio_request_array(ARRAY_AND_SIZE(palmz72_camera_gpios));
  312. if (!ret)
  313. gpio_free_array(ARRAY_AND_SIZE(palmz72_camera_gpios));
  314. else
  315. printk(KERN_ERR "Camera GPIO init failed!\n");
  316. return;
  317. }
  318. static void __init palmz72_camera_init(void)
  319. {
  320. palmz72_cam_gpio_init();
  321. pxa_set_camera_info(&palmz72_pxacamera_platform_data);
  322. gpiod_add_lookup_table(&palmz72_i2c_gpiod_table);
  323. platform_device_register(&palmz72_i2c_bus_device);
  324. platform_device_register(&palmz72_camera);
  325. }
  326. #else
  327. static inline void palmz72_camera_init(void) {}
  328. #endif
  329. /******************************************************************************
  330. * Machine init
  331. ******************************************************************************/
  332. static void __init palmz72_init(void)
  333. {
  334. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
  335. pxa_set_ffuart_info(NULL);
  336. pxa_set_btuart_info(NULL);
  337. pxa_set_stuart_info(NULL);
  338. palm27x_mmc_init(GPIO_NR_PALMZ72_SD_DETECT_N, GPIO_NR_PALMZ72_SD_RO,
  339. GPIO_NR_PALMZ72_SD_POWER_N, 1);
  340. palm27x_lcd_init(-1, &palm_320x320_lcd_mode);
  341. palm27x_udc_init(GPIO_NR_PALMZ72_USB_DETECT_N,
  342. GPIO_NR_PALMZ72_USB_PULLUP, 0);
  343. palm27x_irda_init(GPIO_NR_PALMZ72_IR_DISABLE);
  344. palm27x_ac97_init(PALMZ72_BAT_MIN_VOLTAGE, PALMZ72_BAT_MAX_VOLTAGE,
  345. -1, 113);
  346. palm27x_pwm_init(-1, -1);
  347. palm27x_power_init(-1, -1);
  348. palm27x_pmic_init();
  349. palmz72_kpc_init();
  350. palmz72_leds_init();
  351. palmz72_camera_init();
  352. }
  353. MACHINE_START(PALMZ72, "Palm Zire72")
  354. .atag_offset = 0x100,
  355. .map_io = pxa27x_map_io,
  356. .nr_irqs = PXA_NR_IRQS,
  357. .init_irq = pxa27x_init_irq,
  358. .handle_irq = pxa27x_handle_irq,
  359. .init_time = pxa_timer_init,
  360. .init_machine = palmz72_init,
  361. .restart = pxa_restart,
  362. MACHINE_END