2 * ISA Plug & Play support
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 2000-01-01 Added quirks handling for buggy hardware
22 * Peter Denison <peterd@pnd-pc.demon.co.uk>
23 * 2000-06-14 Added isapnp_probe_devs() and isapnp_activate_dev()
24 * Christoph Hellwig <hch@infradead.org>
25 * 2001-06-03 Added release_region calls to correspond with
26 * request_region calls when a failure occurs. Also
27 * added KERN_* constants to printk() calls.
28 * 2001-11-07 Added isapnp_{,un}register_driver calls along the lines
29 * of the pci driver interface
30 * Kai Germaschewski <kai.germaschewski@gmx.de>
31 * 2002-06-06 Made the use of dma channel 0 configurable
32 * Gerald Teschl <gerald.teschl@univie.ac.at>
33 * 2002-10-06 Ported to PnP Layer - Adam Belay <ambx1@neo.rr.com>
34 * 2003-08-11 Resource Management Updates - Adam Belay <ambx1@neo.rr.com>
37 #include <linux/config.h>
38 #include <linux/module.h>
39 #include <linux/kernel.h>
40 #include <linux/errno.h>
41 #include <linux/slab.h>
42 #include <linux/delay.h>
43 #include <linux/init.h>
44 #include <linux/isapnp.h>
48 #define ISAPNP_REGION_OK
54 int isapnp_disable; /* Disable ISA PnP */
55 int isapnp_rdp; /* Read Data Port */
56 int isapnp_reset = 1; /* reset all PnP cards (deactivate) */
57 int isapnp_verbose = 1; /* verbose mode */
59 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
60 MODULE_DESCRIPTION("Generic ISA Plug & Play support");
61 MODULE_PARM(isapnp_disable, "i");
62 MODULE_PARM_DESC(isapnp_disable, "ISA Plug & Play disable");
63 MODULE_PARM(isapnp_rdp, "i");
64 MODULE_PARM_DESC(isapnp_rdp, "ISA Plug & Play read data port");
65 MODULE_PARM(isapnp_reset, "i");
66 MODULE_PARM_DESC(isapnp_reset, "ISA Plug & Play reset all cards");
67 MODULE_PARM(isapnp_verbose, "i");
68 MODULE_PARM_DESC(isapnp_verbose, "ISA Plug & Play verbose mode");
69 MODULE_LICENSE("GPL");
71 #ifdef CONFIG_X86_PC9800
80 #define _STAG_PNPVERNO 0x01
81 #define _STAG_LOGDEVID 0x02
82 #define _STAG_COMPATDEVID 0x03
83 #define _STAG_IRQ 0x04
84 #define _STAG_DMA 0x05
85 #define _STAG_STARTDEP 0x06
86 #define _STAG_ENDDEP 0x07
87 #define _STAG_IOPORT 0x08
88 #define _STAG_FIXEDIO 0x09
89 #define _STAG_VENDOR 0x0e
90 #define _STAG_END 0x0f
92 #define _LTAG_MEMRANGE 0x81
93 #define _LTAG_ANSISTR 0x82
94 #define _LTAG_UNICODESTR 0x83
95 #define _LTAG_VENDOR 0x84
96 #define _LTAG_MEM32RANGE 0x85
97 #define _LTAG_FIXEDMEM32RANGE 0x86
99 static unsigned char isapnp_checksum_value;
100 static DECLARE_MUTEX(isapnp_cfg_mutex);
101 static int isapnp_detected;
102 static int isapnp_csn_count;
104 /* some prototypes */
106 static inline void write_data(unsigned char x)
111 static inline void write_address(unsigned char x)
117 static inline unsigned char read_data(void)
119 unsigned char val = inb(isapnp_rdp);
123 unsigned char isapnp_read_byte(unsigned char idx)
129 unsigned short isapnp_read_word(unsigned char idx)
133 val = isapnp_read_byte(idx);
134 val = (val << 8) + isapnp_read_byte(idx+1);
138 unsigned int isapnp_read_dword(unsigned char idx)
142 val = isapnp_read_byte(idx);
143 val = (val << 8) + isapnp_read_byte(idx+1);
144 val = (val << 8) + isapnp_read_byte(idx+2);
145 val = (val << 8) + isapnp_read_byte(idx+3);
149 void isapnp_write_byte(unsigned char idx, unsigned char val)
155 void isapnp_write_word(unsigned char idx, unsigned short val)
157 isapnp_write_byte(idx, val >> 8);
158 isapnp_write_byte(idx+1, val);
161 void isapnp_write_dword(unsigned char idx, unsigned int val)
163 isapnp_write_byte(idx, val >> 24);
164 isapnp_write_byte(idx+1, val >> 16);
165 isapnp_write_byte(idx+2, val >> 8);
166 isapnp_write_byte(idx+3, val);
169 void *isapnp_alloc(long size)
173 result = kmalloc(size, GFP_KERNEL);
176 memset(result, 0, size);
180 static void isapnp_key(void)
182 unsigned char code = 0x6a, msb;
191 for (i = 1; i < 32; i++) {
192 msb = ((code & 0x01) ^ ((code & 0x02) >> 1)) << 7;
193 code = (code >> 1) | msb;
198 /* place all pnp cards in wait-for-key state */
199 static void isapnp_wait(void)
201 isapnp_write_byte(0x02, 0x02);
204 void isapnp_wake(unsigned char csn)
206 isapnp_write_byte(0x03, csn);
209 void isapnp_device(unsigned char logdev)
211 isapnp_write_byte(0x07, logdev);
214 void isapnp_activate(unsigned char logdev)
216 isapnp_device(logdev);
217 isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 1);
221 void isapnp_deactivate(unsigned char logdev)
223 isapnp_device(logdev);
224 isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 0);
228 static void __init isapnp_peek(unsigned char *data, int bytes)
233 for (i = 1; i <= bytes; i++) {
234 for (j = 0; j < 20; j++) {
235 d = isapnp_read_byte(0x05);
245 d = isapnp_read_byte(0x04); /* PRESDI */
246 isapnp_checksum_value += d;
252 #define RDP_STEP 32 /* minimum is 4 */
254 static int isapnp_next_rdp(void)
256 int rdp = isapnp_rdp;
257 static int old_rdp = 0;
261 release_region(old_rdp, 1);
264 while (rdp <= 0x3ff) {
266 * We cannot use NE2000 probe spaces for ISAPnP or we
267 * will lock up machines.
269 if ((rdp < 0x280 || rdp > 0x380) && request_region(rdp, 1, "ISAPnP"))
280 /* Set read port address */
281 static inline void isapnp_set_rdp(void)
283 isapnp_write_byte(0x00, isapnp_rdp >> 2);
288 * Perform an isolation. The port selection code now tries to avoid
289 * "dangerous to read" ports.
292 static int __init isapnp_isolate_rdp_select(void)
297 /* Control: reset CSN and conditionally everything else too */
298 isapnp_write_byte(0x02, isapnp_reset ? 0x05 : 0x04);
305 if (isapnp_next_rdp() < 0) {
318 * Isolate (assign uniqued CSN) to all ISA PnP devices.
321 static int __init isapnp_isolate(void)
323 unsigned char checksum = 0x6a;
324 unsigned char chksum = 0x00;
325 unsigned char bit = 0x00;
332 if (isapnp_isolate_rdp_select() < 0)
336 for (i = 1; i <= 64; i++) {
337 data = read_data() << 8;
339 data = data | read_data();
343 checksum = ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7) | (checksum >> 1);
346 for (i = 65; i <= 72; i++) {
347 data = read_data() << 8;
349 data = data | read_data();
352 chksum |= (1 << (i - 65));
354 if (checksum != 0x00 && checksum == chksum) {
357 isapnp_write_byte(0x06, csn);
367 if (iteration == 1) {
368 isapnp_rdp += RDP_STEP;
369 if (isapnp_isolate_rdp_select() < 0)
371 } else if (iteration > 1) {
382 isapnp_csn_count = csn;
387 * Read one tag from stream.
390 static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
392 unsigned char tag, tmp[2];
394 isapnp_peek(&tag, 1);
395 if (tag == 0) /* invalid tag */
397 if (tag & 0x80) { /* large item */
400 *size = (tmp[1] << 8) | tmp[0];
402 *type = (tag >> 3) & 0x0f;
406 printk(KERN_DEBUG "tag = 0x%x, type = 0x%x, size = %i\n", tag, *type, *size);
408 if (type == 0) /* wrong type */
410 if (*type == 0xff && *size == 0xffff) /* probably invalid data */
416 * Skip specified number of bytes from stream.
419 static void __init isapnp_skip_bytes(int count)
421 isapnp_peek(NULL, count);
428 static void isapnp_parse_id(struct pnp_dev * dev, unsigned short vendor, unsigned short device)
433 id = isapnp_alloc(sizeof(struct pnp_id));
436 sprintf(id->id, "%c%c%c%x%x%x%x",
437 'A' + ((vendor >> 2) & 0x3f) - 1,
438 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
439 'A' + ((vendor >> 8) & 0x1f) - 1,
440 (device >> 4) & 0x0f,
442 (device >> 12) & 0x0f,
443 (device >> 8) & 0x0f);
448 * Parse logical device tag.
451 static struct pnp_dev * __init isapnp_parse_device(struct pnp_card *card, int size, int number)
453 unsigned char tmp[6];
456 isapnp_peek(tmp, size);
457 dev = isapnp_alloc(sizeof(struct pnp_dev));
460 dev->number = number;
461 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
465 dev->regs |= tmp[5] << 8;
466 dev->protocol = &isapnp_protocol;
467 dev->capabilities |= PNP_CONFIGURABLE;
468 dev->capabilities |= PNP_READ;
469 dev->capabilities |= PNP_WRITE;
470 dev->capabilities |= PNP_DISABLE;
471 pnp_init_resource_table(&dev->res);
477 * Add IRQ resource to resources list.
480 static void __init isapnp_parse_irq_resource(struct pnp_option *option,
483 unsigned char tmp[3];
486 isapnp_peek(tmp, size);
487 irq = isapnp_alloc(sizeof(struct pnp_irq));
490 irq->map = (tmp[1] << 8) | tmp[0];
494 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
495 pnp_register_irq_resource(option, irq);
500 * Add DMA resource to resources list.
503 static void __init isapnp_parse_dma_resource(struct pnp_option *option,
506 unsigned char tmp[2];
509 isapnp_peek(tmp, size);
510 dma = isapnp_alloc(sizeof(struct pnp_dma));
515 pnp_register_dma_resource(option, dma);
520 * Add port resource to resources list.
523 static void __init isapnp_parse_port_resource(struct pnp_option *option,
526 unsigned char tmp[7];
527 struct pnp_port *port;
529 isapnp_peek(tmp, size);
530 port = isapnp_alloc(sizeof(struct pnp_port));
533 port->min = (tmp[2] << 8) | tmp[1];
534 port->max = (tmp[4] << 8) | tmp[3];
535 port->align = tmp[5];
537 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0;
538 pnp_register_port_resource(option,port);
543 * Add fixed port resource to resources list.
546 static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
549 unsigned char tmp[3];
550 struct pnp_port *port;
552 isapnp_peek(tmp, size);
553 port = isapnp_alloc(sizeof(struct pnp_port));
556 port->min = port->max = (tmp[1] << 8) | tmp[0];
559 port->flags = PNP_PORT_FLAG_FIXED;
560 pnp_register_port_resource(option,port);
565 * Add memory resource to resources list.
568 static void __init isapnp_parse_mem_resource(struct pnp_option *option,
571 unsigned char tmp[9];
574 isapnp_peek(tmp, size);
575 mem = isapnp_alloc(sizeof(struct pnp_mem));
578 mem->min = ((tmp[2] << 8) | tmp[1]) << 8;
579 mem->max = ((tmp[4] << 8) | tmp[3]) << 8;
580 mem->align = (tmp[6] << 8) | tmp[5];
581 mem->size = ((tmp[8] << 8) | tmp[7]) << 8;
583 pnp_register_mem_resource(option,mem);
588 * Add 32-bit memory resource to resources list.
591 static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
594 unsigned char tmp[17];
597 isapnp_peek(tmp, size);
598 mem = isapnp_alloc(sizeof(struct pnp_mem));
601 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
602 mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
603 mem->align = (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9];
604 mem->size = (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
606 pnp_register_mem_resource(option,mem);
610 * Add 32-bit fixed memory resource to resources list.
613 static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
616 unsigned char tmp[9];
619 isapnp_peek(tmp, size);
620 mem = isapnp_alloc(sizeof(struct pnp_mem));
623 mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
624 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
627 pnp_register_mem_resource(option,mem);
631 * Parse card name for ISA PnP device.
635 isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size)
637 if (name[0] == '\0') {
638 unsigned short size1 = *size >= name_max ? (name_max - 1) : *size;
639 isapnp_peek(name, size1);
643 /* clean whitespace from end of string */
644 while (size1 > 0 && name[--size1] == ' ')
650 * Parse resource map for logical device.
653 static int __init isapnp_create_device(struct pnp_card *card,
656 int number = 0, skip = 0, priority = 0, compat = 0;
657 unsigned char type, tmp[17];
658 struct pnp_option *option;
660 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
662 option = pnp_register_independent_option(dev);
665 pnp_add_card_device(card,dev);
668 if (isapnp_read_tag(&type, &size)<0)
670 if (skip && type != _STAG_LOGDEVID && type != _STAG_END)
674 if (size >= 5 && size <= 6) {
675 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
679 option = pnp_register_independent_option(dev);
682 pnp_add_card_device(card,dev);
689 case _STAG_COMPATDEVID:
690 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
692 isapnp_parse_id(dev,(tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
698 if (size < 2 || size > 3)
700 isapnp_parse_irq_resource(option, size);
706 isapnp_parse_dma_resource(option, size);
712 priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE;
714 isapnp_peek(tmp, size);
715 priority = 0x100 | tmp[0];
718 option = pnp_register_dependent_option(dev,priority);
730 isapnp_parse_port_resource(option, size);
736 isapnp_parse_fixed_port_resource(option, size);
744 isapnp_parse_mem_resource(option, size);
748 isapnp_parse_name(dev->name, sizeof(dev->name), &size);
750 case _LTAG_UNICODESTR:
751 /* silently ignore */
752 /* who use unicode for hardware identification? */
756 case _LTAG_MEM32RANGE:
759 isapnp_parse_mem32_resource(option, size);
762 case _LTAG_FIXEDMEM32RANGE:
765 isapnp_parse_fixed_mem32_resource(option, size);
770 isapnp_skip_bytes(size);
773 printk(KERN_ERR "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n", type, dev->number, card->number);
777 isapnp_skip_bytes(size);
783 * Parse resource map for ISA PnP card.
786 static void __init isapnp_parse_resource_map(struct pnp_card *card)
788 unsigned char type, tmp[17];
792 if (isapnp_read_tag(&type, &size)<0)
799 card->pnpver = tmp[0];
800 card->productver = tmp[1];
804 if (size >= 5 && size <= 6) {
805 if (isapnp_create_device(card, size)==1)
813 isapnp_parse_name(card->name, sizeof(card->name), &size);
815 case _LTAG_UNICODESTR:
816 /* silently ignore */
817 /* who use unicode for hardware identification? */
823 isapnp_skip_bytes(size);
826 printk(KERN_ERR "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n", type, card->number);
830 isapnp_skip_bytes(size);
835 * Compute ISA PnP checksum for first eight bytes.
838 static unsigned char __init isapnp_checksum(unsigned char *data)
841 unsigned char checksum = 0x6a, bit, b;
843 for (i = 0; i < 8; i++) {
845 for (j = 0; j < 8; j++) {
849 checksum = ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7) | (checksum >> 1);
856 * Parse EISA id for ISA PnP card.
859 static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device)
861 struct pnp_id * id = isapnp_alloc(sizeof(struct pnp_id));
864 sprintf(id->id, "%c%c%c%x%x%x%x",
865 'A' + ((vendor >> 2) & 0x3f) - 1,
866 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
867 'A' + ((vendor >> 8) & 0x1f) - 1,
868 (device >> 4) & 0x0f,
870 (device >> 12) & 0x0f,
871 (device >> 8) & 0x0f);
872 pnp_add_card_id(id,card);
876 * Build device list for all present ISA PnP devices.
879 static int __init isapnp_build_device_list(void)
882 unsigned char header[9], checksum;
883 struct pnp_card *card;
887 for (csn = 1; csn <= isapnp_csn_count; csn++) {
889 isapnp_peek(header, 9);
890 checksum = isapnp_checksum(header);
892 printk(KERN_DEBUG "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
893 header[0], header[1], header[2], header[3],
894 header[4], header[5], header[6], header[7], header[8]);
895 printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
897 if ((card = isapnp_alloc(sizeof(struct pnp_card))) == NULL)
901 INIT_LIST_HEAD(&card->devices);
902 isapnp_parse_card_id(card, (header[1] << 8) | header[0], (header[3] << 8) | header[2]);
903 card->serial = (header[7] << 24) | (header[6] << 16) | (header[5] << 8) | header[4];
904 isapnp_checksum_value = 0x00;
905 isapnp_parse_resource_map(card);
906 if (isapnp_checksum_value != 0x00)
907 printk(KERN_ERR "isapnp: checksum for device %i is not valid (0x%x)\n", csn, isapnp_checksum_value);
908 card->checksum = isapnp_checksum_value;
909 card->protocol = &isapnp_protocol;
918 * Basic configuration routines.
921 int isapnp_present(void)
923 struct pnp_card *card;
924 pnp_for_each_card(card) {
925 if (card->protocol == &isapnp_protocol)
931 int isapnp_cfg_begin(int csn, int logdev)
933 if (csn < 1 || csn > isapnp_csn_count || logdev > 10)
935 down(&isapnp_cfg_mutex);
940 /* to avoid malfunction when the isapnptools package is used */
941 /* we must set RDP to our value again */
942 /* it is possible to set RDP only in the isolation phase */
943 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
944 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
945 mdelay(2); /* is this necessary? */
946 isapnp_wake(csn); /* bring card into sleep state */
947 isapnp_wake(0); /* bring card into isolation state */
948 isapnp_set_rdp(); /* reset the RDP port */
949 udelay(1000); /* delay 1000us */
950 isapnp_write_byte(0x06, csn); /* reset CSN to previous value */
951 udelay(250); /* is this necessary? */
954 isapnp_device(logdev);
958 int isapnp_cfg_end(void)
961 up(&isapnp_cfg_mutex);
971 EXPORT_SYMBOL(isapnp_protocol);
972 EXPORT_SYMBOL(isapnp_present);
973 EXPORT_SYMBOL(isapnp_cfg_begin);
974 EXPORT_SYMBOL(isapnp_cfg_end);
975 EXPORT_SYMBOL(isapnp_read_byte);
976 EXPORT_SYMBOL(isapnp_read_word);
977 EXPORT_SYMBOL(isapnp_read_dword);
978 EXPORT_SYMBOL(isapnp_write_byte);
979 EXPORT_SYMBOL(isapnp_write_word);
980 EXPORT_SYMBOL(isapnp_write_dword);
981 EXPORT_SYMBOL(isapnp_wake);
982 EXPORT_SYMBOL(isapnp_device);
984 static int isapnp_read_resources(struct pnp_dev *dev, struct pnp_resource_table *res)
988 dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
990 for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) {
991 ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
994 res->port_resource[tmp].start = ret;
995 res->port_resource[tmp].flags = IORESOURCE_IO;
997 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) {
998 ret = isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
1001 res->mem_resource[tmp].start = ret;
1002 res->mem_resource[tmp].flags = IORESOURCE_MEM;
1004 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) {
1005 ret = (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >> 8);
1008 res->irq_resource[tmp].start = res->irq_resource[tmp].end = ret;
1009 res->irq_resource[tmp].flags = IORESOURCE_IRQ;
1011 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) {
1012 ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
1015 res->dma_resource[tmp].start = res->dma_resource[tmp].end = ret;
1016 res->dma_resource[tmp].flags = IORESOURCE_DMA;
1022 static int isapnp_get_resources(struct pnp_dev *dev, struct pnp_resource_table * res)
1025 pnp_init_resource_table(res);
1026 isapnp_cfg_begin(dev->card->number, dev->number);
1027 ret = isapnp_read_resources(dev, res);
1032 static int isapnp_set_resources(struct pnp_dev *dev, struct pnp_resource_table * res)
1036 isapnp_cfg_begin(dev->card->number, dev->number);
1038 for (tmp = 0; tmp < PNP_MAX_PORT && (res->port_resource[tmp].flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO; tmp++)
1039 isapnp_write_word(ISAPNP_CFG_PORT+(tmp<<1), res->port_resource[tmp].start);
1040 for (tmp = 0; tmp < PNP_MAX_IRQ && (res->irq_resource[tmp].flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ; tmp++) {
1041 int irq = res->irq_resource[tmp].start;
1044 isapnp_write_byte(ISAPNP_CFG_IRQ+(tmp<<1), irq);
1046 for (tmp = 0; tmp < PNP_MAX_DMA && (res->dma_resource[tmp].flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA; tmp++)
1047 isapnp_write_byte(ISAPNP_CFG_DMA+tmp, res->dma_resource[tmp].start);
1048 for (tmp = 0; tmp < PNP_MAX_MEM && (res->mem_resource[tmp].flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM; tmp++)
1049 isapnp_write_word(ISAPNP_CFG_MEM+(tmp<<3), (res->mem_resource[tmp].start >> 8) & 0xffff);
1050 /* FIXME: We aren't handling 32bit mems properly here */
1051 isapnp_activate(dev->number);
1056 static int isapnp_disable_resources(struct pnp_dev *dev)
1058 if (!dev || !dev->active)
1060 isapnp_cfg_begin(dev->card->number, dev->number);
1061 isapnp_deactivate(dev->number);
1067 struct pnp_protocol isapnp_protocol = {
1068 .name = "ISA Plug and Play",
1069 .get = isapnp_get_resources,
1070 .set = isapnp_set_resources,
1071 .disable = isapnp_disable_resources,
1074 int __init isapnp_init(void)
1077 struct pnp_card *card;
1078 struct pnp_dev *dev;
1080 if (isapnp_disable) {
1081 isapnp_detected = 0;
1082 printk(KERN_INFO "isapnp: ISA Plug & Play support disabled\n");
1085 #ifdef ISAPNP_REGION_OK
1086 if (!request_region(_PIDXR, 1, "isapnp index")) {
1087 printk(KERN_ERR "isapnp: Index Register 0x%x already used\n", _PIDXR);
1091 if (!request_region(_PNPWRP, 1, "isapnp write")) {
1092 printk(KERN_ERR "isapnp: Write Data Register 0x%x already used\n", _PNPWRP);
1093 #ifdef ISAPNP_REGION_OK
1094 release_region(_PIDXR, 1);
1099 if(pnp_register_protocol(&isapnp_protocol)<0)
1103 * Print a message. The existing ISAPnP code is hanging machines
1104 * so let the user know where.
1107 printk(KERN_INFO "isapnp: Scanning for PnP cards...\n");
1108 if (isapnp_rdp >= 0x203 && isapnp_rdp <= 0x3ff) {
1110 if (!request_region(isapnp_rdp, 1, "isapnp read")) {
1111 printk(KERN_ERR "isapnp: Read Data Register 0x%x already used\n", isapnp_rdp);
1112 #ifdef ISAPNP_REGION_OK
1113 release_region(_PIDXR, 1);
1115 release_region(_PNPWRP, 1);
1120 isapnp_detected = 1;
1121 if (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff) {
1122 cards = isapnp_isolate();
1124 (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff)) {
1125 #ifdef ISAPNP_REGION_OK
1126 release_region(_PIDXR, 1);
1128 release_region(_PNPWRP, 1);
1129 isapnp_detected = 0;
1130 printk(KERN_INFO "isapnp: No Plug & Play device found\n");
1133 request_region(isapnp_rdp, 1, "isapnp read");
1135 isapnp_build_device_list();
1138 protocol_for_each_card(&isapnp_protocol,card) {
1140 if (isapnp_verbose) {
1141 printk(KERN_INFO "isapnp: Card '%s'\n", card->name[0]?card->name:"Unknown");
1142 if (isapnp_verbose < 2)
1144 card_for_each_dev(card,dev) {
1145 printk(KERN_INFO "isapnp: Device '%s'\n", dev->name[0]?dev->name:"Unknown");
1150 printk(KERN_INFO "isapnp: %i Plug & Play card%s detected total\n", cards, cards>1?"s":"");
1152 printk(KERN_INFO "isapnp: No Plug & Play card found\n");
1159 device_initcall(isapnp_init);
1161 /* format is: noisapnp */
1163 static int __init isapnp_setup_disable(char *str)
1169 __setup("noisapnp", isapnp_setup_disable);
1171 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1173 static int __init isapnp_setup_isapnp(char *str)
1175 (void)((get_option(&str,&isapnp_rdp) == 2) &&
1176 (get_option(&str,&isapnp_reset) == 2) &&
1177 (get_option(&str,&isapnp_verbose) == 2));
1181 __setup("isapnp=", isapnp_setup_isapnp);