palmz72.c 9.9 KB

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