palmtx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /*
  2. * Hardware definitions for PalmTX
  3. *
  4. * Author: Marek Vasut <marek.vasut@gmail.com>
  5. *
  6. * Based on work of:
  7. * Alex Osborne <ato@meshy.org>
  8. * Cristiano P. <cristianop@users.sourceforge.net>
  9. * Jan Herman <2hp@seznam.cz>
  10. * Michal Hrusecky
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * (find more info at www.hackndev.com)
  17. *
  18. */
  19. #include <linux/platform_device.h>
  20. #include <linux/delay.h>
  21. #include <linux/irq.h>
  22. #include <linux/gpio_keys.h>
  23. #include <linux/input.h>
  24. #include <linux/pda_power.h>
  25. #include <linux/pwm_backlight.h>
  26. #include <linux/gpio.h>
  27. #include <linux/wm97xx_batt.h>
  28. #include <linux/power_supply.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/map.h>
  32. #include <mach/audio.h>
  33. #include <mach/palmtx.h>
  34. #include <mach/mmc.h>
  35. #include <mach/pxafb.h>
  36. #include <mach/pxa-regs.h>
  37. #include <mach/mfp-pxa27x.h>
  38. #include <mach/irda.h>
  39. #include <mach/pxa27x_keypad.h>
  40. #include <mach/udc.h>
  41. #include "generic.h"
  42. #include "devices.h"
  43. /******************************************************************************
  44. * Pin configuration
  45. ******************************************************************************/
  46. static unsigned long palmtx_pin_config[] __initdata = {
  47. /* MMC */
  48. GPIO32_MMC_CLK,
  49. GPIO92_MMC_DAT_0,
  50. GPIO109_MMC_DAT_1,
  51. GPIO110_MMC_DAT_2,
  52. GPIO111_MMC_DAT_3,
  53. GPIO112_MMC_CMD,
  54. /* AC97 */
  55. GPIO28_AC97_BITCLK,
  56. GPIO29_AC97_SDATA_IN_0,
  57. GPIO30_AC97_SDATA_OUT,
  58. GPIO31_AC97_SYNC,
  59. /* IrDA */
  60. GPIO46_FICP_RXD,
  61. GPIO47_FICP_TXD,
  62. /* PWM */
  63. GPIO16_PWM0_OUT,
  64. /* USB */
  65. GPIO13_GPIO,
  66. /* PCMCIA */
  67. GPIO48_nPOE,
  68. GPIO49_nPWE,
  69. GPIO50_nPIOR,
  70. GPIO51_nPIOW,
  71. GPIO85_nPCE_1,
  72. GPIO54_nPCE_2,
  73. GPIO79_PSKTSEL,
  74. GPIO55_nPREG,
  75. GPIO56_nPWAIT,
  76. GPIO57_nIOIS16,
  77. };
  78. /******************************************************************************
  79. * SD/MMC card controller
  80. ******************************************************************************/
  81. static int palmtx_mci_init(struct device *dev, irq_handler_t palmtx_detect_int,
  82. void *data)
  83. {
  84. int err = 0;
  85. /* Setup an interrupt for detecting card insert/remove events */
  86. err = request_irq(IRQ_GPIO_PALMTX_SD_DETECT_N, palmtx_detect_int,
  87. IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
  88. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  89. "SD/MMC card detect", data);
  90. if (err) {
  91. printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
  92. __func__);
  93. return err;
  94. }
  95. err = gpio_request(GPIO_NR_PALMTX_SD_POWER, "SD_POWER");
  96. if (err)
  97. goto pwr_err;
  98. err = gpio_request(GPIO_NR_PALMTX_SD_READONLY, "SD_READONLY");
  99. if (err)
  100. goto ro_err;
  101. printk(KERN_DEBUG "%s: irq registered\n", __func__);
  102. return 0;
  103. ro_err:
  104. gpio_free(GPIO_NR_PALMTX_SD_POWER);
  105. pwr_err:
  106. free_irq(IRQ_GPIO_PALMTX_SD_DETECT_N, data);
  107. return err;
  108. }
  109. static void palmtx_mci_exit(struct device *dev, void *data)
  110. {
  111. gpio_free(GPIO_NR_PALMTX_SD_READONLY);
  112. gpio_free(GPIO_NR_PALMTX_SD_POWER);
  113. free_irq(IRQ_GPIO_PALMTX_SD_DETECT_N, data);
  114. }
  115. static void palmtx_mci_power(struct device *dev, unsigned int vdd)
  116. {
  117. struct pxamci_platform_data *p_d = dev->platform_data;
  118. gpio_set_value(GPIO_NR_PALMTX_SD_POWER, p_d->ocr_mask & (1 << vdd));
  119. }
  120. static int palmtx_mci_get_ro(struct device *dev)
  121. {
  122. return gpio_get_value(GPIO_NR_PALMTX_SD_READONLY);
  123. }
  124. static struct pxamci_platform_data palmtx_mci_platform_data = {
  125. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  126. .setpower = palmtx_mci_power,
  127. .get_ro = palmtx_mci_get_ro,
  128. .init = palmtx_mci_init,
  129. .exit = palmtx_mci_exit,
  130. };
  131. /******************************************************************************
  132. * GPIO keyboard
  133. ******************************************************************************/
  134. static unsigned int palmtx_matrix_keys[] = {
  135. KEY(0, 0, KEY_POWER),
  136. KEY(0, 1, KEY_F1),
  137. KEY(0, 2, KEY_ENTER),
  138. KEY(1, 0, KEY_F2),
  139. KEY(1, 1, KEY_F3),
  140. KEY(1, 2, KEY_F4),
  141. KEY(2, 0, KEY_UP),
  142. KEY(2, 2, KEY_DOWN),
  143. KEY(3, 0, KEY_RIGHT),
  144. KEY(3, 2, KEY_LEFT),
  145. };
  146. static struct pxa27x_keypad_platform_data palmtx_keypad_platform_data = {
  147. .matrix_key_rows = 4,
  148. .matrix_key_cols = 3,
  149. .matrix_key_map = palmtx_matrix_keys,
  150. .matrix_key_map_size = ARRAY_SIZE(palmtx_matrix_keys),
  151. .debounce_interval = 30,
  152. };
  153. /******************************************************************************
  154. * GPIO keys
  155. ******************************************************************************/
  156. static struct gpio_keys_button palmtx_pxa_buttons[] = {
  157. {KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
  158. };
  159. static struct gpio_keys_platform_data palmtx_pxa_keys_data = {
  160. .buttons = palmtx_pxa_buttons,
  161. .nbuttons = ARRAY_SIZE(palmtx_pxa_buttons),
  162. };
  163. static struct platform_device palmtx_pxa_keys = {
  164. .name = "gpio-keys",
  165. .id = -1,
  166. .dev = {
  167. .platform_data = &palmtx_pxa_keys_data,
  168. },
  169. };
  170. /******************************************************************************
  171. * Backlight
  172. ******************************************************************************/
  173. static int palmtx_backlight_init(struct device *dev)
  174. {
  175. int ret;
  176. ret = gpio_request(GPIO_NR_PALMTX_BL_POWER, "BL POWER");
  177. if (ret)
  178. goto err;
  179. ret = gpio_request(GPIO_NR_PALMTX_LCD_POWER, "LCD POWER");
  180. if (ret)
  181. goto err2;
  182. return 0;
  183. err2:
  184. gpio_free(GPIO_NR_PALMTX_BL_POWER);
  185. err:
  186. return ret;
  187. }
  188. static int palmtx_backlight_notify(int brightness)
  189. {
  190. gpio_set_value(GPIO_NR_PALMTX_BL_POWER, brightness);
  191. gpio_set_value(GPIO_NR_PALMTX_LCD_POWER, brightness);
  192. return brightness;
  193. }
  194. static void palmtx_backlight_exit(struct device *dev)
  195. {
  196. gpio_free(GPIO_NR_PALMTX_BL_POWER);
  197. gpio_free(GPIO_NR_PALMTX_LCD_POWER);
  198. }
  199. static struct platform_pwm_backlight_data palmtx_backlight_data = {
  200. .pwm_id = 0,
  201. .max_brightness = PALMTX_MAX_INTENSITY,
  202. .dft_brightness = PALMTX_MAX_INTENSITY,
  203. .pwm_period_ns = PALMTX_PERIOD_NS,
  204. .init = palmtx_backlight_init,
  205. .notify = palmtx_backlight_notify,
  206. .exit = palmtx_backlight_exit,
  207. };
  208. static struct platform_device palmtx_backlight = {
  209. .name = "pwm-backlight",
  210. .dev = {
  211. .parent = &pxa27x_device_pwm0.dev,
  212. .platform_data = &palmtx_backlight_data,
  213. },
  214. };
  215. /******************************************************************************
  216. * IrDA
  217. ******************************************************************************/
  218. static void palmtx_irda_transceiver_mode(struct device *dev, int mode)
  219. {
  220. gpio_set_value(GPIO_NR_PALMTX_IR_DISABLE, mode & IR_OFF);
  221. pxa2xx_transceiver_mode(dev, mode);
  222. }
  223. static struct pxaficp_platform_data palmtx_ficp_platform_data = {
  224. .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
  225. .transceiver_mode = palmtx_irda_transceiver_mode,
  226. };
  227. /******************************************************************************
  228. * UDC
  229. ******************************************************************************/
  230. static void palmtx_udc_command(int cmd)
  231. {
  232. gpio_set_value(GPIO_NR_PALMTX_USB_POWER, !cmd);
  233. udelay(50);
  234. gpio_set_value(GPIO_NR_PALMTX_USB_PULLUP, !cmd);
  235. }
  236. static struct pxa2xx_udc_mach_info palmtx_udc_info __initdata = {
  237. .gpio_vbus = GPIO_NR_PALMTX_USB_DETECT_N,
  238. .gpio_vbus_inverted = 1,
  239. .udc_command = palmtx_udc_command,
  240. };
  241. /******************************************************************************
  242. * Power supply
  243. ******************************************************************************/
  244. static int power_supply_init(struct device *dev)
  245. {
  246. int ret;
  247. ret = gpio_request(GPIO_NR_PALMTX_POWER_DETECT, "CABLE_STATE_AC");
  248. if (ret)
  249. goto err_cs_ac;
  250. ret = gpio_request(GPIO_NR_PALMTX_USB_DETECT_N, "CABLE_STATE_USB");
  251. if (ret)
  252. goto err_cs_usb;
  253. return 0;
  254. err_cs_usb:
  255. gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
  256. err_cs_ac:
  257. return ret;
  258. }
  259. static int palmtx_is_ac_online(void)
  260. {
  261. return gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT);
  262. }
  263. static int palmtx_is_usb_online(void)
  264. {
  265. return !gpio_get_value(GPIO_NR_PALMTX_USB_DETECT_N);
  266. }
  267. static void power_supply_exit(struct device *dev)
  268. {
  269. gpio_free(GPIO_NR_PALMTX_USB_DETECT_N);
  270. gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
  271. }
  272. static char *palmtx_supplicants[] = {
  273. "main-battery",
  274. };
  275. static struct pda_power_pdata power_supply_info = {
  276. .init = power_supply_init,
  277. .is_ac_online = palmtx_is_ac_online,
  278. .is_usb_online = palmtx_is_usb_online,
  279. .exit = power_supply_exit,
  280. .supplied_to = palmtx_supplicants,
  281. .num_supplicants = ARRAY_SIZE(palmtx_supplicants),
  282. };
  283. static struct platform_device power_supply = {
  284. .name = "pda-power",
  285. .id = -1,
  286. .dev = {
  287. .platform_data = &power_supply_info,
  288. },
  289. };
  290. /******************************************************************************
  291. * WM97xx battery
  292. ******************************************************************************/
  293. static struct wm97xx_batt_info wm97xx_batt_pdata = {
  294. .batt_aux = WM97XX_AUX_ID3,
  295. .temp_aux = WM97XX_AUX_ID2,
  296. .charge_gpio = -1,
  297. .max_voltage = PALMTX_BAT_MAX_VOLTAGE,
  298. .min_voltage = PALMTX_BAT_MIN_VOLTAGE,
  299. .batt_mult = 1000,
  300. .batt_div = 414,
  301. .temp_mult = 1,
  302. .temp_div = 1,
  303. .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
  304. .batt_name = "main-batt",
  305. };
  306. /******************************************************************************
  307. * Framebuffer
  308. ******************************************************************************/
  309. static struct pxafb_mode_info palmtx_lcd_modes[] = {
  310. {
  311. .pixclock = 57692,
  312. .xres = 320,
  313. .yres = 480,
  314. .bpp = 16,
  315. .left_margin = 32,
  316. .right_margin = 1,
  317. .upper_margin = 7,
  318. .lower_margin = 1,
  319. .hsync_len = 4,
  320. .vsync_len = 1,
  321. },
  322. };
  323. static struct pxafb_mach_info palmtx_lcd_screen = {
  324. .modes = palmtx_lcd_modes,
  325. .num_modes = ARRAY_SIZE(palmtx_lcd_modes),
  326. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  327. };
  328. /******************************************************************************
  329. * Machine init
  330. ******************************************************************************/
  331. static struct platform_device *devices[] __initdata = {
  332. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  333. &palmtx_pxa_keys,
  334. #endif
  335. &palmtx_backlight,
  336. &power_supply,
  337. };
  338. static struct map_desc palmtx_io_desc[] __initdata = {
  339. {
  340. .virtual = PALMTX_PCMCIA_VIRT,
  341. .pfn = __phys_to_pfn(PALMTX_PCMCIA_PHYS),
  342. .length = PALMTX_PCMCIA_SIZE,
  343. .type = MT_DEVICE
  344. },
  345. };
  346. static void __init palmtx_map_io(void)
  347. {
  348. pxa_map_io();
  349. iotable_init(palmtx_io_desc, ARRAY_SIZE(palmtx_io_desc));
  350. }
  351. static void __init palmtx_init(void)
  352. {
  353. pxa2xx_mfp_config(ARRAY_AND_SIZE(palmtx_pin_config));
  354. set_pxa_fb_info(&palmtx_lcd_screen);
  355. pxa_set_mci_info(&palmtx_mci_platform_data);
  356. pxa_set_udc_info(&palmtx_udc_info);
  357. pxa_set_ac97_info(NULL);
  358. pxa_set_ficp_info(&palmtx_ficp_platform_data);
  359. pxa_set_keypad_info(&palmtx_keypad_platform_data);
  360. wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
  361. platform_add_devices(devices, ARRAY_SIZE(devices));
  362. }
  363. MACHINE_START(PALMTX, "Palm T|X")
  364. .phys_io = PALMTX_PHYS_IO_START,
  365. .io_pg_offst = io_p2v(0x40000000),
  366. .boot_params = 0xa0000100,
  367. .map_io = palmtx_map_io,
  368. .init_irq = pxa27x_init_irq,
  369. .timer = &pxa_timer,
  370. .init_machine = palmtx_init
  371. MACHINE_END