blob: 2891958cd8420303a5e11cac8c72f359b7c2c229 [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>
Yinghai Lub187f182007-07-18 00:49:10 -070013#include <linux/serial_8250.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/delay.h>
15#include <linux/dio.h>
16#include <linux/console.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/io.h>
19
Russell King2b49aba2005-04-26 15:37:45 +010020#include "8250.h"
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#if !defined(CONFIG_HPDCA) && !defined(CONFIG_HPAPCI)
Daniele Forsic10b7392014-08-08 17:56:30 +020023#warning CONFIG_SERIAL_8250 defined but neither CONFIG_HPDCA nor CONFIG_HPAPCI defined, are you sure?
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#endif
25
26#ifdef CONFIG_HPAPCI
27struct hp300_port
28{
29 struct hp300_port *next; /* next port */
30 int line; /* line (tty) number */
31};
32
33static struct hp300_port *hp300_ports;
34#endif
35
36#ifdef CONFIG_HPDCA
37
Bill Pemberton9671f092012-11-19 13:21:50 -050038static int hpdca_init_one(struct dio_dev *d,
Alan Cox0fe1c132008-02-08 04:18:50 -080039 const struct dio_device_id *ent);
Bill Pembertonae8d8a12012-11-19 13:26:18 -050040static void hpdca_remove_one(struct dio_dev *d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42static struct dio_device_id hpdca_dio_tbl[] = {
43 { DIO_ID_DCA0 },
44 { DIO_ID_DCA0REM },
45 { DIO_ID_DCA1 },
46 { DIO_ID_DCA1REM },
47 { 0 }
48};
49
50static struct dio_driver hpdca_driver = {
51 .name = "hpdca",
52 .id_table = hpdca_dio_tbl,
53 .probe = hpdca_init_one,
Bill Pemberton2d47b712012-11-19 13:21:34 -050054 .remove = hpdca_remove_one,
Linus Torvalds1da177e2005-04-16 15:20:36 -070055};
56
57#endif
58
Bjorn Helgaase51c01b2006-03-25 03:07:17 -080059static unsigned int num_ports;
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061extern int hp300_uart_scode;
62
63/* Offset to UART registers from base of DCA */
64#define UART_OFFSET 17
65
66#define DCA_ID 0x01 /* ID (read), reset (write) */
67#define DCA_IC 0x03 /* Interrupt control */
68
69/* Interrupt control */
70#define DCA_IC_IE 0x80 /* Master interrupt enable */
71
72#define HPDCA_BAUD_BASE 153600
73
74/* Base address of the Frodo part */
75#define FRODO_BASE (0x41c000)
76
77/*
78 * Where we find the 8250-like APCI ports, and how far apart they are.
79 */
80#define FRODO_APCIBASE 0x0
81#define FRODO_APCISPACE 0x20
82#define FRODO_APCI_OFFSET(x) (FRODO_APCIBASE + ((x) * FRODO_APCISPACE))
83
84#define HPAPCI_BAUD_BASE 500400
85
86#ifdef CONFIG_SERIAL_8250_CONSOLE
87/*
Alan Cox0fe1c132008-02-08 04:18:50 -080088 * Parse the bootinfo to find descriptions for headless console and
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 * debug serial ports and register them with the 8250 driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 */
91int __init hp300_setup_serial_console(void)
92{
93 int scode;
94 struct uart_port port;
95
96 memset(&port, 0, sizeof(port));
97
98 if (hp300_uart_scode < 0 || hp300_uart_scode > DIO_SCMAX)
99 return 0;
100
101 if (DIO_SCINHOLE(hp300_uart_scode))
102 return 0;
103
104 scode = hp300_uart_scode;
105
106 /* Memory mapped I/O */
107 port.iotype = UPIO_MEM;
108 port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
109 port.type = PORT_UNKNOWN;
110
111 /* Check for APCI console */
112 if (scode == 256) {
113#ifdef CONFIG_HPAPCI
114 printk(KERN_INFO "Serial console is HP APCI 1\n");
115
116 port.uartclk = HPAPCI_BAUD_BASE * 16;
117 port.mapbase = (FRODO_BASE + FRODO_APCI_OFFSET(1));
118 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
119 port.regshift = 2;
120 add_preferred_console("ttyS", port.line, "9600n8");
121#else
122 printk(KERN_WARNING "Serial console is APCI but support is disabled (CONFIG_HPAPCI)!\n");
123 return 0;
124#endif
Alan Cox0fe1c132008-02-08 04:18:50 -0800125 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#ifdef CONFIG_HPDCA
127 unsigned long pa = dio_scodetophysaddr(scode);
Alan Cox0fe1c132008-02-08 04:18:50 -0800128 if (!pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 printk(KERN_INFO "Serial console is HP DCA at select code %d\n", scode);
132
133 port.uartclk = HPDCA_BAUD_BASE * 16;
134 port.mapbase = (pa + UART_OFFSET);
135 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
136 port.regshift = 1;
137 port.irq = DIO_IPL(pa + DIO_VIRADDRBASE);
138
139 /* Enable board-interrupts */
140 out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
141
Alan Cox0fe1c132008-02-08 04:18:50 -0800142 if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 add_preferred_console("ttyS", port.line, "9600n8");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#else
145 printk(KERN_WARNING "Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
146 return 0;
147#endif
148 }
149
Alan Cox0fe1c132008-02-08 04:18:50 -0800150 if (early_serial_setup(&port) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 return 0;
153}
154#endif /* CONFIG_SERIAL_8250_CONSOLE */
155
156#ifdef CONFIG_HPDCA
Bill Pemberton9671f092012-11-19 13:21:50 -0500157static int hpdca_init_one(struct dio_dev *d,
Alan Cox0fe1c132008-02-08 04:18:50 -0800158 const struct dio_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Geert Uytterhoeven3e5bde82012-10-15 22:13:12 +0200160 struct uart_8250_port uart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 int line;
162
163#ifdef CONFIG_SERIAL_8250_CONSOLE
164 if (hp300_uart_scode == d->scode) {
165 /* Already got it. */
166 return 0;
167 }
168#endif
Alan Cox2655a2c2012-07-12 12:59:50 +0100169 memset(&uart, 0, sizeof(uart));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 /* Memory mapped I/O */
Geert Uytterhoeven3e5bde82012-10-15 22:13:12 +0200172 uart.port.iotype = UPIO_MEM;
173 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
174 uart.port.irq = d->ipl;
175 uart.port.uartclk = HPDCA_BAUD_BASE * 16;
176 uart.port.mapbase = (d->resource.start + UART_OFFSET);
177 uart.port.membase = (char *)(uart.port.mapbase + DIO_VIRADDRBASE);
178 uart.port.regshift = 1;
179 uart.port.dev = &d->dev;
Alan Cox2655a2c2012-07-12 12:59:50 +0100180 line = serial8250_register_8250_port(&uart);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 if (line < 0) {
183 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
Geert Uytterhoeven3e5bde82012-10-15 22:13:12 +0200184 " irq %d failed\n", d->scode, uart.port.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return -ENOMEM;
186 }
187
188 /* Enable board-interrupts */
189 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
190 dio_set_drvdata(d, (void *)line);
191
192 /* Reset the DCA */
193 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
194 udelay(100);
195
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800196 num_ports++;
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 return 0;
199}
200#endif
201
202static int __init hp300_8250_init(void)
203{
Alan Cox0fe1c132008-02-08 04:18:50 -0800204 static int called;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#ifdef CONFIG_HPAPCI
206 int line;
207 unsigned long base;
Alan Cox2655a2c2012-07-12 12:59:50 +0100208 struct uart_8250_port uart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 struct hp300_port *port;
210 int i;
211#endif
212 if (called)
213 return -ENODEV;
214 called = 1;
215
216 if (!MACH_IS_HP300)
217 return -ENODEV;
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#ifdef CONFIG_HPDCA
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800220 dio_register_driver(&hpdca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#endif
222#ifdef CONFIG_HPAPCI
223 if (hp300_model < HP_400) {
224 if (!num_ports)
225 return -ENODEV;
226 return 0;
227 }
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.
231 */
232 for (i = 1; i < 4; i++) {
Alan Cox0fe1c132008-02-08 04:18:50 -0800233 /* Port 1 is the console on a 425e, on other machines it's
234 * mapped to DCA.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 */
236#ifdef CONFIG_SERIAL_8250_CONSOLE
Alan Cox0fe1c132008-02-08 04:18:50 -0800237 if (i == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239#endif
240
241 /* Create new serial device */
242 port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL);
243 if (!port)
244 return -ENOMEM;
245
Alan Cox2655a2c2012-07-12 12:59:50 +0100246 memset(&uart, 0, sizeof(uart));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
249
250 /* Memory mapped I/O */
Alan Cox2655a2c2012-07-12 12:59:50 +0100251 uart.port.iotype = UPIO_MEM;
252 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ \
Alan Cox0fe1c132008-02-08 04:18:50 -0800253 | UPF_BOOT_AUTOCONF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 /* XXX - no interrupt support yet */
Alan Cox2655a2c2012-07-12 12:59:50 +0100255 uart.port.irq = 0;
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Alan Cox2655a2c2012-07-12 12:59:50 +0100261 line = serial8250_register_8250_port(&uart);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 if (line < 0) {
Alan Cox0fe1c132008-02-08 04:18:50 -0800264 printk(KERN_NOTICE "8250_hp300: register_serial() APCI"
Alan Cox2655a2c2012-07-12 12:59:50 +0100265 " %d irq %d failed\n", i, uart.port.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 kfree(port);
267 continue;
268 }
269
270 port->line = line;
271 port->next = hp300_ports;
272 hp300_ports = port;
273
274 num_ports++;
275 }
276#endif
277
278 /* Any boards found? */
279 if (!num_ports)
280 return -ENODEV;
281
282 return 0;
283}
284
285#ifdef CONFIG_HPDCA
Bill Pembertonae8d8a12012-11-19 13:26:18 -0500286static void hpdca_remove_one(struct dio_dev *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 int line;
289
290 line = (int) dio_get_drvdata(d);
291 if (d->resource.start) {
292 /* Disable board-interrupts */
293 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0);
294 }
Russell King2b49aba2005-04-26 15:37:45 +0100295 serial8250_unregister_port(line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297#endif
298
299static void __exit hp300_8250_exit(void)
300{
301#ifdef CONFIG_HPAPCI
302 struct hp300_port *port, *to_free;
303
304 for (port = hp300_ports; port; ) {
Russell King2b49aba2005-04-26 15:37:45 +0100305 serial8250_unregister_port(port->line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 to_free = port;
307 port = port->next;
308 kfree(to_free);
309 }
310
311 hp300_ports = NULL;
312#endif
313#ifdef CONFIG_HPDCA
314 dio_unregister_driver(&hpdca_driver);
315#endif
316}
317
318module_init(hp300_8250_init);
319module_exit(hp300_8250_exit);
320MODULE_DESCRIPTION("HP DCA/APCI serial driver");
321MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
322MODULE_LICENSE("GPL");