h3xxx.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * Support for Compaq iPAQ H3100 and H3600 handheld computers (common code)
  3. *
  4. * Copyright (c) 2000,1 Compaq Computer Corporation. (Author: Jamey Hicks)
  5. * Copyright (c) 2009 Dmitry Artamonow <mad_soft@inbox.ru>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/gpio.h>
  14. #include <linux/gpio_keys.h>
  15. #include <linux/input.h>
  16. #include <linux/mfd/htc-egpio.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/partitions.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/serial_core.h>
  21. #include <asm/mach/flash.h>
  22. #include <asm/mach/map.h>
  23. #include <asm/mach/serial_sa1100.h>
  24. #include <mach/h3xxx.h>
  25. #include "generic.h"
  26. void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
  27. {
  28. while (n--) {
  29. const char *name = s->name;
  30. int err;
  31. if (!name)
  32. name = "[init]";
  33. err = gpio_request(s->gpio, name);
  34. if (err) {
  35. printk(KERN_ERR "gpio%u: unable to request: %d\n",
  36. s->gpio, err);
  37. continue;
  38. }
  39. if (s->mode >= 0) {
  40. err = gpio_direction_output(s->gpio, s->mode);
  41. } else {
  42. err = gpio_direction_input(s->gpio);
  43. }
  44. if (err) {
  45. printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
  46. s->gpio, err);
  47. continue;
  48. }
  49. if (!s->name)
  50. gpio_free(s->gpio);
  51. s++;
  52. }
  53. }
  54. /*
  55. * H3xxx flash support
  56. */
  57. static struct mtd_partition h3xxx_partitions[] = {
  58. {
  59. .name = "H3XXX boot firmware",
  60. .size = 0x00040000,
  61. .offset = 0,
  62. .mask_flags = MTD_WRITEABLE, /* force read-only */
  63. }, {
  64. .name = "H3XXX rootfs",
  65. .size = MTDPART_SIZ_FULL,
  66. .offset = 0x00040000,
  67. }
  68. };
  69. static void h3xxx_set_vpp(int vpp)
  70. {
  71. gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
  72. }
  73. static int h3xxx_flash_init(void)
  74. {
  75. int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
  76. if (err) {
  77. pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__);
  78. return err;
  79. }
  80. err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
  81. if (err)
  82. gpio_free(H3XXX_EGPIO_VPP_ON);
  83. return err;
  84. }
  85. static void h3xxx_flash_exit(void)
  86. {
  87. gpio_free(H3XXX_EGPIO_VPP_ON);
  88. }
  89. static struct flash_platform_data h3xxx_flash_data = {
  90. .map_name = "cfi_probe",
  91. .set_vpp = h3xxx_set_vpp,
  92. .init = h3xxx_flash_init,
  93. .exit = h3xxx_flash_exit,
  94. .parts = h3xxx_partitions,
  95. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  96. };
  97. static struct resource h3xxx_flash_resource = {
  98. .start = SA1100_CS0_PHYS,
  99. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  100. .flags = IORESOURCE_MEM,
  101. };
  102. /*
  103. * H3xxx uart support
  104. */
  105. static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  106. {
  107. if (port->mapbase == _Ser3UTCR0) {
  108. gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
  109. }
  110. }
  111. static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
  112. {
  113. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  114. if (port->mapbase == _Ser3UTCR0) {
  115. /*
  116. * DCD and CTS bits are inverted in GPLR by RS232 transceiver
  117. */
  118. if (gpio_get_value(H3XXX_GPIO_COM_DCD))
  119. ret &= ~TIOCM_CD;
  120. if (gpio_get_value(H3XXX_GPIO_COM_CTS))
  121. ret &= ~TIOCM_CTS;
  122. }
  123. return ret;
  124. }
  125. static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  126. {
  127. if (port->mapbase == _Ser3UTCR0) {
  128. if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
  129. gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
  130. gpio_free(H3XXX_EGPIO_RS232_ON);
  131. } else {
  132. pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
  133. __func__);
  134. }
  135. }
  136. }
  137. /*
  138. * Enable/Disable wake up events for this serial port.
  139. * Obviously, we only support this on the normal COM port.
  140. */
  141. static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
  142. {
  143. int err = -EINVAL;
  144. if (port->mapbase == _Ser3UTCR0) {
  145. if (enable)
  146. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  147. else
  148. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  149. err = 0;
  150. }
  151. return err;
  152. }
  153. static struct sa1100_port_fns h3xxx_port_fns __initdata = {
  154. .set_mctrl = h3xxx_uart_set_mctrl,
  155. .get_mctrl = h3xxx_uart_get_mctrl,
  156. .pm = h3xxx_uart_pm,
  157. .set_wake = h3xxx_uart_set_wake,
  158. };
  159. /*
  160. * EGPIO
  161. */
  162. static struct resource egpio_resources[] = {
  163. [0] = {
  164. .start = H3600_EGPIO_PHYS,
  165. .end = H3600_EGPIO_PHYS + 0x4 - 1,
  166. .flags = IORESOURCE_MEM,
  167. },
  168. };
  169. static struct htc_egpio_chip egpio_chips[] = {
  170. [0] = {
  171. .reg_start = 0,
  172. .gpio_base = H3XXX_EGPIO_BASE,
  173. .num_gpios = 16,
  174. .direction = HTC_EGPIO_OUTPUT,
  175. .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
  176. },
  177. };
  178. static struct htc_egpio_platform_data egpio_info = {
  179. .reg_width = 16,
  180. .bus_width = 16,
  181. .chip = egpio_chips,
  182. .num_chips = ARRAY_SIZE(egpio_chips),
  183. };
  184. static struct platform_device h3xxx_egpio = {
  185. .name = "htc-egpio",
  186. .id = -1,
  187. .resource = egpio_resources,
  188. .num_resources = ARRAY_SIZE(egpio_resources),
  189. .dev = {
  190. .platform_data = &egpio_info,
  191. },
  192. };
  193. /*
  194. * GPIO keys
  195. */
  196. static struct gpio_keys_button h3xxx_button_table[] = {
  197. {
  198. .code = KEY_POWER,
  199. .gpio = H3XXX_GPIO_PWR_BUTTON,
  200. .desc = "Power Button",
  201. .active_low = 1,
  202. .type = EV_KEY,
  203. .wakeup = 1,
  204. }, {
  205. .code = KEY_ENTER,
  206. .gpio = H3XXX_GPIO_ACTION_BUTTON,
  207. .active_low = 1,
  208. .desc = "Action button",
  209. .type = EV_KEY,
  210. .wakeup = 0,
  211. },
  212. };
  213. static struct gpio_keys_platform_data h3xxx_keys_data = {
  214. .buttons = h3xxx_button_table,
  215. .nbuttons = ARRAY_SIZE(h3xxx_button_table),
  216. };
  217. static struct platform_device h3xxx_keys = {
  218. .name = "gpio-keys",
  219. .id = -1,
  220. .dev = {
  221. .platform_data = &h3xxx_keys_data,
  222. },
  223. };
  224. static struct platform_device *h3xxx_devices[] = {
  225. &h3xxx_egpio,
  226. &h3xxx_keys,
  227. };
  228. void __init h3xxx_mach_init(void)
  229. {
  230. sa1100_register_uart_fns(&h3xxx_port_fns);
  231. sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  232. platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
  233. }
  234. static struct map_desc h3600_io_desc[] __initdata = {
  235. { /* static memory bank 2 CS#2 */
  236. .virtual = H3600_BANK_2_VIRT,
  237. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  238. .length = 0x02800000,
  239. .type = MT_DEVICE
  240. }, { /* static memory bank 4 CS#4 */
  241. .virtual = H3600_BANK_4_VIRT,
  242. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  243. .length = 0x00800000,
  244. .type = MT_DEVICE
  245. }, { /* EGPIO 0 CS#5 */
  246. .virtual = H3600_EGPIO_VIRT,
  247. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  248. .length = 0x01000000,
  249. .type = MT_DEVICE
  250. }
  251. };
  252. /*
  253. * Common map_io initialization
  254. */
  255. void __init h3xxx_map_io(void)
  256. {
  257. sa1100_map_io();
  258. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  259. sa1100_register_uart(0, 3); /* Common serial port */
  260. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  261. /* Ensure those pins are outputs and driving low */
  262. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  263. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  264. /* Configure suspend conditions */
  265. PGSR = 0;
  266. PCFR = PCFR_OPDE;
  267. PSDR = 0;
  268. GPCR = 0x0fffffff; /* All outputs are set low by default */
  269. GPDR = 0; /* Configure all GPIOs as input */
  270. }