h3xxx.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M);
  99. /*
  100. * H3xxx uart support
  101. */
  102. static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  103. {
  104. if (port->mapbase == _Ser3UTCR0) {
  105. gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
  106. }
  107. }
  108. static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
  109. {
  110. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  111. if (port->mapbase == _Ser3UTCR0) {
  112. /*
  113. * DCD and CTS bits are inverted in GPLR by RS232 transceiver
  114. */
  115. if (gpio_get_value(H3XXX_GPIO_COM_DCD))
  116. ret &= ~TIOCM_CD;
  117. if (gpio_get_value(H3XXX_GPIO_COM_CTS))
  118. ret &= ~TIOCM_CTS;
  119. }
  120. return ret;
  121. }
  122. static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  123. {
  124. if (port->mapbase == _Ser3UTCR0) {
  125. if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
  126. gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
  127. gpio_free(H3XXX_EGPIO_RS232_ON);
  128. } else {
  129. pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
  130. __func__);
  131. }
  132. }
  133. }
  134. /*
  135. * Enable/Disable wake up events for this serial port.
  136. * Obviously, we only support this on the normal COM port.
  137. */
  138. static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
  139. {
  140. int err = -EINVAL;
  141. if (port->mapbase == _Ser3UTCR0) {
  142. if (enable)
  143. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  144. else
  145. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  146. err = 0;
  147. }
  148. return err;
  149. }
  150. static struct sa1100_port_fns h3xxx_port_fns __initdata = {
  151. .set_mctrl = h3xxx_uart_set_mctrl,
  152. .get_mctrl = h3xxx_uart_get_mctrl,
  153. .pm = h3xxx_uart_pm,
  154. .set_wake = h3xxx_uart_set_wake,
  155. };
  156. /*
  157. * EGPIO
  158. */
  159. static struct resource egpio_resources[] = {
  160. [0] = DEFINE_RES_MEM(H3600_EGPIO_PHYS, 0x4),
  161. };
  162. static struct htc_egpio_chip egpio_chips[] = {
  163. [0] = {
  164. .reg_start = 0,
  165. .gpio_base = H3XXX_EGPIO_BASE,
  166. .num_gpios = 16,
  167. .direction = HTC_EGPIO_OUTPUT,
  168. .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
  169. },
  170. };
  171. static struct htc_egpio_platform_data egpio_info = {
  172. .reg_width = 16,
  173. .bus_width = 16,
  174. .chip = egpio_chips,
  175. .num_chips = ARRAY_SIZE(egpio_chips),
  176. };
  177. static struct platform_device h3xxx_egpio = {
  178. .name = "htc-egpio",
  179. .id = -1,
  180. .resource = egpio_resources,
  181. .num_resources = ARRAY_SIZE(egpio_resources),
  182. .dev = {
  183. .platform_data = &egpio_info,
  184. },
  185. };
  186. /*
  187. * GPIO keys
  188. */
  189. static struct gpio_keys_button h3xxx_button_table[] = {
  190. {
  191. .code = KEY_POWER,
  192. .gpio = H3XXX_GPIO_PWR_BUTTON,
  193. .desc = "Power Button",
  194. .active_low = 1,
  195. .type = EV_KEY,
  196. .wakeup = 1,
  197. }, {
  198. .code = KEY_ENTER,
  199. .gpio = H3XXX_GPIO_ACTION_BUTTON,
  200. .active_low = 1,
  201. .desc = "Action button",
  202. .type = EV_KEY,
  203. .wakeup = 0,
  204. },
  205. };
  206. static struct gpio_keys_platform_data h3xxx_keys_data = {
  207. .buttons = h3xxx_button_table,
  208. .nbuttons = ARRAY_SIZE(h3xxx_button_table),
  209. };
  210. static struct platform_device h3xxx_keys = {
  211. .name = "gpio-keys",
  212. .id = -1,
  213. .dev = {
  214. .platform_data = &h3xxx_keys_data,
  215. },
  216. };
  217. static struct platform_device *h3xxx_devices[] = {
  218. &h3xxx_egpio,
  219. &h3xxx_keys,
  220. };
  221. void __init h3xxx_mach_init(void)
  222. {
  223. sa1100_register_uart_fns(&h3xxx_port_fns);
  224. sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  225. platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
  226. }
  227. static struct map_desc h3600_io_desc[] __initdata = {
  228. { /* static memory bank 2 CS#2 */
  229. .virtual = H3600_BANK_2_VIRT,
  230. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  231. .length = 0x02800000,
  232. .type = MT_DEVICE
  233. }, { /* static memory bank 4 CS#4 */
  234. .virtual = H3600_BANK_4_VIRT,
  235. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  236. .length = 0x00800000,
  237. .type = MT_DEVICE
  238. }, { /* EGPIO 0 CS#5 */
  239. .virtual = H3600_EGPIO_VIRT,
  240. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  241. .length = 0x01000000,
  242. .type = MT_DEVICE
  243. }
  244. };
  245. /*
  246. * Common map_io initialization
  247. */
  248. void __init h3xxx_map_io(void)
  249. {
  250. sa1100_map_io();
  251. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  252. sa1100_register_uart(0, 3); /* Common serial port */
  253. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  254. /* Ensure those pins are outputs and driving low */
  255. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  256. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  257. /* Configure suspend conditions */
  258. PGSR = 0;
  259. PCFR = PCFR_OPDE;
  260. PSDR = 0;
  261. GPCR = 0x0fffffff; /* All outputs are set low by default */
  262. GPDR = 0; /* Configure all GPIOs as input */
  263. }