documentation: update s390 header file paths
[linux-2.6] / drivers / serial / 8250_pnp.c
1 /*
2  *  linux/drivers/char/8250_pnp.c
3  *
4  *  Probe module for 8250/16550-type ISAPNP serial ports.
5  *
6  *  Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
7  *
8  *  Copyright (C) 2001 Russell King, All Rights Reserved.
9  *
10  *  Ported to the Linux PnP Layer - (C) Adam Belay.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License.
15  */
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/pci.h>
19 #include <linux/pnp.h>
20 #include <linux/string.h>
21 #include <linux/kernel.h>
22 #include <linux/serial_core.h>
23 #include <linux/bitops.h>
24
25 #include <asm/byteorder.h>
26
27 #include "8250.h"
28
29 #define UNKNOWN_DEV 0x3000
30
31
32 static const struct pnp_device_id pnp_dev_table[] = {
33         /* Archtek America Corp. */
34         /* Archtek SmartLink Modem 3334BT Plug & Play */
35         {       "AAC000F",              0       },
36         /* Anchor Datacomm BV */
37         /* SXPro 144 External Data Fax Modem Plug & Play */
38         {       "ADC0001",              0       },
39         /* SXPro 288 External Data Fax Modem Plug & Play */
40         {       "ADC0002",              0       },
41         /* PROLiNK 1456VH ISA PnP K56flex Fax Modem */
42         {       "AEI0250",              0       },
43         /* Actiontec ISA PNP 56K X2 Fax Modem */
44         {       "AEI1240",              0       },
45         /* Rockwell 56K ACF II Fax+Data+Voice Modem */
46         {       "AKY1021",              0 /*SPCI_FL_NO_SHIRQ*/  },
47         /* AZT3005 PnP SOUND DEVICE */
48         {       "AZT4001",              0       },
49         /* Best Data Products Inc. Smart One 336F PnP Modem */
50         {       "BDP3336",              0       },
51         /*  Boca Research */
52         /* Boca Complete Ofc Communicator 14.4 Data-FAX */
53         {       "BRI0A49",              0       },
54         /* Boca Research 33,600 ACF Modem */
55         {       "BRI1400",              0       },
56         /* Boca 33.6 Kbps Internal FD34FSVD */
57         {       "BRI3400",              0       },
58         /* Boca 33.6 Kbps Internal FD34FSVD */
59         {       "BRI0A49",              0       },
60         /* Best Data Products Inc. Smart One 336F PnP Modem */
61         {       "BDP3336",              0       },
62         /* Computer Peripherals Inc */
63         /* EuroViVa CommCenter-33.6 SP PnP */
64         {       "CPI4050",              0       },
65         /* Creative Labs */
66         /* Creative Labs Phone Blaster 28.8 DSVD PnP Voice */
67         {       "CTL3001",              0       },
68         /* Creative Labs Modem Blaster 28.8 DSVD PnP Voice */
69         {       "CTL3011",              0       },
70         /* Davicom ISA 33.6K Modem */
71         {       "DAV0336",              0       },
72         /* Creative */
73         /* Creative Modem Blaster Flash56 DI5601-1 */
74         {       "DMB1032",              0       },
75         /* Creative Modem Blaster V.90 DI5660 */
76         {       "DMB2001",              0       },
77         /* E-Tech */
78         /* E-Tech CyberBULLET PC56RVP */
79         {       "ETT0002",              0       },
80         /* FUJITSU */
81         /* Fujitsu 33600 PnP-I2 R Plug & Play */
82         {       "FUJ0202",              0       },
83         /* Fujitsu FMV-FX431 Plug & Play */
84         {       "FUJ0205",              0       },
85         /* Fujitsu 33600 PnP-I4 R Plug & Play */
86         {       "FUJ0206",              0       },
87         /* Fujitsu Fax Voice 33600 PNP-I5 R Plug & Play */
88         {       "FUJ0209",              0       },
89         /* Archtek America Corp. */
90         /* Archtek SmartLink Modem 3334BT Plug & Play */
91         {       "GVC000F",              0       },
92         /* Archtek SmartLink Modem 3334BRV 33.6K Data Fax Voice */
93         {       "GVC0303",              0       },
94         /* Hayes */
95         /* Hayes Optima 288 V.34-V.FC + FAX + Voice Plug & Play */
96         {       "HAY0001",              0       },
97         /* Hayes Optima 336 V.34 + FAX + Voice PnP */
98         {       "HAY000C",              0       },
99         /* Hayes Optima 336B V.34 + FAX + Voice PnP */
100         {       "HAY000D",              0       },
101         /* Hayes Accura 56K Ext Fax Modem PnP */
102         {       "HAY5670",              0       },
103         /* Hayes Accura 56K Ext Fax Modem PnP */
104         {       "HAY5674",              0       },
105         /* Hayes Accura 56K Fax Modem PnP */
106         {       "HAY5675",              0       },
107         /* Hayes 288, V.34 + FAX */
108         {       "HAYF000",              0       },
109         /* Hayes Optima 288 V.34 + FAX + Voice, Plug & Play */
110         {       "HAYF001",              0       },
111         /* IBM */
112         /* IBM Thinkpad 701 Internal Modem Voice */
113         {       "IBM0033",              0       },
114         /* Intertex */
115         /* Intertex 28k8 33k6 Voice EXT PnP */
116         {       "IXDC801",              0       },
117         /* Intertex 33k6 56k Voice EXT PnP */
118         {       "IXDC901",              0       },
119         /* Intertex 28k8 33k6 Voice SP EXT PnP */
120         {       "IXDD801",              0       },
121         /* Intertex 33k6 56k Voice SP EXT PnP */
122         {       "IXDD901",              0       },
123         /* Intertex 28k8 33k6 Voice SP INT PnP */
124         {       "IXDF401",              0       },
125         /* Intertex 28k8 33k6 Voice SP EXT PnP */
126         {       "IXDF801",              0       },
127         /* Intertex 33k6 56k Voice SP EXT PnP */
128         {       "IXDF901",              0       },
129         /* Kortex International */
130         /* KORTEX 28800 Externe PnP */
131         {       "KOR4522",              0       },
132         /* KXPro 33.6 Vocal ASVD PnP */
133         {       "KORF661",              0       },
134         /* Lasat */
135         /* LASAT Internet 33600 PnP */
136         {       "LAS4040",              0       },
137         /* Lasat Safire 560 PnP */
138         {       "LAS4540",              0       },
139         /* Lasat Safire 336  PnP */
140         {       "LAS5440",              0       },
141         /* Microcom, Inc. */
142         /* Microcom TravelPorte FAST V.34 Plug & Play */
143         {       "MNP0281",              0       },
144         /* Microcom DeskPorte V.34 FAST or FAST+ Plug & Play */
145         {       "MNP0336",              0       },
146         /* Microcom DeskPorte FAST EP 28.8 Plug & Play */
147         {       "MNP0339",              0       },
148         /* Microcom DeskPorte 28.8P Plug & Play */
149         {       "MNP0342",              0       },
150         /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
151         {       "MNP0500",              0       },
152         /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
153         {       "MNP0501",              0       },
154         /* Microcom DeskPorte 28.8S Internal Plug & Play */
155         {       "MNP0502",              0       },
156         /* Motorola */
157         /* Motorola BitSURFR Plug & Play */
158         {       "MOT1105",              0       },
159         /* Motorola TA210 Plug & Play */
160         {       "MOT1111",              0       },
161         /* Motorola HMTA 200 (ISDN) Plug & Play */
162         {       "MOT1114",              0       },
163         /* Motorola BitSURFR Plug & Play */
164         {       "MOT1115",              0       },
165         /* Motorola Lifestyle 28.8 Internal */
166         {       "MOT1190",              0       },
167         /* Motorola V.3400 Plug & Play */
168         {       "MOT1501",              0       },
169         /* Motorola Lifestyle 28.8 V.34 Plug & Play */
170         {       "MOT1502",              0       },
171         /* Motorola Power 28.8 V.34 Plug & Play */
172         {       "MOT1505",              0       },
173         /* Motorola ModemSURFR External 28.8 Plug & Play */
174         {       "MOT1509",              0       },
175         /* Motorola Premier 33.6 Desktop Plug & Play */
176         {       "MOT150A",              0       },
177         /* Motorola VoiceSURFR 56K External PnP */
178         {       "MOT150F",              0       },
179         /* Motorola ModemSURFR 56K External PnP */
180         {       "MOT1510",              0       },
181         /* Motorola ModemSURFR 56K Internal PnP */
182         {       "MOT1550",              0       },
183         /* Motorola ModemSURFR Internal 28.8 Plug & Play */
184         {       "MOT1560",              0       },
185         /* Motorola Premier 33.6 Internal Plug & Play */
186         {       "MOT1580",              0       },
187         /* Motorola OnlineSURFR 28.8 Internal Plug & Play */
188         {       "MOT15B0",              0       },
189         /* Motorola VoiceSURFR 56K Internal PnP */
190         {       "MOT15F0",              0       },
191         /* Com 1 */
192         /*  Deskline K56 Phone System PnP */
193         {       "MVX00A1",              0       },
194         /* PC Rider K56 Phone System PnP */
195         {       "MVX00F2",              0       },
196         /* NEC 98NOTE SPEAKER PHONE FAX MODEM(33600bps) */
197         {       "nEC8241",              0       },
198         /* Pace 56 Voice Internal Plug & Play Modem */
199         {       "PMC2430",              0       },
200         /* Generic */
201         /* Generic standard PC COM port  */
202         {       "PNP0500",              0       },
203         /* Generic 16550A-compatible COM port */
204         {       "PNP0501",              0       },
205         /* Compaq 14400 Modem */
206         {       "PNPC000",              0       },
207         /* Compaq 2400/9600 Modem */
208         {       "PNPC001",              0       },
209         /* Dial-Up Networking Serial Cable between 2 PCs */
210         {       "PNPC031",              0       },
211         /* Dial-Up Networking Parallel Cable between 2 PCs */
212         {       "PNPC032",              0       },
213         /* Standard 9600 bps Modem */
214         {       "PNPC100",              0       },
215         /* Standard 14400 bps Modem */
216         {       "PNPC101",              0       },
217         /*  Standard 28800 bps Modem*/
218         {       "PNPC102",              0       },
219         /*  Standard Modem*/
220         {       "PNPC103",              0       },
221         /*  Standard 9600 bps Modem*/
222         {       "PNPC104",              0       },
223         /*  Standard 14400 bps Modem*/
224         {       "PNPC105",              0       },
225         /*  Standard 28800 bps Modem*/
226         {       "PNPC106",              0       },
227         /*  Standard Modem */
228         {       "PNPC107",              0       },
229         /* Standard 9600 bps Modem */
230         {       "PNPC108",              0       },
231         /* Standard 14400 bps Modem */
232         {       "PNPC109",              0       },
233         /* Standard 28800 bps Modem */
234         {       "PNPC10A",              0       },
235         /* Standard Modem */
236         {       "PNPC10B",              0       },
237         /* Standard 9600 bps Modem */
238         {       "PNPC10C",              0       },
239         /* Standard 14400 bps Modem */
240         {       "PNPC10D",              0       },
241         /* Standard 28800 bps Modem */
242         {       "PNPC10E",              0       },
243         /* Standard Modem */
244         {       "PNPC10F",              0       },
245         /* Standard PCMCIA Card Modem */
246         {       "PNP2000",              0       },
247         /* Rockwell */
248         /* Modular Technology */
249         /* Rockwell 33.6 DPF Internal PnP */
250         /* Modular Technology 33.6 Internal PnP */
251         {       "ROK0030",              0       },
252         /* Kortex International */
253         /* KORTEX 14400 Externe PnP */
254         {       "ROK0100",              0       },
255         /* Rockwell 28.8 */
256         {       "ROK4120",              0       },
257         /* Viking Components, Inc */
258         /* Viking 28.8 INTERNAL Fax+Data+Voice PnP */
259         {       "ROK4920",              0       },
260         /* Rockwell */
261         /* British Telecom */
262         /* Modular Technology */
263         /* Rockwell 33.6 DPF External PnP */
264         /* BT Prologue 33.6 External PnP */
265         /* Modular Technology 33.6 External PnP */
266         {       "RSS00A0",              0       },
267         /* Viking 56K FAX INT */
268         {       "RSS0262",              0       },
269         /* K56 par,VV,Voice,Speakphone,AudioSpan,PnP */
270         {       "RSS0250",              0       },
271         /* SupraExpress 28.8 Data/Fax PnP modem */
272         {       "SUP1310",              0       },
273         /* SupraExpress 33.6 Data/Fax PnP modem */
274         {       "SUP1421",              0       },
275         /* SupraExpress 33.6 Data/Fax PnP modem */
276         {       "SUP1590",              0       },
277         /* SupraExpress 336i Sp ASVD */
278         {       "SUP1620",              0       },
279         /* SupraExpress 33.6 Data/Fax PnP modem */
280         {       "SUP1760",              0       },
281         /* SupraExpress 56i Sp Intl */
282         {       "SUP2171",              0       },
283         /* Phoebe Micro */
284         /* Phoebe Micro 33.6 Data Fax 1433VQH Plug & Play */
285         {       "TEX0011",              0       },
286         /* Archtek America Corp. */
287         /* Archtek SmartLink Modem 3334BT Plug & Play */
288         {       "UAC000F",              0       },
289         /* 3Com Corp. */
290         /* Gateway Telepath IIvi 33.6 */
291         {       "USR0000",              0       },
292         /* U.S. Robotics Sporster 33.6K Fax INT PnP */
293         {       "USR0002",              0       },
294         /*  Sportster Vi 14.4 PnP FAX Voicemail */
295         {       "USR0004",              0       },
296         /* U.S. Robotics 33.6K Voice INT PnP */
297         {       "USR0006",              0       },
298         /* U.S. Robotics 33.6K Voice EXT PnP */
299         {       "USR0007",              0       },
300         /* U.S. Robotics Courier V.Everything INT PnP */
301         {       "USR0009",              0       },
302         /* U.S. Robotics 33.6K Voice INT PnP */
303         {       "USR2002",              0       },
304         /* U.S. Robotics 56K Voice INT PnP */
305         {       "USR2070",              0       },
306         /* U.S. Robotics 56K Voice EXT PnP */
307         {       "USR2080",              0       },
308         /* U.S. Robotics 56K FAX INT */
309         {       "USR3031",              0       },
310         /* U.S. Robotics 56K FAX INT */
311         {       "USR3050",              0       },
312         /* U.S. Robotics 56K Voice INT PnP */
313         {       "USR3070",              0       },
314         /* U.S. Robotics 56K Voice EXT PnP */
315         {       "USR3080",              0       },
316         /* U.S. Robotics 56K Voice INT PnP */
317         {       "USR3090",              0       },
318         /* U.S. Robotics 56K Message  */
319         {       "USR9100",              0       },
320         /* U.S. Robotics 56K FAX EXT PnP*/
321         {       "USR9160",              0       },
322         /* U.S. Robotics 56K FAX INT PnP*/
323         {       "USR9170",              0       },
324         /* U.S. Robotics 56K Voice EXT PnP*/
325         {       "USR9180",              0       },
326         /* U.S. Robotics 56K Voice INT PnP*/
327         {       "USR9190",              0       },
328         /* Wacom tablets */
329         {       "WACF004",              0       },
330         {       "WACF005",              0       },
331         {       "WACF006",              0       },
332         {       "WACF007",              0       },
333         {       "WACF008",              0       },
334         /* Compaq touchscreen */
335         {       "FPI2002",              0 },
336         /* Fujitsu Stylistic touchscreens */
337         {       "FUJ02B2",              0 },
338         {       "FUJ02B3",              0 },
339         /* Fujitsu Stylistic LT touchscreens */
340         {       "FUJ02B4",              0 },
341         /* Passive Fujitsu Stylistic touchscreens */
342         {       "FUJ02B6",              0 },
343         {       "FUJ02B7",              0 },
344         {       "FUJ02B8",              0 },
345         {       "FUJ02B9",              0 },
346         {       "FUJ02BC",              0 },
347         /* Fujitsu Wacom Tablet PC devices */
348         {       "FUJ02E5",              0       },
349         {       "FUJ02E6",              0       },
350         /*
351          * LG C1 EXPRESS DUAL (C1-PB11A3) touch screen (actually a FUJ02E6 in
352          * disguise)
353          */
354         {       "LTS0001",              0       },
355         /* Rockwell's (PORALiNK) 33600 INT PNP */
356         {       "WCI0003",              0       },
357         /* Unkown PnP modems */
358         {       "PNPCXXX",              UNKNOWN_DEV     },
359         /* More unkown PnP modems */
360         {       "PNPDXXX",              UNKNOWN_DEV     },
361         {       "",                     0       }
362 };
363
364 MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
365
366 static char *modem_names[] __devinitdata = {
367         "MODEM", "Modem", "modem", "FAX", "Fax", "fax",
368         "56K", "56k", "K56", "33.6", "28.8", "14.4",
369         "33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
370         "33600", "28800", "14400", "V.90", "V.34", "V.32", NULL
371 };
372
373 static int __devinit check_name(char *name)
374 {
375         char **tmp;
376
377         for (tmp = modem_names; *tmp; tmp++)
378                 if (strstr(name, *tmp))
379                         return 1;
380
381         return 0;
382 }
383
384 static int __devinit check_resources(struct pnp_dev *dev)
385 {
386         resource_size_t base[] = {0x2f8, 0x3f8, 0x2e8, 0x3e8};
387         int i;
388
389         for (i = 0; i < ARRAY_SIZE(base); i++) {
390                 if (pnp_possible_config(dev, IORESOURCE_IO, base[i], 8))
391                         return 1;
392         }
393
394         return 0;
395 }
396
397 /*
398  * Given a complete unknown PnP device, try to use some heuristics to
399  * detect modems. Currently use such heuristic set:
400  *     - dev->name or dev->bus->name must contain "modem" substring;
401  *     - device must have only one IO region (8 byte long) with base address
402  *       0x2e8, 0x3e8, 0x2f8 or 0x3f8.
403  *
404  * Such detection looks very ugly, but can detect at least some of numerous
405  * PnP modems, alternatively we must hardcode all modems in pnp_devices[]
406  * table.
407  */
408 static int __devinit serial_pnp_guess_board(struct pnp_dev *dev, int *flags)
409 {
410         if (!(check_name(pnp_dev_name(dev)) ||
411                 (dev->card && check_name(dev->card->name))))
412                         return -ENODEV;
413
414         if (check_resources(dev))
415                 return 0;
416
417         return -ENODEV;
418 }
419
420 static int __devinit
421 serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
422 {
423         struct uart_port port;
424         int ret, line, flags = dev_id->driver_data;
425
426         if (flags & UNKNOWN_DEV) {
427                 ret = serial_pnp_guess_board(dev, &flags);
428                 if (ret < 0)
429                         return ret;
430         }
431
432         memset(&port, 0, sizeof(struct uart_port));
433         if (pnp_irq_valid(dev, 0))
434                 port.irq = pnp_irq(dev, 0);
435         if (pnp_port_valid(dev, 0)) {
436                 port.iobase = pnp_port_start(dev, 0);
437                 port.iotype = UPIO_PORT;
438         } else if (pnp_mem_valid(dev, 0)) {
439                 port.mapbase = pnp_mem_start(dev, 0);
440                 port.iotype = UPIO_MEM;
441                 port.flags = UPF_IOREMAP;
442         } else
443                 return -ENODEV;
444
445 #ifdef SERIAL_DEBUG_PNP
446         printk(KERN_DEBUG
447                 "Setup PNP port: port %x, mem 0x%lx, irq %d, type %d\n",
448                        port.iobase, port.mapbase, port.irq, port.iotype);
449 #endif
450
451         port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
452         if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
453                 port.flags |= UPF_SHARE_IRQ;
454         port.uartclk = 1843200;
455         port.dev = &dev->dev;
456
457         line = serial8250_register_port(&port);
458         if (line < 0)
459                 return -ENODEV;
460
461         pnp_set_drvdata(dev, (void *)((long)line + 1));
462         return 0;
463 }
464
465 static void __devexit serial_pnp_remove(struct pnp_dev *dev)
466 {
467         long line = (long)pnp_get_drvdata(dev);
468         if (line)
469                 serial8250_unregister_port(line - 1);
470 }
471
472 #ifdef CONFIG_PM
473 static int serial_pnp_suspend(struct pnp_dev *dev, pm_message_t state)
474 {
475         long line = (long)pnp_get_drvdata(dev);
476
477         if (!line)
478                 return -ENODEV;
479         serial8250_suspend_port(line - 1);
480         return 0;
481 }
482
483 static int serial_pnp_resume(struct pnp_dev *dev)
484 {
485         long line = (long)pnp_get_drvdata(dev);
486
487         if (!line)
488                 return -ENODEV;
489         serial8250_resume_port(line - 1);
490         return 0;
491 }
492 #else
493 #define serial_pnp_suspend NULL
494 #define serial_pnp_resume NULL
495 #endif /* CONFIG_PM */
496
497 static struct pnp_driver serial_pnp_driver = {
498         .name           = "serial",
499         .probe          = serial_pnp_probe,
500         .remove         = __devexit_p(serial_pnp_remove),
501         .suspend        = serial_pnp_suspend,
502         .resume         = serial_pnp_resume,
503         .id_table       = pnp_dev_table,
504 };
505
506 static int __init serial8250_pnp_init(void)
507 {
508         return pnp_register_driver(&serial_pnp_driver);
509 }
510
511 static void __exit serial8250_pnp_exit(void)
512 {
513         pnp_unregister_driver(&serial_pnp_driver);
514 }
515
516 module_init(serial8250_pnp_init);
517 module_exit(serial8250_pnp_exit);
518
519 MODULE_LICENSE("GPL");
520 MODULE_DESCRIPTION("Generic 8250/16x50 PnP serial driver");