blob: b4882082b2470d38acc1f61947b823850d711b60 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/serial_core.h>
Yinghai Lub187f182007-07-18 00:49:10 -070014#include <linux/serial_8250.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/delay.h>
16#include <linux/dio.h>
17#include <linux/console.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/io.h>
20
Russell King2b49aba2005-04-26 15:37:45 +010021#include "8250.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#if !defined(CONFIG_HPDCA) && !defined(CONFIG_HPAPCI)
Daniele Forsic10b7392014-08-08 17:56:30 +020024#warning CONFIG_SERIAL_8250 defined but neither CONFIG_HPDCA nor CONFIG_HPAPCI defined, are you sure?
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#endif
26
27#ifdef CONFIG_HPAPCI
28struct hp300_port
29{
30 struct hp300_port *next; /* next port */
31 int line; /* line (tty) number */
32};
33
34static struct hp300_port *hp300_ports;
35#endif
36
37#ifdef CONFIG_HPDCA
38
Bill Pemberton9671f092012-11-19 13:21:50 -050039static int hpdca_init_one(struct dio_dev *d,
Alan Cox0fe1c132008-02-08 04:18:50 -080040 const struct dio_device_id *ent);
Bill Pembertonae8d8a12012-11-19 13:26:18 -050041static void hpdca_remove_one(struct dio_dev *d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43static struct dio_device_id hpdca_dio_tbl[] = {
44 { DIO_ID_DCA0 },
45 { DIO_ID_DCA0REM },
46 { DIO_ID_DCA1 },
47 { DIO_ID_DCA1REM },
48 { 0 }
49};
50
51static struct dio_driver hpdca_driver = {
52 .name = "hpdca",
53 .id_table = hpdca_dio_tbl,
54 .probe = hpdca_init_one,
Bill Pemberton2d47b712012-11-19 13:21:34 -050055 .remove = hpdca_remove_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
58#endif
59
Bjorn Helgaase51c01b2006-03-25 03:07:17 -080060static unsigned int num_ports;
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062extern int hp300_uart_scode;
63
64/* Offset to UART registers from base of DCA */
65#define UART_OFFSET 17
66
67#define DCA_ID 0x01 /* ID (read), reset (write) */
68#define DCA_IC 0x03 /* Interrupt control */
69
70/* Interrupt control */
71#define DCA_IC_IE 0x80 /* Master interrupt enable */
72
73#define HPDCA_BAUD_BASE 153600
74
75/* Base address of the Frodo part */
76#define FRODO_BASE (0x41c000)
77
78/*
79 * Where we find the 8250-like APCI ports, and how far apart they are.
80 */
81#define FRODO_APCIBASE 0x0
82#define FRODO_APCISPACE 0x20
83#define FRODO_APCI_OFFSET(x) (FRODO_APCIBASE + ((x) * FRODO_APCISPACE))
84
85#define HPAPCI_BAUD_BASE 500400
86
87#ifdef CONFIG_SERIAL_8250_CONSOLE
88/*
Alan Cox0fe1c132008-02-08 04:18:50 -080089 * Parse the bootinfo to find descriptions for headless console and
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 * debug serial ports and register them with the 8250 driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 */
92int __init hp300_setup_serial_console(void)
93{
94 int scode;
95 struct uart_port port;
96
97 memset(&port, 0, sizeof(port));
98
99 if (hp300_uart_scode < 0 || hp300_uart_scode > DIO_SCMAX)
100 return 0;
101
102 if (DIO_SCINHOLE(hp300_uart_scode))
103 return 0;
104
105 scode = hp300_uart_scode;
106
107 /* Memory mapped I/O */
108 port.iotype = UPIO_MEM;
109 port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
110 port.type = PORT_UNKNOWN;
111
112 /* Check for APCI console */
113 if (scode == 256) {
114#ifdef CONFIG_HPAPCI
115 printk(KERN_INFO "Serial console is HP APCI 1\n");
116
117 port.uartclk = HPAPCI_BAUD_BASE * 16;
118 port.mapbase = (FRODO_BASE + FRODO_APCI_OFFSET(1));
119 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
120 port.regshift = 2;
121 add_preferred_console("ttyS", port.line, "9600n8");
122#else
123 printk(KERN_WARNING "Serial console is APCI but support is disabled (CONFIG_HPAPCI)!\n");
124 return 0;
125#endif
Alan Cox0fe1c132008-02-08 04:18:50 -0800126 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#ifdef CONFIG_HPDCA
128 unsigned long pa = dio_scodetophysaddr(scode);
Alan Cox0fe1c132008-02-08 04:18:50 -0800129 if (!pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 printk(KERN_INFO "Serial console is HP DCA at select code %d\n", scode);
133
134 port.uartclk = HPDCA_BAUD_BASE * 16;
135 port.mapbase = (pa + UART_OFFSET);
136 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
137 port.regshift = 1;
138 port.irq = DIO_IPL(pa + DIO_VIRADDRBASE);
139
140 /* Enable board-interrupts */
141 out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
142
Alan Cox0fe1c132008-02-08 04:18:50 -0800143 if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 add_preferred_console("ttyS", port.line, "9600n8");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#else
146 printk(KERN_WARNING "Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
147 return 0;
148#endif
149 }
150
Alan Cox0fe1c132008-02-08 04:18:50 -0800151 if (early_serial_setup(&port) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return 0;
154}
155#endif /* CONFIG_SERIAL_8250_CONSOLE */
156
157#ifdef CONFIG_HPDCA
Bill Pemberton9671f092012-11-19 13:21:50 -0500158static int hpdca_init_one(struct dio_dev *d,
Alan Cox0fe1c132008-02-08 04:18:50 -0800159 const struct dio_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Geert Uytterhoeven3e5bde82012-10-15 22:13:12 +0200161 struct uart_8250_port uart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 int line;
163
164#ifdef CONFIG_SERIAL_8250_CONSOLE
165 if (hp300_uart_scode == d->scode) {
166 /* Already got it. */
167 return 0;
168 }
169#endif
Alan Cox2655a2c2012-07-12 12:59:50 +0100170 memset(&uart, 0, sizeof(uart));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /* Memory mapped I/O */
Geert Uytterhoeven3e5bde82012-10-15 22:13:12 +0200173 uart.port.iotype = UPIO_MEM;
174 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
175 uart.port.irq = d->ipl;
176 uart.port.uartclk = HPDCA_BAUD_BASE * 16;
177 uart.port.mapbase = (d->resource.start + UART_OFFSET);
178 uart.port.membase = (char *)(uart.port.mapbase + DIO_VIRADDRBASE);
179 uart.port.regshift = 1;
180 uart.port.dev = &d->dev;
Alan Cox2655a2c2012-07-12 12:59:50 +0100181 line = serial8250_register_8250_port(&uart);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 if (line < 0) {
184 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
Geert Uytterhoeven3e5bde82012-10-15 22:13:12 +0200185 " irq %d failed\n", d->scode, uart.port.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 return -ENOMEM;
187 }
188
189 /* Enable board-interrupts */
190 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
191 dio_set_drvdata(d, (void *)line);
192
193 /* Reset the DCA */
194 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
195 udelay(100);
196
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800197 num_ports++;
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return 0;
200}
201#endif
202
203static int __init hp300_8250_init(void)
204{
Alan Cox0fe1c132008-02-08 04:18:50 -0800205 static int called;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#ifdef CONFIG_HPAPCI
207 int line;
208 unsigned long base;
Alan Cox2655a2c2012-07-12 12:59:50 +0100209 struct uart_8250_port uart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 struct hp300_port *port;
211 int i;
212#endif
213 if (called)
214 return -ENODEV;
215 called = 1;
216
217 if (!MACH_IS_HP300)
218 return -ENODEV;
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#ifdef CONFIG_HPDCA
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800221 dio_register_driver(&hpdca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#endif
223#ifdef CONFIG_HPAPCI
224 if (hp300_model < HP_400) {
225 if (!num_ports)
226 return -ENODEV;
227 return 0;
228 }
229 /* These models have the Frodo chip.
230 * Port 0 is reserved for the Apollo Domain keyboard.
231 * Port 1 is either the console or the DCA.
232 */
233 for (i = 1; i < 4; i++) {
Alan Cox0fe1c132008-02-08 04:18:50 -0800234 /* Port 1 is the console on a 425e, on other machines it's
235 * mapped to DCA.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 */
237#ifdef CONFIG_SERIAL_8250_CONSOLE
Alan Cox0fe1c132008-02-08 04:18:50 -0800238 if (i == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240#endif
241
242 /* Create new serial device */
243 port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL);
244 if (!port)
245 return -ENOMEM;
246
Alan Cox2655a2c2012-07-12 12:59:50 +0100247 memset(&uart, 0, sizeof(uart));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
250
251 /* Memory mapped I/O */
Alan Cox2655a2c2012-07-12 12:59:50 +0100252 uart.port.iotype = UPIO_MEM;
253 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ \
Alan Cox0fe1c132008-02-08 04:18:50 -0800254 | UPF_BOOT_AUTOCONF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 /* XXX - no interrupt support yet */
Alan Cox2655a2c2012-07-12 12:59:50 +0100256 uart.port.irq = 0;
257 uart.port.uartclk = HPAPCI_BAUD_BASE * 16;
258 uart.port.mapbase = base;
259 uart.port.membase = (char *)(base + DIO_VIRADDRBASE);
260 uart.port.regshift = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Alan Cox2655a2c2012-07-12 12:59:50 +0100262 line = serial8250_register_8250_port(&uart);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 if (line < 0) {
Alan Cox0fe1c132008-02-08 04:18:50 -0800265 printk(KERN_NOTICE "8250_hp300: register_serial() APCI"
Alan Cox2655a2c2012-07-12 12:59:50 +0100266 " %d irq %d failed\n", i, uart.port.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 kfree(port);
268 continue;
269 }
270
271 port->line = line;
272 port->next = hp300_ports;
273 hp300_ports = port;
274
275 num_ports++;
276 }
277#endif
278
279 /* Any boards found? */
280 if (!num_ports)
281 return -ENODEV;
282
283 return 0;
284}
285
286#ifdef CONFIG_HPDCA
Bill Pembertonae8d8a12012-11-19 13:26:18 -0500287static void hpdca_remove_one(struct dio_dev *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 int line;
290
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);
295 }
Russell King2b49aba2005-04-26 15:37:45 +0100296 serial8250_unregister_port(line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298#endif
299
300static void __exit hp300_8250_exit(void)
301{
302#ifdef CONFIG_HPAPCI
303 struct hp300_port *port, *to_free;
304
305 for (port = hp300_ports; port; ) {
Russell King2b49aba2005-04-26 15:37:45 +0100306 serial8250_unregister_port(port->line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 to_free = port;
308 port = port->next;
309 kfree(to_free);
310 }
311
312 hp300_ports = NULL;
313#endif
314#ifdef CONFIG_HPDCA
315 dio_unregister_driver(&hpdca_driver);
316#endif
317}
318
319module_init(hp300_8250_init);
320module_exit(hp300_8250_exit);
321MODULE_DESCRIPTION("HP DCA/APCI serial driver");
322MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
323MODULE_LICENSE("GPL");