8250_hp300.c 7.6 KB

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