patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / 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  *  $Id: 8250_pnp.c,v 1.10 2002/07/21 21:32:30 rmk Exp $
17  */
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/pci.h>
21 #include <linux/pnp.h>
22 #include <linux/string.h>
23 #include <linux/kernel.h>
24 #include <linux/tty.h>
25 #include <linux/serial.h>
26 #include <linux/serialP.h>
27 #include <linux/serial_core.h>
28
29 #include <asm/bitops.h>
30 #include <asm/byteorder.h>
31 #include <asm/serial.h>
32
33 #include "8250.h"
34
35 #define UNKNOWN_DEV 0x3000
36
37
38 static const struct pnp_device_id pnp_dev_table[] = {
39         /* Archtek America Corp. */
40         /* Archtek SmartLink Modem 3334BT Plug & Play */
41         {       "AAC000F",              0       },
42         /* Anchor Datacomm BV */
43         /* SXPro 144 External Data Fax Modem Plug & Play */
44         {       "ADC0001",              0       },
45         /* SXPro 288 External Data Fax Modem Plug & Play */
46         {       "ADC0002",              0       },
47         /* PROLiNK 1456VH ISA PnP K56flex Fax Modem */
48         {       "AEI0250",              0       },
49         /* Actiontec ISA PNP 56K X2 Fax Modem */
50         {       "AEI1240",              0       },
51         /* Rockwell 56K ACF II Fax+Data+Voice Modem */
52         {       "AKY1021",              SPCI_FL_NO_SHIRQ        },
53         /* AZT3005 PnP SOUND DEVICE */
54         {       "AZT4001",              0       },
55         /* Best Data Products Inc. Smart One 336F PnP Modem */
56         {       "BDP3336",              0       },
57         /*  Boca Research */
58         /* Boca Complete Ofc Communicator 14.4 Data-FAX */
59         {       "BRI0A49",              0       },
60         /* Boca Research 33,600 ACF Modem */
61         {       "BRI1400",              0       },
62         /* Boca 33.6 Kbps Internal FD34FSVD */
63         {       "BRI3400",              0       },
64         /* Boca 33.6 Kbps Internal FD34FSVD */
65         {       "BRI0A49",              0       },
66         /* Best Data Products Inc. Smart One 336F PnP Modem */
67         {       "BDP3336",              0       },
68         /* Computer Peripherals Inc */
69         /* EuroViVa CommCenter-33.6 SP PnP */
70         {       "CPI4050",              0       },
71         /* Creative Labs */
72         /* Creative Labs Phone Blaster 28.8 DSVD PnP Voice */
73         {       "CTL3001",              0       },
74         /* Creative Labs Modem Blaster 28.8 DSVD PnP Voice */
75         {       "CTL3011",              0       },
76         /* Creative */
77         /* Creative Modem Blaster Flash56 DI5601-1 */
78         {       "DMB1032",              0       },
79         /* Creative Modem Blaster V.90 DI5660 */
80         {       "DMB2001",              0       },
81         /* E-Tech */
82         /* E-Tech CyberBULLET PC56RVP */
83         {       "ETT0002",              0       },
84         /* FUJITSU */
85         /* Fujitsu 33600 PnP-I2 R Plug & Play */
86         {       "FUJ0202",              0       },
87         /* Fujitsu FMV-FX431 Plug & Play */
88         {       "FUJ0205",              0       },
89         /* Fujitsu 33600 PnP-I4 R Plug & Play */
90         {       "FUJ0206",              0       },
91         /* Fujitsu Fax Voice 33600 PNP-I5 R Plug & Play */
92         {       "FUJ0209",              0       },
93         /* Archtek America Corp. */
94         /* Archtek SmartLink Modem 3334BT Plug & Play */
95         {       "GVC000F",              0       },
96         /* Hayes */
97         /* Hayes Optima 288 V.34-V.FC + FAX + Voice Plug & Play */
98         {       "HAY0001",              0       },
99         /* Hayes Optima 336 V.34 + FAX + Voice PnP */
100         {       "HAY000C",              0       },
101         /* Hayes Optima 336B V.34 + FAX + Voice PnP */
102         {       "HAY000D",              0       },
103         /* Hayes Accura 56K Ext Fax Modem PnP */
104         {       "HAY5670",              0       },
105         /* Hayes Accura 56K Ext Fax Modem PnP */
106         {       "HAY5674",              0       },
107         /* Hayes Accura 56K Fax Modem PnP */
108         {       "HAY5675",              0       },
109         /* Hayes 288, V.34 + FAX */
110         {       "HAYF000",              0       },
111         /* Hayes Optima 288 V.34 + FAX + Voice, Plug & Play */
112         {       "HAYF001",              0       },
113         /* IBM */
114         /* IBM Thinkpad 701 Internal Modem Voice */
115         {       "IBM0033",              0       },
116         /* Intertex */
117         /* Intertex 28k8 33k6 Voice EXT PnP */
118         {       "IXDC801",              0       },
119         /* Intertex 33k6 56k Voice EXT PnP */
120         {       "IXDC901",              0       },
121         /* Intertex 28k8 33k6 Voice SP EXT PnP */
122         {       "IXDD801",              0       },
123         /* Intertex 33k6 56k Voice SP EXT PnP */
124         {       "IXDD901",              0       },
125         /* Intertex 28k8 33k6 Voice SP INT PnP */
126         {       "IXDF401",              0       },
127         /* Intertex 28k8 33k6 Voice SP EXT PnP */
128         {       "IXDF801",              0       },
129         /* Intertex 33k6 56k Voice SP EXT PnP */
130         {       "IXDF901",              0       },
131         /* Kortex International */
132         /* KORTEX 28800 Externe PnP */
133         {       "KOR4522",              0       },
134         /* KXPro 33.6 Vocal ASVD PnP */
135         {       "KORF661",              0       },
136         /* Lasat */
137         /* LASAT Internet 33600 PnP */
138         {       "LAS4040",              0       },
139         /* Lasat Safire 560 PnP */
140         {       "LAS4540",              0       },
141         /* Lasat Safire 336  PnP */
142         {       "LAS5440",              0       },
143         /* Microcom, Inc. */
144         /* Microcom TravelPorte FAST V.34 Plug & Play */
145         {       "MNP0281",              0       },
146         /* Microcom DeskPorte V.34 FAST or FAST+ Plug & Play */
147         {       "MNP0336",              0       },
148         /* Microcom DeskPorte FAST EP 28.8 Plug & Play */
149         {       "MNP0339",              0       },
150         /* Microcom DeskPorte 28.8P Plug & Play */
151         {       "MNP0342",              0       },
152         /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
153         {       "MNP0500",              0       },
154         /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
155         {       "MNP0501",              0       },
156         /* Microcom DeskPorte 28.8S Internal Plug & Play */
157         {       "MNP0502",              0       },
158         /* Motorola */
159         /* Motorola BitSURFR Plug & Play */
160         {       "MOT1105",              0       },
161         /* Motorola TA210 Plug & Play */
162         {       "MOT1111",              0       },
163         /* Motorola HMTA 200 (ISDN) Plug & Play */
164         {       "MOT1114",              0       },
165         /* Motorola BitSURFR Plug & Play */
166         {       "MOT1115",              0       },
167         /* Motorola Lifestyle 28.8 Internal */
168         {       "MOT1190",              0       },
169         /* Motorola V.3400 Plug & Play */
170         {       "MOT1501",              0       },
171         /* Motorola Lifestyle 28.8 V.34 Plug & Play */
172         {       "MOT1502",              0       },
173         /* Motorola Power 28.8 V.34 Plug & Play */
174         {       "MOT1505",              0       },
175         /* Motorola ModemSURFR External 28.8 Plug & Play */
176         {       "MOT1509",              0       },
177         /* Motorola Premier 33.6 Desktop Plug & Play */
178         {       "MOT150A",              0       },
179         /* Motorola VoiceSURFR 56K External PnP */
180         {       "MOT150F",              0       },
181         /* Motorola ModemSURFR 56K External PnP */
182         {       "MOT1510",              0       },
183         /* Motorola ModemSURFR 56K Internal PnP */
184         {       "MOT1550",              0       },
185         /* Motorola ModemSURFR Internal 28.8 Plug & Play */
186         {       "MOT1560",              0       },
187         /* Motorola Premier 33.6 Internal Plug & Play */
188         {       "MOT1580",              0       },
189         /* Motorola OnlineSURFR 28.8 Internal Plug & Play */
190         {       "MOT15B0",              0       },
191         /* Motorola VoiceSURFR 56K Internal PnP */
192         {       "MOT15F0",              0       },
193         /* Com 1 */
194         /*  Deskline K56 Phone System PnP */
195         {       "MVX00A1",              0       },
196         /* PC Rider K56 Phone System PnP */
197         {       "MVX00F2",              0       },
198         /* NEC 98NOTE SPEAKER PHONE FAX MODEM(33600bps) */
199         {       "nEC8241",              0       },
200         /* Pace 56 Voice Internal Plug & Play Modem */
201         {       "PMC2430",              0       },
202         /* Generic */
203         /* Generic standard PC COM port  */
204         {       "PNP0500",              0       },
205         /* Generic 16550A-compatible COM port */
206         {       "PNP0501",              0       },
207         /* Compaq 14400 Modem */
208         {       "PNPC000",              0       },
209         /* Compaq 2400/9600 Modem */
210         {       "PNPC001",              0       },
211         /* Dial-Up Networking Serial Cable between 2 PCs */
212         {       "PNPC031",              0       },
213         /* Dial-Up Networking Parallel Cable between 2 PCs */
214         {       "PNPC032",              0       },
215         /* Standard 9600 bps Modem */
216         {       "PNPC100",              0       },
217         /* Standard 14400 bps Modem */
218         {       "PNPC101",              0       },
219         /*  Standard 28800 bps Modem*/
220         {       "PNPC102",              0       },
221         /*  Standard Modem*/
222         {       "PNPC103",              0       },
223         /*  Standard 9600 bps Modem*/
224         {       "PNPC104",              0       },
225         /*  Standard 14400 bps Modem*/
226         {       "PNPC105",              0       },
227         /*  Standard 28800 bps Modem*/
228         {       "PNPC106",              0       },
229         /*  Standard Modem */
230         {       "PNPC107",              0       },
231         /* Standard 9600 bps Modem */
232         {       "PNPC108",              0       },
233         /* Standard 14400 bps Modem */
234         {       "PNPC109",              0       },
235         /* Standard 28800 bps Modem */
236         {       "PNPC10A",              0       },
237         /* Standard Modem */
238         {       "PNPC10B",              0       },
239         /* Standard 9600 bps Modem */
240         {       "PNPC10C",              0       },
241         /* Standard 14400 bps Modem */
242         {       "PNPC10D",              0       },
243         /* Standard 28800 bps Modem */
244         {       "PNPC10E",              0       },
245         /* Standard Modem */
246         {       "PNPC10F",              0       },
247         /* Standard PCMCIA Card Modem */
248         {       "PNP2000",              0       },
249         /* Rockwell */
250         /* Modular Technology */
251         /* Rockwell 33.6 DPF Internal PnP */
252         /* Modular Technology 33.6 Internal PnP */
253         {       "ROK0030",              0       },
254         /* Kortex International */
255         /* KORTEX 14400 Externe PnP */
256         {       "ROK0100",              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 33.6 Data/Fax PnP modem */
278         {       "SUP1760",              0       },
279         /* Phoebe Micro */
280         /* Phoebe Micro 33.6 Data Fax 1433VQH Plug & Play */
281         {       "TEX0011",              0       },
282         /* Archtek America Corp. */
283         /* Archtek SmartLink Modem 3334BT Plug & Play */
284         {       "UAC000F",              0       },
285         /* 3Com Corp. */
286         /* Gateway Telepath IIvi 33.6 */
287         {       "USR0000",              0       },
288         /* U.S. Robotics Sporster 33.6K Fax INT PnP */
289         {       "USR0002",              0       },
290         /*  Sportster Vi 14.4 PnP FAX Voicemail */
291         {       "USR0004",              0       },
292         /* U.S. Robotics 33.6K Voice INT PnP */
293         {       "USR0006",              0       },
294         /* U.S. Robotics 33.6K Voice EXT PnP */
295         {       "USR0007",              0       },
296         /* U.S. Robotics 33.6K Voice INT PnP */
297         {       "USR2002",              0       },
298         /* U.S. Robotics 56K Voice INT PnP */
299         {       "USR2070",              0       },
300         /* U.S. Robotics 56K Voice EXT PnP */
301         {       "USR2080",              0       },
302         /* U.S. Robotics 56K FAX INT */
303         {       "USR3031",              0       },
304         /* U.S. Robotics 56K FAX INT */
305         {       "USR3050",              0       },
306         /* U.S. Robotics 56K Voice INT PnP */
307         {       "USR3070",              0       },
308         /* U.S. Robotics 56K Voice EXT PnP */
309         {       "USR3080",              0       },
310         /* U.S. Robotics 56K Voice INT PnP */
311         {       "USR3090",              0       },
312         /* U.S. Robotics 56K Message  */
313         {       "USR9100",              0       },
314         /* U.S. Robotics 56K FAX EXT PnP*/
315         {       "USR9160",              0       },
316         /* U.S. Robotics 56K FAX INT PnP*/
317         {       "USR9170",              0       },
318         /* U.S. Robotics 56K Voice EXT PnP*/
319         {       "USR9180",              0       },
320         /* U.S. Robotics 56K Voice INT PnP*/
321         {       "USR9190",              0       },
322         /* Rockwell's (PORALiNK) 33600 INT PNP */
323         {       "WCI0003",              0       },
324         /* Unkown PnP modems */
325         {       "PNPCXXX",              UNKNOWN_DEV     },
326         /* More unkown PnP modems */
327         {       "PNPDXXX",              UNKNOWN_DEV     },
328         {       "",                     0       }
329 };
330
331 MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
332
333 static char *modem_names[] __devinitdata = {
334         "MODEM", "Modem", "modem", "FAX", "Fax", "fax",
335         "56K", "56k", "K56", "33.6", "28.8", "14.4",
336         "33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
337         "33600", "28800", "14400", "V.90", "V.34", "V.32", 0
338 };
339
340 static int __devinit check_name(char *name)
341 {
342         char **tmp;
343
344         for (tmp = modem_names; *tmp; tmp++)
345                 if (strstr(name, *tmp))
346                         return 1;
347
348         return 0;
349 }
350
351 static int __devinit check_resources(struct pnp_option *option)
352 {
353         struct pnp_option *tmp;
354         if (!option)
355                 return 0;
356
357         for (tmp = option; tmp; tmp = tmp->next) {
358                 struct pnp_port *port;
359                 for (port = tmp->port; port; port = port->next)
360                         if ((port->size == 8) &&
361                             ((port->min == 0x2f8) ||
362                              (port->min == 0x3f8) ||
363                              (port->min == 0x2e8) ||
364 #ifdef CONFIG_X86_PC9800
365                              (port->min == 0x8b0) ||
366 #endif
367                              (port->min == 0x3e8)))
368                                 return 1;
369         }
370
371         return 0;
372 }
373
374 /*
375  * Given a complete unknown PnP device, try to use some heuristics to
376  * detect modems. Currently use such heuristic set:
377  *     - dev->name or dev->bus->name must contain "modem" substring;
378  *     - device must have only one IO region (8 byte long) with base address
379  *       0x2e8, 0x3e8, 0x2f8 or 0x3f8.
380  *
381  * Such detection looks very ugly, but can detect at least some of numerous
382  * PnP modems, alternatively we must hardcode all modems in pnp_devices[]
383  * table.
384  */
385 static int __devinit serial_pnp_guess_board(struct pnp_dev *dev, int *flags)
386 {
387         if (!(check_name(pnp_dev_name(dev)) || (dev->card && check_name(dev->card->name))))
388                 return -ENODEV;
389
390         if (check_resources(dev->independent))
391                 return 0;
392
393         if (check_resources(dev->dependent))
394                 return 0;
395
396         return -ENODEV;
397 }
398
399 static int __devinit
400 serial_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
401 {
402         struct serial_struct serial_req;
403         int ret, line, flags = dev_id->driver_data;
404         if (flags & UNKNOWN_DEV) {
405                 ret = serial_pnp_guess_board(dev, &flags);
406                 if (ret < 0)
407                         return ret;
408         }
409         memset(&serial_req, 0, sizeof(serial_req));
410         serial_req.irq = pnp_irq(dev,0);
411         serial_req.port = pnp_port_start(dev, 0);
412         if (HIGH_BITS_OFFSET)
413                 serial_req.port = pnp_port_start(dev, 0) >> HIGH_BITS_OFFSET;
414 #ifdef SERIAL_DEBUG_PNP
415         printk("Setup PNP port: port %x, irq %d, type %d\n",
416                serial_req.port, serial_req.irq, serial_req.io_type);
417 #endif
418
419         serial_req.flags = UPF_SKIP_TEST | UPF_AUTOPROBE  | UPF_RESOURCES;
420         serial_req.baud_base = 115200;
421         line = register_serial(&serial_req);
422
423         if (line >= 0)
424                 pnp_set_drvdata(dev, (void *)(line + 1));
425         return line >= 0 ? 0 : -ENODEV;
426
427 }
428
429 static void __devexit serial_pnp_remove(struct pnp_dev * dev)
430 {
431         int line = (int)pnp_get_drvdata(dev);
432         if (line)
433                 unregister_serial(line - 1);
434 }
435
436 static struct pnp_driver serial_pnp_driver = {
437         .name           = "serial",
438         .id_table       = pnp_dev_table,
439         .probe          = serial_pnp_probe,
440         .remove         = __devexit_p(serial_pnp_remove),
441 };
442
443 static int __init serial8250_pnp_init(void)
444 {
445         return pnp_register_driver(&serial_pnp_driver);
446 }
447
448 static void __exit serial8250_pnp_exit(void)
449 {
450         pnp_unregister_driver(&serial_pnp_driver);
451 }
452
453 module_init(serial8250_pnp_init);
454 module_exit(serial8250_pnp_exit);
455
456 MODULE_LICENSE("GPL");
457 MODULE_DESCRIPTION("Generic 8250/16x50 PnP serial driver");