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