h3xxx.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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/mtd/mtd.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <linux/platform_data/gpio-htc-egpio.h>
  19. #include <linux/platform_data/sa11x0-serial.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/serial_core.h>
  22. #include <asm/mach/flash.h>
  23. #include <asm/mach/map.h>
  24. #include <mach/h3xxx.h>
  25. #include <mach/irqs.h>
  26. #include "generic.h"
  27. /*
  28. * H3xxx flash support
  29. */
  30. static struct mtd_partition h3xxx_partitions[] = {
  31. {
  32. .name = "H3XXX boot firmware",
  33. .size = 0x00040000,
  34. .offset = 0,
  35. .mask_flags = MTD_WRITEABLE, /* force read-only */
  36. }, {
  37. .name = "H3XXX rootfs",
  38. .size = MTDPART_SIZ_FULL,
  39. .offset = 0x00040000,
  40. }
  41. };
  42. static void h3xxx_set_vpp(int vpp)
  43. {
  44. gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
  45. }
  46. static int h3xxx_flash_init(void)
  47. {
  48. int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
  49. if (err) {
  50. pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__);
  51. return err;
  52. }
  53. err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
  54. if (err)
  55. gpio_free(H3XXX_EGPIO_VPP_ON);
  56. return err;
  57. }
  58. static void h3xxx_flash_exit(void)
  59. {
  60. gpio_free(H3XXX_EGPIO_VPP_ON);
  61. }
  62. static struct flash_platform_data h3xxx_flash_data = {
  63. .map_name = "cfi_probe",
  64. .set_vpp = h3xxx_set_vpp,
  65. .init = h3xxx_flash_init,
  66. .exit = h3xxx_flash_exit,
  67. .parts = h3xxx_partitions,
  68. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  69. };
  70. static struct resource h3xxx_flash_resource =
  71. DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M);
  72. /*
  73. * H3xxx uart support
  74. */
  75. static struct gpio h3xxx_uart_gpio[] = {
  76. { H3XXX_GPIO_COM_DCD, GPIOF_IN, "COM DCD" },
  77. { H3XXX_GPIO_COM_CTS, GPIOF_IN, "COM CTS" },
  78. { H3XXX_GPIO_COM_RTS, GPIOF_OUT_INIT_LOW, "COM RTS" },
  79. };
  80. static bool h3xxx_uart_request_gpios(void)
  81. {
  82. static bool h3xxx_uart_gpio_ok;
  83. int rc;
  84. if (h3xxx_uart_gpio_ok)
  85. return true;
  86. rc = gpio_request_array(h3xxx_uart_gpio, ARRAY_SIZE(h3xxx_uart_gpio));
  87. if (rc)
  88. pr_err("h3xxx_uart_request_gpios: error %d\n", rc);
  89. else
  90. h3xxx_uart_gpio_ok = true;
  91. return h3xxx_uart_gpio_ok;
  92. }
  93. static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  94. {
  95. if (port->mapbase == _Ser3UTCR0) {
  96. if (!h3xxx_uart_request_gpios())
  97. return;
  98. gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
  99. }
  100. }
  101. static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
  102. {
  103. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  104. if (port->mapbase == _Ser3UTCR0) {
  105. if (!h3xxx_uart_request_gpios())
  106. return ret;
  107. /*
  108. * DCD and CTS bits are inverted in GPLR by RS232 transceiver
  109. */
  110. if (gpio_get_value(H3XXX_GPIO_COM_DCD))
  111. ret &= ~TIOCM_CD;
  112. if (gpio_get_value(H3XXX_GPIO_COM_CTS))
  113. ret &= ~TIOCM_CTS;
  114. }
  115. return ret;
  116. }
  117. static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  118. {
  119. if (port->mapbase == _Ser3UTCR0) {
  120. if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
  121. gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
  122. gpio_free(H3XXX_EGPIO_RS232_ON);
  123. } else {
  124. pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
  125. __func__);
  126. }
  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] = DEFINE_RES_MEM(H3600_EGPIO_PHYS, 0x4),
  156. };
  157. static struct htc_egpio_chip egpio_chips[] = {
  158. [0] = {
  159. .reg_start = 0,
  160. .gpio_base = H3XXX_EGPIO_BASE,
  161. .num_gpios = 16,
  162. .direction = HTC_EGPIO_OUTPUT,
  163. .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
  164. },
  165. };
  166. static struct htc_egpio_platform_data egpio_info = {
  167. .reg_width = 16,
  168. .bus_width = 16,
  169. .chip = egpio_chips,
  170. .num_chips = ARRAY_SIZE(egpio_chips),
  171. };
  172. static struct platform_device h3xxx_egpio = {
  173. .name = "htc-egpio",
  174. .id = -1,
  175. .resource = egpio_resources,
  176. .num_resources = ARRAY_SIZE(egpio_resources),
  177. .dev = {
  178. .platform_data = &egpio_info,
  179. },
  180. };
  181. /*
  182. * GPIO keys
  183. */
  184. static struct gpio_keys_button h3xxx_button_table[] = {
  185. {
  186. .code = KEY_POWER,
  187. .gpio = H3XXX_GPIO_PWR_BUTTON,
  188. .desc = "Power Button",
  189. .active_low = 1,
  190. .type = EV_KEY,
  191. .wakeup = 1,
  192. }, {
  193. .code = KEY_ENTER,
  194. .gpio = H3XXX_GPIO_ACTION_BUTTON,
  195. .active_low = 1,
  196. .desc = "Action button",
  197. .type = EV_KEY,
  198. .wakeup = 0,
  199. },
  200. };
  201. static struct gpio_keys_platform_data h3xxx_keys_data = {
  202. .buttons = h3xxx_button_table,
  203. .nbuttons = ARRAY_SIZE(h3xxx_button_table),
  204. };
  205. static struct platform_device h3xxx_keys = {
  206. .name = "gpio-keys",
  207. .id = -1,
  208. .dev = {
  209. .platform_data = &h3xxx_keys_data,
  210. },
  211. };
  212. static struct resource h3xxx_micro_resources[] = {
  213. DEFINE_RES_MEM(0x80010000, SZ_4K),
  214. DEFINE_RES_MEM(0x80020000, SZ_4K),
  215. DEFINE_RES_IRQ(IRQ_Ser1UART),
  216. };
  217. struct platform_device h3xxx_micro_asic = {
  218. .name = "ipaq-h3xxx-micro",
  219. .id = -1,
  220. .resource = h3xxx_micro_resources,
  221. .num_resources = ARRAY_SIZE(h3xxx_micro_resources),
  222. };
  223. static struct platform_device *h3xxx_devices[] = {
  224. &h3xxx_egpio,
  225. &h3xxx_keys,
  226. &h3xxx_micro_asic,
  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. }