palmtx.c 10 KB

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