8250_hp300.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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/delay.h>
  15. #include <linux/dio.h>
  16. #include <linux/console.h>
  17. #include <asm/io.h>
  18. #include "8250.h"
  19. #if !defined(CONFIG_HPDCA) && !defined(CONFIG_HPAPCI)
  20. #warning CONFIG_8250 defined but neither CONFIG_HPDCA nor CONFIG_HPAPCI defined, are you sure?
  21. #endif
  22. #ifdef CONFIG_HPAPCI
  23. struct hp300_port
  24. {
  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 __devinit hpdca_init_one(struct dio_dev *d,
  32. const struct dio_device_id *ent);
  33. static void __devexit 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 = __devexit_p(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. * This function should be called before serial_console_init() is called
  71. * to make sure the serial console will be available for use. IA-64 kernel
  72. * calls this function from setup_arch() after the EFI and ACPI tables have
  73. * been parsed.
  74. */
  75. int __init hp300_setup_serial_console(void)
  76. {
  77. int scode;
  78. struct uart_port port;
  79. memset(&port, 0, sizeof(port));
  80. if (hp300_uart_scode < 0 || hp300_uart_scode > DIO_SCMAX)
  81. return 0;
  82. if (DIO_SCINHOLE(hp300_uart_scode))
  83. return 0;
  84. scode = hp300_uart_scode;
  85. /* Memory mapped I/O */
  86. port.iotype = UPIO_MEM;
  87. port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
  88. port.type = PORT_UNKNOWN;
  89. /* Check for APCI console */
  90. if (scode == 256) {
  91. #ifdef CONFIG_HPAPCI
  92. printk(KERN_INFO "Serial console is HP APCI 1\n");
  93. port.uartclk = HPAPCI_BAUD_BASE * 16;
  94. port.mapbase = (FRODO_BASE + FRODO_APCI_OFFSET(1));
  95. port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
  96. port.regshift = 2;
  97. add_preferred_console("ttyS", port.line, "9600n8");
  98. #else
  99. printk(KERN_WARNING "Serial console is APCI but support is disabled (CONFIG_HPAPCI)!\n");
  100. return 0;
  101. #endif
  102. }
  103. else {
  104. #ifdef CONFIG_HPDCA
  105. unsigned long pa = dio_scodetophysaddr(scode);
  106. if (!pa) {
  107. return 0;
  108. }
  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. }
  120. #else
  121. printk(KERN_WARNING "Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
  122. return 0;
  123. #endif
  124. }
  125. if (early_serial_setup(&port) < 0) {
  126. printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n");
  127. }
  128. return 0;
  129. }
  130. #endif /* CONFIG_SERIAL_8250_CONSOLE */
  131. #ifdef CONFIG_HPDCA
  132. static int __devinit hpdca_init_one(struct dio_dev *d,
  133. const struct dio_device_id *ent)
  134. {
  135. struct uart_port port;
  136. int line;
  137. #ifdef CONFIG_SERIAL_8250_CONSOLE
  138. if (hp300_uart_scode == d->scode) {
  139. /* Already got it. */
  140. return 0;
  141. }
  142. #endif
  143. memset(&port, 0, sizeof(struct uart_port));
  144. /* Memory mapped I/O */
  145. port.iotype = UPIO_MEM;
  146. port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
  147. port.irq = d->ipl;
  148. port.uartclk = HPDCA_BAUD_BASE * 16;
  149. port.mapbase = (d->resource.start + UART_OFFSET);
  150. port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
  151. port.regshift = 1;
  152. port.dev = &d->dev;
  153. line = serial8250_register_port(&port);
  154. if (line < 0) {
  155. printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
  156. " irq %d failed\n", d->scode, port.irq);
  157. return -ENOMEM;
  158. }
  159. /* Enable board-interrupts */
  160. out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
  161. dio_set_drvdata(d, (void *)line);
  162. /* Reset the DCA */
  163. out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
  164. udelay(100);
  165. num_ports++;
  166. return 0;
  167. }
  168. #endif
  169. static int __init hp300_8250_init(void)
  170. {
  171. static int called = 0;
  172. #ifdef CONFIG_HPAPCI
  173. int line;
  174. unsigned long base;
  175. struct uart_port uport;
  176. struct hp300_port *port;
  177. int i;
  178. #endif
  179. if (called)
  180. return -ENODEV;
  181. called = 1;
  182. if (!MACH_IS_HP300)
  183. return -ENODEV;
  184. #ifdef CONFIG_HPDCA
  185. dio_register_driver(&hpdca_driver);
  186. #endif
  187. #ifdef CONFIG_HPAPCI
  188. if (hp300_model < HP_400) {
  189. if (!num_ports)
  190. return -ENODEV;
  191. return 0;
  192. }
  193. /* These models have the Frodo chip.
  194. * Port 0 is reserved for the Apollo Domain keyboard.
  195. * Port 1 is either the console or the DCA.
  196. */
  197. for (i = 1; i < 4; i++) {
  198. /* Port 1 is the console on a 425e, on other machines it's mapped to
  199. * DCA.
  200. */
  201. #ifdef CONFIG_SERIAL_8250_CONSOLE
  202. if (i == 1) {
  203. continue;
  204. }
  205. #endif
  206. /* Create new serial device */
  207. port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL);
  208. if (!port)
  209. return -ENOMEM;
  210. memset(&uport, 0, sizeof(struct uart_port));
  211. base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
  212. /* Memory mapped I/O */
  213. uport.iotype = UPIO_MEM;
  214. uport.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
  215. /* XXX - no interrupt support yet */
  216. uport.irq = 0;
  217. uport.uartclk = HPAPCI_BAUD_BASE * 16;
  218. uport.mapbase = base;
  219. uport.membase = (char *)(base + DIO_VIRADDRBASE);
  220. uport.regshift = 2;
  221. line = serial8250_register_port(&uport);
  222. if (line < 0) {
  223. printk(KERN_NOTICE "8250_hp300: register_serial() APCI %d"
  224. " irq %d failed\n", i, uport.irq);
  225. kfree(port);
  226. continue;
  227. }
  228. port->line = line;
  229. port->next = hp300_ports;
  230. hp300_ports = port;
  231. num_ports++;
  232. }
  233. #endif
  234. /* Any boards found? */
  235. if (!num_ports)
  236. return -ENODEV;
  237. return 0;
  238. }
  239. #ifdef CONFIG_HPDCA
  240. static void __devexit hpdca_remove_one(struct dio_dev *d)
  241. {
  242. int line;
  243. line = (int) dio_get_drvdata(d);
  244. if (d->resource.start) {
  245. /* Disable board-interrupts */
  246. out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0);
  247. }
  248. serial8250_unregister_port(line);
  249. }
  250. #endif
  251. static void __exit hp300_8250_exit(void)
  252. {
  253. #ifdef CONFIG_HPAPCI
  254. struct hp300_port *port, *to_free;
  255. for (port = hp300_ports; port; ) {
  256. serial8250_unregister_port(port->line);
  257. to_free = port;
  258. port = port->next;
  259. kfree(to_free);
  260. }
  261. hp300_ports = NULL;
  262. #endif
  263. #ifdef CONFIG_HPDCA
  264. dio_unregister_driver(&hpdca_driver);
  265. #endif
  266. }
  267. module_init(hp300_8250_init);
  268. module_exit(hp300_8250_exit);
  269. MODULE_DESCRIPTION("HP DCA/APCI serial driver");
  270. MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
  271. MODULE_LICENSE("GPL");