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