1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/pci.h>
17#include <linux/pnp.h>
18#include <linux/string.h>
19#include <linux/kernel.h>
20#include <linux/serial_core.h>
21#include <linux/bitops.h>
22
23#include <asm/byteorder.h>
24
25#include "8250.h"
26
27#define UNKNOWN_DEV 0x3000
28#define CIR_PORT 0x0800
29
30static const struct pnp_device_id pnp_dev_table[] = {
31
32
33 { "AAC000F", 0 },
34
35
36 { "ADC0001", 0 },
37
38 { "ADC0002", 0 },
39
40 { "AEI0250", 0 },
41
42 { "AEI1240", 0 },
43
44 { "AKY1021", 0 },
45
46 { "AZT4001", 0 },
47
48 { "BDP3336", 0 },
49
50
51 { "BRI0A49", 0 },
52
53 { "BRI1400", 0 },
54
55 { "BRI3400", 0 },
56
57 { "BRI0A49", 0 },
58
59 { "BDP3336", 0 },
60
61
62 { "CPI4050", 0 },
63
64
65 { "CTL3001", 0 },
66
67 { "CTL3011", 0 },
68
69 { "DAV0336", 0 },
70
71
72 { "DMB1032", 0 },
73
74 { "DMB2001", 0 },
75
76
77 { "ETT0002", 0 },
78
79
80 { "FUJ0202", 0 },
81
82 { "FUJ0205", 0 },
83
84 { "FUJ0206", 0 },
85
86 { "FUJ0209", 0 },
87
88
89 { "GVC000F", 0 },
90
91 { "GVC0303", 0 },
92
93
94 { "HAY0001", 0 },
95
96 { "HAY000C", 0 },
97
98 { "HAY000D", 0 },
99
100 { "HAY5670", 0 },
101
102 { "HAY5674", 0 },
103
104 { "HAY5675", 0 },
105
106 { "HAYF000", 0 },
107
108 { "HAYF001", 0 },
109
110
111 { "IBM0033", 0 },
112
113
114 { "PNP4972", 0 },
115
116
117 { "IXDC801", 0 },
118
119 { "IXDC901", 0 },
120
121 { "IXDD801", 0 },
122
123 { "IXDD901", 0 },
124
125 { "IXDF401", 0 },
126
127 { "IXDF801", 0 },
128
129 { "IXDF901", 0 },
130
131
132 { "KOR4522", 0 },
133
134 { "KORF661", 0 },
135
136
137 { "LAS4040", 0 },
138
139 { "LAS4540", 0 },
140
141 { "LAS5440", 0 },
142
143
144 { "MNP0281", 0 },
145
146 { "MNP0336", 0 },
147
148 { "MNP0339", 0 },
149
150 { "MNP0342", 0 },
151
152 { "MNP0500", 0 },
153
154 { "MNP0501", 0 },
155
156 { "MNP0502", 0 },
157
158
159 { "MOT1105", 0 },
160
161 { "MOT1111", 0 },
162
163 { "MOT1114", 0 },
164
165 { "MOT1115", 0 },
166
167 { "MOT1190", 0 },
168
169 { "MOT1501", 0 },
170
171 { "MOT1502", 0 },
172
173 { "MOT1505", 0 },
174
175 { "MOT1509", 0 },
176
177 { "MOT150A", 0 },
178
179 { "MOT150F", 0 },
180
181 { "MOT1510", 0 },
182
183 { "MOT1550", 0 },
184
185 { "MOT1560", 0 },
186
187 { "MOT1580", 0 },
188
189 { "MOT15B0", 0 },
190
191 { "MOT15F0", 0 },
192
193
194 { "MVX00A1", 0 },
195
196 { "MVX00F2", 0 },
197
198 { "nEC8241", 0 },
199
200 { "PMC2430", 0 },
201
202
203 { "PNP0500", 0 },
204
205 { "PNP0501", 0 },
206
207 { "PNPC000", 0 },
208
209 { "PNPC001", 0 },
210
211 { "PNPC031", 0 },
212
213 { "PNPC032", 0 },
214
215 { "PNPC100", 0 },
216
217 { "PNPC101", 0 },
218
219 { "PNPC102", 0 },
220
221 { "PNPC103", 0 },
222
223 { "PNPC104", 0 },
224
225 { "PNPC105", 0 },
226
227 { "PNPC106", 0 },
228
229 { "PNPC107", 0 },
230
231 { "PNPC108", 0 },
232
233 { "PNPC109", 0 },
234
235 { "PNPC10A", 0 },
236
237 { "PNPC10B", 0 },
238
239 { "PNPC10C", 0 },
240
241 { "PNPC10D", 0 },
242
243 { "PNPC10E", 0 },
244
245 { "PNPC10F", 0 },
246
247 { "PNP2000", 0 },
248
249
250
251
252 { "ROK0030", 0 },
253
254
255 { "ROK0100", 0 },
256
257 { "ROK4120", 0 },
258
259
260 { "ROK4920", 0 },
261
262
263
264
265
266
267 { "RSS00A0", 0 },
268
269 { "RSS0262", 0 },
270
271 { "RSS0250", 0 },
272
273 { "SUP1310", 0 },
274
275 { "SUP1381", 0 },
276
277 { "SUP1421", 0 },
278
279 { "SUP1590", 0 },
280
281 { "SUP1620", 0 },
282
283 { "SUP1760", 0 },
284
285 { "SUP2171", 0 },
286
287
288 { "TEX0011", 0 },
289
290
291 { "UAC000F", 0 },
292
293
294 { "USR0000", 0 },
295
296 { "USR0002", 0 },
297
298 { "USR0004", 0 },
299
300 { "USR0006", 0 },
301
302 { "USR0007", 0 },
303
304 { "USR0009", 0 },
305
306 { "USR2002", 0 },
307
308 { "USR2070", 0 },
309
310 { "USR2080", 0 },
311
312 { "USR3031", 0 },
313
314 { "USR3050", 0 },
315
316 { "USR3070", 0 },
317
318 { "USR3080", 0 },
319
320 { "USR3090", 0 },
321
322 { "USR9100", 0 },
323
324 { "USR9160", 0 },
325
326 { "USR9170", 0 },
327
328 { "USR9180", 0 },
329
330 { "USR9190", 0 },
331
332 { "WACFXXX", 0 },
333
334 { "FPI2002", 0 },
335
336 { "FUJ02B2", 0 },
337 { "FUJ02B3", 0 },
338
339 { "FUJ02B4", 0 },
340
341 { "FUJ02B6", 0 },
342 { "FUJ02B7", 0 },
343 { "FUJ02B8", 0 },
344 { "FUJ02B9", 0 },
345 { "FUJ02BC", 0 },
346
347 { "FUJ02E5", 0 },
348
349 { "FUJ02E6", 0 },
350
351 { "FUJ02E7", 0 },
352
353 { "FUJ02E9", 0 },
354
355
356
357
358 { "LTS0001", 0 },
359
360 { "WCI0003", 0 },
361
362 { "PNPCXXX", UNKNOWN_DEV },
363
364 { "PNPDXXX", UNKNOWN_DEV },
365
366
367 { "WEC1022", CIR_PORT },
368 { "", 0 }
369};
370
371MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
372
373static char *modem_names[] = {
374 "MODEM", "Modem", "modem", "FAX", "Fax", "fax",
375 "56K", "56k", "K56", "33.6", "28.8", "14.4",
376 "33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
377 "33600", "28800", "14400", "V.90", "V.34", "V.32", NULL
378};
379
380static int check_name(char *name)
381{
382 char **tmp;
383
384 for (tmp = modem_names; *tmp; tmp++)
385 if (strstr(name, *tmp))
386 return 1;
387
388 return 0;
389}
390
391static int check_resources(struct pnp_dev *dev)
392{
393 resource_size_t base[] = {0x2f8, 0x3f8, 0x2e8, 0x3e8};
394 int i;
395
396 for (i = 0; i < ARRAY_SIZE(base); i++) {
397 if (pnp_possible_config(dev, IORESOURCE_IO, base[i], 8))
398 return 1;
399 }
400
401 return 0;
402}
403
404
405
406
407
408
409
410
411
412
413
414
415static int serial_pnp_guess_board(struct pnp_dev *dev)
416{
417 if (!(check_name(pnp_dev_name(dev)) ||
418 (dev->card && check_name(dev->card->name))))
419 return -ENODEV;
420
421 if (check_resources(dev))
422 return 0;
423
424 return -ENODEV;
425}
426
427static int
428serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
429{
430 struct uart_8250_port uart, *port;
431 int ret, line, flags = dev_id->driver_data;
432
433 if (flags & UNKNOWN_DEV) {
434 ret = serial_pnp_guess_board(dev);
435 if (ret < 0)
436 return ret;
437 }
438
439 memset(&uart, 0, sizeof(uart));
440 if (pnp_irq_valid(dev, 0))
441 uart.port.irq = pnp_irq(dev, 0);
442 if ((flags & CIR_PORT) && pnp_port_valid(dev, 2)) {
443 uart.port.iobase = pnp_port_start(dev, 2);
444 uart.port.iotype = UPIO_PORT;
445 } else if (pnp_port_valid(dev, 0)) {
446 uart.port.iobase = pnp_port_start(dev, 0);
447 uart.port.iotype = UPIO_PORT;
448 } else if (pnp_mem_valid(dev, 0)) {
449 uart.port.mapbase = pnp_mem_start(dev, 0);
450 uart.port.iotype = UPIO_MEM;
451 uart.port.flags = UPF_IOREMAP;
452 } else
453 return -ENODEV;
454
455#ifdef SERIAL_DEBUG_PNP
456 printk(KERN_DEBUG
457 "Setup PNP port: port %x, mem 0x%lx, irq %d, type %d\n",
458 uart.port.iobase, uart.port.mapbase, uart.port.irq, uart.port.iotype);
459#endif
460 if (flags & CIR_PORT) {
461 uart.port.flags |= UPF_FIXED_PORT | UPF_FIXED_TYPE;
462 uart.port.type = PORT_8250_CIR;
463 }
464
465 uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
466 if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
467 uart.port.flags |= UPF_SHARE_IRQ;
468 uart.port.uartclk = 1843200;
469 uart.port.dev = &dev->dev;
470
471 line = serial8250_register_8250_port(&uart);
472 if (line < 0 || (flags & CIR_PORT))
473 return -ENODEV;
474
475 port = serial8250_get_port(line);
476 if (uart_console(&port->port))
477 dev->capabilities |= PNP_CONSOLE;
478
479 pnp_set_drvdata(dev, (void *)((long)line + 1));
480 return 0;
481}
482
483static void serial_pnp_remove(struct pnp_dev *dev)
484{
485 long line = (long)pnp_get_drvdata(dev);
486
487 dev->capabilities &= ~PNP_CONSOLE;
488 if (line)
489 serial8250_unregister_port(line - 1);
490}
491
492#ifdef CONFIG_PM
493static int serial_pnp_suspend(struct pnp_dev *dev, pm_message_t state)
494{
495 long line = (long)pnp_get_drvdata(dev);
496
497 if (!line)
498 return -ENODEV;
499 serial8250_suspend_port(line - 1);
500 return 0;
501}
502
503static int serial_pnp_resume(struct pnp_dev *dev)
504{
505 long line = (long)pnp_get_drvdata(dev);
506
507 if (!line)
508 return -ENODEV;
509 serial8250_resume_port(line - 1);
510 return 0;
511}
512#else
513#define serial_pnp_suspend NULL
514#define serial_pnp_resume NULL
515#endif
516
517static struct pnp_driver serial_pnp_driver = {
518 .name = "serial",
519 .probe = serial_pnp_probe,
520 .remove = serial_pnp_remove,
521 .suspend = serial_pnp_suspend,
522 .resume = serial_pnp_resume,
523 .id_table = pnp_dev_table,
524};
525
526int serial8250_pnp_init(void)
527{
528 return pnp_register_driver(&serial_pnp_driver);
529}
530
531void serial8250_pnp_exit(void)
532{
533 pnp_unregister_driver(&serial_pnp_driver);
534}
535
536