palmz72.c 10 KB

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