8250_hp300.c 7.4 KB

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