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_param(isapnp_disable, int, 0);
62 MODULE_PARM_DESC(isapnp_disable, "ISA Plug & Play disable");
63 module_param(isapnp_rdp, int, 0);
64 MODULE_PARM_DESC(isapnp_rdp, "ISA Plug & Play read data port");
65 module_param(isapnp_reset, int, 0);
66 MODULE_PARM_DESC(isapnp_reset, "ISA Plug & Play reset all cards");
67 module_param(isapnp_verbose, int, 0);
68 MODULE_PARM_DESC(isapnp_verbose, "ISA Plug & Play verbose mode");
69 MODULE_LICENSE("GPL");
75 #define _STAG_PNPVERNO 0x01
76 #define _STAG_LOGDEVID 0x02
77 #define _STAG_COMPATDEVID 0x03
78 #define _STAG_IRQ 0x04
79 #define _STAG_DMA 0x05
80 #define _STAG_STARTDEP 0x06
81 #define _STAG_ENDDEP 0x07
82 #define _STAG_IOPORT 0x08
83 #define _STAG_FIXEDIO 0x09
84 #define _STAG_VENDOR 0x0e
85 #define _STAG_END 0x0f
87 #define _LTAG_MEMRANGE 0x81
88 #define _LTAG_ANSISTR 0x82
89 #define _LTAG_UNICODESTR 0x83
90 #define _LTAG_VENDOR 0x84
91 #define _LTAG_MEM32RANGE 0x85
92 #define _LTAG_FIXEDMEM32RANGE 0x86
94 static unsigned char isapnp_checksum_value;
95 static DECLARE_MUTEX(isapnp_cfg_mutex);
96 static int isapnp_detected;
97 static int isapnp_csn_count;
101 static inline void write_data(unsigned char x)
106 static inline void write_address(unsigned char x)
112 static inline unsigned char read_data(void)
114 unsigned char val = inb(isapnp_rdp);
118 unsigned char isapnp_read_byte(unsigned char idx)
124 unsigned short isapnp_read_word(unsigned char idx)
128 val = isapnp_read_byte(idx);
129 val = (val << 8) + isapnp_read_byte(idx+1);
133 unsigned int isapnp_read_dword(unsigned char idx)
137 val = isapnp_read_byte(idx);
138 val = (val << 8) + isapnp_read_byte(idx+1);
139 val = (val << 8) + isapnp_read_byte(idx+2);
140 val = (val << 8) + isapnp_read_byte(idx+3);
144 void isapnp_write_byte(unsigned char idx, unsigned char val)
150 void isapnp_write_word(unsigned char idx, unsigned short val)
152 isapnp_write_byte(idx, val >> 8);
153 isapnp_write_byte(idx+1, val);
156 void isapnp_write_dword(unsigned char idx, unsigned int val)
158 isapnp_write_byte(idx, val >> 24);
159 isapnp_write_byte(idx+1, val >> 16);
160 isapnp_write_byte(idx+2, val >> 8);
161 isapnp_write_byte(idx+3, val);
164 void *isapnp_alloc(long size)
168 result = kmalloc(size, GFP_KERNEL);
171 memset(result, 0, size);
175 static void isapnp_key(void)
177 unsigned char code = 0x6a, msb;
186 for (i = 1; i < 32; i++) {
187 msb = ((code & 0x01) ^ ((code & 0x02) >> 1)) << 7;
188 code = (code >> 1) | msb;
193 /* place all pnp cards in wait-for-key state */
194 static void isapnp_wait(void)
196 isapnp_write_byte(0x02, 0x02);
199 void isapnp_wake(unsigned char csn)
201 isapnp_write_byte(0x03, csn);
204 void isapnp_device(unsigned char logdev)
206 isapnp_write_byte(0x07, logdev);
209 void isapnp_activate(unsigned char logdev)
211 isapnp_device(logdev);
212 isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 1);
216 void isapnp_deactivate(unsigned char logdev)
218 isapnp_device(logdev);
219 isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 0);
223 static void __init isapnp_peek(unsigned char *data, int bytes)
228 for (i = 1; i <= bytes; i++) {
229 for (j = 0; j < 20; j++) {
230 d = isapnp_read_byte(0x05);
240 d = isapnp_read_byte(0x04); /* PRESDI */
241 isapnp_checksum_value += d;
247 #define RDP_STEP 32 /* minimum is 4 */
249 static int isapnp_next_rdp(void)
251 int rdp = isapnp_rdp;
252 static int old_rdp = 0;
256 release_region(old_rdp, 1);
259 while (rdp <= 0x3ff) {
261 * We cannot use NE2000 probe spaces for ISAPnP or we
262 * will lock up machines.
264 if ((rdp < 0x280 || rdp > 0x380) && request_region(rdp, 1, "ISAPnP"))
275 /* Set read port address */
276 static inline void isapnp_set_rdp(void)
278 isapnp_write_byte(0x00, isapnp_rdp >> 2);
283 * Perform an isolation. The port selection code now tries to avoid
284 * "dangerous to read" ports.
287 static int __init isapnp_isolate_rdp_select(void)
292 /* Control: reset CSN and conditionally everything else too */
293 isapnp_write_byte(0x02, isapnp_reset ? 0x05 : 0x04);
300 if (isapnp_next_rdp() < 0) {
313 * Isolate (assign uniqued CSN) to all ISA PnP devices.
316 static int __init isapnp_isolate(void)
318 unsigned char checksum = 0x6a;
319 unsigned char chksum = 0x00;
320 unsigned char bit = 0x00;
327 if (isapnp_isolate_rdp_select() < 0)
331 for (i = 1; i <= 64; i++) {
332 data = read_data() << 8;
334 data = data | read_data();
338 checksum = ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7) | (checksum >> 1);
341 for (i = 65; i <= 72; i++) {
342 data = read_data() << 8;
344 data = data | read_data();
347 chksum |= (1 << (i - 65));
349 if (checksum != 0x00 && checksum == chksum) {
352 isapnp_write_byte(0x06, csn);
362 if (iteration == 1) {
363 isapnp_rdp += RDP_STEP;
364 if (isapnp_isolate_rdp_select() < 0)
366 } else if (iteration > 1) {
377 isapnp_csn_count = csn;
382 * Read one tag from stream.
385 static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
387 unsigned char tag, tmp[2];
389 isapnp_peek(&tag, 1);
390 if (tag == 0) /* invalid tag */
392 if (tag & 0x80) { /* large item */
395 *size = (tmp[1] << 8) | tmp[0];
397 *type = (tag >> 3) & 0x0f;
401 printk(KERN_DEBUG "tag = 0x%x, type = 0x%x, size = %i\n", tag, *type, *size);
403 if (type == 0) /* wrong type */
405 if (*type == 0xff && *size == 0xffff) /* probably invalid data */
411 * Skip specified number of bytes from stream.
414 static void __init isapnp_skip_bytes(int count)
416 isapnp_peek(NULL, count);
423 static void isapnp_parse_id(struct pnp_dev * dev, unsigned short vendor, unsigned short device)
428 id = isapnp_alloc(sizeof(struct pnp_id));
431 sprintf(id->id, "%c%c%c%x%x%x%x",
432 'A' + ((vendor >> 2) & 0x3f) - 1,
433 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
434 'A' + ((vendor >> 8) & 0x1f) - 1,
435 (device >> 4) & 0x0f,
437 (device >> 12) & 0x0f,
438 (device >> 8) & 0x0f);
443 * Parse logical device tag.
446 static struct pnp_dev * __init isapnp_parse_device(struct pnp_card *card, int size, int number)
448 unsigned char tmp[6];
451 isapnp_peek(tmp, size);
452 dev = isapnp_alloc(sizeof(struct pnp_dev));
455 dev->number = number;
456 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
460 dev->regs |= tmp[5] << 8;
461 dev->protocol = &isapnp_protocol;
462 dev->capabilities |= PNP_CONFIGURABLE;
463 dev->capabilities |= PNP_READ;
464 dev->capabilities |= PNP_WRITE;
465 dev->capabilities |= PNP_DISABLE;
466 pnp_init_resource_table(&dev->res);
472 * Add IRQ resource to resources list.
475 static void __init isapnp_parse_irq_resource(struct pnp_option *option,
478 unsigned char tmp[3];
482 isapnp_peek(tmp, size);
483 irq = isapnp_alloc(sizeof(struct pnp_irq));
486 bits = (tmp[1] << 8) | tmp[0];
487 bitmap_copy(irq->map, &bits, 16);
491 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
492 pnp_register_irq_resource(option, irq);
497 * Add DMA resource to resources list.
500 static void __init isapnp_parse_dma_resource(struct pnp_option *option,
503 unsigned char tmp[2];
506 isapnp_peek(tmp, size);
507 dma = isapnp_alloc(sizeof(struct pnp_dma));
512 pnp_register_dma_resource(option, dma);
517 * Add port resource to resources list.
520 static void __init isapnp_parse_port_resource(struct pnp_option *option,
523 unsigned char tmp[7];
524 struct pnp_port *port;
526 isapnp_peek(tmp, size);
527 port = isapnp_alloc(sizeof(struct pnp_port));
530 port->min = (tmp[2] << 8) | tmp[1];
531 port->max = (tmp[4] << 8) | tmp[3];
532 port->align = tmp[5];
534 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0;
535 pnp_register_port_resource(option,port);
540 * Add fixed port resource to resources list.
543 static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
546 unsigned char tmp[3];
547 struct pnp_port *port;
549 isapnp_peek(tmp, size);
550 port = isapnp_alloc(sizeof(struct pnp_port));
553 port->min = port->max = (tmp[1] << 8) | tmp[0];
556 port->flags = PNP_PORT_FLAG_FIXED;
557 pnp_register_port_resource(option,port);
562 * Add memory resource to resources list.
565 static void __init isapnp_parse_mem_resource(struct pnp_option *option,
568 unsigned char tmp[9];
571 isapnp_peek(tmp, size);
572 mem = isapnp_alloc(sizeof(struct pnp_mem));
575 mem->min = ((tmp[2] << 8) | tmp[1]) << 8;
576 mem->max = ((tmp[4] << 8) | tmp[3]) << 8;
577 mem->align = (tmp[6] << 8) | tmp[5];
578 mem->size = ((tmp[8] << 8) | tmp[7]) << 8;
580 pnp_register_mem_resource(option,mem);
585 * Add 32-bit memory resource to resources list.
588 static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
591 unsigned char tmp[17];
594 isapnp_peek(tmp, size);
595 mem = isapnp_alloc(sizeof(struct pnp_mem));
598 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
599 mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
600 mem->align = (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9];
601 mem->size = (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
603 pnp_register_mem_resource(option,mem);
607 * Add 32-bit fixed memory resource to resources list.
610 static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
613 unsigned char tmp[9];
616 isapnp_peek(tmp, size);
617 mem = isapnp_alloc(sizeof(struct pnp_mem));
620 mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
621 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
624 pnp_register_mem_resource(option,mem);
628 * Parse card name for ISA PnP device.
632 isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size)
634 if (name[0] == '\0') {
635 unsigned short size1 = *size >= name_max ? (name_max - 1) : *size;
636 isapnp_peek(name, size1);
640 /* clean whitespace from end of string */
641 while (size1 > 0 && name[--size1] == ' ')
647 * Parse resource map for logical device.
650 static int __init isapnp_create_device(struct pnp_card *card,
653 int number = 0, skip = 0, priority = 0, compat = 0;
654 unsigned char type, tmp[17];
655 struct pnp_option *option;
657 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
659 option = pnp_register_independent_option(dev);
664 pnp_add_card_device(card,dev);
667 if (isapnp_read_tag(&type, &size)<0)
669 if (skip && type != _STAG_LOGDEVID && type != _STAG_END)
673 if (size >= 5 && size <= 6) {
674 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
678 option = pnp_register_independent_option(dev);
681 pnp_add_card_device(card,dev);
688 case _STAG_COMPATDEVID:
689 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
691 isapnp_parse_id(dev,(tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
697 if (size < 2 || size > 3)
699 isapnp_parse_irq_resource(option, size);
705 isapnp_parse_dma_resource(option, size);
711 priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE;
713 isapnp_peek(tmp, size);
714 priority = 0x100 | tmp[0];
717 option = pnp_register_dependent_option(dev,priority);
729 isapnp_parse_port_resource(option, size);
735 isapnp_parse_fixed_port_resource(option, size);
743 isapnp_parse_mem_resource(option, size);
747 isapnp_parse_name(dev->name, sizeof(dev->name), &size);
749 case _LTAG_UNICODESTR:
750 /* silently ignore */
751 /* who use unicode for hardware identification? */
755 case _LTAG_MEM32RANGE:
758 isapnp_parse_mem32_resource(option, size);
761 case _LTAG_FIXEDMEM32RANGE:
764 isapnp_parse_fixed_mem32_resource(option, size);
769 isapnp_skip_bytes(size);
772 printk(KERN_ERR "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n", type, dev->number, card->number);
776 isapnp_skip_bytes(size);
782 * Parse resource map for ISA PnP card.
785 static void __init isapnp_parse_resource_map(struct pnp_card *card)
787 unsigned char type, tmp[17];
791 if (isapnp_read_tag(&type, &size)<0)
798 card->pnpver = tmp[0];
799 card->productver = tmp[1];
803 if (size >= 5 && size <= 6) {
804 if (isapnp_create_device(card, size)==1)
812 isapnp_parse_name(card->name, sizeof(card->name), &size);
814 case _LTAG_UNICODESTR:
815 /* silently ignore */
816 /* who use unicode for hardware identification? */
822 isapnp_skip_bytes(size);
825 printk(KERN_ERR "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n", type, card->number);
829 isapnp_skip_bytes(size);
834 * Compute ISA PnP checksum for first eight bytes.
837 static unsigned char __init isapnp_checksum(unsigned char *data)
840 unsigned char checksum = 0x6a, bit, b;
842 for (i = 0; i < 8; i++) {
844 for (j = 0; j < 8; j++) {
848 checksum = ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7) | (checksum >> 1);
855 * Parse EISA id for ISA PnP card.
858 static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device)
860 struct pnp_id * id = isapnp_alloc(sizeof(struct pnp_id));
863 sprintf(id->id, "%c%c%c%x%x%x%x",
864 'A' + ((vendor >> 2) & 0x3f) - 1,
865 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
866 'A' + ((vendor >> 8) & 0x1f) - 1,
867 (device >> 4) & 0x0f,
869 (device >> 12) & 0x0f,
870 (device >> 8) & 0x0f);
871 pnp_add_card_id(id,card);
875 * Build device list for all present ISA PnP devices.
878 static int __init isapnp_build_device_list(void)
881 unsigned char header[9], checksum;
882 struct pnp_card *card;
886 for (csn = 1; csn <= isapnp_csn_count; csn++) {
888 isapnp_peek(header, 9);
889 checksum = isapnp_checksum(header);
891 printk(KERN_DEBUG "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
892 header[0], header[1], header[2], header[3],
893 header[4], header[5], header[6], header[7], header[8]);
894 printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
896 if ((card = isapnp_alloc(sizeof(struct pnp_card))) == NULL)
900 INIT_LIST_HEAD(&card->devices);
901 isapnp_parse_card_id(card, (header[1] << 8) | header[0], (header[3] << 8) | header[2]);
902 card->serial = (header[7] << 24) | (header[6] << 16) | (header[5] << 8) | header[4];
903 isapnp_checksum_value = 0x00;
904 isapnp_parse_resource_map(card);
905 if (isapnp_checksum_value != 0x00)
906 printk(KERN_ERR "isapnp: checksum for device %i is not valid (0x%x)\n", csn, isapnp_checksum_value);
907 card->checksum = isapnp_checksum_value;
908 card->protocol = &isapnp_protocol;
917 * Basic configuration routines.
920 int isapnp_present(void)
922 struct pnp_card *card;
923 pnp_for_each_card(card) {
924 if (card->protocol == &isapnp_protocol)
930 int isapnp_cfg_begin(int csn, int logdev)
932 if (csn < 1 || csn > isapnp_csn_count || logdev > 10)
934 down(&isapnp_cfg_mutex);
939 /* to avoid malfunction when the isapnptools package is used */
940 /* we must set RDP to our value again */
941 /* it is possible to set RDP only in the isolation phase */
942 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
943 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
944 mdelay(2); /* is this necessary? */
945 isapnp_wake(csn); /* bring card into sleep state */
946 isapnp_wake(0); /* bring card into isolation state */
947 isapnp_set_rdp(); /* reset the RDP port */
948 udelay(1000); /* delay 1000us */
949 isapnp_write_byte(0x06, csn); /* reset CSN to previous value */
950 udelay(250); /* is this necessary? */
953 isapnp_device(logdev);
957 int isapnp_cfg_end(void)
960 up(&isapnp_cfg_mutex);
970 EXPORT_SYMBOL(isapnp_protocol);
971 EXPORT_SYMBOL(isapnp_present);
972 EXPORT_SYMBOL(isapnp_cfg_begin);
973 EXPORT_SYMBOL(isapnp_cfg_end);
974 EXPORT_SYMBOL(isapnp_read_byte);
975 EXPORT_SYMBOL(isapnp_read_word);
976 EXPORT_SYMBOL(isapnp_read_dword);
977 EXPORT_SYMBOL(isapnp_write_byte);
978 EXPORT_SYMBOL(isapnp_write_word);
979 EXPORT_SYMBOL(isapnp_write_dword);
980 EXPORT_SYMBOL(isapnp_wake);
981 EXPORT_SYMBOL(isapnp_device);
983 static int isapnp_read_resources(struct pnp_dev *dev, struct pnp_resource_table *res)
987 dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
989 for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) {
990 ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
993 res->port_resource[tmp].start = ret;
994 res->port_resource[tmp].flags = IORESOURCE_IO;
996 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) {
997 ret = isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
1000 res->mem_resource[tmp].start = ret;
1001 res->mem_resource[tmp].flags = IORESOURCE_MEM;
1003 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) {
1004 ret = (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >> 8);
1007 res->irq_resource[tmp].start = res->irq_resource[tmp].end = ret;
1008 res->irq_resource[tmp].flags = IORESOURCE_IRQ;
1010 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) {
1011 ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
1014 res->dma_resource[tmp].start = res->dma_resource[tmp].end = ret;
1015 res->dma_resource[tmp].flags = IORESOURCE_DMA;
1021 static int isapnp_get_resources(struct pnp_dev *dev, struct pnp_resource_table * res)
1024 pnp_init_resource_table(res);
1025 isapnp_cfg_begin(dev->card->number, dev->number);
1026 ret = isapnp_read_resources(dev, res);
1031 static int isapnp_set_resources(struct pnp_dev *dev, struct pnp_resource_table * res)
1035 isapnp_cfg_begin(dev->card->number, dev->number);
1037 for (tmp = 0; tmp < PNP_MAX_PORT && (res->port_resource[tmp].flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO; tmp++)
1038 isapnp_write_word(ISAPNP_CFG_PORT+(tmp<<1), res->port_resource[tmp].start);
1039 for (tmp = 0; tmp < PNP_MAX_IRQ && (res->irq_resource[tmp].flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ; tmp++) {
1040 int irq = res->irq_resource[tmp].start;
1043 isapnp_write_byte(ISAPNP_CFG_IRQ+(tmp<<1), irq);
1045 for (tmp = 0; tmp < PNP_MAX_DMA && (res->dma_resource[tmp].flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA; tmp++)
1046 isapnp_write_byte(ISAPNP_CFG_DMA+tmp, res->dma_resource[tmp].start);
1047 for (tmp = 0; tmp < PNP_MAX_MEM && (res->mem_resource[tmp].flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM; tmp++)
1048 isapnp_write_word(ISAPNP_CFG_MEM+(tmp<<3), (res->mem_resource[tmp].start >> 8) & 0xffff);
1049 /* FIXME: We aren't handling 32bit mems properly here */
1050 isapnp_activate(dev->number);
1055 static int isapnp_disable_resources(struct pnp_dev *dev)
1057 if (!dev || !dev->active)
1059 isapnp_cfg_begin(dev->card->number, dev->number);
1060 isapnp_deactivate(dev->number);
1066 struct pnp_protocol isapnp_protocol = {
1067 .name = "ISA Plug and Play",
1068 .get = isapnp_get_resources,
1069 .set = isapnp_set_resources,
1070 .disable = isapnp_disable_resources,
1073 int __init isapnp_init(void)
1076 struct pnp_card *card;
1077 struct pnp_dev *dev;
1079 if (isapnp_disable) {
1080 isapnp_detected = 0;
1081 printk(KERN_INFO "isapnp: ISA Plug & Play support disabled\n");
1084 #ifdef ISAPNP_REGION_OK
1085 if (!request_region(_PIDXR, 1, "isapnp index")) {
1086 printk(KERN_ERR "isapnp: Index Register 0x%x already used\n", _PIDXR);
1090 if (!request_region(_PNPWRP, 1, "isapnp write")) {
1091 printk(KERN_ERR "isapnp: Write Data Register 0x%x already used\n", _PNPWRP);
1092 #ifdef ISAPNP_REGION_OK
1093 release_region(_PIDXR, 1);
1098 if(pnp_register_protocol(&isapnp_protocol)<0)
1102 * Print a message. The existing ISAPnP code is hanging machines
1103 * so let the user know where.
1106 printk(KERN_INFO "isapnp: Scanning for PnP cards...\n");
1107 if (isapnp_rdp >= 0x203 && isapnp_rdp <= 0x3ff) {
1109 if (!request_region(isapnp_rdp, 1, "isapnp read")) {
1110 printk(KERN_ERR "isapnp: Read Data Register 0x%x already used\n", isapnp_rdp);
1111 #ifdef ISAPNP_REGION_OK
1112 release_region(_PIDXR, 1);
1114 release_region(_PNPWRP, 1);
1119 isapnp_detected = 1;
1120 if (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff) {
1121 cards = isapnp_isolate();
1123 (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff)) {
1124 #ifdef ISAPNP_REGION_OK
1125 release_region(_PIDXR, 1);
1127 release_region(_PNPWRP, 1);
1128 isapnp_detected = 0;
1129 printk(KERN_INFO "isapnp: No Plug & Play device found\n");
1132 request_region(isapnp_rdp, 1, "isapnp read");
1134 isapnp_build_device_list();
1137 protocol_for_each_card(&isapnp_protocol,card) {
1139 if (isapnp_verbose) {
1140 printk(KERN_INFO "isapnp: Card '%s'\n", card->name[0]?card->name:"Unknown");
1141 if (isapnp_verbose < 2)
1143 card_for_each_dev(card,dev) {
1144 printk(KERN_INFO "isapnp: Device '%s'\n", dev->name[0]?dev->name:"Unknown");
1149 printk(KERN_INFO "isapnp: %i Plug & Play card%s detected total\n", cards, cards>1?"s":"");
1151 printk(KERN_INFO "isapnp: No Plug & Play card found\n");
1158 device_initcall(isapnp_init);
1160 /* format is: noisapnp */
1162 static int __init isapnp_setup_disable(char *str)
1168 __setup("noisapnp", isapnp_setup_disable);
1170 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1172 static int __init isapnp_setup_isapnp(char *str)
1174 (void)((get_option(&str,&isapnp_rdp) == 2) &&
1175 (get_option(&str,&isapnp_reset) == 2) &&
1176 (get_option(&str,&isapnp_verbose) == 2));
1180 __setup("isapnp=", isapnp_setup_isapnp);