palm27x.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. /*
  2. * Common code for Palm LD, T5, TX, Z72
  3. *
  4. * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/delay.h>
  13. #include <linux/irq.h>
  14. #include <linux/gpio_keys.h>
  15. #include <linux/input.h>
  16. #include <linux/pda_power.h>
  17. #include <linux/pwm.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 <linux/platform_data/i2c-pxa.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/map.h>
  28. #include "pxa27x.h"
  29. #include <mach/audio.h>
  30. #include <linux/platform_data/mmc-pxamci.h>
  31. #include <linux/platform_data/video-pxafb.h>
  32. #include <linux/platform_data/irda-pxaficp.h>
  33. #include "udc.h"
  34. #include <linux/platform_data/asoc-palm27x.h>
  35. #include "palm27x.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. pxa_set_fb_info(NULL, &palm27x_lcd_screen);
  139. }
  140. #endif
  141. /******************************************************************************
  142. * USB Gadget
  143. ******************************************************************************/
  144. #if defined(CONFIG_USB_PXA27X) || \
  145. defined(CONFIG_USB_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 struct pwm_lookup palm27x_pwm_lookup[] = {
  235. PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight.0", NULL, 3500 * 1024,
  236. PWM_POLARITY_NORMAL),
  237. };
  238. static int palm_bl_power;
  239. static int palm_lcd_power;
  240. static int palm27x_backlight_init(struct device *dev)
  241. {
  242. int ret;
  243. ret = gpio_request(palm_bl_power, "BL POWER");
  244. if (ret)
  245. goto err;
  246. ret = gpio_direction_output(palm_bl_power, 0);
  247. if (ret)
  248. goto err2;
  249. if (gpio_is_valid(palm_lcd_power)) {
  250. ret = gpio_request(palm_lcd_power, "LCD POWER");
  251. if (ret)
  252. goto err2;
  253. ret = gpio_direction_output(palm_lcd_power, 0);
  254. if (ret)
  255. goto err3;
  256. }
  257. return 0;
  258. err3:
  259. gpio_free(palm_lcd_power);
  260. err2:
  261. gpio_free(palm_bl_power);
  262. err:
  263. return ret;
  264. }
  265. static int palm27x_backlight_notify(struct device *dev, int brightness)
  266. {
  267. gpio_set_value(palm_bl_power, brightness);
  268. if (gpio_is_valid(palm_lcd_power))
  269. gpio_set_value(palm_lcd_power, brightness);
  270. return brightness;
  271. }
  272. static void palm27x_backlight_exit(struct device *dev)
  273. {
  274. gpio_free(palm_bl_power);
  275. if (gpio_is_valid(palm_lcd_power))
  276. gpio_free(palm_lcd_power);
  277. }
  278. static struct platform_pwm_backlight_data palm27x_backlight_data = {
  279. .max_brightness = 0xfe,
  280. .dft_brightness = 0x7e,
  281. .enable_gpio = -1,
  282. .init = palm27x_backlight_init,
  283. .notify = palm27x_backlight_notify,
  284. .exit = palm27x_backlight_exit,
  285. };
  286. static struct platform_device palm27x_backlight = {
  287. .name = "pwm-backlight",
  288. .dev = {
  289. .parent = &pxa27x_device_pwm0.dev,
  290. .platform_data = &palm27x_backlight_data,
  291. },
  292. };
  293. void __init palm27x_pwm_init(int bl, int lcd)
  294. {
  295. palm_bl_power = bl;
  296. palm_lcd_power = lcd;
  297. pwm_add_table(palm27x_pwm_lookup, ARRAY_SIZE(palm27x_pwm_lookup));
  298. platform_device_register(&palm27x_backlight);
  299. }
  300. #endif
  301. /******************************************************************************
  302. * Power supply
  303. ******************************************************************************/
  304. #if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
  305. static int palm_ac_state;
  306. static int palm_usb_state;
  307. static int palm27x_power_supply_init(struct device *dev)
  308. {
  309. int ret;
  310. ret = gpio_request(palm_ac_state, "AC state");
  311. if (ret)
  312. goto err1;
  313. ret = gpio_direction_input(palm_ac_state);
  314. if (ret)
  315. goto err2;
  316. if (gpio_is_valid(palm_usb_state)) {
  317. ret = gpio_request(palm_usb_state, "USB state");
  318. if (ret)
  319. goto err2;
  320. ret = gpio_direction_input(palm_usb_state);
  321. if (ret)
  322. goto err3;
  323. }
  324. return 0;
  325. err3:
  326. gpio_free(palm_usb_state);
  327. err2:
  328. gpio_free(palm_ac_state);
  329. err1:
  330. return ret;
  331. }
  332. static void palm27x_power_supply_exit(struct device *dev)
  333. {
  334. gpio_free(palm_usb_state);
  335. gpio_free(palm_ac_state);
  336. }
  337. static int palm27x_is_ac_online(void)
  338. {
  339. return gpio_get_value(palm_ac_state);
  340. }
  341. static int palm27x_is_usb_online(void)
  342. {
  343. return !gpio_get_value(palm_usb_state);
  344. }
  345. static char *palm27x_supplicants[] = {
  346. "main-battery",
  347. };
  348. static struct pda_power_pdata palm27x_ps_info = {
  349. .init = palm27x_power_supply_init,
  350. .exit = palm27x_power_supply_exit,
  351. .is_ac_online = palm27x_is_ac_online,
  352. .is_usb_online = palm27x_is_usb_online,
  353. .supplied_to = palm27x_supplicants,
  354. .num_supplicants = ARRAY_SIZE(palm27x_supplicants),
  355. };
  356. static struct platform_device palm27x_power_supply = {
  357. .name = "pda-power",
  358. .id = -1,
  359. .dev = {
  360. .platform_data = &palm27x_ps_info,
  361. },
  362. };
  363. void __init palm27x_power_init(int ac, int usb)
  364. {
  365. palm_ac_state = ac;
  366. palm_usb_state = usb;
  367. platform_device_register(&palm27x_power_supply);
  368. }
  369. #endif
  370. /******************************************************************************
  371. * Core power regulator
  372. ******************************************************************************/
  373. #if defined(CONFIG_REGULATOR_MAX1586) || \
  374. defined(CONFIG_REGULATOR_MAX1586_MODULE)
  375. static struct regulator_consumer_supply palm27x_max1587a_consumers[] = {
  376. REGULATOR_SUPPLY("vcc_core", NULL),
  377. };
  378. static struct regulator_init_data palm27x_max1587a_v3_info = {
  379. .constraints = {
  380. .name = "vcc_core range",
  381. .min_uV = 900000,
  382. .max_uV = 1705000,
  383. .always_on = 1,
  384. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
  385. },
  386. .consumer_supplies = palm27x_max1587a_consumers,
  387. .num_consumer_supplies = ARRAY_SIZE(palm27x_max1587a_consumers),
  388. };
  389. static struct max1586_subdev_data palm27x_max1587a_subdevs[] = {
  390. {
  391. .name = "vcc_core",
  392. .id = MAX1586_V3,
  393. .platform_data = &palm27x_max1587a_v3_info,
  394. }
  395. };
  396. static struct max1586_platform_data palm27x_max1587a_info = {
  397. .subdevs = palm27x_max1587a_subdevs,
  398. .num_subdevs = ARRAY_SIZE(palm27x_max1587a_subdevs),
  399. .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
  400. };
  401. static struct i2c_board_info __initdata palm27x_pi2c_board_info[] = {
  402. {
  403. I2C_BOARD_INFO("max1586", 0x14),
  404. .platform_data = &palm27x_max1587a_info,
  405. },
  406. };
  407. static struct i2c_pxa_platform_data palm27x_i2c_power_info = {
  408. .use_pio = 1,
  409. };
  410. void __init palm27x_pmic_init(void)
  411. {
  412. i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info));
  413. pxa27x_set_i2c_power_info(&palm27x_i2c_power_info);
  414. }
  415. #endif