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