aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/8250_hp300.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/serial/8250_hp300.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/serial/8250_hp300.c')
-rw-r--r--drivers/serial/8250_hp300.c329
1 files changed, 329 insertions, 0 deletions
diff --git a/drivers/serial/8250_hp300.c b/drivers/serial/8250_hp300.c
new file mode 100644
index 000000000000..b8d51eb56bff
--- /dev/null
+++ b/drivers/serial/8250_hp300.c
@@ -0,0 +1,329 @@
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/tty.h>
13#include <linux/serial.h>
14#include <linux/serialP.h>
15#include <linux/serial_core.h>
16#include <linux/delay.h>
17#include <linux/dio.h>
18#include <linux/console.h>
19#include <asm/io.h>
20
21#if !defined(CONFIG_HPDCA) && !defined(CONFIG_HPAPCI)
22#warning CONFIG_8250 defined but neither CONFIG_HPDCA nor CONFIG_HPAPCI defined, are you sure?
23#endif
24
25#ifdef CONFIG_HPAPCI
26struct hp300_port
27{
28 struct hp300_port *next; /* next port */
29 int line; /* line (tty) number */
30};
31
32static struct hp300_port *hp300_ports;
33#endif
34
35#ifdef CONFIG_HPDCA
36
37static int __devinit hpdca_init_one(struct dio_dev *d,
38 const struct dio_device_id *ent);
39static void __devexit hpdca_remove_one(struct dio_dev *d);
40
41static struct dio_device_id hpdca_dio_tbl[] = {
42 { DIO_ID_DCA0 },
43 { DIO_ID_DCA0REM },
44 { DIO_ID_DCA1 },
45 { DIO_ID_DCA1REM },
46 { 0 }
47};
48
49static struct dio_driver hpdca_driver = {
50 .name = "hpdca",
51 .id_table = hpdca_dio_tbl,
52 .probe = hpdca_init_one,
53 .remove = __devexit_p(hpdca_remove_one),
54};
55
56#endif
57
58extern int hp300_uart_scode;
59
60/* Offset to UART registers from base of DCA */
61#define UART_OFFSET 17
62
63#define DCA_ID 0x01 /* ID (read), reset (write) */
64#define DCA_IC 0x03 /* Interrupt control */
65
66/* Interrupt control */
67#define DCA_IC_IE 0x80 /* Master interrupt enable */
68
69#define HPDCA_BAUD_BASE 153600
70
71/* Base address of the Frodo part */
72#define FRODO_BASE (0x41c000)
73
74/*
75 * Where we find the 8250-like APCI ports, and how far apart they are.
76 */
77#define FRODO_APCIBASE 0x0
78#define FRODO_APCISPACE 0x20
79#define FRODO_APCI_OFFSET(x) (FRODO_APCIBASE + ((x) * FRODO_APCISPACE))
80
81#define HPAPCI_BAUD_BASE 500400
82
83#ifdef CONFIG_SERIAL_8250_CONSOLE
84/*
85 * Parse the bootinfo to find descriptions for headless console and
86 * debug serial ports and register them with the 8250 driver.
87 * This function should be called before serial_console_init() is called
88 * to make sure the serial console will be available for use. IA-64 kernel
89 * calls this function from setup_arch() after the EFI and ACPI tables have
90 * been parsed.
91 */
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
126 }
127 else {
128#ifdef CONFIG_HPDCA
129 unsigned long pa = dio_scodetophysaddr(scode);
130 if (!pa) {
131 return 0;
132 }
133
134 printk(KERN_INFO "Serial console is HP DCA at select code %d\n", scode);
135
136 port.uartclk = HPDCA_BAUD_BASE * 16;
137 port.mapbase = (pa + UART_OFFSET);
138 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
139 port.regshift = 1;
140 port.irq = DIO_IPL(pa + DIO_VIRADDRBASE);
141
142 /* Enable board-interrupts */
143 out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
144
145 if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80) {
146 add_preferred_console("ttyS", port.line, "9600n8");
147 }
148#else
149 printk(KERN_WARNING "Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
150 return 0;
151#endif
152 }
153
154 if (early_serial_setup(&port) < 0) {
155 printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n");
156 }
157
158 return 0;
159}
160#endif /* CONFIG_SERIAL_8250_CONSOLE */
161
162#ifdef CONFIG_HPDCA
163static int __devinit hpdca_init_one(struct dio_dev *d,
164 const struct dio_device_id *ent)
165{
166 struct serial_struct serial_req;
167 int line;
168
169#ifdef CONFIG_SERIAL_8250_CONSOLE
170 if (hp300_uart_scode == d->scode) {
171 /* Already got it. */
172 return 0;
173 }
174#endif
175 memset(&serial_req, 0, sizeof(struct serial_struct));
176
177 /* Memory mapped I/O */
178 serial_req.io_type = SERIAL_IO_MEM;
179 serial_req.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
180 serial_req.irq = d->ipl;
181 serial_req.baud_base = HPDCA_BAUD_BASE;
182 serial_req.iomap_base = (d->resource.start + UART_OFFSET);
183 serial_req.iomem_base = (char *)(serial_req.iomap_base + DIO_VIRADDRBASE);
184 serial_req.iomem_reg_shift = 1;
185 line = register_serial(&serial_req);
186
187 if (line < 0) {
188 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
189 " irq %d failed\n", d->scode, serial_req.irq);
190 return -ENOMEM;
191 }
192
193 /* Enable board-interrupts */
194 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
195 dio_set_drvdata(d, (void *)line);
196
197 /* Reset the DCA */
198 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
199 udelay(100);
200
201 return 0;
202}
203#endif
204
205static int __init hp300_8250_init(void)
206{
207 static int called = 0;
208 int num_ports;
209#ifdef CONFIG_HPAPCI
210 int line;
211 unsigned long base;
212 struct serial_struct serial_req;
213 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
223 num_ports = 0;
224
225#ifdef CONFIG_HPDCA
226 if (dio_module_init(&hpdca_driver) == 0)
227 num_ports++;
228#endif
229#ifdef CONFIG_HPAPCI
230 if (hp300_model < HP_400) {
231 if (!num_ports)
232 return -ENODEV;
233 return 0;
234 }
235 /* These models have the Frodo chip.
236 * Port 0 is reserved for the Apollo Domain keyboard.
237 * Port 1 is either the console or the DCA.
238 */
239 for (i = 1; i < 4; i++) {
240 /* Port 1 is the console on a 425e, on other machines it's mapped to
241 * DCA.
242 */
243#ifdef CONFIG_SERIAL_8250_CONSOLE
244 if (i == 1) {
245 continue;
246 }
247#endif
248
249 /* Create new serial device */
250 port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL);
251 if (!port)
252 return -ENOMEM;
253
254 memset(&serial_req, 0, sizeof(struct serial_struct));
255
256 base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
257
258 /* Memory mapped I/O */
259 serial_req.io_type = SERIAL_IO_MEM;
260 serial_req.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
261 /* XXX - no interrupt support yet */
262 serial_req.irq = 0;
263 serial_req.baud_base = HPAPCI_BAUD_BASE;
264 serial_req.iomap_base = base;
265 serial_req.iomem_base = (char *)(serial_req.iomap_base + DIO_VIRADDRBASE);
266 serial_req.iomem_reg_shift = 2;
267
268 line = register_serial(&serial_req);
269
270 if (line < 0) {
271 printk(KERN_NOTICE "8250_hp300: register_serial() APCI %d"
272 " irq %d failed\n", i, serial_req.irq);
273 kfree(port);
274 continue;
275 }
276
277 port->line = line;
278 port->next = hp300_ports;
279 hp300_ports = port;
280
281 num_ports++;
282 }
283#endif
284
285 /* Any boards found? */
286 if (!num_ports)
287 return -ENODEV;
288
289 return 0;
290}
291
292#ifdef CONFIG_HPDCA
293static void __devexit hpdca_remove_one(struct dio_dev *d)
294{
295 int line;
296
297 line = (int) dio_get_drvdata(d);
298 if (d->resource.start) {
299 /* Disable board-interrupts */
300 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0);
301 }
302 unregister_serial(line);
303}
304#endif
305
306static void __exit hp300_8250_exit(void)
307{
308#ifdef CONFIG_HPAPCI
309 struct hp300_port *port, *to_free;
310
311 for (port = hp300_ports; port; ) {
312 unregister_serial(port->line);
313 to_free = port;
314 port = port->next;
315 kfree(to_free);
316 }
317
318 hp300_ports = NULL;
319#endif
320#ifdef CONFIG_HPDCA
321 dio_unregister_driver(&hpdca_driver);
322#endif
323}
324
325module_init(hp300_8250_init);
326module_exit(hp300_8250_exit);
327MODULE_DESCRIPTION("HP DCA/APCI serial driver");
328MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
329MODULE_LICENSE("GPL");