palm27x.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /*
  2. * Common code for Palm LD, T5, TX, Z72
  3. *
  4. * Copyright (C) 2010
  5. * Marek Vasut <marek.vasut@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. */
  12. #include <linux/platform_device.h>
  13. #include <linux/delay.h>
  14. #include <linux/irq.h>
  15. #include <linux/gpio_keys.h>
  16. #include <linux/input.h>
  17. #include <linux/pda_power.h>
  18. #include <linux/pwm_backlight.h>
  19. #include <linux/gpio.h>
  20. #include <linux/wm97xx.h>
  21. #include <linux/power_supply.h>
  22. #include <linux/usb/gpio_vbus.h>
  23. #include <linux/regulator/max1586.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/mach/arch.h>
  26. #include <asm/mach/map.h>
  27. #include <mach/pxa27x.h>
  28. #include <mach/audio.h>
  29. #include <mach/mmc.h>
  30. #include <mach/pxafb.h>
  31. #include <mach/irda.h>
  32. #include <mach/udc.h>
  33. #include <mach/palmasoc.h>
  34. #include <mach/palm27x.h>
  35. #include <plat/i2c.h>
  36. #include "generic.h"
  37. #include "devices.h"
  38. /******************************************************************************
  39. * SD/MMC card controller
  40. ******************************************************************************/
  41. #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
  42. static struct pxamci_platform_data palm27x_mci_platform_data = {
  43. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  44. .detect_delay_ms = 200,
  45. };
  46. void __init palm27x_mmc_init(int detect, int ro, int power,
  47. int power_inverted)
  48. {
  49. palm27x_mci_platform_data.gpio_card_detect = detect;
  50. palm27x_mci_platform_data.gpio_card_ro = ro;
  51. palm27x_mci_platform_data.gpio_power = power;
  52. palm27x_mci_platform_data.gpio_power_invert = power_inverted;
  53. pxa_set_mci_info(&palm27x_mci_platform_data);
  54. }
  55. #endif
  56. /******************************************************************************
  57. * Power management - standby
  58. ******************************************************************************/
  59. #if defined(CONFIG_SUSPEND)
  60. void __init palm27x_pm_init(unsigned long str_base)
  61. {
  62. static const unsigned long resume[] = {
  63. 0xe3a00101, /* mov r0, #0x40000000 */
  64. 0xe380060f, /* orr r0, r0, #0x00f00000 */
  65. 0xe590f008, /* ldr pc, [r0, #0x08] */
  66. };
  67. /*
  68. * Copy the bootloader.
  69. * NOTE: PalmZ72 uses a different wakeup method!
  70. */
  71. memcpy(phys_to_virt(str_base), resume, sizeof(resume));
  72. }
  73. #endif
  74. /******************************************************************************
  75. * Framebuffer
  76. ******************************************************************************/
  77. #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
  78. struct pxafb_mode_info palm_320x480_lcd_mode = {
  79. .pixclock = 57692,
  80. .xres = 320,
  81. .yres = 480,
  82. .bpp = 16,
  83. .left_margin = 32,
  84. .right_margin = 1,
  85. .upper_margin = 7,
  86. .lower_margin = 1,
  87. .hsync_len = 4,
  88. .vsync_len = 1,
  89. };
  90. struct pxafb_mode_info palm_320x320_lcd_mode = {
  91. .pixclock = 115384,
  92. .xres = 320,
  93. .yres = 320,
  94. .bpp = 16,
  95. .left_margin = 27,
  96. .right_margin = 7,
  97. .upper_margin = 7,
  98. .lower_margin = 8,
  99. .hsync_len = 6,
  100. .vsync_len = 1,
  101. };
  102. struct pxafb_mode_info palm_320x320_new_lcd_mode = {
  103. .pixclock = 86538,
  104. .xres = 320,
  105. .yres = 320,
  106. .bpp = 16,
  107. .left_margin = 20,
  108. .right_margin = 8,
  109. .upper_margin = 8,
  110. .lower_margin = 5,
  111. .hsync_len = 4,
  112. .vsync_len = 1,
  113. };
  114. static struct pxafb_mach_info palm27x_lcd_screen = {
  115. .num_modes = 1,
  116. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  117. };
  118. static int palm27x_lcd_power;
  119. static void palm27x_lcd_ctl(int on, struct fb_var_screeninfo *info)
  120. {
  121. gpio_set_value(palm27x_lcd_power, on);
  122. }
  123. void __init palm27x_lcd_init(int power, struct pxafb_mode_info *mode)
  124. {
  125. palm27x_lcd_screen.modes = mode;
  126. if (gpio_is_valid(power)) {
  127. if (!gpio_request(power, "LCD power")) {
  128. pr_err("Palm27x: failed to claim lcd power gpio!\n");
  129. return;
  130. }
  131. if (!gpio_direction_output(power, 1)) {
  132. pr_err("Palm27x: lcd power configuration failed!\n");
  133. return;
  134. }
  135. palm27x_lcd_power = power;
  136. palm27x_lcd_screen.pxafb_lcd_power = palm27x_lcd_ctl;
  137. }
  138. set_pxa_fb_info(&palm27x_lcd_screen);
  139. }
  140. #endif
  141. /******************************************************************************
  142. * USB Gadget
  143. ******************************************************************************/
  144. #if defined(CONFIG_USB_GADGET_PXA27X) || \
  145. defined(CONFIG_USB_GADGET_PXA27X_MODULE)
  146. static struct gpio_vbus_mach_info palm27x_udc_info = {
  147. .gpio_vbus_inverted = 1,
  148. };
  149. static struct platform_device palm27x_gpio_vbus = {
  150. .name = "gpio-vbus",
  151. .id = -1,
  152. .dev = {
  153. .platform_data = &palm27x_udc_info,
  154. },
  155. };
  156. void __init palm27x_udc_init(int vbus, int pullup, int vbus_inverted)
  157. {
  158. palm27x_udc_info.gpio_vbus = vbus;
  159. palm27x_udc_info.gpio_pullup = pullup;
  160. palm27x_udc_info.gpio_vbus_inverted = vbus_inverted;
  161. if (!gpio_request(pullup, "USB Pullup")) {
  162. gpio_direction_output(pullup,
  163. palm27x_udc_info.gpio_vbus_inverted);
  164. gpio_free(pullup);
  165. } else
  166. return;
  167. platform_device_register(&palm27x_gpio_vbus);
  168. }
  169. #endif
  170. /******************************************************************************
  171. * IrDA
  172. ******************************************************************************/
  173. #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
  174. static struct pxaficp_platform_data palm27x_ficp_platform_data = {
  175. .transceiver_cap = IR_SIRMODE | IR_OFF,
  176. };
  177. void __init palm27x_irda_init(int pwdn)
  178. {
  179. palm27x_ficp_platform_data.gpio_pwdown = pwdn;
  180. pxa_set_ficp_info(&palm27x_ficp_platform_data);
  181. }
  182. #endif
  183. /******************************************************************************
  184. * WM97xx audio, battery
  185. ******************************************************************************/
  186. #if defined(CONFIG_TOUCHSCREEN_WM97XX) || \
  187. defined(CONFIG_TOUCHSCREEN_WM97XX_MODULE)
  188. static struct wm97xx_batt_pdata palm27x_batt_pdata = {
  189. .batt_aux = WM97XX_AUX_ID3,
  190. .temp_aux = WM97XX_AUX_ID2,
  191. .charge_gpio = -1,
  192. .batt_mult = 1000,
  193. .batt_div = 414,
  194. .temp_mult = 1,
  195. .temp_div = 1,
  196. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  197. .batt_name = "main-batt",
  198. };
  199. static struct wm97xx_pdata palm27x_wm97xx_pdata = {
  200. .batt_pdata = &palm27x_batt_pdata,
  201. };
  202. static pxa2xx_audio_ops_t palm27x_ac97_pdata = {
  203. .codec_pdata = { &palm27x_wm97xx_pdata, },
  204. };
  205. static struct palm27x_asoc_info palm27x_asoc_pdata = {
  206. .jack_gpio = -1,
  207. };
  208. static struct platform_device palm27x_asoc = {
  209. .name = "palm27x-asoc",
  210. .id = -1,
  211. .dev = {
  212. .platform_data = &palm27x_asoc_pdata,
  213. },
  214. };
  215. void __init palm27x_ac97_init(int minv, int maxv, int jack, int reset)
  216. {
  217. palm27x_ac97_pdata.reset_gpio = reset;
  218. palm27x_asoc_pdata.jack_gpio = jack;
  219. if (minv < 0 || maxv < 0) {
  220. palm27x_ac97_pdata.codec_pdata[0] = NULL;
  221. pxa_set_ac97_info(&palm27x_ac97_pdata);
  222. } else {
  223. palm27x_batt_pdata.min_voltage = minv,
  224. palm27x_batt_pdata.max_voltage = maxv,
  225. pxa_set_ac97_info(&palm27x_ac97_pdata);
  226. platform_device_register(&palm27x_asoc);
  227. }
  228. }
  229. #endif
  230. /******************************************************************************
  231. * Backlight
  232. ******************************************************************************/
  233. #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
  234. static int palm_bl_power;
  235. static int palm_lcd_power;
  236. static int palm27x_backlight_init(struct device *dev)
  237. {
  238. int ret;
  239. ret = gpio_request(palm_bl_power, "BL POWER");
  240. if (ret)
  241. goto err;
  242. ret = gpio_direction_output(palm_bl_power, 0);
  243. if (ret)
  244. goto err2;
  245. if (gpio_is_valid(palm_lcd_power)) {
  246. ret = gpio_request(palm_lcd_power, "LCD POWER");
  247. if (ret)
  248. goto err2;
  249. ret = gpio_direction_output(palm_lcd_power, 0);
  250. if (ret)
  251. goto err3;
  252. }
  253. return 0;
  254. err3:
  255. gpio_free(palm_lcd_power);
  256. err2:
  257. gpio_free(palm_bl_power);
  258. err:
  259. return ret;
  260. }
  261. static int palm27x_backlight_notify(struct device *dev, int brightness)
  262. {
  263. gpio_set_value(palm_bl_power, brightness);
  264. if (gpio_is_valid(palm_lcd_power))
  265. gpio_set_value(palm_lcd_power, brightness);
  266. return brightness;
  267. }
  268. static void palm27x_backlight_exit(struct device *dev)
  269. {
  270. gpio_free(palm_bl_power);
  271. if (gpio_is_valid(palm_lcd_power))
  272. gpio_free(palm_lcd_power);
  273. }
  274. static struct platform_pwm_backlight_data palm27x_backlight_data = {
  275. .pwm_id = 0,
  276. .max_brightness = 0xfe,
  277. .dft_brightness = 0x7e,
  278. .pwm_period_ns = 3500,
  279. .init = palm27x_backlight_init,
  280. .notify = palm27x_backlight_notify,
  281. .exit = palm27x_backlight_exit,
  282. };
  283. static struct platform_device palm27x_backlight = {
  284. .name = "pwm-backlight",
  285. .dev = {
  286. .parent = &pxa27x_device_pwm0.dev,
  287. .platform_data = &palm27x_backlight_data,
  288. },
  289. };
  290. void __init palm27x_pwm_init(int bl, int lcd)
  291. {
  292. palm_bl_power = bl;
  293. palm_lcd_power = lcd;
  294. platform_device_register(&palm27x_backlight);
  295. }
  296. #endif
  297. /******************************************************************************
  298. * Power supply
  299. ******************************************************************************/
  300. #if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
  301. static int palm_ac_state;
  302. static int palm_usb_state;
  303. static int palm27x_power_supply_init(struct device *dev)
  304. {
  305. int ret;
  306. ret = gpio_request(palm_ac_state, "AC state");
  307. if (ret)
  308. goto err1;
  309. ret = gpio_direction_input(palm_ac_state);
  310. if (ret)
  311. goto err2;
  312. if (gpio_is_valid(palm_usb_state)) {
  313. ret = gpio_request(palm_usb_state, "USB state");
  314. if (ret)
  315. goto err2;
  316. ret = gpio_direction_input(palm_usb_state);
  317. if (ret)
  318. goto err3;
  319. }
  320. return 0;
  321. err3:
  322. gpio_free(palm_usb_state);
  323. err2:
  324. gpio_free(palm_ac_state);
  325. err1:
  326. return ret;
  327. }
  328. static void palm27x_power_supply_exit(struct device *dev)
  329. {
  330. gpio_free(palm_usb_state);
  331. gpio_free(palm_ac_state);
  332. }
  333. static int palm27x_is_ac_online(void)
  334. {
  335. return gpio_get_value(palm_ac_state);
  336. }
  337. static int palm27x_is_usb_online(void)
  338. {
  339. return !gpio_get_value(palm_usb_state);
  340. }
  341. static char *palm27x_supplicants[] = {
  342. "main-battery",
  343. };
  344. static struct pda_power_pdata palm27x_ps_info = {
  345. .init = palm27x_power_supply_init,
  346. .exit = palm27x_power_supply_exit,
  347. .is_ac_online = palm27x_is_ac_online,
  348. .is_usb_online = palm27x_is_usb_online,
  349. .supplied_to = palm27x_supplicants,
  350. .num_supplicants = ARRAY_SIZE(palm27x_supplicants),
  351. };
  352. static struct platform_device palm27x_power_supply = {
  353. .name = "pda-power",
  354. .id = -1,
  355. .dev = {
  356. .platform_data = &palm27x_ps_info,
  357. },
  358. };
  359. void __init palm27x_power_init(int ac, int usb)
  360. {
  361. palm_ac_state = ac;
  362. palm_usb_state = usb;
  363. platform_device_register(&palm27x_power_supply);
  364. }
  365. #endif
  366. /******************************************************************************
  367. * Core power regulator
  368. ******************************************************************************/
  369. #if defined(CONFIG_REGULATOR_MAX1586) || \
  370. defined(CONFIG_REGULATOR_MAX1586_MODULE)
  371. static struct regulator_consumer_supply palm27x_max1587a_consumers[] = {
  372. {
  373. .supply = "vcc_core",
  374. }
  375. };
  376. static struct regulator_init_data palm27x_max1587a_v3_info = {
  377. .constraints = {
  378. .name = "vcc_core range",
  379. .min_uV = 900000,
  380. .max_uV = 1705000,
  381. .always_on = 1,
  382. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
  383. },
  384. .consumer_supplies = palm27x_max1587a_consumers,
  385. .num_consumer_supplies = ARRAY_SIZE(palm27x_max1587a_consumers),
  386. };
  387. static struct max1586_subdev_data palm27x_max1587a_subdevs[] = {
  388. {
  389. .name = "vcc_core",
  390. .id = MAX1586_V3,
  391. .platform_data = &palm27x_max1587a_v3_info,
  392. }
  393. };
  394. static struct max1586_platform_data palm27x_max1587a_info = {
  395. .subdevs = palm27x_max1587a_subdevs,
  396. .num_subdevs = ARRAY_SIZE(palm27x_max1587a_subdevs),
  397. .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
  398. };
  399. static struct i2c_board_info __initdata palm27x_pi2c_board_info[] = {
  400. {
  401. I2C_BOARD_INFO("max1586", 0x14),
  402. .platform_data = &palm27x_max1587a_info,
  403. },
  404. };
  405. static struct i2c_pxa_platform_data palm27x_i2c_power_info = {
  406. .use_pio = 1,
  407. };
  408. void __init palm27x_pmic_init(void)
  409. {
  410. i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info));
  411. pxa27x_set_i2c_power_info(&palm27x_i2c_power_info);
  412. }
  413. #endif