palmte2.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*
  2. * Hardware definitions for Palm Tungsten|E2
  3. *
  4. * Author:
  5. * Carlos Eduardo Medaglia Dyonisio <cadu@nerdfeliz.com>
  6. *
  7. * Rewrite for mainline:
  8. * Marek Vasut <marek.vasut@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * (find more info at www.hackndev.com)
  15. *
  16. */
  17. #include <linux/platform_device.h>
  18. #include <linux/delay.h>
  19. #include <linux/irq.h>
  20. #include <linux/gpio_keys.h>
  21. #include <linux/input.h>
  22. #include <linux/pda_power.h>
  23. #include <linux/pwm_backlight.h>
  24. #include <linux/gpio.h>
  25. #include <linux/wm97xx_batt.h>
  26. #include <linux/power_supply.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/map.h>
  30. #include <mach/audio.h>
  31. #include <mach/palmte2.h>
  32. #include <mach/mmc.h>
  33. #include <mach/pxafb.h>
  34. #include <mach/mfp-pxa25x.h>
  35. #include <mach/irda.h>
  36. #include <mach/udc.h>
  37. #include "generic.h"
  38. #include "devices.h"
  39. /******************************************************************************
  40. * Pin configuration
  41. ******************************************************************************/
  42. static unsigned long palmte2_pin_config[] __initdata = {
  43. /* MMC */
  44. GPIO6_MMC_CLK,
  45. GPIO8_MMC_CS0,
  46. GPIO10_GPIO, /* SD detect */
  47. GPIO55_GPIO, /* SD power */
  48. GPIO51_GPIO, /* SD r/o switch */
  49. /* AC97 */
  50. GPIO28_AC97_BITCLK,
  51. GPIO29_AC97_SDATA_IN_0,
  52. GPIO30_AC97_SDATA_OUT,
  53. GPIO31_AC97_SYNC,
  54. /* PWM */
  55. GPIO16_PWM0_OUT,
  56. /* USB */
  57. GPIO15_GPIO, /* usb detect */
  58. GPIO53_GPIO, /* usb power */
  59. /* IrDA */
  60. GPIO48_GPIO, /* ir disable */
  61. GPIO46_FICP_RXD,
  62. GPIO47_FICP_TXD,
  63. /* LCD */
  64. GPIO58_LCD_LDD_0,
  65. GPIO59_LCD_LDD_1,
  66. GPIO60_LCD_LDD_2,
  67. GPIO61_LCD_LDD_3,
  68. GPIO62_LCD_LDD_4,
  69. GPIO63_LCD_LDD_5,
  70. GPIO64_LCD_LDD_6,
  71. GPIO65_LCD_LDD_7,
  72. GPIO66_LCD_LDD_8,
  73. GPIO67_LCD_LDD_9,
  74. GPIO68_LCD_LDD_10,
  75. GPIO69_LCD_LDD_11,
  76. GPIO70_LCD_LDD_12,
  77. GPIO71_LCD_LDD_13,
  78. GPIO72_LCD_LDD_14,
  79. GPIO73_LCD_LDD_15,
  80. GPIO74_LCD_FCLK,
  81. GPIO75_LCD_LCLK,
  82. GPIO76_LCD_PCLK,
  83. GPIO77_LCD_BIAS,
  84. /* GPIO KEYS */
  85. GPIO5_GPIO, /* notes */
  86. GPIO7_GPIO, /* tasks */
  87. GPIO11_GPIO, /* calendar */
  88. GPIO13_GPIO, /* contacts */
  89. GPIO14_GPIO, /* center */
  90. GPIO19_GPIO, /* left */
  91. GPIO20_GPIO, /* right */
  92. GPIO21_GPIO, /* down */
  93. GPIO22_GPIO, /* up */
  94. /* MISC */
  95. GPIO1_RST, /* reset */
  96. GPIO4_GPIO, /* Hotsync button */
  97. GPIO9_GPIO, /* power detect */
  98. GPIO37_GPIO, /* LCD power */
  99. GPIO56_GPIO, /* Backlight power */
  100. };
  101. /******************************************************************************
  102. * SD/MMC card controller
  103. ******************************************************************************/
  104. static int palmte2_mci_init(struct device *dev,
  105. irq_handler_t palmte2_detect_int, void *data)
  106. {
  107. int err = 0;
  108. /* Setup an interrupt for detecting card insert/remove events */
  109. err = gpio_request(GPIO_NR_PALMTE2_SD_DETECT_N, "SD IRQ");
  110. if (err)
  111. goto err;
  112. err = gpio_direction_input(GPIO_NR_PALMTE2_SD_DETECT_N);
  113. if (err)
  114. goto err2;
  115. err = request_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N),
  116. palmte2_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  117. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  118. "SD/MMC card detect", data);
  119. if (err) {
  120. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  121. __func__);
  122. goto err2;
  123. }
  124. err = gpio_request(GPIO_NR_PALMTE2_SD_POWER, "SD_POWER");
  125. if (err)
  126. goto err3;
  127. err = gpio_direction_output(GPIO_NR_PALMTE2_SD_POWER, 0);
  128. if (err)
  129. goto err4;
  130. err = gpio_request(GPIO_NR_PALMTE2_SD_READONLY, "SD_READONLY");
  131. if (err)
  132. goto err4;
  133. err = gpio_direction_input(GPIO_NR_PALMTE2_SD_READONLY);
  134. if (err)
  135. goto err5;
  136. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  137. return 0;
  138. err5:
  139. gpio_free(GPIO_NR_PALMTE2_SD_READONLY);
  140. err4:
  141. gpio_free(GPIO_NR_PALMTE2_SD_POWER);
  142. err3:
  143. free_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N), data);
  144. err2:
  145. gpio_free(GPIO_NR_PALMTE2_SD_DETECT_N);
  146. err:
  147. return err;
  148. }
  149. static void palmte2_mci_exit(struct device *dev, void *data)
  150. {
  151. gpio_free(GPIO_NR_PALMTE2_SD_READONLY);
  152. gpio_free(GPIO_NR_PALMTE2_SD_POWER);
  153. free_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N), data);
  154. gpio_free(GPIO_NR_PALMTE2_SD_DETECT_N);
  155. }
  156. static void palmte2_mci_power(struct device *dev, unsigned int vdd)
  157. {
  158. struct pxamci_platform_data *p_d = dev->platform_data;
  159. gpio_set_value(GPIO_NR_PALMTE2_SD_POWER, p_d->ocr_mask & (1 << vdd));
  160. }
  161. static int palmte2_mci_get_ro(struct device *dev)
  162. {
  163. return gpio_get_value(GPIO_NR_PALMTE2_SD_READONLY);
  164. }
  165. static struct pxamci_platform_data palmte2_mci_platform_data = {
  166. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  167. .setpower = palmte2_mci_power,
  168. .get_ro = palmte2_mci_get_ro,
  169. .init = palmte2_mci_init,
  170. .exit = palmte2_mci_exit,
  171. };
  172. /******************************************************************************
  173. * GPIO keys
  174. ******************************************************************************/
  175. static struct gpio_keys_button palmte2_pxa_buttons[] = {
  176. {KEY_F1, GPIO_NR_PALMTE2_KEY_CONTACTS, 1, "Contacts" },
  177. {KEY_F2, GPIO_NR_PALMTE2_KEY_CALENDAR, 1, "Calendar" },
  178. {KEY_F3, GPIO_NR_PALMTE2_KEY_TASKS, 1, "Tasks" },
  179. {KEY_F4, GPIO_NR_PALMTE2_KEY_NOTES, 1, "Notes" },
  180. {KEY_ENTER, GPIO_NR_PALMTE2_KEY_CENTER, 1, "Center" },
  181. {KEY_LEFT, GPIO_NR_PALMTE2_KEY_LEFT, 1, "Left" },
  182. {KEY_RIGHT, GPIO_NR_PALMTE2_KEY_RIGHT, 1, "Right" },
  183. {KEY_DOWN, GPIO_NR_PALMTE2_KEY_DOWN, 1, "Down" },
  184. {KEY_UP, GPIO_NR_PALMTE2_KEY_UP, 1, "Up" },
  185. };
  186. static struct gpio_keys_platform_data palmte2_pxa_keys_data = {
  187. .buttons = palmte2_pxa_buttons,
  188. .nbuttons = ARRAY_SIZE(palmte2_pxa_buttons),
  189. };
  190. static struct platform_device palmte2_pxa_keys = {
  191. .name = "gpio-keys",
  192. .id = -1,
  193. .dev = {
  194. .platform_data = &palmte2_pxa_keys_data,
  195. },
  196. };
  197. /******************************************************************************
  198. * Backlight
  199. ******************************************************************************/
  200. static int palmte2_backlight_init(struct device *dev)
  201. {
  202. int ret;
  203. ret = gpio_request(GPIO_NR_PALMTE2_BL_POWER, "BL POWER");
  204. if (ret)
  205. goto err;
  206. ret = gpio_direction_output(GPIO_NR_PALMTE2_BL_POWER, 0);
  207. if (ret)
  208. goto err2;
  209. ret = gpio_request(GPIO_NR_PALMTE2_LCD_POWER, "LCD POWER");
  210. if (ret)
  211. goto err2;
  212. ret = gpio_direction_output(GPIO_NR_PALMTE2_LCD_POWER, 0);
  213. if (ret)
  214. goto err3;
  215. return 0;
  216. err3:
  217. gpio_free(GPIO_NR_PALMTE2_LCD_POWER);
  218. err2:
  219. gpio_free(GPIO_NR_PALMTE2_BL_POWER);
  220. err:
  221. return ret;
  222. }
  223. static int palmte2_backlight_notify(int brightness)
  224. {
  225. gpio_set_value(GPIO_NR_PALMTE2_BL_POWER, brightness);
  226. gpio_set_value(GPIO_NR_PALMTE2_LCD_POWER, brightness);
  227. return brightness;
  228. }
  229. static void palmte2_backlight_exit(struct device *dev)
  230. {
  231. gpio_free(GPIO_NR_PALMTE2_BL_POWER);
  232. gpio_free(GPIO_NR_PALMTE2_LCD_POWER);
  233. }
  234. static struct platform_pwm_backlight_data palmte2_backlight_data = {
  235. .pwm_id = 0,
  236. .max_brightness = PALMTE2_MAX_INTENSITY,
  237. .dft_brightness = PALMTE2_MAX_INTENSITY,
  238. .pwm_period_ns = PALMTE2_PERIOD_NS,
  239. .init = palmte2_backlight_init,
  240. .notify = palmte2_backlight_notify,
  241. .exit = palmte2_backlight_exit,
  242. };
  243. static struct platform_device palmte2_backlight = {
  244. .name = "pwm-backlight",
  245. .dev = {
  246. .parent = &pxa25x_device_pwm0.dev,
  247. .platform_data = &palmte2_backlight_data,
  248. },
  249. };
  250. /******************************************************************************
  251. * IrDA
  252. ******************************************************************************/
  253. static int palmte2_irda_startup(struct device *dev)
  254. {
  255. int err;
  256. err = gpio_request(GPIO_NR_PALMTE2_IR_DISABLE, "IR DISABLE");
  257. if (err)
  258. goto err;
  259. err = gpio_direction_output(GPIO_NR_PALMTE2_IR_DISABLE, 1);
  260. if (err)
  261. gpio_free(GPIO_NR_PALMTE2_IR_DISABLE);
  262. err:
  263. return err;
  264. }
  265. static void palmte2_irda_shutdown(struct device *dev)
  266. {
  267. gpio_free(GPIO_NR_PALMTE2_IR_DISABLE);
  268. }
  269. static void palmte2_irda_transceiver_mode(struct device *dev, int mode)
  270. {
  271. gpio_set_value(GPIO_NR_PALMTE2_IR_DISABLE, mode & IR_OFF);
  272. pxa2xx_transceiver_mode(dev, mode);
  273. }
  274. static struct pxaficp_platform_data palmte2_ficp_platform_data = {
  275. .startup = palmte2_irda_startup,
  276. .shutdown = palmte2_irda_shutdown,
  277. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  278. .transceiver_mode = palmte2_irda_transceiver_mode,
  279. };
  280. /******************************************************************************
  281. * UDC
  282. ******************************************************************************/
  283. static struct pxa2xx_udc_mach_info palmte2_udc_info __initdata = {
  284. .gpio_vbus = GPIO_NR_PALMTE2_USB_DETECT_N,
  285. .gpio_vbus_inverted = 1,
  286. .gpio_pullup = GPIO_NR_PALMTE2_USB_PULLUP,
  287. .gpio_pullup_inverted = 0,
  288. };
  289. /******************************************************************************
  290. * Power supply
  291. ******************************************************************************/
  292. static int power_supply_init(struct device *dev)
  293. {
  294. int ret;
  295. ret = gpio_request(GPIO_NR_PALMTE2_POWER_DETECT, "CABLE_STATE_AC");
  296. if (ret)
  297. goto err1;
  298. ret = gpio_direction_input(GPIO_NR_PALMTE2_POWER_DETECT);
  299. if (ret)
  300. goto err2;
  301. return 0;
  302. err2:
  303. gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
  304. err1:
  305. return ret;
  306. }
  307. static int palmte2_is_ac_online(void)
  308. {
  309. return gpio_get_value(GPIO_NR_PALMTE2_POWER_DETECT);
  310. }
  311. static void power_supply_exit(struct device *dev)
  312. {
  313. gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
  314. }
  315. static char *palmte2_supplicants[] = {
  316. "main-battery",
  317. };
  318. static struct pda_power_pdata power_supply_info = {
  319. .init = power_supply_init,
  320. .is_ac_online = palmte2_is_ac_online,
  321. .exit = power_supply_exit,
  322. .supplied_to = palmte2_supplicants,
  323. .num_supplicants = ARRAY_SIZE(palmte2_supplicants),
  324. };
  325. static struct platform_device power_supply = {
  326. .name = "pda-power",
  327. .id = -1,
  328. .dev = {
  329. .platform_data = &power_supply_info,
  330. },
  331. };
  332. /******************************************************************************
  333. * WM97xx battery
  334. ******************************************************************************/
  335. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  336. .batt_aux = WM97XX_AUX_ID3,
  337. .temp_aux = WM97XX_AUX_ID2,
  338. .charge_gpio = -1,
  339. .max_voltage = PALMTE2_BAT_MAX_VOLTAGE,
  340. .min_voltage = PALMTE2_BAT_MIN_VOLTAGE,
  341. .batt_mult = 1000,
  342. .batt_div = 414,
  343. .temp_mult = 1,
  344. .temp_div = 1,
  345. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  346. .batt_name = "main-batt",
  347. };
  348. /******************************************************************************
  349. * Framebuffer
  350. ******************************************************************************/
  351. static struct pxafb_mode_info palmte2_lcd_modes[] = {
  352. {
  353. .pixclock = 77757,
  354. .xres = 320,
  355. .yres = 320,
  356. .bpp = 16,
  357. .left_margin = 28,
  358. .right_margin = 7,
  359. .upper_margin = 7,
  360. .lower_margin = 5,
  361. .hsync_len = 4,
  362. .vsync_len = 1,
  363. },
  364. };
  365. static struct pxafb_mach_info palmte2_lcd_screen = {
  366. .modes = palmte2_lcd_modes,
  367. .num_modes = ARRAY_SIZE(palmte2_lcd_modes),
  368. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  369. };
  370. /******************************************************************************
  371. * Machine init
  372. ******************************************************************************/
  373. static struct platform_device *devices[] __initdata = {
  374. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  375. &palmte2_pxa_keys,
  376. #endif
  377. &palmte2_backlight,
  378. &power_supply,
  379. };
  380. /* setup udc GPIOs initial state */
  381. static void __init palmte2_udc_init(void)
  382. {
  383. if (!gpio_request(GPIO_NR_PALMTE2_USB_PULLUP, "UDC Vbus")) {
  384. gpio_direction_output(GPIO_NR_PALMTE2_USB_PULLUP, 1);
  385. gpio_free(GPIO_NR_PALMTE2_USB_PULLUP);
  386. }
  387. }
  388. static void __init palmte2_init(void)
  389. {
  390. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmte2_pin_config));
  391. set_pxa_fb_info(&palmte2_lcd_screen);
  392. pxa_set_mci_info(&palmte2_mci_platform_data);
  393. palmte2_udc_init();
  394. pxa_set_udc_info(&palmte2_udc_info);
  395. pxa_set_ac97_info(NULL);
  396. pxa_set_ficp_info(&palmte2_ficp_platform_data);
  397. wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
  398. platform_add_devices(devices, ARRAY_SIZE(devices));
  399. }
  400. MACHINE_START(PALMTE2, "Palm Tungsten|E2")
  401. .phys_io = 0x40000000,
  402. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  403. .boot_params = 0xa0000100,
  404. .map_io = pxa_map_io,
  405. .init_irq = pxa25x_init_irq,
  406. .timer = &pxa_timer,
  407. .init_machine = palmte2_init
  408. MACHINE_END