2 * Driver for the 98626/98644/internal serial interface on hp300/hp400
3 * (based on the National Semiconductor INS8250/NS16550AF/WD16C552 UARTs)
5 * Ported from 2.2 and modified to use the normal 8250 driver
6 * by Kars de Jong <jongk@linux-m68k.org>, May 2004.
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>
22 #if !defined(CONFIG_HPDCA) && !defined(CONFIG_HPAPCI)
23 #warning CONFIG_SERIAL_8250 defined but neither CONFIG_HPDCA nor CONFIG_HPAPCI defined, are you sure?
28 struct hp300_port *next; /* next port */
29 int line; /* line (tty) number */
32 static struct hp300_port *hp300_ports;
37 static int hpdca_init_one(struct dio_dev *d,
38 const struct dio_device_id *ent);
39 static void hpdca_remove_one(struct dio_dev *d);
41 static struct dio_device_id hpdca_dio_tbl[] = {
49 static struct dio_driver hpdca_driver = {
51 .id_table = hpdca_dio_tbl,
52 .probe = hpdca_init_one,
53 .remove = hpdca_remove_one,
58 static unsigned int num_ports;
60 extern int hp300_uart_scode;
62 /* Offset to UART registers from base of DCA */
63 #define UART_OFFSET 17
65 #define DCA_ID 0x01 /* ID (read), reset (write) */
66 #define DCA_IC 0x03 /* Interrupt control */
68 /* Interrupt control */
69 #define DCA_IC_IE 0x80 /* Master interrupt enable */
71 #define HPDCA_BAUD_BASE 153600
73 /* Base address of the Frodo part */
74 #define FRODO_BASE (0x41c000)
77 * Where we find the 8250-like APCI ports, and how far apart they are.
79 #define FRODO_APCIBASE 0x0
80 #define FRODO_APCISPACE 0x20
81 #define FRODO_APCI_OFFSET(x) (FRODO_APCIBASE + ((x) * FRODO_APCISPACE))
83 #define HPAPCI_BAUD_BASE 500400
85 #ifdef CONFIG_SERIAL_8250_CONSOLE
87 * Parse the bootinfo to find descriptions for headless console and
88 * debug serial ports and register them with the 8250 driver.
90 int __init hp300_setup_serial_console(void)
93 struct uart_port port;
95 memset(&port, 0, sizeof(port));
97 if (hp300_uart_scode < 0 || hp300_uart_scode > DIO_SCMAX)
100 if (DIO_SCINHOLE(hp300_uart_scode))
103 scode = hp300_uart_scode;
105 /* Memory mapped I/O */
106 port.iotype = UPIO_MEM;
107 port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
108 port.type = PORT_UNKNOWN;
110 /* Check for APCI console */
113 pr_info("Serial console is HP APCI 1\n");
115 port.uartclk = HPAPCI_BAUD_BASE * 16;
116 port.mapbase = (FRODO_BASE + FRODO_APCI_OFFSET(1));
117 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
119 add_preferred_console("ttyS", port.line, "9600n8");
121 pr_warn("Serial console is APCI but support is disabled (CONFIG_HPAPCI)!\n");
126 unsigned long pa = dio_scodetophysaddr(scode);
130 pr_info("Serial console is HP DCA at select code %d\n", scode);
132 port.uartclk = HPDCA_BAUD_BASE * 16;
133 port.mapbase = (pa + UART_OFFSET);
134 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
136 port.irq = DIO_IPL(pa + DIO_VIRADDRBASE);
138 /* Enable board-interrupts */
139 out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
141 if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80)
142 add_preferred_console("ttyS", port.line, "9600n8");
144 pr_warn("Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
149 if (early_serial_setup(&port) < 0)
150 pr_warn("%s: early_serial_setup() failed.\n", __func__);
153 #endif /* CONFIG_SERIAL_8250_CONSOLE */
156 static int hpdca_init_one(struct dio_dev *d,
157 const struct dio_device_id *ent)
159 struct uart_8250_port uart;
162 #ifdef CONFIG_SERIAL_8250_CONSOLE
163 if (hp300_uart_scode == d->scode) {
164 /* Already got it. */
168 memset(&uart, 0, sizeof(uart));
170 /* Memory mapped I/O */
171 uart.port.iotype = UPIO_MEM;
172 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
173 uart.port.irq = d->ipl;
174 uart.port.uartclk = HPDCA_BAUD_BASE * 16;
175 uart.port.mapbase = (d->resource.start + UART_OFFSET);
176 uart.port.membase = (char *)(uart.port.mapbase + DIO_VIRADDRBASE);
177 uart.port.regshift = 1;
178 uart.port.dev = &d->dev;
179 line = serial8250_register_8250_port(&uart);
183 "8250_hp300: register_serial() DCA scode %d irq %d failed\n",
184 d->scode, uart.port.irq);
188 /* Enable board-interrupts */
189 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
190 dio_set_drvdata(d, (void *)line);
193 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
202 static int __init hp300_8250_init(void)
208 struct uart_8250_port uart;
209 struct hp300_port *port;
220 dio_register_driver(&hpdca_driver);
223 if (hp300_model < HP_400) {
228 /* These models have the Frodo chip.
229 * Port 0 is reserved for the Apollo Domain keyboard.
230 * Port 1 is either the console or the DCA.
232 for (i = 1; i < 4; i++) {
233 /* Port 1 is the console on a 425e, on other machines it's
236 #ifdef CONFIG_SERIAL_8250_CONSOLE
241 /* Create new serial device */
242 port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL);
246 memset(&uart, 0, sizeof(uart));
248 base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
250 /* Memory mapped I/O */
251 uart.port.iotype = UPIO_MEM;
252 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ
254 /* XXX - no interrupt support yet */
256 uart.port.uartclk = HPAPCI_BAUD_BASE * 16;
257 uart.port.mapbase = base;
258 uart.port.membase = (char *)(base + DIO_VIRADDRBASE);
259 uart.port.regshift = 2;
261 line = serial8250_register_8250_port(&uart);
264 dev_notice(uart.port.dev,
265 "8250_hp300: register_serial() APCI %d irq %d failed\n",
272 port->next = hp300_ports;
279 /* Any boards found? */
287 static void hpdca_remove_one(struct dio_dev *d)
291 line = (int) dio_get_drvdata(d);
292 if (d->resource.start) {
293 /* Disable board-interrupts */
294 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0);
296 serial8250_unregister_port(line);
300 static void __exit hp300_8250_exit(void)
303 struct hp300_port *port, *to_free;
305 for (port = hp300_ports; port; ) {
306 serial8250_unregister_port(port->line);
315 dio_unregister_driver(&hpdca_driver);
319 module_init(hp300_8250_init);
320 module_exit(hp300_8250_exit);
321 MODULE_DESCRIPTION("HP DCA/APCI serial driver");
322 MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
323 MODULE_LICENSE("GPL");