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");
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];
481 isapnp_peek(tmp, size);
482 irq = isapnp_alloc(sizeof(struct pnp_irq));
485 irq->map = (tmp[1] << 8) | tmp[0];
489 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
490 pnp_register_irq_resource(option, irq);
495 * Add DMA resource to resources list.
498 static void __init isapnp_parse_dma_resource(struct pnp_option *option,
501 unsigned char tmp[2];
504 isapnp_peek(tmp, size);
505 dma = isapnp_alloc(sizeof(struct pnp_dma));
510 pnp_register_dma_resource(option, dma);
515 * Add port resource to resources list.
518 static void __init isapnp_parse_port_resource(struct pnp_option *option,
521 unsigned char tmp[7];
522 struct pnp_port *port;
524 isapnp_peek(tmp, size);
525 port = isapnp_alloc(sizeof(struct pnp_port));
528 port->min = (tmp[2] << 8) | tmp[1];
529 port->max = (tmp[4] << 8) | tmp[3];
530 port->align = tmp[5];
532 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0;
533 pnp_register_port_resource(option,port);
538 * Add fixed port resource to resources list.
541 static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
544 unsigned char tmp[3];
545 struct pnp_port *port;
547 isapnp_peek(tmp, size);
548 port = isapnp_alloc(sizeof(struct pnp_port));
551 port->min = port->max = (tmp[1] << 8) | tmp[0];
554 port->flags = PNP_PORT_FLAG_FIXED;
555 pnp_register_port_resource(option,port);
560 * Add memory resource to resources list.
563 static void __init isapnp_parse_mem_resource(struct pnp_option *option,
566 unsigned char tmp[9];
569 isapnp_peek(tmp, size);
570 mem = isapnp_alloc(sizeof(struct pnp_mem));
573 mem->min = ((tmp[2] << 8) | tmp[1]) << 8;
574 mem->max = ((tmp[4] << 8) | tmp[3]) << 8;
575 mem->align = (tmp[6] << 8) | tmp[5];
576 mem->size = ((tmp[8] << 8) | tmp[7]) << 8;
578 pnp_register_mem_resource(option,mem);
583 * Add 32-bit memory resource to resources list.
586 static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
589 unsigned char tmp[17];
592 isapnp_peek(tmp, size);
593 mem = isapnp_alloc(sizeof(struct pnp_mem));
596 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
597 mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
598 mem->align = (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9];
599 mem->size = (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
601 pnp_register_mem_resource(option,mem);
605 * Add 32-bit fixed memory resource to resources list.
608 static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
611 unsigned char tmp[9];
614 isapnp_peek(tmp, size);
615 mem = isapnp_alloc(sizeof(struct pnp_mem));
618 mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
619 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
622 pnp_register_mem_resource(option,mem);
626 * Parse card name for ISA PnP device.
630 isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size)
632 if (name[0] == '\0') {
633 unsigned short size1 = *size >= name_max ? (name_max - 1) : *size;
634 isapnp_peek(name, size1);
638 /* clean whitespace from end of string */
639 while (size1 > 0 && name[--size1] == ' ')
645 * Parse resource map for logical device.
648 static int __init isapnp_create_device(struct pnp_card *card,
651 int number = 0, skip = 0, priority = 0, compat = 0;
652 unsigned char type, tmp[17];
653 struct pnp_option *option;
655 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
657 option = pnp_register_independent_option(dev);
662 pnp_add_card_device(card,dev);
665 if (isapnp_read_tag(&type, &size)<0)
667 if (skip && type != _STAG_LOGDEVID && type != _STAG_END)
671 if (size >= 5 && size <= 6) {
672 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
676 option = pnp_register_independent_option(dev);
679 pnp_add_card_device(card,dev);
686 case _STAG_COMPATDEVID:
687 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
689 isapnp_parse_id(dev,(tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
695 if (size < 2 || size > 3)
697 isapnp_parse_irq_resource(option, size);
703 isapnp_parse_dma_resource(option, size);
709 priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE;
711 isapnp_peek(tmp, size);
712 priority = 0x100 | tmp[0];
715 option = pnp_register_dependent_option(dev,priority);
727 isapnp_parse_port_resource(option, size);
733 isapnp_parse_fixed_port_resource(option, size);
741 isapnp_parse_mem_resource(option, size);
745 isapnp_parse_name(dev->name, sizeof(dev->name), &size);
747 case _LTAG_UNICODESTR:
748 /* silently ignore */
749 /* who use unicode for hardware identification? */
753 case _LTAG_MEM32RANGE:
756 isapnp_parse_mem32_resource(option, size);
759 case _LTAG_FIXEDMEM32RANGE:
762 isapnp_parse_fixed_mem32_resource(option, size);
767 isapnp_skip_bytes(size);
770 printk(KERN_ERR "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n", type, dev->number, card->number);
774 isapnp_skip_bytes(size);
780 * Parse resource map for ISA PnP card.
783 static void __init isapnp_parse_resource_map(struct pnp_card *card)
785 unsigned char type, tmp[17];
789 if (isapnp_read_tag(&type, &size)<0)
796 card->pnpver = tmp[0];
797 card->productver = tmp[1];
801 if (size >= 5 && size <= 6) {
802 if (isapnp_create_device(card, size)==1)
810 isapnp_parse_name(card->name, sizeof(card->name), &size);
812 case _LTAG_UNICODESTR:
813 /* silently ignore */
814 /* who use unicode for hardware identification? */
820 isapnp_skip_bytes(size);
823 printk(KERN_ERR "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n", type, card->number);
827 isapnp_skip_bytes(size);
832 * Compute ISA PnP checksum for first eight bytes.
835 static unsigned char __init isapnp_checksum(unsigned char *data)
838 unsigned char checksum = 0x6a, bit, b;
840 for (i = 0; i < 8; i++) {
842 for (j = 0; j < 8; j++) {
846 checksum = ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7) | (checksum >> 1);
853 * Parse EISA id for ISA PnP card.
856 static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device)
858 struct pnp_id * id = isapnp_alloc(sizeof(struct pnp_id));
861 sprintf(id->id, "%c%c%c%x%x%x%x",
862 'A' + ((vendor >> 2) & 0x3f) - 1,
863 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
864 'A' + ((vendor >> 8) & 0x1f) - 1,
865 (device >> 4) & 0x0f,
867 (device >> 12) & 0x0f,
868 (device >> 8) & 0x0f);
869 pnp_add_card_id(id,card);
873 * Build device list for all present ISA PnP devices.
876 static int __init isapnp_build_device_list(void)
879 unsigned char header[9], checksum;
880 struct pnp_card *card;
884 for (csn = 1; csn <= isapnp_csn_count; csn++) {
886 isapnp_peek(header, 9);
887 checksum = isapnp_checksum(header);
889 printk(KERN_DEBUG "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
890 header[0], header[1], header[2], header[3],
891 header[4], header[5], header[6], header[7], header[8]);
892 printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
894 if ((card = isapnp_alloc(sizeof(struct pnp_card))) == NULL)
898 INIT_LIST_HEAD(&card->devices);
899 isapnp_parse_card_id(card, (header[1] << 8) | header[0], (header[3] << 8) | header[2]);
900 card->serial = (header[7] << 24) | (header[6] << 16) | (header[5] << 8) | header[4];
901 isapnp_checksum_value = 0x00;
902 isapnp_parse_resource_map(card);
903 if (isapnp_checksum_value != 0x00)
904 printk(KERN_ERR "isapnp: checksum for device %i is not valid (0x%x)\n", csn, isapnp_checksum_value);
905 card->checksum = isapnp_checksum_value;
906 card->protocol = &isapnp_protocol;
915 * Basic configuration routines.
918 int isapnp_present(void)
920 struct pnp_card *card;
921 pnp_for_each_card(card) {
922 if (card->protocol == &isapnp_protocol)
928 int isapnp_cfg_begin(int csn, int logdev)
930 if (csn < 1 || csn > isapnp_csn_count || logdev > 10)
932 down(&isapnp_cfg_mutex);
937 /* to avoid malfunction when the isapnptools package is used */
938 /* we must set RDP to our value again */
939 /* it is possible to set RDP only in the isolation phase */
940 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
941 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
942 mdelay(2); /* is this necessary? */
943 isapnp_wake(csn); /* bring card into sleep state */
944 isapnp_wake(0); /* bring card into isolation state */
945 isapnp_set_rdp(); /* reset the RDP port */
946 udelay(1000); /* delay 1000us */
947 isapnp_write_byte(0x06, csn); /* reset CSN to previous value */
948 udelay(250); /* is this necessary? */
951 isapnp_device(logdev);
955 int isapnp_cfg_end(void)
958 up(&isapnp_cfg_mutex);
968 EXPORT_SYMBOL(isapnp_protocol);
969 EXPORT_SYMBOL(isapnp_present);
970 EXPORT_SYMBOL(isapnp_cfg_begin);
971 EXPORT_SYMBOL(isapnp_cfg_end);
972 EXPORT_SYMBOL(isapnp_read_byte);
973 EXPORT_SYMBOL(isapnp_read_word);
974 EXPORT_SYMBOL(isapnp_read_dword);
975 EXPORT_SYMBOL(isapnp_write_byte);
976 EXPORT_SYMBOL(isapnp_write_word);
977 EXPORT_SYMBOL(isapnp_write_dword);
978 EXPORT_SYMBOL(isapnp_wake);
979 EXPORT_SYMBOL(isapnp_device);
981 static int isapnp_read_resources(struct pnp_dev *dev, struct pnp_resource_table *res)
985 dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
987 for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) {
988 ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
991 res->port_resource[tmp].start = ret;
992 res->port_resource[tmp].flags = IORESOURCE_IO;
994 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) {
995 ret = isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
998 res->mem_resource[tmp].start = ret;
999 res->mem_resource[tmp].flags = IORESOURCE_MEM;
1001 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) {
1002 ret = (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >> 8);
1005 res->irq_resource[tmp].start = res->irq_resource[tmp].end = ret;
1006 res->irq_resource[tmp].flags = IORESOURCE_IRQ;
1008 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) {
1009 ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
1012 res->dma_resource[tmp].start = res->dma_resource[tmp].end = ret;
1013 res->dma_resource[tmp].flags = IORESOURCE_DMA;
1019 static int isapnp_get_resources(struct pnp_dev *dev, struct pnp_resource_table * res)
1022 pnp_init_resource_table(res);
1023 isapnp_cfg_begin(dev->card->number, dev->number);
1024 ret = isapnp_read_resources(dev, res);
1029 static int isapnp_set_resources(struct pnp_dev *dev, struct pnp_resource_table * res)
1033 isapnp_cfg_begin(dev->card->number, dev->number);
1035 for (tmp = 0; tmp < PNP_MAX_PORT && (res->port_resource[tmp].flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO; tmp++)
1036 isapnp_write_word(ISAPNP_CFG_PORT+(tmp<<1), res->port_resource[tmp].start);
1037 for (tmp = 0; tmp < PNP_MAX_IRQ && (res->irq_resource[tmp].flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ; tmp++) {
1038 int irq = res->irq_resource[tmp].start;
1041 isapnp_write_byte(ISAPNP_CFG_IRQ+(tmp<<1), irq);
1043 for (tmp = 0; tmp < PNP_MAX_DMA && (res->dma_resource[tmp].flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA; tmp++)
1044 isapnp_write_byte(ISAPNP_CFG_DMA+tmp, res->dma_resource[tmp].start);
1045 for (tmp = 0; tmp < PNP_MAX_MEM && (res->mem_resource[tmp].flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM; tmp++)
1046 isapnp_write_word(ISAPNP_CFG_MEM+(tmp<<3), (res->mem_resource[tmp].start >> 8) & 0xffff);
1047 /* FIXME: We aren't handling 32bit mems properly here */
1048 isapnp_activate(dev->number);
1053 static int isapnp_disable_resources(struct pnp_dev *dev)
1055 if (!dev || !dev->active)
1057 isapnp_cfg_begin(dev->card->number, dev->number);
1058 isapnp_deactivate(dev->number);
1064 struct pnp_protocol isapnp_protocol = {
1065 .name = "ISA Plug and Play",
1066 .get = isapnp_get_resources,
1067 .set = isapnp_set_resources,
1068 .disable = isapnp_disable_resources,
1071 int __init isapnp_init(void)
1074 struct pnp_card *card;
1075 struct pnp_dev *dev;
1077 if (isapnp_disable) {
1078 isapnp_detected = 0;
1079 printk(KERN_INFO "isapnp: ISA Plug & Play support disabled\n");
1082 #ifdef ISAPNP_REGION_OK
1083 if (!request_region(_PIDXR, 1, "isapnp index")) {
1084 printk(KERN_ERR "isapnp: Index Register 0x%x already used\n", _PIDXR);
1088 if (!request_region(_PNPWRP, 1, "isapnp write")) {
1089 printk(KERN_ERR "isapnp: Write Data Register 0x%x already used\n", _PNPWRP);
1090 #ifdef ISAPNP_REGION_OK
1091 release_region(_PIDXR, 1);
1096 if(pnp_register_protocol(&isapnp_protocol)<0)
1100 * Print a message. The existing ISAPnP code is hanging machines
1101 * so let the user know where.
1104 printk(KERN_INFO "isapnp: Scanning for PnP cards...\n");
1105 if (isapnp_rdp >= 0x203 && isapnp_rdp <= 0x3ff) {
1107 if (!request_region(isapnp_rdp, 1, "isapnp read")) {
1108 printk(KERN_ERR "isapnp: Read Data Register 0x%x already used\n", isapnp_rdp);
1109 #ifdef ISAPNP_REGION_OK
1110 release_region(_PIDXR, 1);
1112 release_region(_PNPWRP, 1);
1117 isapnp_detected = 1;
1118 if (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff) {
1119 cards = isapnp_isolate();
1121 (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff)) {
1122 #ifdef ISAPNP_REGION_OK
1123 release_region(_PIDXR, 1);
1125 release_region(_PNPWRP, 1);
1126 isapnp_detected = 0;
1127 printk(KERN_INFO "isapnp: No Plug & Play device found\n");
1130 request_region(isapnp_rdp, 1, "isapnp read");
1132 isapnp_build_device_list();
1135 protocol_for_each_card(&isapnp_protocol,card) {
1137 if (isapnp_verbose) {
1138 printk(KERN_INFO "isapnp: Card '%s'\n", card->name[0]?card->name:"Unknown");
1139 if (isapnp_verbose < 2)
1141 card_for_each_dev(card,dev) {
1142 printk(KERN_INFO "isapnp: Device '%s'\n", dev->name[0]?dev->name:"Unknown");
1147 printk(KERN_INFO "isapnp: %i Plug & Play card%s detected total\n", cards, cards>1?"s":"");
1149 printk(KERN_INFO "isapnp: No Plug & Play card found\n");
1156 device_initcall(isapnp_init);
1158 /* format is: noisapnp */
1160 static int __init isapnp_setup_disable(char *str)
1166 __setup("noisapnp", isapnp_setup_disable);
1168 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1170 static int __init isapnp_setup_isapnp(char *str)
1172 (void)((get_option(&str,&isapnp_rdp) == 2) &&
1173 (get_option(&str,&isapnp_reset) == 2) &&
1174 (get_option(&str,&isapnp_verbose) == 2));
1178 __setup("isapnp=", isapnp_setup_isapnp);