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 361 * in 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 /* 371 * Winbond CIR port, should not be probed. We should keep track of 372 * it to prevent the legacy serial driver from probing it. 373 */ 374 { "WEC1022", CIR_PORT }, 375 /* 376 * SMSC IrCC SIR/FIR port, should not be probed by serial driver as 377 * well so its own driver can bind to it. 378 */ 379 { "SMCF010", CIR_PORT }, 380 { "", 0 } 381 }; 382 383 MODULE_DEVICE_TABLE(pnp, pnp_dev_table); 384 385 static const char *modem_names[] = { 386 "MODEM", "Modem", "modem", "FAX", "Fax", "fax", 387 "56K", "56k", "K56", "33.6", "28.8", "14.4", 388 "33,600", "28,800", "14,400", "33.600", "28.800", "14.400", 389 "33600", "28800", "14400", "V.90", "V.34", "V.32", NULL 390 }; 391 392 static bool check_name(const char *name) 393 { 394 const char **tmp; 395 396 for (tmp = modem_names; *tmp; tmp++) 397 if (strstr(name, *tmp)) 398 return true; 399 400 return false; 401 } 402 403 static bool check_resources(struct pnp_dev *dev) 404 { 405 static const resource_size_t base[] = {0x2f8, 0x3f8, 0x2e8, 0x3e8}; 406 unsigned int i; 407 408 for (i = 0; i < ARRAY_SIZE(base); i++) { 409 if (pnp_possible_config(dev, IORESOURCE_IO, base[i], 8)) 410 return true; 411 } 412 413 return false; 414 } 415 416 /* 417 * Given a complete unknown PnP device, try to use some heuristics to 418 * detect modems. Currently use such heuristic set: 419 * - dev->name or dev->bus->name must contain "modem" substring; 420 * - device must have only one IO region (8 byte long) with base address 421 * 0x2e8, 0x3e8, 0x2f8 or 0x3f8. 422 * 423 * Such detection looks very ugly, but can detect at least some of numerous 424 * PnP modems, alternatively we must hardcode all modems in pnp_devices[] 425 * table. 426 */ 427 static int serial_pnp_guess_board(struct pnp_dev *dev) 428 { 429 if (!(check_name(pnp_dev_name(dev)) || 430 (dev->card && check_name(dev->card->name)))) 431 return -ENODEV; 432 433 if (check_resources(dev)) 434 return 0; 435 436 return -ENODEV; 437 } 438 439 static int 440 serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) 441 { 442 struct uart_8250_port uart, *port; 443 int ret, line, flags = dev_id->driver_data; 444 445 if (flags & UNKNOWN_DEV) { 446 ret = serial_pnp_guess_board(dev); 447 if (ret < 0) 448 return ret; 449 } 450 451 memset(&uart, 0, sizeof(uart)); 452 if (pnp_irq_valid(dev, 0)) 453 uart.port.irq = pnp_irq(dev, 0); 454 if ((flags & CIR_PORT) && pnp_port_valid(dev, 2)) { 455 uart.port.iobase = pnp_port_start(dev, 2); 456 uart.port.iotype = UPIO_PORT; 457 } else if (pnp_port_valid(dev, 0)) { 458 uart.port.iobase = pnp_port_start(dev, 0); 459 uart.port.iotype = UPIO_PORT; 460 } else if (pnp_mem_valid(dev, 0)) { 461 uart.port.mapbase = pnp_mem_start(dev, 0); 462 uart.port.iotype = UPIO_MEM; 463 uart.port.flags = UPF_IOREMAP; 464 } else 465 return -ENODEV; 466 467 dev_dbg(&dev->dev, 468 "Setup PNP port: port %lx, mem %pa, irq %d, type %d\n", 469 uart.port.iobase, &uart.port.mapbase, 470 uart.port.irq, uart.port.iotype); 471 472 if (flags & CIR_PORT) { 473 uart.port.flags |= UPF_FIXED_PORT | UPF_FIXED_TYPE; 474 uart.port.type = PORT_8250_CIR; 475 } 476 477 uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; 478 if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE) 479 uart.port.flags |= UPF_SHARE_IRQ; 480 uart.port.uartclk = 1843200; 481 uart.port.dev = &dev->dev; 482 483 line = serial8250_register_8250_port(&uart); 484 if (line < 0 || (flags & CIR_PORT)) 485 return -ENODEV; 486 487 port = serial8250_get_port(line); 488 if (uart_console(&port->port)) 489 dev->capabilities |= PNP_CONSOLE; 490 491 pnp_set_drvdata(dev, (void *)((long)line + 1)); 492 return 0; 493 } 494 495 static void serial_pnp_remove(struct pnp_dev *dev) 496 { 497 long line = (long)pnp_get_drvdata(dev); 498 499 dev->capabilities &= ~PNP_CONSOLE; 500 if (line) 501 serial8250_unregister_port(line - 1); 502 } 503 504 #ifdef CONFIG_PM 505 static int serial_pnp_suspend(struct pnp_dev *dev, pm_message_t state) 506 { 507 long line = (long)pnp_get_drvdata(dev); 508 509 if (!line) 510 return -ENODEV; 511 serial8250_suspend_port(line - 1); 512 return 0; 513 } 514 515 static int serial_pnp_resume(struct pnp_dev *dev) 516 { 517 long line = (long)pnp_get_drvdata(dev); 518 519 if (!line) 520 return -ENODEV; 521 serial8250_resume_port(line - 1); 522 return 0; 523 } 524 #else 525 #define serial_pnp_suspend NULL 526 #define serial_pnp_resume NULL 527 #endif /* CONFIG_PM */ 528 529 static struct pnp_driver serial_pnp_driver = { 530 .name = "serial", 531 .probe = serial_pnp_probe, 532 .remove = serial_pnp_remove, 533 .suspend = serial_pnp_suspend, 534 .resume = serial_pnp_resume, 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