8250_hp300.c 7.6 KB

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