1 // SPDX-License-Identifier: GPL-2.0
3 * Probe for 8250/16550-type ISAPNP serial ports.
5 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
7 * Copyright (C) 2001 Russell King, All Rights Reserved.
9 * Ported to the Linux PnP Layer - (C) Adam Belay.
11 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <linux/pnp.h>
14 #include <linux/string.h>
15 #include <linux/kernel.h>
16 #include <linux/serial_core.h>
17 #include <linux/bitops.h>
19 #include <asm/byteorder.h>
23 #define UNKNOWN_DEV 0x3000
24 #define CIR_PORT 0x0800
26 static const struct pnp_device_id pnp_dev_table
[] = {
27 /* Archtek America Corp. */
28 /* Archtek SmartLink Modem 3334BT Plug & Play */
30 /* Anchor Datacomm BV */
31 /* SXPro 144 External Data Fax Modem Plug & Play */
33 /* SXPro 288 External Data Fax Modem Plug & Play */
35 /* PROLiNK 1456VH ISA PnP K56flex Fax Modem */
37 /* Actiontec ISA PNP 56K X2 Fax Modem */
39 /* Rockwell 56K ACF II Fax+Data+Voice Modem */
40 { "AKY1021", 0 /*SPCI_FL_NO_SHIRQ*/ },
42 * ALi Fast Infrared Controller
43 * Native driver (ali-ircc) is broken so at least
44 * it can be used with irtty-sir.
47 /* AZT3005 PnP SOUND DEVICE */
49 /* Best Data Products Inc. Smart One 336F PnP Modem */
52 /* Boca Complete Ofc Communicator 14.4 Data-FAX */
54 /* Boca Research 33,600 ACF Modem */
56 /* Boca 33.6 Kbps Internal FD34FSVD */
58 /* Boca 33.6 Kbps Internal FD34FSVD */
60 /* Best Data Products Inc. Smart One 336F PnP Modem */
62 /* Computer Peripherals Inc */
63 /* EuroViVa CommCenter-33.6 SP PnP */
66 /* Creative Labs Phone Blaster 28.8 DSVD PnP Voice */
68 /* Creative Labs Modem Blaster 28.8 DSVD PnP Voice */
70 /* Davicom ISA 33.6K Modem */
73 /* Creative Modem Blaster Flash56 DI5601-1 */
75 /* Creative Modem Blaster V.90 DI5660 */
78 /* E-Tech CyberBULLET PC56RVP */
81 /* Fujitsu 33600 PnP-I2 R Plug & Play */
83 /* Fujitsu FMV-FX431 Plug & Play */
85 /* Fujitsu 33600 PnP-I4 R Plug & Play */
87 /* Fujitsu Fax Voice 33600 PNP-I5 R Plug & Play */
89 /* Archtek America Corp. */
90 /* Archtek SmartLink Modem 3334BT Plug & Play */
92 /* Archtek SmartLink Modem 3334BRV 33.6K Data Fax Voice */
95 /* Hayes Optima 288 V.34-V.FC + FAX + Voice Plug & Play */
97 /* Hayes Optima 336 V.34 + FAX + Voice PnP */
99 /* Hayes Optima 336B V.34 + FAX + Voice PnP */
101 /* Hayes Accura 56K Ext Fax Modem PnP */
103 /* Hayes Accura 56K Ext Fax Modem PnP */
105 /* Hayes Accura 56K Fax Modem PnP */
107 /* Hayes 288, V.34 + FAX */
109 /* Hayes Optima 288 V.34 + FAX + Voice, Plug & Play */
112 /* IBM Thinkpad 701 Internal Modem Voice */
115 /* Intermec CV60 touchscreen port */
118 /* Intertex 28k8 33k6 Voice EXT PnP */
120 /* Intertex 33k6 56k Voice EXT PnP */
122 /* Intertex 28k8 33k6 Voice SP EXT PnP */
124 /* Intertex 33k6 56k Voice SP EXT PnP */
126 /* Intertex 28k8 33k6 Voice SP INT PnP */
128 /* Intertex 28k8 33k6 Voice SP EXT PnP */
130 /* Intertex 33k6 56k Voice SP EXT PnP */
132 /* Kortex International */
133 /* KORTEX 28800 Externe PnP */
135 /* KXPro 33.6 Vocal ASVD PnP */
138 /* LASAT Internet 33600 PnP */
140 /* Lasat Safire 560 PnP */
142 /* Lasat Safire 336 PnP */
145 /* Microcom TravelPorte FAST V.34 Plug & Play */
147 /* Microcom DeskPorte V.34 FAST or FAST+ Plug & Play */
149 /* Microcom DeskPorte FAST EP 28.8 Plug & Play */
151 /* Microcom DeskPorte 28.8P Plug & Play */
153 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
155 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
157 /* Microcom DeskPorte 28.8S Internal Plug & Play */
160 /* Motorola BitSURFR Plug & Play */
162 /* Motorola TA210 Plug & Play */
164 /* Motorola HMTA 200 (ISDN) Plug & Play */
166 /* Motorola BitSURFR Plug & Play */
168 /* Motorola Lifestyle 28.8 Internal */
170 /* Motorola V.3400 Plug & Play */
172 /* Motorola Lifestyle 28.8 V.34 Plug & Play */
174 /* Motorola Power 28.8 V.34 Plug & Play */
176 /* Motorola ModemSURFR External 28.8 Plug & Play */
178 /* Motorola Premier 33.6 Desktop Plug & Play */
180 /* Motorola VoiceSURFR 56K External PnP */
182 /* Motorola ModemSURFR 56K External PnP */
184 /* Motorola ModemSURFR 56K Internal PnP */
186 /* Motorola ModemSURFR Internal 28.8 Plug & Play */
188 /* Motorola Premier 33.6 Internal Plug & Play */
190 /* Motorola OnlineSURFR 28.8 Internal Plug & Play */
192 /* Motorola VoiceSURFR 56K Internal PnP */
195 /* Deskline K56 Phone System PnP */
197 /* PC Rider K56 Phone System PnP */
199 /* NEC 98NOTE SPEAKER PHONE FAX MODEM(33600bps) */
201 /* Pace 56 Voice Internal Plug & Play Modem */
204 /* Generic standard PC COM port */
206 /* Generic 16550A-compatible COM port */
208 /* Compaq 14400 Modem */
210 /* Compaq 2400/9600 Modem */
212 /* Dial-Up Networking Serial Cable between 2 PCs */
214 /* Dial-Up Networking Parallel Cable between 2 PCs */
216 /* Standard 9600 bps Modem */
218 /* Standard 14400 bps Modem */
220 /* Standard 28800 bps Modem*/
224 /* Standard 9600 bps Modem*/
226 /* Standard 14400 bps Modem*/
228 /* Standard 28800 bps Modem*/
232 /* Standard 9600 bps Modem */
234 /* Standard 14400 bps Modem */
236 /* Standard 28800 bps Modem */
240 /* Standard 9600 bps Modem */
242 /* Standard 14400 bps Modem */
244 /* Standard 28800 bps Modem */
248 /* Standard PCMCIA Card Modem */
251 /* Modular Technology */
252 /* Rockwell 33.6 DPF Internal PnP */
253 /* Modular Technology 33.6 Internal PnP */
255 /* Kortex International */
256 /* KORTEX 14400 Externe PnP */
260 /* Viking Components, Inc */
261 /* Viking 28.8 INTERNAL Fax+Data+Voice PnP */
264 /* British Telecom */
265 /* Modular Technology */
266 /* Rockwell 33.6 DPF External PnP */
267 /* BT Prologue 33.6 External PnP */
268 /* Modular Technology 33.6 External PnP */
270 /* Viking 56K FAX INT */
272 /* K56 par,VV,Voice,Speakphone,AudioSpan,PnP */
274 /* SupraExpress 28.8 Data/Fax PnP modem */
276 /* SupraExpress 336i PnP Voice Modem */
278 /* SupraExpress 33.6 Data/Fax PnP modem */
280 /* SupraExpress 33.6 Data/Fax PnP modem */
282 /* SupraExpress 336i Sp ASVD */
284 /* SupraExpress 33.6 Data/Fax PnP modem */
286 /* SupraExpress 56i Sp Intl */
289 /* Phoebe Micro 33.6 Data Fax 1433VQH Plug & Play */
291 /* Archtek America Corp. */
292 /* Archtek SmartLink Modem 3334BT Plug & Play */
295 /* Gateway Telepath IIvi 33.6 */
297 /* U.S. Robotics Sporster 33.6K Fax INT PnP */
299 /* Sportster Vi 14.4 PnP FAX Voicemail */
301 /* U.S. Robotics 33.6K Voice INT PnP */
303 /* U.S. Robotics 33.6K Voice EXT PnP */
305 /* U.S. Robotics Courier V.Everything INT PnP */
307 /* U.S. Robotics 33.6K Voice INT PnP */
309 /* U.S. Robotics 56K Voice INT PnP */
311 /* U.S. Robotics 56K Voice EXT PnP */
313 /* U.S. Robotics 56K FAX INT */
315 /* U.S. Robotics 56K FAX INT */
317 /* U.S. Robotics 56K Voice INT PnP */
319 /* U.S. Robotics 56K Voice EXT PnP */
321 /* U.S. Robotics 56K Voice INT PnP */
323 /* U.S. Robotics 56K Message */
325 /* U.S. Robotics 56K FAX EXT PnP*/
327 /* U.S. Robotics 56K FAX INT PnP*/
329 /* U.S. Robotics 56K Voice EXT PnP*/
331 /* U.S. Robotics 56K Voice INT PnP*/
335 /* Compaq touchscreen */
337 /* Fujitsu Stylistic touchscreens */
340 /* Fujitsu Stylistic LT touchscreens */
342 /* Passive Fujitsu Stylistic touchscreens */
348 /* Fujitsu Wacom Tablet PC device */
350 /* Fujitsu P-series tablet PC device */
352 /* Fujitsu Wacom 2FGT Tablet PC device */
354 /* Fujitsu Wacom 1FGT Tablet PC device */
357 * LG C1 EXPRESS DUAL (C1-PB11A3) touch screen (actually a FUJ02E6
361 /* Rockwell's (PORALiNK) 33600 INT PNP */
363 /* Unknown PnP modems */
364 { "PNPCXXX", UNKNOWN_DEV
},
365 /* More unknown PnP modems */
366 { "PNPDXXX", UNKNOWN_DEV
},
368 * Winbond CIR port, should not be probed. We should keep track of
369 * it to prevent the legacy serial driver from probing it.
371 { "WEC1022", CIR_PORT
},
373 * SMSC IrCC SIR/FIR port, should not be probed by serial driver as
374 * well so its own driver can bind to it.
376 { "SMCF010", CIR_PORT
},
380 MODULE_DEVICE_TABLE(pnp
, pnp_dev_table
);
382 static const char *modem_names
[] = {
383 "MODEM", "Modem", "modem", "FAX", "Fax", "fax",
384 "56K", "56k", "K56", "33.6", "28.8", "14.4",
385 "33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
386 "33600", "28800", "14400", "V.90", "V.34", "V.32", NULL
389 static bool check_name(const char *name
)
393 for (tmp
= modem_names
; *tmp
; tmp
++)
394 if (strstr(name
, *tmp
))
400 static bool check_resources(struct pnp_dev
*dev
)
402 static const resource_size_t base
[] = {0x2f8, 0x3f8, 0x2e8, 0x3e8};
405 for (i
= 0; i
< ARRAY_SIZE(base
); i
++) {
406 if (pnp_possible_config(dev
, IORESOURCE_IO
, base
[i
], 8))
414 * Given a complete unknown PnP device, try to use some heuristics to
415 * detect modems. Currently use such heuristic set:
416 * - dev->name or dev->bus->name must contain "modem" substring;
417 * - device must have only one IO region (8 byte long) with base address
418 * 0x2e8, 0x3e8, 0x2f8 or 0x3f8.
420 * Such detection looks very ugly, but can detect at least some of numerous
421 * PnP modems, alternatively we must hardcode all modems in pnp_devices[]
424 static int serial_pnp_guess_board(struct pnp_dev
*dev
)
426 if (!(check_name(pnp_dev_name(dev
)) ||
427 (dev
->card
&& check_name(dev
->card
->name
))))
430 if (check_resources(dev
))
437 serial_pnp_probe(struct pnp_dev
*dev
, const struct pnp_device_id
*dev_id
)
439 struct uart_8250_port uart
, *port
;
440 int ret
, line
, flags
= dev_id
->driver_data
;
442 if (flags
& UNKNOWN_DEV
) {
443 ret
= serial_pnp_guess_board(dev
);
448 memset(&uart
, 0, sizeof(uart
));
449 if (pnp_irq_valid(dev
, 0))
450 uart
.port
.irq
= pnp_irq(dev
, 0);
451 if ((flags
& CIR_PORT
) && pnp_port_valid(dev
, 2)) {
452 uart
.port
.iobase
= pnp_port_start(dev
, 2);
453 uart
.port
.iotype
= UPIO_PORT
;
454 } else if (pnp_port_valid(dev
, 0)) {
455 uart
.port
.iobase
= pnp_port_start(dev
, 0);
456 uart
.port
.iotype
= UPIO_PORT
;
457 } else if (pnp_mem_valid(dev
, 0)) {
458 uart
.port
.mapbase
= pnp_mem_start(dev
, 0);
459 uart
.port
.iotype
= UPIO_MEM
;
460 uart
.port
.flags
= UPF_IOREMAP
;
465 "Setup PNP port: port %#lx, mem %#llx, irq %u, type %u\n",
466 uart
.port
.iobase
, (unsigned long long)uart
.port
.mapbase
,
467 uart
.port
.irq
, uart
.port
.iotype
);
469 if (flags
& CIR_PORT
) {
470 uart
.port
.flags
|= UPF_FIXED_PORT
| UPF_FIXED_TYPE
;
471 uart
.port
.type
= PORT_8250_CIR
;
474 uart
.port
.flags
|= UPF_SKIP_TEST
| UPF_BOOT_AUTOCONF
;
475 if (pnp_irq_flags(dev
, 0) & IORESOURCE_IRQ_SHAREABLE
)
476 uart
.port
.flags
|= UPF_SHARE_IRQ
;
477 uart
.port
.uartclk
= 1843200;
478 uart
.port
.dev
= &dev
->dev
;
480 line
= serial8250_register_8250_port(&uart
);
481 if (line
< 0 || (flags
& CIR_PORT
))
484 port
= serial8250_get_port(line
);
485 if (uart_console(&port
->port
))
486 dev
->capabilities
|= PNP_CONSOLE
;
488 pnp_set_drvdata(dev
, (void *)((long)line
+ 1));
492 static void serial_pnp_remove(struct pnp_dev
*dev
)
494 long line
= (long)pnp_get_drvdata(dev
);
496 dev
->capabilities
&= ~PNP_CONSOLE
;
498 serial8250_unregister_port(line
- 1);
501 static int __maybe_unused
serial_pnp_suspend(struct device
*dev
)
503 long line
= (long)dev_get_drvdata(dev
);
507 serial8250_suspend_port(line
- 1);
511 static int __maybe_unused
serial_pnp_resume(struct device
*dev
)
513 long line
= (long)dev_get_drvdata(dev
);
517 serial8250_resume_port(line
- 1);
521 static SIMPLE_DEV_PM_OPS(serial_pnp_pm_ops
, serial_pnp_suspend
, serial_pnp_resume
);
523 static struct pnp_driver serial_pnp_driver
= {
525 .probe
= serial_pnp_probe
,
526 .remove
= serial_pnp_remove
,
528 .pm
= &serial_pnp_pm_ops
,
530 .id_table
= pnp_dev_table
,
533 int serial8250_pnp_init(void)
535 return pnp_register_driver(&serial_pnp_driver
);
538 void serial8250_pnp_exit(void)
540 pnp_unregister_driver(&serial_pnp_driver
);