h3xxx.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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/machine.h>
  14. #include <linux/gpio.h>
  15. #include <linux/gpio_keys.h>
  16. #include <linux/input.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/partitions.h>
  19. #include <linux/platform_data/gpio-htc-egpio.h>
  20. #include <linux/platform_data/sa11x0-serial.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/serial_core.h>
  23. #include <asm/mach/flash.h>
  24. #include <asm/mach/map.h>
  25. #include <mach/h3xxx.h>
  26. #include <mach/irqs.h>
  27. #include "generic.h"
  28. /*
  29. * H3xxx flash support
  30. */
  31. static struct mtd_partition h3xxx_partitions[] = {
  32. {
  33. .name = "H3XXX boot firmware",
  34. .size = 0x00040000,
  35. .offset = 0,
  36. .mask_flags = MTD_WRITEABLE, /* force read-only */
  37. }, {
  38. .name = "H3XXX rootfs",
  39. .size = MTDPART_SIZ_FULL,
  40. .offset = 0x00040000,
  41. }
  42. };
  43. static void h3xxx_set_vpp(int vpp)
  44. {
  45. gpio_set_value(H3XXX_EGPIO_VPP_ON, vpp);
  46. }
  47. static int h3xxx_flash_init(void)
  48. {
  49. int err = gpio_request(H3XXX_EGPIO_VPP_ON, "Flash Vpp");
  50. if (err) {
  51. pr_err("%s: can't request H3XXX_EGPIO_VPP_ON\n", __func__);
  52. return err;
  53. }
  54. err = gpio_direction_output(H3XXX_EGPIO_VPP_ON, 0);
  55. if (err)
  56. gpio_free(H3XXX_EGPIO_VPP_ON);
  57. return err;
  58. }
  59. static void h3xxx_flash_exit(void)
  60. {
  61. gpio_free(H3XXX_EGPIO_VPP_ON);
  62. }
  63. static struct flash_platform_data h3xxx_flash_data = {
  64. .map_name = "cfi_probe",
  65. .set_vpp = h3xxx_set_vpp,
  66. .init = h3xxx_flash_init,
  67. .exit = h3xxx_flash_exit,
  68. .parts = h3xxx_partitions,
  69. .nr_parts = ARRAY_SIZE(h3xxx_partitions),
  70. };
  71. static struct resource h3xxx_flash_resource =
  72. DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M);
  73. /*
  74. * H3xxx uart support
  75. */
  76. static struct gpio h3xxx_uart_gpio[] = {
  77. { H3XXX_GPIO_COM_DCD, GPIOF_IN, "COM DCD" },
  78. { H3XXX_GPIO_COM_CTS, GPIOF_IN, "COM CTS" },
  79. { H3XXX_GPIO_COM_RTS, GPIOF_OUT_INIT_LOW, "COM RTS" },
  80. };
  81. static bool h3xxx_uart_request_gpios(void)
  82. {
  83. static bool h3xxx_uart_gpio_ok;
  84. int rc;
  85. if (h3xxx_uart_gpio_ok)
  86. return true;
  87. rc = gpio_request_array(h3xxx_uart_gpio, ARRAY_SIZE(h3xxx_uart_gpio));
  88. if (rc)
  89. pr_err("h3xxx_uart_request_gpios: error %d\n", rc);
  90. else
  91. h3xxx_uart_gpio_ok = true;
  92. return h3xxx_uart_gpio_ok;
  93. }
  94. static void h3xxx_uart_set_mctrl(struct uart_port *port, u_int mctrl)
  95. {
  96. if (port->mapbase == _Ser3UTCR0) {
  97. if (!h3xxx_uart_request_gpios())
  98. return;
  99. gpio_set_value(H3XXX_GPIO_COM_RTS, !(mctrl & TIOCM_RTS));
  100. }
  101. }
  102. static u_int h3xxx_uart_get_mctrl(struct uart_port *port)
  103. {
  104. u_int ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
  105. if (port->mapbase == _Ser3UTCR0) {
  106. if (!h3xxx_uart_request_gpios())
  107. return ret;
  108. /*
  109. * DCD and CTS bits are inverted in GPLR by RS232 transceiver
  110. */
  111. if (gpio_get_value(H3XXX_GPIO_COM_DCD))
  112. ret &= ~TIOCM_CD;
  113. if (gpio_get_value(H3XXX_GPIO_COM_CTS))
  114. ret &= ~TIOCM_CTS;
  115. }
  116. return ret;
  117. }
  118. static void h3xxx_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
  119. {
  120. if (port->mapbase == _Ser3UTCR0) {
  121. if (!gpio_request(H3XXX_EGPIO_RS232_ON, "RS232 transceiver")) {
  122. gpio_direction_output(H3XXX_EGPIO_RS232_ON, !state);
  123. gpio_free(H3XXX_EGPIO_RS232_ON);
  124. } else {
  125. pr_err("%s: can't request H3XXX_EGPIO_RS232_ON\n",
  126. __func__);
  127. }
  128. }
  129. }
  130. /*
  131. * Enable/Disable wake up events for this serial port.
  132. * Obviously, we only support this on the normal COM port.
  133. */
  134. static int h3xxx_uart_set_wake(struct uart_port *port, u_int enable)
  135. {
  136. int err = -EINVAL;
  137. if (port->mapbase == _Ser3UTCR0) {
  138. if (enable)
  139. PWER |= PWER_GPIO23 | PWER_GPIO25; /* DCD and CTS */
  140. else
  141. PWER &= ~(PWER_GPIO23 | PWER_GPIO25); /* DCD and CTS */
  142. err = 0;
  143. }
  144. return err;
  145. }
  146. static struct sa1100_port_fns h3xxx_port_fns __initdata = {
  147. .set_mctrl = h3xxx_uart_set_mctrl,
  148. .get_mctrl = h3xxx_uart_get_mctrl,
  149. .pm = h3xxx_uart_pm,
  150. .set_wake = h3xxx_uart_set_wake,
  151. };
  152. /*
  153. * EGPIO
  154. */
  155. static struct resource egpio_resources[] = {
  156. [0] = DEFINE_RES_MEM(H3600_EGPIO_PHYS, 0x4),
  157. };
  158. static struct htc_egpio_chip egpio_chips[] = {
  159. [0] = {
  160. .reg_start = 0,
  161. .gpio_base = H3XXX_EGPIO_BASE,
  162. .num_gpios = 16,
  163. .direction = HTC_EGPIO_OUTPUT,
  164. .initial_values = 0x0080, /* H3XXX_EGPIO_RS232_ON */
  165. },
  166. };
  167. static struct htc_egpio_platform_data egpio_info = {
  168. .reg_width = 16,
  169. .bus_width = 16,
  170. .chip = egpio_chips,
  171. .num_chips = ARRAY_SIZE(egpio_chips),
  172. };
  173. static struct platform_device h3xxx_egpio = {
  174. .name = "htc-egpio",
  175. .id = -1,
  176. .resource = egpio_resources,
  177. .num_resources = ARRAY_SIZE(egpio_resources),
  178. .dev = {
  179. .platform_data = &egpio_info,
  180. },
  181. };
  182. /*
  183. * GPIO keys
  184. */
  185. static struct gpio_keys_button h3xxx_button_table[] = {
  186. {
  187. .code = KEY_POWER,
  188. .gpio = H3XXX_GPIO_PWR_BUTTON,
  189. .desc = "Power Button",
  190. .active_low = 1,
  191. .type = EV_KEY,
  192. .wakeup = 1,
  193. }, {
  194. .code = KEY_ENTER,
  195. .gpio = H3XXX_GPIO_ACTION_BUTTON,
  196. .active_low = 1,
  197. .desc = "Action button",
  198. .type = EV_KEY,
  199. .wakeup = 0,
  200. },
  201. };
  202. static struct gpio_keys_platform_data h3xxx_keys_data = {
  203. .buttons = h3xxx_button_table,
  204. .nbuttons = ARRAY_SIZE(h3xxx_button_table),
  205. };
  206. static struct platform_device h3xxx_keys = {
  207. .name = "gpio-keys",
  208. .id = -1,
  209. .dev = {
  210. .platform_data = &h3xxx_keys_data,
  211. },
  212. };
  213. static struct resource h3xxx_micro_resources[] = {
  214. DEFINE_RES_MEM(0x80010000, SZ_4K),
  215. DEFINE_RES_MEM(0x80020000, SZ_4K),
  216. DEFINE_RES_IRQ(IRQ_Ser1UART),
  217. };
  218. struct platform_device h3xxx_micro_asic = {
  219. .name = "ipaq-h3xxx-micro",
  220. .id = -1,
  221. .resource = h3xxx_micro_resources,
  222. .num_resources = ARRAY_SIZE(h3xxx_micro_resources),
  223. };
  224. static struct platform_device *h3xxx_devices[] = {
  225. &h3xxx_egpio,
  226. &h3xxx_keys,
  227. &h3xxx_micro_asic,
  228. };
  229. static struct gpiod_lookup_table h3xxx_pcmcia_gpio_table = {
  230. .dev_id = "sa11x0-pcmcia",
  231. .table = {
  232. GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD0,
  233. "pcmcia0-detect", GPIO_ACTIVE_LOW),
  234. GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ0,
  235. "pcmcia0-ready", GPIO_ACTIVE_HIGH),
  236. GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_CD1,
  237. "pcmcia1-detect", GPIO_ACTIVE_LOW),
  238. GPIO_LOOKUP("gpio", H3XXX_GPIO_PCMCIA_IRQ1,
  239. "pcmcia1-ready", GPIO_ACTIVE_HIGH),
  240. { },
  241. },
  242. };
  243. void __init h3xxx_mach_init(void)
  244. {
  245. gpiod_add_lookup_table(&h3xxx_pcmcia_gpio_table);
  246. sa1100_register_uart_fns(&h3xxx_port_fns);
  247. sa11x0_register_mtd(&h3xxx_flash_data, &h3xxx_flash_resource, 1);
  248. platform_add_devices(h3xxx_devices, ARRAY_SIZE(h3xxx_devices));
  249. }
  250. static struct map_desc h3600_io_desc[] __initdata = {
  251. { /* static memory bank 2 CS#2 */
  252. .virtual = H3600_BANK_2_VIRT,
  253. .pfn = __phys_to_pfn(SA1100_CS2_PHYS),
  254. .length = 0x02800000,
  255. .type = MT_DEVICE
  256. }, { /* static memory bank 4 CS#4 */
  257. .virtual = H3600_BANK_4_VIRT,
  258. .pfn = __phys_to_pfn(SA1100_CS4_PHYS),
  259. .length = 0x00800000,
  260. .type = MT_DEVICE
  261. }, { /* EGPIO 0 CS#5 */
  262. .virtual = H3600_EGPIO_VIRT,
  263. .pfn = __phys_to_pfn(H3600_EGPIO_PHYS),
  264. .length = 0x01000000,
  265. .type = MT_DEVICE
  266. }
  267. };
  268. /*
  269. * Common map_io initialization
  270. */
  271. void __init h3xxx_map_io(void)
  272. {
  273. sa1100_map_io();
  274. iotable_init(h3600_io_desc, ARRAY_SIZE(h3600_io_desc));
  275. sa1100_register_uart(0, 3); /* Common serial port */
  276. // sa1100_register_uart(1, 1); /* Microcontroller on 3100/3600 */
  277. /* Ensure those pins are outputs and driving low */
  278. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  279. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  280. /* Configure suspend conditions */
  281. PGSR = 0;
  282. PCFR = PCFR_OPDE;
  283. PSDR = 0;
  284. GPCR = 0x0fffffff; /* All outputs are set low by default */
  285. GPDR = 0; /* Configure all GPIOs as input */
  286. }