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/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.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. /* sys_device for Palm Zire 72 PM */
  201. static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
  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 int palmz72_pm_resume(struct sys_device *dev)
  212. {
  213. *PALMZ72_SAVE_DWORD = store_ptr;
  214. return 0;
  215. }
  216. static struct sysdev_class palmz72_pm_sysclass = {
  217. .name = "palmz72_pm",
  218. .suspend = palmz72_pm_suspend,
  219. .resume = palmz72_pm_resume,
  220. };
  221. static struct sys_device palmz72_pm_device = {
  222. .cls = &palmz72_pm_sysclass,
  223. };
  224. static int __init palmz72_pm_init(void)
  225. {
  226. int ret = -ENODEV;
  227. if (machine_is_palmz72()) {
  228. ret = sysdev_class_register(&palmz72_pm_sysclass);
  229. if (ret == 0)
  230. ret = sysdev_register(&palmz72_pm_device);
  231. }
  232. return ret;
  233. }
  234. device_initcall(palmz72_pm_init);
  235. #endif
  236. /******************************************************************************
  237. * SoC Camera
  238. ******************************************************************************/
  239. #if defined(CONFIG_SOC_CAMERA_OV9640) || \
  240. defined(CONFIG_SOC_CAMERA_OV9640_MODULE)
  241. static struct pxacamera_platform_data palmz72_pxacamera_platform_data = {
  242. .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
  243. PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
  244. .mclk_10khz = 2600,
  245. };
  246. /* Board I2C devices. */
  247. static struct i2c_board_info palmz72_i2c_device[] = {
  248. {
  249. I2C_BOARD_INFO("ov9640", 0x30),
  250. }
  251. };
  252. static int palmz72_camera_power(struct device *dev, int power)
  253. {
  254. gpio_set_value(GPIO_NR_PALMZ72_CAM_PWDN, !power);
  255. mdelay(50);
  256. return 0;
  257. }
  258. static int palmz72_camera_reset(struct device *dev)
  259. {
  260. gpio_set_value(GPIO_NR_PALMZ72_CAM_RESET, 1);
  261. mdelay(50);
  262. gpio_set_value(GPIO_NR_PALMZ72_CAM_RESET, 0);
  263. mdelay(50);
  264. return 0;
  265. }
  266. static struct soc_camera_link palmz72_iclink = {
  267. .bus_id = 0, /* Match id in pxa27x_device_camera in device.c */
  268. .board_info = &palmz72_i2c_device[0],
  269. .i2c_adapter_id = 0,
  270. .module_name = "ov96xx",
  271. .power = &palmz72_camera_power,
  272. .reset = &palmz72_camera_reset,
  273. .flags = SOCAM_DATAWIDTH_8,
  274. };
  275. static struct i2c_gpio_platform_data palmz72_i2c_bus_data = {
  276. .sda_pin = 118,
  277. .scl_pin = 117,
  278. .udelay = 10,
  279. .timeout = 100,
  280. };
  281. static struct platform_device palmz72_i2c_bus_device = {
  282. .name = "i2c-gpio",
  283. .id = 0, /* we use this as a replacement for i2c-pxa */
  284. .dev = {
  285. .platform_data = &palmz72_i2c_bus_data,
  286. }
  287. };
  288. static struct platform_device palmz72_camera = {
  289. .name = "soc-camera-pdrv",
  290. .id = -1,
  291. .dev = {
  292. .platform_data = &palmz72_iclink,
  293. },
  294. };
  295. /* Here we request the camera GPIOs and configure them. We power up the camera
  296. * module, deassert the reset pin, but put it into powerdown (low to no power
  297. * consumption) mode. This allows us to later bring the module up fast. */
  298. static struct gpio palmz72_camera_gpios[] = {
  299. { GPIO_NR_PALMZ72_CAM_POWER, GPIOF_INIT_HIGH,"Camera DVDD" },
  300. { GPIO_NR_PALMZ72_CAM_RESET, GPIOF_INIT_LOW, "Camera RESET" },
  301. { GPIO_NR_PALMZ72_CAM_PWDN, GPIOF_INIT_LOW, "Camera PWDN" },
  302. };
  303. static inline void __init palmz72_cam_gpio_init(void)
  304. {
  305. int ret;
  306. ret = gpio_request_array(ARRAY_AND_SIZE(palmz72_camera_gpios));
  307. if (!ret)
  308. gpio_free_array(ARRAY_AND_SIZE(palmz72_camera_gpios));
  309. else
  310. printk(KERN_ERR "Camera GPIO init failed!\n");
  311. return;
  312. }
  313. static void __init palmz72_camera_init(void)
  314. {
  315. palmz72_cam_gpio_init();
  316. pxa_set_camera_info(&palmz72_pxacamera_platform_data);
  317. platform_device_register(&palmz72_i2c_bus_device);
  318. platform_device_register(&palmz72_camera);
  319. }
  320. #else
  321. static inline void palmz72_camera_init(void) {}
  322. #endif
  323. /******************************************************************************
  324. * Machine init
  325. ******************************************************************************/
  326. static void __init palmz72_init(void)
  327. {
  328. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
  329. pxa_set_ffuart_info(NULL);
  330. pxa_set_btuart_info(NULL);
  331. pxa_set_stuart_info(NULL);
  332. palm27x_mmc_init(GPIO_NR_PALMZ72_SD_DETECT_N, GPIO_NR_PALMZ72_SD_RO,
  333. GPIO_NR_PALMZ72_SD_POWER_N, 1);
  334. palm27x_lcd_init(-1, &palm_320x320_lcd_mode);
  335. palm27x_udc_init(GPIO_NR_PALMZ72_USB_DETECT_N,
  336. GPIO_NR_PALMZ72_USB_PULLUP, 0);
  337. palm27x_irda_init(GPIO_NR_PALMZ72_IR_DISABLE);
  338. palm27x_ac97_init(PALMZ72_BAT_MIN_VOLTAGE, PALMZ72_BAT_MAX_VOLTAGE,
  339. -1, 113);
  340. palm27x_pwm_init(-1, -1);
  341. palm27x_power_init(-1, -1);
  342. palm27x_pmic_init();
  343. palmz72_kpc_init();
  344. palmz72_leds_init();
  345. palmz72_camera_init();
  346. }
  347. MACHINE_START(PALMZ72, "Palm Zire72")
  348. .boot_params = 0xa0000100,
  349. .map_io = pxa27x_map_io,
  350. .init_irq = pxa27x_init_irq,
  351. .timer = &pxa_timer,
  352. .init_machine = palmz72_init
  353. MACHINE_END