8250_hp300.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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)
  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. {
  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. printk(KERN_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. printk(KERN_WARNING "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. printk(KERN_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. printk(KERN_WARNING "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. printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n");
  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. printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
  149. " irq %d failed\n", 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. printk(KERN_NOTICE "8250_hp300: register_serial() APCI"
  217. " %d irq %d failed\n", i, uart.port.irq);
  218. kfree(port);
  219. continue;
  220. }
  221. port->line = line;
  222. port->next = hp300_ports;
  223. hp300_ports = port;
  224. num_ports++;
  225. }
  226. #endif
  227. /* Any boards found? */
  228. if (!num_ports)
  229. return -ENODEV;
  230. return 0;
  231. }
  232. #ifdef CONFIG_HPDCA
  233. static void hpdca_remove_one(struct dio_dev *d)
  234. {
  235. int line;
  236. line = (int) dio_get_drvdata(d);
  237. if (d->resource.start) {
  238. /* Disable board-interrupts */
  239. out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0);
  240. }
  241. serial8250_unregister_port(line);
  242. }
  243. #endif
  244. static void __exit hp300_8250_exit(void)
  245. {
  246. #ifdef CONFIG_HPAPCI
  247. struct hp300_port *port, *to_free;
  248. for (port = hp300_ports; port; ) {
  249. serial8250_unregister_port(port->line);
  250. to_free = port;
  251. port = port->next;
  252. kfree(to_free);
  253. }
  254. hp300_ports = NULL;
  255. #endif
  256. #ifdef CONFIG_HPDCA
  257. dio_unregister_driver(&hpdca_driver);
  258. #endif
  259. }
  260. module_init(hp300_8250_init);
  261. module_exit(hp300_8250_exit);
  262. MODULE_DESCRIPTION("HP DCA/APCI serial driver");
  263. MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
  264. MODULE_LICENSE("GPL");