blob: 0e1410f2c03394362f25a07b6ce27981dff38ab2 [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>
18#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)
23#warning CONFIG_8250 defined but neither CONFIG_HPDCA nor CONFIG_HPAPCI defined, are you sure?
24#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
38static int __devinit hpdca_init_one(struct dio_dev *d,
Alan Cox0fe1c132008-02-08 04:18:50 -080039 const struct dio_device_id *ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static void __devexit hpdca_remove_one(struct dio_dev *d);
41
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,
54 .remove = __devexit_p(hpdca_remove_one),
55};
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.
90 * This function should be called before serial_console_init() is called
91 * to make sure the serial console will be available for use. IA-64 kernel
92 * calls this function from setup_arch() after the EFI and ACPI tables have
93 * been parsed.
94 */
95int __init hp300_setup_serial_console(void)
96{
97 int scode;
98 struct uart_port port;
99
100 memset(&port, 0, sizeof(port));
101
102 if (hp300_uart_scode < 0 || hp300_uart_scode > DIO_SCMAX)
103 return 0;
104
105 if (DIO_SCINHOLE(hp300_uart_scode))
106 return 0;
107
108 scode = hp300_uart_scode;
109
110 /* Memory mapped I/O */
111 port.iotype = UPIO_MEM;
112 port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
113 port.type = PORT_UNKNOWN;
114
115 /* Check for APCI console */
116 if (scode == 256) {
117#ifdef CONFIG_HPAPCI
118 printk(KERN_INFO "Serial console is HP APCI 1\n");
119
120 port.uartclk = HPAPCI_BAUD_BASE * 16;
121 port.mapbase = (FRODO_BASE + FRODO_APCI_OFFSET(1));
122 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
123 port.regshift = 2;
124 add_preferred_console("ttyS", port.line, "9600n8");
125#else
126 printk(KERN_WARNING "Serial console is APCI but support is disabled (CONFIG_HPAPCI)!\n");
127 return 0;
128#endif
Alan Cox0fe1c132008-02-08 04:18:50 -0800129 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#ifdef CONFIG_HPDCA
131 unsigned long pa = dio_scodetophysaddr(scode);
Alan Cox0fe1c132008-02-08 04:18:50 -0800132 if (!pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 printk(KERN_INFO "Serial console is HP DCA at select code %d\n", scode);
136
137 port.uartclk = HPDCA_BAUD_BASE * 16;
138 port.mapbase = (pa + UART_OFFSET);
139 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
140 port.regshift = 1;
141 port.irq = DIO_IPL(pa + DIO_VIRADDRBASE);
142
143 /* Enable board-interrupts */
144 out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
145
Alan Cox0fe1c132008-02-08 04:18:50 -0800146 if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 add_preferred_console("ttyS", port.line, "9600n8");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#else
149 printk(KERN_WARNING "Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
150 return 0;
151#endif
152 }
153
Alan Cox0fe1c132008-02-08 04:18:50 -0800154 if (early_serial_setup(&port) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return 0;
157}
158#endif /* CONFIG_SERIAL_8250_CONSOLE */
159
160#ifdef CONFIG_HPDCA
161static int __devinit hpdca_init_one(struct dio_dev *d,
Alan Cox0fe1c132008-02-08 04:18:50 -0800162 const struct dio_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Russell King2b49aba2005-04-26 15:37:45 +0100164 struct uart_port port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 int line;
166
167#ifdef CONFIG_SERIAL_8250_CONSOLE
168 if (hp300_uart_scode == d->scode) {
169 /* Already got it. */
170 return 0;
171 }
172#endif
Russell King2b49aba2005-04-26 15:37:45 +0100173 memset(&port, 0, sizeof(struct uart_port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /* Memory mapped I/O */
Russell King2b49aba2005-04-26 15:37:45 +0100176 port.iotype = UPIO_MEM;
177 port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
178 port.irq = d->ipl;
179 port.uartclk = HPDCA_BAUD_BASE * 16;
180 port.mapbase = (d->resource.start + UART_OFFSET);
181 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
182 port.regshift = 1;
183 port.dev = &d->dev;
184 line = serial8250_register_port(&port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 if (line < 0) {
187 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
Russell King2b49aba2005-04-26 15:37:45 +0100188 " irq %d failed\n", d->scode, port.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 return -ENOMEM;
190 }
191
192 /* Enable board-interrupts */
193 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
194 dio_set_drvdata(d, (void *)line);
195
196 /* Reset the DCA */
197 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
198 udelay(100);
199
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800200 num_ports++;
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return 0;
203}
204#endif
205
206static int __init hp300_8250_init(void)
207{
Alan Cox0fe1c132008-02-08 04:18:50 -0800208 static int called;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209#ifdef CONFIG_HPAPCI
210 int line;
211 unsigned long base;
Russell King2b49aba2005-04-26 15:37:45 +0100212 struct uart_port uport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 struct hp300_port *port;
214 int i;
215#endif
216 if (called)
217 return -ENODEV;
218 called = 1;
219
220 if (!MACH_IS_HP300)
221 return -ENODEV;
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#ifdef CONFIG_HPDCA
Bjorn Helgaase51c01b2006-03-25 03:07:17 -0800224 dio_register_driver(&hpdca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#endif
226#ifdef CONFIG_HPAPCI
227 if (hp300_model < HP_400) {
228 if (!num_ports)
229 return -ENODEV;
230 return 0;
231 }
232 /* These models have the Frodo chip.
233 * Port 0 is reserved for the Apollo Domain keyboard.
234 * Port 1 is either the console or the DCA.
235 */
236 for (i = 1; i < 4; i++) {
Alan Cox0fe1c132008-02-08 04:18:50 -0800237 /* Port 1 is the console on a 425e, on other machines it's
238 * mapped to DCA.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 */
240#ifdef CONFIG_SERIAL_8250_CONSOLE
Alan Cox0fe1c132008-02-08 04:18:50 -0800241 if (i == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#endif
244
245 /* Create new serial device */
246 port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL);
247 if (!port)
248 return -ENOMEM;
249
Russell King2b49aba2005-04-26 15:37:45 +0100250 memset(&uport, 0, sizeof(struct uart_port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
253
254 /* Memory mapped I/O */
Russell King2b49aba2005-04-26 15:37:45 +0100255 uport.iotype = UPIO_MEM;
Alan Cox0fe1c132008-02-08 04:18:50 -0800256 uport.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ \
257 | UPF_BOOT_AUTOCONF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 /* XXX - no interrupt support yet */
Russell King2b49aba2005-04-26 15:37:45 +0100259 uport.irq = 0;
260 uport.uartclk = HPAPCI_BAUD_BASE * 16;
261 uport.mapbase = base;
262 uport.membase = (char *)(base + DIO_VIRADDRBASE);
263 uport.regshift = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Russell King2b49aba2005-04-26 15:37:45 +0100265 line = serial8250_register_port(&uport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 if (line < 0) {
Alan Cox0fe1c132008-02-08 04:18:50 -0800268 printk(KERN_NOTICE "8250_hp300: register_serial() APCI"
269 " %d irq %d failed\n", i, uport.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 kfree(port);
271 continue;
272 }
273
274 port->line = line;
275 port->next = hp300_ports;
276 hp300_ports = port;
277
278 num_ports++;
279 }
280#endif
281
282 /* Any boards found? */
283 if (!num_ports)
284 return -ENODEV;
285
286 return 0;
287}
288
289#ifdef CONFIG_HPDCA
290static void __devexit hpdca_remove_one(struct dio_dev *d)
291{
292 int line;
293
294 line = (int) dio_get_drvdata(d);
295 if (d->resource.start) {
296 /* Disable board-interrupts */
297 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0);
298 }
Russell King2b49aba2005-04-26 15:37:45 +0100299 serial8250_unregister_port(line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
301#endif
302
303static void __exit hp300_8250_exit(void)
304{
305#ifdef CONFIG_HPAPCI
306 struct hp300_port *port, *to_free;
307
308 for (port = hp300_ports; port; ) {
Russell King2b49aba2005-04-26 15:37:45 +0100309 serial8250_unregister_port(port->line);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 to_free = port;
311 port = port->next;
312 kfree(to_free);
313 }
314
315 hp300_ports = NULL;
316#endif
317#ifdef CONFIG_HPDCA
318 dio_unregister_driver(&hpdca_driver);
319#endif
320}
321
322module_init(hp300_8250_init);
323module_exit(hp300_8250_exit);
324MODULE_DESCRIPTION("HP DCA/APCI serial driver");
325MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
326MODULE_LICENSE("GPL");