palm27x.c 12 KB

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