h3xxx.c 6.6 KB

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