8250_hp300.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for the 98626/98644/internal serial interface on hp300/hp400
  4. * (based on the National Semiconductor INS8250/NS16550AF/WD16C552 UARTs)
  5. *
  6. * Ported from 2.2 and modified to use the normal 8250 driver
  7. * by Kars de Jong <jongk@linux-m68k.org>, May 2004.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/string.h>
  12. #include <linux/kernel.h>
  13. #include <linux/serial.h>
  14. #include <linux/serial_8250.h>
  15. #include <linux/delay.h>
  16. #include <linux/dio.h>
  17. #include <linux/console.h>
  18. #include <linux/slab.h>
  19. #include <asm/io.h>
  20. #include "8250.h"
  21. #if !defined(CONFIG_HPDCA) && !defined(CONFIG_HPAPCI) && !defined(CONFIG_COMPILE_TEST)
  22. #warning CONFIG_SERIAL_8250 defined but neither CONFIG_HPDCA nor CONFIG_HPAPCI defined, are you sure?
  23. #endif
  24. #ifdef CONFIG_HPAPCI
  25. struct hp300_port {
  26. struct hp300_port *next; /* next port */
  27. int line; /* line (tty) number */
  28. };
  29. static struct hp300_port *hp300_ports;
  30. #endif
  31. #ifdef CONFIG_HPDCA
  32. static int hpdca_init_one(struct dio_dev *d,
  33. const struct dio_device_id *ent);
  34. static void hpdca_remove_one(struct dio_dev *d);
  35. static struct dio_device_id hpdca_dio_tbl[] = {
  36. { DIO_ID_DCA0 },
  37. { DIO_ID_DCA0REM },
  38. { DIO_ID_DCA1 },
  39. { DIO_ID_DCA1REM },
  40. { 0 }
  41. };
  42. static struct dio_driver hpdca_driver = {
  43. .name = "hpdca",
  44. .id_table = hpdca_dio_tbl,
  45. .probe = hpdca_init_one,
  46. .remove = hpdca_remove_one,
  47. };
  48. #endif
  49. static unsigned int num_ports;
  50. extern int hp300_uart_scode;
  51. /* Offset to UART registers from base of DCA */
  52. #define UART_OFFSET 17
  53. #define DCA_ID 0x01 /* ID (read), reset (write) */
  54. #define DCA_IC 0x03 /* Interrupt control */
  55. /* Interrupt control */
  56. #define DCA_IC_IE 0x80 /* Master interrupt enable */
  57. #define HPDCA_BAUD_BASE 153600
  58. /* Base address of the Frodo part */
  59. #define FRODO_BASE (0x41c000)
  60. /*
  61. * Where we find the 8250-like APCI ports, and how far apart they are.
  62. */
  63. #define FRODO_APCIBASE 0x0
  64. #define FRODO_APCISPACE 0x20
  65. #define FRODO_APCI_OFFSET(x) (FRODO_APCIBASE + ((x) * FRODO_APCISPACE))
  66. #define HPAPCI_BAUD_BASE 500400
  67. #ifdef CONFIG_SERIAL_8250_CONSOLE
  68. /*
  69. * Parse the bootinfo to find descriptions for headless console and
  70. * debug serial ports and register them with the 8250 driver.
  71. */
  72. int __init hp300_setup_serial_console(void)
  73. {
  74. int scode;
  75. struct uart_port port;
  76. memset(&port, 0, sizeof(port));
  77. if (hp300_uart_scode < 0 || hp300_uart_scode > DIO_SCMAX)
  78. return 0;
  79. if (DIO_SCINHOLE(hp300_uart_scode))
  80. return 0;
  81. scode = hp300_uart_scode;
  82. /* Memory mapped I/O */
  83. port.iotype = UPIO_MEM;
  84. port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
  85. port.type = PORT_UNKNOWN;
  86. /* Check for APCI console */
  87. if (scode == 256) {
  88. #ifdef CONFIG_HPAPCI
  89. pr_info("Serial console is HP APCI 1\n");
  90. port.uartclk = HPAPCI_BAUD_BASE * 16;
  91. port.mapbase = (FRODO_BASE + FRODO_APCI_OFFSET(1));
  92. port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
  93. port.regshift = 2;
  94. add_preferred_console("ttyS", port.line, "9600n8");
  95. #else
  96. pr_warn("Serial console is APCI but support is disabled (CONFIG_HPAPCI)!\n");
  97. return 0;
  98. #endif
  99. } else {
  100. #ifdef CONFIG_HPDCA
  101. unsigned long pa = dio_scodetophysaddr(scode);
  102. if (!pa)
  103. return 0;
  104. pr_info("Serial console is HP DCA at select code %d\n", scode);
  105. port.uartclk = HPDCA_BAUD_BASE * 16;
  106. port.mapbase = (pa + UART_OFFSET);
  107. port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
  108. port.regshift = 1;
  109. port.irq = DIO_IPL(pa + DIO_VIRADDRBASE);
  110. /* Enable board-interrupts */
  111. out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
  112. if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80)
  113. add_preferred_console("ttyS", port.line, "9600n8");
  114. #else
  115. pr_warn("Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
  116. return 0;
  117. #endif
  118. }
  119. if (early_serial_setup(&port) < 0)
  120. pr_warn("%s: early_serial_setup() failed.\n", __func__);
  121. return 0;
  122. }
  123. #endif /* CONFIG_SERIAL_8250_CONSOLE */
  124. #ifdef CONFIG_HPDCA
  125. static int hpdca_init_one(struct dio_dev *d,
  126. const struct dio_device_id *ent)
  127. {
  128. struct uart_8250_port uart;
  129. int line;
  130. #ifdef CONFIG_SERIAL_8250_CONSOLE
  131. if (hp300_uart_scode == d->scode) {
  132. /* Already got it. */
  133. return 0;
  134. }
  135. #endif
  136. memset(&uart, 0, sizeof(uart));
  137. /* Memory mapped I/O */
  138. uart.port.iotype = UPIO_MEM;
  139. uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
  140. uart.port.irq = d->ipl;
  141. uart.port.uartclk = HPDCA_BAUD_BASE * 16;
  142. uart.port.mapbase = (d->resource.start + UART_OFFSET);
  143. uart.port.membase = (char *)(uart.port.mapbase + DIO_VIRADDRBASE);
  144. uart.port.regshift = 1;
  145. uart.port.dev = &d->dev;
  146. line = serial8250_register_8250_port(&uart);
  147. if (line < 0) {
  148. dev_notice(&d->dev,
  149. "8250_hp300: register_serial() DCA scode %d irq %d failed\n",
  150. d->scode, uart.port.irq);
  151. return -ENOMEM;
  152. }
  153. /* Enable board-interrupts */
  154. out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
  155. dio_set_drvdata(d, (void *)line);
  156. /* Reset the DCA */
  157. out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
  158. udelay(100);
  159. num_ports++;
  160. return 0;
  161. }
  162. #endif
  163. static int __init hp300_8250_init(void)
  164. {
  165. static int called;
  166. #ifdef CONFIG_HPAPCI
  167. int line;
  168. unsigned long base;
  169. struct uart_8250_port uart;
  170. struct hp300_port *port;
  171. int i;
  172. #endif
  173. if (called)
  174. return -ENODEV;
  175. called = 1;
  176. if (!MACH_IS_HP300)
  177. return -ENODEV;
  178. #ifdef CONFIG_HPDCA
  179. dio_register_driver(&hpdca_driver);
  180. #endif
  181. #ifdef CONFIG_HPAPCI
  182. if (hp300_model < HP_400) {
  183. if (!num_ports)
  184. return -ENODEV;
  185. return 0;
  186. }
  187. /* These models have the Frodo chip.
  188. * Port 0 is reserved for the Apollo Domain keyboard.
  189. * Port 1 is either the console or the DCA.
  190. */
  191. for (i = 1; i < 4; i++) {
  192. /* Port 1 is the console on a 425e, on other machines it's
  193. * mapped to DCA.
  194. */
  195. #ifdef CONFIG_SERIAL_8250_CONSOLE
  196. if (i == 1)
  197. continue;
  198. #endif
  199. /* Create new serial device */
  200. port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL);
  201. if (!port)
  202. return -ENOMEM;
  203. memset(&uart, 0, sizeof(uart));
  204. base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
  205. /* Memory mapped I/O */
  206. uart.port.iotype = UPIO_MEM;
  207. uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ
  208. | UPF_BOOT_AUTOCONF;
  209. /* XXX - no interrupt support yet */
  210. uart.port.irq = 0;
  211. uart.port.uartclk = HPAPCI_BAUD_BASE * 16;
  212. uart.port.mapbase = base;
  213. uart.port.membase = (char *)(base + DIO_VIRADDRBASE);
  214. uart.port.regshift = 2;
  215. line = serial8250_register_8250_port(&uart);
  216. if (line < 0) {
  217. dev_notice(uart.port.dev,
  218. "8250_hp300: register_serial() APCI %d irq %d failed\n",
  219. i, uart.port.irq);
  220. kfree(port);
  221. continue;
  222. }
  223. port->line = line;
  224. port->next = hp300_ports;
  225. hp300_ports = port;
  226. num_ports++;
  227. }
  228. #endif
  229. /* Any boards found? */
  230. if (!num_ports)
  231. return -ENODEV;
  232. return 0;
  233. }
  234. #ifdef CONFIG_HPDCA
  235. static void hpdca_remove_one(struct dio_dev *d)
  236. {
  237. int line;
  238. line = (int) dio_get_drvdata(d);
  239. if (d->resource.start) {
  240. /* Disable board-interrupts */
  241. out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0);
  242. }
  243. serial8250_unregister_port(line);
  244. }
  245. #endif
  246. static void __exit hp300_8250_exit(void)
  247. {
  248. #ifdef CONFIG_HPAPCI
  249. struct hp300_port *port, *to_free;
  250. for (port = hp300_ports; port; ) {
  251. serial8250_unregister_port(port->line);
  252. to_free = port;
  253. port = port->next;
  254. kfree(to_free);
  255. }
  256. hp300_ports = NULL;
  257. #endif
  258. #ifdef CONFIG_HPDCA
  259. dio_unregister_driver(&hpdca_driver);
  260. #endif
  261. }
  262. module_init(hp300_8250_init);
  263. module_exit(hp300_8250_exit);
  264. MODULE_DESCRIPTION("HP DCA/APCI serial driver");
  265. MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
  266. MODULE_LICENSE("GPL");