8250_pnp.c 12.6 KB
Newer Older
Russell King's avatar
Russell King committed
1
/*
2
 *  linux/drivers/char/8250_pnp.c
Russell King's avatar
Russell King committed
3 4 5 6 7 8 9
 *
 *  Probe module for 8250/16550-type ISAPNP serial ports.
 *
 *  Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
 *
 *  Copyright (C) 2001 Russell King, All Rights Reserved.
 *
10 11
 *  Ported to the Linux PnP Layer - (C) Adam Belay.
 *
Russell King's avatar
Russell King committed
12 13 14 15
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 *
16
 *  $Id: 8250_pnp.c,v 1.10 2002/07/21 21:32:30 rmk Exp $
Russell King's avatar
Russell King committed
17 18 19 20
 */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/pci.h>
21
#include <linux/pnp.h>
Russell King's avatar
Russell King committed
22 23
#include <linux/string.h>
#include <linux/kernel.h>
24
#include <linux/tty.h>
Russell King's avatar
Russell King committed
25 26
#include <linux/serial.h>
#include <linux/serialP.h>
27
#include <linux/serial_core.h>
28
#include <linux/bitops.h>
29
#include <linux/8250.h>
Russell King's avatar
Russell King committed
30 31 32 33

#include <asm/byteorder.h>
#include <asm/serial.h>

34 35 36
#define UNKNOWN_DEV 0x3000


37
static const struct pnp_device_id pnp_dev_table[] = {
Russell King's avatar
Russell King committed
38 39 40 41 42 43 44 45
	/* Archtek America Corp. */
	/* Archtek SmartLink Modem 3334BT Plug & Play */
	{	"AAC000F",		0	},
	/* Anchor Datacomm BV */
	/* SXPro 144 External Data Fax Modem Plug & Play */
	{	"ADC0001",		0	},
	/* SXPro 288 External Data Fax Modem Plug & Play */
	{	"ADC0002",		0	},
46 47
	/* PROLiNK 1456VH ISA PnP K56flex Fax Modem */
	{	"AEI0250",		0	},
48 49
	/* Actiontec ISA PNP 56K X2 Fax Modem */
	{	"AEI1240",		0	},
Russell King's avatar
Russell King committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
	/* Rockwell 56K ACF II Fax+Data+Voice Modem */
	{	"AKY1021",		SPCI_FL_NO_SHIRQ	},
	/* AZT3005 PnP SOUND DEVICE */
	{	"AZT4001",		0	},
	/* Best Data Products Inc. Smart One 336F PnP Modem */
	{	"BDP3336",		0	},
	/*  Boca Research */
	/* Boca Complete Ofc Communicator 14.4 Data-FAX */
	{	"BRI0A49",		0	},
	/* Boca Research 33,600 ACF Modem */
	{	"BRI1400",		0	},
	/* Boca 33.6 Kbps Internal FD34FSVD */
	{	"BRI3400",		0	},
	/* Boca 33.6 Kbps Internal FD34FSVD */
	{	"BRI0A49",		0	},
	/* Best Data Products Inc. Smart One 336F PnP Modem */
	{	"BDP3336",		0	},
	/* Computer Peripherals Inc */
	/* EuroViVa CommCenter-33.6 SP PnP */
	{	"CPI4050",		0	},
	/* Creative Labs */
	/* Creative Labs Phone Blaster 28.8 DSVD PnP Voice */
	{	"CTL3001",		0	},
	/* Creative Labs Modem Blaster 28.8 DSVD PnP Voice */
	{	"CTL3011",		0	},
	/* Creative */
	/* Creative Modem Blaster Flash56 DI5601-1 */
	{	"DMB1032",		0	},
	/* Creative Modem Blaster V.90 DI5660 */
	{	"DMB2001",		0	},
80 81 82
	/* E-Tech */
	/* E-Tech CyberBULLET PC56RVP */
	{	"ETT0002",		0	},
Russell King's avatar
Russell King committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
	/* FUJITSU */
	/* Fujitsu 33600 PnP-I2 R Plug & Play */
	{	"FUJ0202",		0	},
	/* Fujitsu FMV-FX431 Plug & Play */
	{	"FUJ0205",		0	},
	/* Fujitsu 33600 PnP-I4 R Plug & Play */
	{	"FUJ0206",		0	},
	/* Fujitsu Fax Voice 33600 PNP-I5 R Plug & Play */
	{	"FUJ0209",		0	},
	/* Archtek America Corp. */
	/* Archtek SmartLink Modem 3334BT Plug & Play */
	{	"GVC000F",		0	},
	/* Hayes */
	/* Hayes Optima 288 V.34-V.FC + FAX + Voice Plug & Play */
	{	"HAY0001",		0	},
	/* Hayes Optima 336 V.34 + FAX + Voice PnP */
	{	"HAY000C",		0	},
	/* Hayes Optima 336B V.34 + FAX + Voice PnP */
	{	"HAY000D",		0	},
	/* Hayes Accura 56K Ext Fax Modem PnP */
	{	"HAY5670",		0	},
	/* Hayes Accura 56K Ext Fax Modem PnP */
	{	"HAY5674",		0	},
	/* Hayes Accura 56K Fax Modem PnP */
	{	"HAY5675",		0	},
	/* Hayes 288, V.34 + FAX */
	{	"HAYF000",		0	},
	/* Hayes Optima 288 V.34 + FAX + Voice, Plug & Play */
	{	"HAYF001",		0	},
	/* IBM */
	/* IBM Thinkpad 701 Internal Modem Voice */
	{	"IBM0033",		0	},
	/* Intertex */
	/* Intertex 28k8 33k6 Voice EXT PnP */
	{	"IXDC801",		0	},
	/* Intertex 33k6 56k Voice EXT PnP */
	{	"IXDC901",		0	},
	/* Intertex 28k8 33k6 Voice SP EXT PnP */
	{	"IXDD801",		0	},
	/* Intertex 33k6 56k Voice SP EXT PnP */
	{	"IXDD901",		0	},
	/* Intertex 28k8 33k6 Voice SP INT PnP */
	{	"IXDF401",		0	},
	/* Intertex 28k8 33k6 Voice SP EXT PnP */
	{	"IXDF801",		0	},
	/* Intertex 33k6 56k Voice SP EXT PnP */
	{	"IXDF901",		0	},
	/* Kortex International */
	/* KORTEX 28800 Externe PnP */
	{	"KOR4522",		0	},
	/* KXPro 33.6 Vocal ASVD PnP */
	{	"KORF661",		0	},
	/* Lasat */
	/* LASAT Internet 33600 PnP */
	{	"LAS4040",		0	},
	/* Lasat Safire 560 PnP */
	{	"LAS4540",		0	},
	/* Lasat Safire 336  PnP */
	{	"LAS5440",		0	},
	/* Microcom, Inc. */
	/* Microcom TravelPorte FAST V.34 Plug & Play */
	{	"MNP0281",		0	},
	/* Microcom DeskPorte V.34 FAST or FAST+ Plug & Play */
	{	"MNP0336",		0	},
	/* Microcom DeskPorte FAST EP 28.8 Plug & Play */
	{	"MNP0339",		0	},
	/* Microcom DeskPorte 28.8P Plug & Play */
	{	"MNP0342",		0	},
	/* Microcom DeskPorte FAST ES 28.8 Plug & Play */
	{	"MNP0500",		0	},
	/* Microcom DeskPorte FAST ES 28.8 Plug & Play */
	{	"MNP0501",		0	},
	/* Microcom DeskPorte 28.8S Internal Plug & Play */
	{	"MNP0502",		0	},
	/* Motorola */
	/* Motorola BitSURFR Plug & Play */
	{	"MOT1105",		0	},
	/* Motorola TA210 Plug & Play */
	{	"MOT1111",		0	},
	/* Motorola HMTA 200 (ISDN) Plug & Play */
	{	"MOT1114",		0	},
	/* Motorola BitSURFR Plug & Play */
	{	"MOT1115",		0	},
	/* Motorola Lifestyle 28.8 Internal */
	{	"MOT1190",		0	},
	/* Motorola V.3400 Plug & Play */
	{	"MOT1501",		0	},
	/* Motorola Lifestyle 28.8 V.34 Plug & Play */
	{	"MOT1502",		0	},
	/* Motorola Power 28.8 V.34 Plug & Play */
	{	"MOT1505",		0	},
	/* Motorola ModemSURFR External 28.8 Plug & Play */
	{	"MOT1509",		0	},
	/* Motorola Premier 33.6 Desktop Plug & Play */
	{	"MOT150A",		0	},
	/* Motorola VoiceSURFR 56K External PnP */
	{	"MOT150F",		0	},
	/* Motorola ModemSURFR 56K External PnP */
	{	"MOT1510",		0	},
	/* Motorola ModemSURFR 56K Internal PnP */
	{	"MOT1550",		0	},
	/* Motorola ModemSURFR Internal 28.8 Plug & Play */
	{	"MOT1560",		0	},
	/* Motorola Premier 33.6 Internal Plug & Play */
	{	"MOT1580",		0	},
	/* Motorola OnlineSURFR 28.8 Internal Plug & Play */
	{	"MOT15B0",		0	},
	/* Motorola VoiceSURFR 56K Internal PnP */
	{	"MOT15F0",		0	},
	/* Com 1 */
	/*  Deskline K56 Phone System PnP */
	{	"MVX00A1",		0	},
	/* PC Rider K56 Phone System PnP */
	{	"MVX00F2",		0	},
197 198
	/* NEC 98NOTE SPEAKER PHONE FAX MODEM(33600bps) */
	{	"nEC8241",		0	},
Russell King's avatar
Russell King committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
	/* Pace 56 Voice Internal Plug & Play Modem */
	{	"PMC2430",		0	},
	/* Generic */
	/* Generic standard PC COM port	 */
	{	"PNP0500",		0	},
	/* Generic 16550A-compatible COM port */
	{	"PNP0501",		0	},
	/* Compaq 14400 Modem */
	{	"PNPC000",		0	},
	/* Compaq 2400/9600 Modem */
	{	"PNPC001",		0	},
	/* Dial-Up Networking Serial Cable between 2 PCs */
	{	"PNPC031",		0	},
	/* Dial-Up Networking Parallel Cable between 2 PCs */
	{	"PNPC032",		0	},
	/* Standard 9600 bps Modem */
	{	"PNPC100",		0	},
	/* Standard 14400 bps Modem */
	{	"PNPC101",		0	},
	/*  Standard 28800 bps Modem*/
	{	"PNPC102",		0	},
	/*  Standard Modem*/
	{	"PNPC103",		0	},
	/*  Standard 9600 bps Modem*/
	{	"PNPC104",		0	},
	/*  Standard 14400 bps Modem*/
	{	"PNPC105",		0	},
	/*  Standard 28800 bps Modem*/
	{	"PNPC106",		0	},
	/*  Standard Modem */
	{	"PNPC107",		0	},
	/* Standard 9600 bps Modem */
	{	"PNPC108",		0	},
	/* Standard 14400 bps Modem */
	{	"PNPC109",		0	},
	/* Standard 28800 bps Modem */
	{	"PNPC10A",		0	},
	/* Standard Modem */
	{	"PNPC10B",		0	},
	/* Standard 9600 bps Modem */
	{	"PNPC10C",		0	},
	/* Standard 14400 bps Modem */
	{	"PNPC10D",		0	},
	/* Standard 28800 bps Modem */
	{	"PNPC10E",		0	},
	/* Standard Modem */
	{	"PNPC10F",		0	},
	/* Standard PCMCIA Card Modem */
	{	"PNP2000",		0	},
	/* Rockwell */
	/* Modular Technology */
	/* Rockwell 33.6 DPF Internal PnP */
	/* Modular Technology 33.6 Internal PnP */
	{	"ROK0030",		0	},
	/* Kortex International */
	/* KORTEX 14400 Externe PnP */
	{	"ROK0100",		0	},
	/* Viking Components, Inc */
	/* Viking 28.8 INTERNAL Fax+Data+Voice PnP */
	{	"ROK4920",		0	},
	/* Rockwell */
	/* British Telecom */
	/* Modular Technology */
	/* Rockwell 33.6 DPF External PnP */
	/* BT Prologue 33.6 External PnP */
	/* Modular Technology 33.6 External PnP */
	{	"RSS00A0",		0	},
	/* Viking 56K FAX INT */
	{	"RSS0262",		0	},
Adam Belay's avatar
Adam Belay committed
268 269
	/* K56 par,VV,Voice,Speakphone,AudioSpan,PnP */
	{       "RSS0250",              0       },
Russell King's avatar
Russell King committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
	/* SupraExpress 28.8 Data/Fax PnP modem */
	{	"SUP1310",		0	},
	/* SupraExpress 33.6 Data/Fax PnP modem */
	{	"SUP1421",		0	},
	/* SupraExpress 33.6 Data/Fax PnP modem */
	{	"SUP1590",		0	},
	/* SupraExpress 33.6 Data/Fax PnP modem */
	{	"SUP1760",		0	},
	/* Phoebe Micro */
	/* Phoebe Micro 33.6 Data Fax 1433VQH Plug & Play */
	{	"TEX0011",		0	},
	/* Archtek America Corp. */
	/* Archtek SmartLink Modem 3334BT Plug & Play */
	{	"UAC000F",		0	},
	/* 3Com Corp. */
	/* Gateway Telepath IIvi 33.6 */
	{	"USR0000",		0	},
Adam Belay's avatar
Adam Belay committed
287 288
	/* U.S. Robotics Sporster 33.6K Fax INT PnP */
	{	"USR0002",		0	},
Russell King's avatar
Russell King committed
289 290 291 292 293 294
	/*  Sportster Vi 14.4 PnP FAX Voicemail */
	{	"USR0004",		0	},
	/* U.S. Robotics 33.6K Voice INT PnP */
	{	"USR0006",		0	},
	/* U.S. Robotics 33.6K Voice EXT PnP */
	{	"USR0007",		0	},
295 296
	/* U.S. Robotics Courier V.Everything INT PnP */
	{	"USR0009",		0	},
Russell King's avatar
Russell King committed
297 298 299 300 301 302 303 304
	/* U.S. Robotics 33.6K Voice INT PnP */
	{	"USR2002",		0	},
	/* U.S. Robotics 56K Voice INT PnP */
	{	"USR2070",		0	},
	/* U.S. Robotics 56K Voice EXT PnP */
	{	"USR2080",		0	},
	/* U.S. Robotics 56K FAX INT */
	{	"USR3031",		0	},
305 306
	/* U.S. Robotics 56K FAX INT */
	{	"USR3050",		0	},
Russell King's avatar
Russell King committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
	/* U.S. Robotics 56K Voice INT PnP */
	{	"USR3070",		0	},
	/* U.S. Robotics 56K Voice EXT PnP */
	{	"USR3080",		0	},
	/* U.S. Robotics 56K Voice INT PnP */
	{	"USR3090",		0	},
	/* U.S. Robotics 56K Message  */
	{	"USR9100",		0	},
	/* U.S. Robotics 56K FAX EXT PnP*/
	{	"USR9160",		0	},
	/* U.S. Robotics 56K FAX INT PnP*/
	{	"USR9170",		0	},
	/* U.S. Robotics 56K Voice EXT PnP*/
	{	"USR9180",		0	},
	/* U.S. Robotics 56K Voice INT PnP*/
	{	"USR9190",		0	},
Adam Belay's avatar
Adam Belay committed
323 324
	/* Rockwell's (PORALiNK) 33600 INT PNP */
	{	"WCI0003",		0	},
325 326 327 328
	/* Unkown PnP modems */
	{	"PNPCXXX",		UNKNOWN_DEV	},
	/* More unkown PnP modems */
	{	"PNPDXXX",		UNKNOWN_DEV	},
Russell King's avatar
Russell King committed
329 330 331
	{	"",			0	}
};

332 333
MODULE_DEVICE_TABLE(pnp, pnp_dev_table);

Russell King's avatar
Russell King committed
334 335 336 337
static char *modem_names[] __devinitdata = {
	"MODEM", "Modem", "modem", "FAX", "Fax", "fax",
	"56K", "56k", "K56", "33.6", "28.8", "14.4",
	"33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
338
	"33600", "28800", "14400", "V.90", "V.34", "V.32", NULL
Russell King's avatar
Russell King committed
339 340 341 342 343 344 345 346 347 348 349 350 351
};

static int __devinit check_name(char *name)
{
	char **tmp;

	for (tmp = modem_names; *tmp; tmp++)
		if (strstr(name, *tmp))
			return 1;

	return 0;
}

352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
static int __devinit check_resources(struct pnp_option *option)
{
	struct pnp_option *tmp;
	if (!option)
		return 0;

	for (tmp = option; tmp; tmp = tmp->next) {
		struct pnp_port *port;
		for (port = tmp->port; port; port = port->next)
			if ((port->size == 8) &&
			    ((port->min == 0x2f8) ||
			     (port->min == 0x3f8) ||
			     (port->min == 0x2e8) ||
			     (port->min == 0x3e8)))
				return 1;
	}

	return 0;
}

Russell King's avatar
Russell King committed
372
/*
373
 * Given a complete unknown PnP device, try to use some heuristics to
Russell King's avatar
Russell King committed
374 375
 * detect modems. Currently use such heuristic set:
 *     - dev->name or dev->bus->name must contain "modem" substring;
376
 *     - device must have only one IO region (8 byte long) with base address
Russell King's avatar
Russell King committed
377 378 379
 *       0x2e8, 0x3e8, 0x2f8 or 0x3f8.
 *
 * Such detection looks very ugly, but can detect at least some of numerous
380
 * PnP modems, alternatively we must hardcode all modems in pnp_devices[]
Russell King's avatar
Russell King committed
381 382
 * table.
 */
383
static int __devinit serial_pnp_guess_board(struct pnp_dev *dev, int *flags)
Russell King's avatar
Russell King committed
384
{
385
	if (!(check_name(pnp_dev_name(dev)) || (dev->card && check_name(dev->card->name))))
Russell King's avatar
Russell King committed
386 387
		return -ENODEV;

388 389
	if (check_resources(dev->independent))
		return 0;
Russell King's avatar
Russell King committed
390

391 392
	if (check_resources(dev->dependent))
		return 0;
Russell King's avatar
Russell King committed
393 394 395 396

	return -ENODEV;
}

397
static int __devinit
398
serial_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
Russell King's avatar
Russell King committed
399 400
{
	struct serial_struct serial_req;
401
	int ret, line, flags = dev_id->driver_data;
Jaroslav Kysela's avatar
Jaroslav Kysela committed
402
	if (flags & UNKNOWN_DEV) {
Russell King's avatar
Russell King committed
403
		ret = serial_pnp_guess_board(dev, &flags);
Jaroslav Kysela's avatar
Jaroslav Kysela committed
404 405 406
		if (ret < 0)
			return ret;
	}
Russell King's avatar
Russell King committed
407
	memset(&serial_req, 0, sizeof(serial_req));
408 409
	serial_req.irq = pnp_irq(dev,0);
	serial_req.port = pnp_port_start(dev, 0);
Russell King's avatar
Russell King committed
410
	if (HIGH_BITS_OFFSET)
411
		serial_req.port = pnp_port_start(dev, 0) >> HIGH_BITS_OFFSET;
Russell King's avatar
Russell King committed
412 413 414 415 416
#ifdef SERIAL_DEBUG_PNP
	printk("Setup PNP port: port %x, irq %d, type %d\n",
	       serial_req.port, serial_req.irq, serial_req.io_type);
#endif

Russell King's avatar
Russell King committed
417
	serial_req.flags = UPF_SKIP_TEST | UPF_AUTOPROBE;
Russell King's avatar
Russell King committed
418 419 420
	serial_req.baud_base = 115200;
	line = register_serial(&serial_req);

421
	if (line >= 0)
422
		pnp_set_drvdata(dev, (void *)(line + 1));
Russell King's avatar
Russell King committed
423 424 425 426
	return line >= 0 ? 0 : -ENODEV;

}

427
static void __devexit serial_pnp_remove(struct pnp_dev * dev)
Russell King's avatar
Russell King committed
428
{
Adam Belay's avatar
Adam Belay committed
429 430 431
	int line = (int)pnp_get_drvdata(dev);
	if (line)
		unregister_serial(line - 1);
Russell King's avatar
Russell King committed
432 433
}

434 435 436 437
static struct pnp_driver serial_pnp_driver = {
	.name		= "serial",
	.id_table	= pnp_dev_table,
	.probe		= serial_pnp_probe,
438
	.remove		= __devexit_p(serial_pnp_remove),
439 440
};

Russell King's avatar
Russell King committed
441 442
static int __init serial8250_pnp_init(void)
{
443
	return pnp_register_driver(&serial_pnp_driver);
Russell King's avatar
Russell King committed
444 445 446 447
}

static void __exit serial8250_pnp_exit(void)
{
Adam Belay's avatar
Adam Belay committed
448
	pnp_unregister_driver(&serial_pnp_driver);
Russell King's avatar
Russell King committed
449 450 451 452 453 454
}

module_init(serial8250_pnp_init);
module_exit(serial8250_pnp_exit);

MODULE_LICENSE("GPL");
455
MODULE_DESCRIPTION("Generic 8250/16x50 PnP serial driver");