]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1da177e4 | 12 | #include <linux/serial.h> |
1da177e4 | 13 | #include <linux/serial_core.h> |
b187f180 | 14 | #include <linux/serial_8250.h> |
1da177e4 LT |
15 | #include <linux/delay.h> |
16 | #include <linux/dio.h> | |
17 | #include <linux/console.h> | |
18 | #include <asm/io.h> | |
19 | ||
2b49abac RK |
20 | #include "8250.h" |
21 | ||
1da177e4 LT |
22 | #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 | |
27 | struct hp300_port | |
28 | { | |
29 | struct hp300_port *next; /* next port */ | |
30 | int line; /* line (tty) number */ | |
31 | }; | |
32 | ||
33 | static struct hp300_port *hp300_ports; | |
34 | #endif | |
35 | ||
36 | #ifdef CONFIG_HPDCA | |
37 | ||
38 | static int __devinit hpdca_init_one(struct dio_dev *d, | |
39 | const struct dio_device_id *ent); | |
40 | static void __devexit hpdca_remove_one(struct dio_dev *d); | |
41 | ||
42 | static 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 | ||
50 | static 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 | ||
e51c01b0 BH |
59 | static unsigned int num_ports; |
60 | ||
1da177e4 LT |
61 | extern 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 | /* | |
88 | * Parse the bootinfo to find descriptions for headless console and | |
89 | * 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 | */ | |
95 | int __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 | |
129 | } | |
130 | else { | |
131 | #ifdef CONFIG_HPDCA | |
132 | unsigned long pa = dio_scodetophysaddr(scode); | |
133 | if (!pa) { | |
134 | return 0; | |
135 | } | |
136 | ||
137 | printk(KERN_INFO "Serial console is HP DCA at select code %d\n", scode); | |
138 | ||
139 | port.uartclk = HPDCA_BAUD_BASE * 16; | |
140 | port.mapbase = (pa + UART_OFFSET); | |
141 | port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE); | |
142 | port.regshift = 1; | |
143 | port.irq = DIO_IPL(pa + DIO_VIRADDRBASE); | |
144 | ||
145 | /* Enable board-interrupts */ | |
146 | out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE); | |
147 | ||
148 | if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80) { | |
149 | add_preferred_console("ttyS", port.line, "9600n8"); | |
150 | } | |
151 | #else | |
152 | printk(KERN_WARNING "Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n"); | |
153 | return 0; | |
154 | #endif | |
155 | } | |
156 | ||
157 | if (early_serial_setup(&port) < 0) { | |
158 | printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n"); | |
159 | } | |
160 | ||
161 | return 0; | |
162 | } | |
163 | #endif /* CONFIG_SERIAL_8250_CONSOLE */ | |
164 | ||
165 | #ifdef CONFIG_HPDCA | |
166 | static int __devinit hpdca_init_one(struct dio_dev *d, | |
167 | const struct dio_device_id *ent) | |
168 | { | |
2b49abac | 169 | struct uart_port port; |
1da177e4 LT |
170 | int line; |
171 | ||
172 | #ifdef CONFIG_SERIAL_8250_CONSOLE | |
173 | if (hp300_uart_scode == d->scode) { | |
174 | /* Already got it. */ | |
175 | return 0; | |
176 | } | |
177 | #endif | |
2b49abac | 178 | memset(&port, 0, sizeof(struct uart_port)); |
1da177e4 LT |
179 | |
180 | /* Memory mapped I/O */ | |
2b49abac RK |
181 | port.iotype = UPIO_MEM; |
182 | port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF; | |
183 | port.irq = d->ipl; | |
184 | port.uartclk = HPDCA_BAUD_BASE * 16; | |
185 | port.mapbase = (d->resource.start + UART_OFFSET); | |
186 | port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE); | |
187 | port.regshift = 1; | |
188 | port.dev = &d->dev; | |
189 | line = serial8250_register_port(&port); | |
1da177e4 LT |
190 | |
191 | if (line < 0) { | |
192 | printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d" | |
2b49abac | 193 | " irq %d failed\n", d->scode, port.irq); |
1da177e4 LT |
194 | return -ENOMEM; |
195 | } | |
196 | ||
197 | /* Enable board-interrupts */ | |
198 | out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE); | |
199 | dio_set_drvdata(d, (void *)line); | |
200 | ||
201 | /* Reset the DCA */ | |
202 | out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff); | |
203 | udelay(100); | |
204 | ||
e51c01b0 BH |
205 | num_ports++; |
206 | ||
1da177e4 LT |
207 | return 0; |
208 | } | |
209 | #endif | |
210 | ||
211 | static int __init hp300_8250_init(void) | |
212 | { | |
213 | static int called = 0; | |
1da177e4 LT |
214 | #ifdef CONFIG_HPAPCI |
215 | int line; | |
216 | unsigned long base; | |
2b49abac | 217 | struct uart_port uport; |
1da177e4 LT |
218 | struct hp300_port *port; |
219 | int i; | |
220 | #endif | |
221 | if (called) | |
222 | return -ENODEV; | |
223 | called = 1; | |
224 | ||
225 | if (!MACH_IS_HP300) | |
226 | return -ENODEV; | |
227 | ||
1da177e4 | 228 | #ifdef CONFIG_HPDCA |
e51c01b0 | 229 | dio_register_driver(&hpdca_driver); |
1da177e4 LT |
230 | #endif |
231 | #ifdef CONFIG_HPAPCI | |
232 | if (hp300_model < HP_400) { | |
233 | if (!num_ports) | |
234 | return -ENODEV; | |
235 | return 0; | |
236 | } | |
237 | /* These models have the Frodo chip. | |
238 | * Port 0 is reserved for the Apollo Domain keyboard. | |
239 | * Port 1 is either the console or the DCA. | |
240 | */ | |
241 | for (i = 1; i < 4; i++) { | |
242 | /* Port 1 is the console on a 425e, on other machines it's mapped to | |
243 | * DCA. | |
244 | */ | |
245 | #ifdef CONFIG_SERIAL_8250_CONSOLE | |
246 | if (i == 1) { | |
247 | continue; | |
248 | } | |
249 | #endif | |
250 | ||
251 | /* Create new serial device */ | |
252 | port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL); | |
253 | if (!port) | |
254 | return -ENOMEM; | |
255 | ||
2b49abac | 256 | memset(&uport, 0, sizeof(struct uart_port)); |
1da177e4 LT |
257 | |
258 | base = (FRODO_BASE + FRODO_APCI_OFFSET(i)); | |
259 | ||
260 | /* Memory mapped I/O */ | |
2b49abac RK |
261 | uport.iotype = UPIO_MEM; |
262 | uport.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF; | |
1da177e4 | 263 | /* XXX - no interrupt support yet */ |
2b49abac RK |
264 | uport.irq = 0; |
265 | uport.uartclk = HPAPCI_BAUD_BASE * 16; | |
266 | uport.mapbase = base; | |
267 | uport.membase = (char *)(base + DIO_VIRADDRBASE); | |
268 | uport.regshift = 2; | |
1da177e4 | 269 | |
2b49abac | 270 | line = serial8250_register_port(&uport); |
1da177e4 LT |
271 | |
272 | if (line < 0) { | |
273 | printk(KERN_NOTICE "8250_hp300: register_serial() APCI %d" | |
2b49abac | 274 | " irq %d failed\n", i, uport.irq); |
1da177e4 LT |
275 | kfree(port); |
276 | continue; | |
277 | } | |
278 | ||
279 | port->line = line; | |
280 | port->next = hp300_ports; | |
281 | hp300_ports = port; | |
282 | ||
283 | num_ports++; | |
284 | } | |
285 | #endif | |
286 | ||
287 | /* Any boards found? */ | |
288 | if (!num_ports) | |
289 | return -ENODEV; | |
290 | ||
291 | return 0; | |
292 | } | |
293 | ||
294 | #ifdef CONFIG_HPDCA | |
295 | static void __devexit hpdca_remove_one(struct dio_dev *d) | |
296 | { | |
297 | int line; | |
298 | ||
299 | line = (int) dio_get_drvdata(d); | |
300 | if (d->resource.start) { | |
301 | /* Disable board-interrupts */ | |
302 | out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0); | |
303 | } | |
2b49abac | 304 | serial8250_unregister_port(line); |
1da177e4 LT |
305 | } |
306 | #endif | |
307 | ||
308 | static void __exit hp300_8250_exit(void) | |
309 | { | |
310 | #ifdef CONFIG_HPAPCI | |
311 | struct hp300_port *port, *to_free; | |
312 | ||
313 | for (port = hp300_ports; port; ) { | |
2b49abac | 314 | serial8250_unregister_port(port->line); |
1da177e4 LT |
315 | to_free = port; |
316 | port = port->next; | |
317 | kfree(to_free); | |
318 | } | |
319 | ||
320 | hp300_ports = NULL; | |
321 | #endif | |
322 | #ifdef CONFIG_HPDCA | |
323 | dio_unregister_driver(&hpdca_driver); | |
324 | #endif | |
325 | } | |
326 | ||
327 | module_init(hp300_8250_init); | |
328 | module_exit(hp300_8250_exit); | |
329 | MODULE_DESCRIPTION("HP DCA/APCI serial driver"); | |
330 | MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>"); | |
331 | MODULE_LICENSE("GPL"); |