palmz72.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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 "pxa27x.h"
  38. #include <mach/audio.h>
  39. #include "palmz72.h"
  40. #include <linux/platform_data/mmc-pxamci.h>
  41. #include <linux/platform_data/video-pxafb.h>
  42. #include <linux/platform_data/irda-pxaficp.h>
  43. #include <linux/platform_data/keypad-pxa27x.h>
  44. #include "udc.h"
  45. #include <linux/platform_data/asoc-palm27x.h>
  46. #include "palm27x.h"
  47. #include "pm.h"
  48. #include <linux/platform_data/media/camera-pxa.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 const 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 matrix_keymap_data almz72_matrix_keymap_data = {
  137. .keymap = palmz72_matrix_keys,
  138. .keymap_size = ARRAY_SIZE(palmz72_matrix_keys),
  139. };
  140. static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
  141. .matrix_key_rows = 4,
  142. .matrix_key_cols = 3,
  143. .matrix_keymap_data = &almz72_matrix_keymap_data,
  144. .debounce_interval = 30,
  145. };
  146. static void __init palmz72_kpc_init(void)
  147. {
  148. pxa_set_keypad_info(&palmz72_keypad_platform_data);
  149. }
  150. #else
  151. static inline void palmz72_kpc_init(void) {}
  152. #endif
  153. /******************************************************************************
  154. * LEDs
  155. ******************************************************************************/
  156. #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  157. static struct gpio_led gpio_leds[] = {
  158. {
  159. .name = "palmz72:green:led",
  160. .default_trigger = "none",
  161. .gpio = GPIO_NR_PALMZ72_LED_GREEN,
  162. },
  163. };
  164. static struct gpio_led_platform_data gpio_led_info = {
  165. .leds = gpio_leds,
  166. .num_leds = ARRAY_SIZE(gpio_leds),
  167. };
  168. static struct platform_device palmz72_leds = {
  169. .name = "leds-gpio",
  170. .id = -1,
  171. .dev = {
  172. .platform_data = &gpio_led_info,
  173. }
  174. };
  175. static void __init palmz72_leds_init(void)
  176. {
  177. platform_device_register(&palmz72_leds);
  178. }
  179. #else
  180. static inline void palmz72_leds_init(void) {}
  181. #endif
  182. #ifdef CONFIG_PM
  183. /* We have some black magic here
  184. * PalmOS ROM on recover expects special struct physical address
  185. * to be transferred via PSPR. Using this struct PalmOS restores
  186. * its state after sleep. As for Linux, we need to setup it the
  187. * same way. More than that, PalmOS ROM changes some values in memory.
  188. * For now only one location is found, which needs special treatment.
  189. * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
  190. * for reading backtraces for me :)
  191. */
  192. #define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
  193. static struct palmz72_resume_info palmz72_resume_info = {
  194. .magic0 = 0xb4e6,
  195. .magic1 = 1,
  196. /* reset state, MMU off etc */
  197. .arm_control = 0,
  198. .aux_control = 0,
  199. .ttb = 0,
  200. .domain_access = 0,
  201. .process_id = 0,
  202. };
  203. static unsigned long store_ptr;
  204. /* syscore_ops for Palm Zire 72 PM */
  205. static int palmz72_pm_suspend(void)
  206. {
  207. /* setup the resume_info struct for the original bootloader */
  208. palmz72_resume_info.resume_addr = (u32) cpu_resume;
  209. /* Storing memory touched by ROM */
  210. store_ptr = *PALMZ72_SAVE_DWORD;
  211. /* Setting PSPR to a proper value */
  212. PSPR = virt_to_phys(&palmz72_resume_info);
  213. return 0;
  214. }
  215. static void palmz72_pm_resume(void)
  216. {
  217. *PALMZ72_SAVE_DWORD = store_ptr;
  218. }
  219. static struct syscore_ops palmz72_pm_syscore_ops = {
  220. .suspend = palmz72_pm_suspend,
  221. .resume = palmz72_pm_resume,
  222. };
  223. static int __init palmz72_pm_init(void)
  224. {
  225. if (machine_is_palmz72()) {
  226. register_syscore_ops(&palmz72_pm_syscore_ops);
  227. return 0;
  228. }
  229. return -ENODEV;
  230. }
  231. device_initcall(palmz72_pm_init);
  232. #endif
  233. /******************************************************************************
  234. * SoC Camera
  235. ******************************************************************************/
  236. #if defined(CONFIG_SOC_CAMERA_OV9640) || \
  237. defined(CONFIG_SOC_CAMERA_OV9640_MODULE)
  238. static struct pxacamera_platform_data palmz72_pxacamera_platform_data = {
  239. .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
  240. PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
  241. .mclk_10khz = 2600,
  242. };
  243. /* Board I2C devices. */
  244. static struct i2c_board_info palmz72_i2c_device[] = {
  245. {
  246. I2C_BOARD_INFO("ov9640", 0x30),
  247. }
  248. };
  249. static int palmz72_camera_power(struct device *dev, int power)
  250. {
  251. gpio_set_value(GPIO_NR_PALMZ72_CAM_PWDN, !power);
  252. mdelay(50);
  253. return 0;
  254. }
  255. static int palmz72_camera_reset(struct device *dev)
  256. {
  257. gpio_set_value(GPIO_NR_PALMZ72_CAM_RESET, 1);
  258. mdelay(50);
  259. gpio_set_value(GPIO_NR_PALMZ72_CAM_RESET, 0);
  260. mdelay(50);
  261. return 0;
  262. }
  263. static struct soc_camera_link palmz72_iclink = {
  264. .bus_id = 0, /* Match id in pxa27x_device_camera in device.c */
  265. .board_info = &palmz72_i2c_device[0],
  266. .i2c_adapter_id = 0,
  267. .module_name = "ov96xx",
  268. .power = &palmz72_camera_power,
  269. .reset = &palmz72_camera_reset,
  270. .flags = SOCAM_DATAWIDTH_8,
  271. };
  272. static struct i2c_gpio_platform_data palmz72_i2c_bus_data = {
  273. .sda_pin = 118,
  274. .scl_pin = 117,
  275. .udelay = 10,
  276. .timeout = 100,
  277. };
  278. static struct platform_device palmz72_i2c_bus_device = {
  279. .name = "i2c-gpio",
  280. .id = 0, /* we use this as a replacement for i2c-pxa */
  281. .dev = {
  282. .platform_data = &palmz72_i2c_bus_data,
  283. }
  284. };
  285. static struct platform_device palmz72_camera = {
  286. .name = "soc-camera-pdrv",
  287. .id = -1,
  288. .dev = {
  289. .platform_data = &palmz72_iclink,
  290. },
  291. };
  292. /* Here we request the camera GPIOs and configure them. We power up the camera
  293. * module, deassert the reset pin, but put it into powerdown (low to no power
  294. * consumption) mode. This allows us to later bring the module up fast. */
  295. static struct gpio palmz72_camera_gpios[] = {
  296. { GPIO_NR_PALMZ72_CAM_POWER, GPIOF_INIT_HIGH,"Camera DVDD" },
  297. { GPIO_NR_PALMZ72_CAM_RESET, GPIOF_INIT_LOW, "Camera RESET" },
  298. { GPIO_NR_PALMZ72_CAM_PWDN, GPIOF_INIT_LOW, "Camera PWDN" },
  299. };
  300. static inline void __init palmz72_cam_gpio_init(void)
  301. {
  302. int ret;
  303. ret = gpio_request_array(ARRAY_AND_SIZE(palmz72_camera_gpios));
  304. if (!ret)
  305. gpio_free_array(ARRAY_AND_SIZE(palmz72_camera_gpios));
  306. else
  307. printk(KERN_ERR "Camera GPIO init failed!\n");
  308. return;
  309. }
  310. static void __init palmz72_camera_init(void)
  311. {
  312. palmz72_cam_gpio_init();
  313. pxa_set_camera_info(&palmz72_pxacamera_platform_data);
  314. platform_device_register(&palmz72_i2c_bus_device);
  315. platform_device_register(&palmz72_camera);
  316. }
  317. #else
  318. static inline void palmz72_camera_init(void) {}
  319. #endif
  320. /******************************************************************************
  321. * Machine init
  322. ******************************************************************************/
  323. static void __init palmz72_init(void)
  324. {
  325. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
  326. pxa_set_ffuart_info(NULL);
  327. pxa_set_btuart_info(NULL);
  328. pxa_set_stuart_info(NULL);
  329. palm27x_mmc_init(GPIO_NR_PALMZ72_SD_DETECT_N, GPIO_NR_PALMZ72_SD_RO,
  330. GPIO_NR_PALMZ72_SD_POWER_N, 1);
  331. palm27x_lcd_init(-1, &palm_320x320_lcd_mode);
  332. palm27x_udc_init(GPIO_NR_PALMZ72_USB_DETECT_N,
  333. GPIO_NR_PALMZ72_USB_PULLUP, 0);
  334. palm27x_irda_init(GPIO_NR_PALMZ72_IR_DISABLE);
  335. palm27x_ac97_init(PALMZ72_BAT_MIN_VOLTAGE, PALMZ72_BAT_MAX_VOLTAGE,
  336. -1, 113);
  337. palm27x_pwm_init(-1, -1);
  338. palm27x_power_init(-1, -1);
  339. palm27x_pmic_init();
  340. palmz72_kpc_init();
  341. palmz72_leds_init();
  342. palmz72_camera_init();
  343. }
  344. MACHINE_START(PALMZ72, "Palm Zire72")
  345. .atag_offset = 0x100,
  346. .map_io = pxa27x_map_io,
  347. .nr_irqs = PXA_NR_IRQS,
  348. .init_irq = pxa27x_init_irq,
  349. .handle_irq = pxa27x_handle_irq,
  350. .init_time = pxa_timer_init,
  351. .init_machine = palmz72_init,
  352. .restart = pxa_restart,
  353. MACHINE_END