h3xxx.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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/mfd/htc-egpio.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/serial_core.h>
  19. #include <asm/mach/flash.h>
  20. #include <asm/mach/map.h>
  21. #include <asm/mach/serial_sa1100.h>
  22. #include <mach/h3xxx.h>
  23. #include "generic.h"
  24. void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
  25. {
  26. while (n--) {
  27. const char *name = s->name;
  28. int err;
  29. if (!name)
  30. name = "[init]";
  31. err = gpio_request(s->gpio, name);
  32. if (err) {
  33. printk(KERN_ERR "gpio%u: unable to request: %d\n",
  34. s->gpio, err);
  35. continue;
  36. }
  37. if (s->mode >= 0) {
  38. err = gpio_direction_output(s->gpio, s->mode);
  39. } else {
  40. err = gpio_direction_input(s->gpio);
  41. }
  42. if (err) {
  43. printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
  44. s->gpio, err);
  45. continue;
  46. }
  47. if (!s->name)
  48. gpio_free(s->gpio);
  49. s++;
  50. }
  51. }
  52. /*
  53. * H3xxx flash support
  54. */
  55. static struct mtd_partition h3xxx_partitions[] = {
  56. {
  57. .name = "H3XXX boot firmware",
  58. .size = 0x00040000,
  59. .offset = 0,
  60. .mask_flags = MTD_WRITEABLE, /* force read-only */
  61. }, {
  62. .name = "H3XXX rootfs",
  63. .size = MTDPART_SIZ_FULL,
  64. .offset = 0x00040000,
  65. }
  66. };
  67. static void h3xxx_set_vpp(int vpp)
  68. {
  69. gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
  70. }
  71. static int h3xxx_flash_init(void)
  72. {
  73. int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
  74. if (err)
  75. return err;
  76. err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
  77. if (err)
  78. gpio_free(H3XXX_EGPIO_VPP_ON);
  79. return err;
  80. }
  81. static void h3xxx_flash_exit(void)
  82. {
  83. gpio_free(H3XXX_EGPIO_VPP_ON);
  84. }
  85. static struct flash_platform_data h3xxx_flash_data = {
  86. .map_name = "cfi_probe",
  87. .set_vpp = h3xxx_set_vpp,
  88. .init = h3xxx_flash_init,
  89. .exit = h3xxx_flash_exit,
  90. .parts = h3xxx_partitions,
  91. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  92. };
  93. static struct resource h3xxx_flash_resource = {
  94. .start = SA1100_CS0_PHYS,
  95. .end = SA1100_CS0_PHYS + SZ_32M - 1,
  96. .flags = IORESOURCE_MEM,
  97. };
  98. /*
  99. * H3xxx uart support
  100. */
  101. static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  102. {
  103. if (port->mapbase == _Ser3UTCR0) {
  104. gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
  105. }
  106. }
  107. static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
  108. {
  109. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  110. if (port->mapbase == _Ser3UTCR0) {
  111. /*
  112. * DCD and CTS bits are inverted in GPLR by RS232 transceiver
  113. */
  114. if (gpio_get_value(H3XXX_GPIO_COM_DCD))
  115. ret &= ~TIOCM_CD;
  116. if (gpio_get_value(H3XXX_GPIO_COM_CTS))
  117. ret &= ~TIOCM_CTS;
  118. }
  119. return ret;
  120. }
  121. static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  122. {
  123. if (port->mapbase == _Ser3UTCR0)
  124. if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
  125. gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
  126. gpio_free(H3XXX_EGPIO_RS232_ON);
  127. }
  128. }
  129. /*
  130. * Enable/Disable wake up events for this serial port.
  131. * Obviously, we only support this on the normal COM port.
  132. */
  133. static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
  134. {
  135. int err = -EINVAL;
  136. if (port->mapbase == _Ser3UTCR0) {
  137. if (enable)
  138. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  139. else
  140. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  141. err = 0;
  142. }
  143. return err;
  144. }
  145. static struct sa1100_port_fns h3xxx_port_fns __initdata = {
  146. .set_mctrl = h3xxx_uart_set_mctrl,
  147. .get_mctrl = h3xxx_uart_get_mctrl,
  148. .pm = h3xxx_uart_pm,
  149. .set_wake = h3xxx_uart_set_wake,
  150. };
  151. /*
  152. * EGPIO
  153. */
  154. static struct resource egpio_resources[] = {
  155. [0] = {
  156. .start = H3600_EGPIO_PHYS,
  157. .end = H3600_EGPIO_PHYS + 0x4 - 1,
  158. .flags = IORESOURCE_MEM,
  159. },
  160. };
  161. static struct htc_egpio_chip egpio_chips[] = {
  162. [0] = {
  163. .reg_start = 0,
  164. .gpio_base = H3XXX_EGPIO_BASE,
  165. .num_gpios = 16,
  166. .direction = HTC_EGPIO_OUTPUT,
  167. .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
  168. },
  169. };
  170. static struct htc_egpio_platform_data egpio_info = {
  171. .reg_width = 16,
  172. .bus_width = 16,
  173. .chip = egpio_chips,
  174. .num_chips = ARRAY_SIZE(egpio_chips),
  175. };
  176. static struct platform_device h3xxx_egpio = {
  177. .name = "htc-egpio",
  178. .id = -1,
  179. .resource = egpio_resources,
  180. .num_resources = ARRAY_SIZE(egpio_resources),
  181. .dev = {
  182. .platform_data = &egpio_info,
  183. },
  184. };
  185. static struct platform_device *h3xxx_devices[] = {
  186. &h3xxx_egpio,
  187. };
  188. void __init h3xxx_mach_init(void)
  189. {
  190. sa1100_register_uart_fns(&h3xxx_port_fns);
  191. sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  192. platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
  193. }
  194. static struct map_desc h3600_io_desc[] __initdata = {
  195. { /* static memory bank 2 CS#2 */
  196. .virtual = H3600_BANK_2_VIRT,
  197. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  198. .length = 0x02800000,
  199. .type = MT_DEVICE
  200. }, { /* static memory bank 4 CS#4 */
  201. .virtual = H3600_BANK_4_VIRT,
  202. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  203. .length = 0x00800000,
  204. .type = MT_DEVICE
  205. }, { /* EGPIO 0 CS#5 */
  206. .virtual = H3600_EGPIO_VIRT,
  207. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  208. .length = 0x01000000,
  209. .type = MT_DEVICE
  210. }
  211. };
  212. /*
  213. * Common map_io initialization
  214. */
  215. void __init h3xxx_map_io(void)
  216. {
  217. sa1100_map_io();
  218. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  219. sa1100_register_uart(0, 3); /* Common serial port */
  220. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  221. /* Ensure those pins are outputs and driving low */
  222. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  223. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  224. /* Configure suspend conditions */
  225. PGSR = 0;
  226. PWER = PWER_GPIO0;
  227. PCFR = PCFR_OPDE;
  228. PSDR = 0;
  229. GPCR = 0x0fffffff; /* All outputs are set low by default */
  230. GPDR = 0; /* Configure all GPIOs as input */
  231. }