palmte2.c 13 KB

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