2 * ISA Plug & Play support
3 * Copyright (c) by Jaroslav Kysela <perex@perex.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/module.h>
38 #include <linux/kernel.h>
39 #include <linux/errno.h>
40 #include <linux/slab.h>
41 #include <linux/delay.h>
42 #include <linux/init.h>
43 #include <linux/isapnp.h>
44 #include <linux/mutex.h>
48 #define ISAPNP_REGION_OK
51 int isapnp_disable; /* Disable ISA PnP */
52 static int isapnp_rdp; /* Read Data Port */
53 static int isapnp_reset = 1; /* reset all PnP cards (deactivate) */
54 static int isapnp_verbose = 1; /* verbose mode */
56 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
57 MODULE_DESCRIPTION("Generic ISA Plug & Play support");
58 module_param(isapnp_disable, int, 0);
59 MODULE_PARM_DESC(isapnp_disable, "ISA Plug & Play disable");
60 module_param(isapnp_rdp, int, 0);
61 MODULE_PARM_DESC(isapnp_rdp, "ISA Plug & Play read data port");
62 module_param(isapnp_reset, int, 0);
63 MODULE_PARM_DESC(isapnp_reset, "ISA Plug & Play reset all cards");
64 module_param(isapnp_verbose, int, 0);
65 MODULE_PARM_DESC(isapnp_verbose, "ISA Plug & Play verbose mode");
66 MODULE_LICENSE("GPL");
72 #define _STAG_PNPVERNO 0x01
73 #define _STAG_LOGDEVID 0x02
74 #define _STAG_COMPATDEVID 0x03
75 #define _STAG_IRQ 0x04
76 #define _STAG_DMA 0x05
77 #define _STAG_STARTDEP 0x06
78 #define _STAG_ENDDEP 0x07
79 #define _STAG_IOPORT 0x08
80 #define _STAG_FIXEDIO 0x09
81 #define _STAG_VENDOR 0x0e
82 #define _STAG_END 0x0f
84 #define _LTAG_MEMRANGE 0x81
85 #define _LTAG_ANSISTR 0x82
86 #define _LTAG_UNICODESTR 0x83
87 #define _LTAG_VENDOR 0x84
88 #define _LTAG_MEM32RANGE 0x85
89 #define _LTAG_FIXEDMEM32RANGE 0x86
91 /* Logical device control and configuration registers */
93 #define ISAPNP_CFG_ACTIVATE 0x30 /* byte */
94 #define ISAPNP_CFG_MEM 0x40 /* 4 * dword */
95 #define ISAPNP_CFG_PORT 0x60 /* 8 * word */
96 #define ISAPNP_CFG_IRQ 0x70 /* 2 * word */
97 #define ISAPNP_CFG_DMA 0x74 /* 2 * byte */
100 * Sizes of ISAPNP logical device configuration register sets.
101 * See PNP-ISA-v1.0a.pdf, Appendix A.
103 #define ISAPNP_MAX_MEM 4
104 #define ISAPNP_MAX_PORT 8
105 #define ISAPNP_MAX_IRQ 2
106 #define ISAPNP_MAX_DMA 2
108 static unsigned char isapnp_checksum_value;
109 static DEFINE_MUTEX(isapnp_cfg_mutex);
110 static int isapnp_csn_count;
112 /* some prototypes */
114 static inline void write_data(unsigned char x)
119 static inline void write_address(unsigned char x)
125 static inline unsigned char read_data(void)
127 unsigned char val = inb(isapnp_rdp);
131 unsigned char isapnp_read_byte(unsigned char idx)
137 static unsigned short isapnp_read_word(unsigned char idx)
141 val = isapnp_read_byte(idx);
142 val = (val << 8) + isapnp_read_byte(idx + 1);
146 void isapnp_write_byte(unsigned char idx, unsigned char val)
152 static void isapnp_write_word(unsigned char idx, unsigned short val)
154 isapnp_write_byte(idx, val >> 8);
155 isapnp_write_byte(idx + 1, val);
158 static void isapnp_key(void)
160 unsigned char code = 0x6a, msb;
169 for (i = 1; i < 32; i++) {
170 msb = ((code & 0x01) ^ ((code & 0x02) >> 1)) << 7;
171 code = (code >> 1) | msb;
176 /* place all pnp cards in wait-for-key state */
177 static void isapnp_wait(void)
179 isapnp_write_byte(0x02, 0x02);
182 static void isapnp_wake(unsigned char csn)
184 isapnp_write_byte(0x03, csn);
187 static void isapnp_device(unsigned char logdev)
189 isapnp_write_byte(0x07, logdev);
192 static void isapnp_activate(unsigned char logdev)
194 isapnp_device(logdev);
195 isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 1);
199 static void isapnp_deactivate(unsigned char logdev)
201 isapnp_device(logdev);
202 isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 0);
206 static void __init isapnp_peek(unsigned char *data, int bytes)
211 for (i = 1; i <= bytes; i++) {
212 for (j = 0; j < 20; j++) {
213 d = isapnp_read_byte(0x05);
223 d = isapnp_read_byte(0x04); /* PRESDI */
224 isapnp_checksum_value += d;
230 #define RDP_STEP 32 /* minimum is 4 */
232 static int isapnp_next_rdp(void)
234 int rdp = isapnp_rdp;
235 static int old_rdp = 0;
238 release_region(old_rdp, 1);
241 while (rdp <= 0x3ff) {
243 * We cannot use NE2000 probe spaces for ISAPnP or we
244 * will lock up machines.
246 if ((rdp < 0x280 || rdp > 0x380)
247 && request_region(rdp, 1, "ISAPnP")) {
257 /* Set read port address */
258 static inline void isapnp_set_rdp(void)
260 isapnp_write_byte(0x00, isapnp_rdp >> 2);
265 * Perform an isolation. The port selection code now tries to avoid
266 * "dangerous to read" ports.
268 static int __init isapnp_isolate_rdp_select(void)
273 /* Control: reset CSN and conditionally everything else too */
274 isapnp_write_byte(0x02, isapnp_reset ? 0x05 : 0x04);
281 if (isapnp_next_rdp() < 0) {
294 * Isolate (assign uniqued CSN) to all ISA PnP devices.
296 static int __init isapnp_isolate(void)
298 unsigned char checksum = 0x6a;
299 unsigned char chksum = 0x00;
300 unsigned char bit = 0x00;
307 if (isapnp_isolate_rdp_select() < 0)
311 for (i = 1; i <= 64; i++) {
312 data = read_data() << 8;
314 data = data | read_data();
319 ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7)
323 for (i = 65; i <= 72; i++) {
324 data = read_data() << 8;
326 data = data | read_data();
329 chksum |= (1 << (i - 65));
331 if (checksum != 0x00 && checksum == chksum) {
334 isapnp_write_byte(0x06, csn);
344 if (iteration == 1) {
345 isapnp_rdp += RDP_STEP;
346 if (isapnp_isolate_rdp_select() < 0)
348 } else if (iteration > 1) {
359 isapnp_csn_count = csn;
364 * Read one tag from stream.
366 static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
368 unsigned char tag, tmp[2];
370 isapnp_peek(&tag, 1);
371 if (tag == 0) /* invalid tag */
373 if (tag & 0x80) { /* large item */
376 *size = (tmp[1] << 8) | tmp[0];
378 *type = (tag >> 3) & 0x0f;
382 printk(KERN_DEBUG "tag = 0x%x, type = 0x%x, size = %i\n", tag, *type,
385 if (*type == 0xff && *size == 0xffff) /* probably invalid data */
391 * Skip specified number of bytes from stream.
393 static void __init isapnp_skip_bytes(int count)
395 isapnp_peek(NULL, count);
401 static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
402 unsigned short device)
408 id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
411 sprintf(id->id, "%c%c%c%x%x%x%x",
412 'A' + ((vendor >> 2) & 0x3f) - 1,
413 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
414 'A' + ((vendor >> 8) & 0x1f) - 1,
415 (device >> 4) & 0x0f,
416 device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
421 * Parse logical device tag.
423 static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
424 int size, int number)
426 unsigned char tmp[6];
429 isapnp_peek(tmp, size);
430 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
433 dev->number = number;
434 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
438 dev->regs |= tmp[5] << 8;
439 dev->protocol = &isapnp_protocol;
440 dev->capabilities |= PNP_CONFIGURABLE;
441 dev->capabilities |= PNP_READ;
442 dev->capabilities |= PNP_WRITE;
443 dev->capabilities |= PNP_DISABLE;
444 pnp_init_resource_table(&dev->res);
449 * Add IRQ resource to resources list.
451 static void __init isapnp_parse_irq_resource(struct pnp_option *option,
454 unsigned char tmp[3];
458 isapnp_peek(tmp, size);
459 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
462 bits = (tmp[1] << 8) | tmp[0];
463 bitmap_copy(irq->map, &bits, 16);
467 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
468 pnp_register_irq_resource(option, irq);
472 * Add DMA resource to resources list.
474 static void __init isapnp_parse_dma_resource(struct pnp_option *option,
477 unsigned char tmp[2];
480 isapnp_peek(tmp, size);
481 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
486 pnp_register_dma_resource(option, dma);
490 * Add port resource to resources list.
492 static void __init isapnp_parse_port_resource(struct pnp_option *option,
495 unsigned char tmp[7];
496 struct pnp_port *port;
498 isapnp_peek(tmp, size);
499 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
502 port->min = (tmp[2] << 8) | tmp[1];
503 port->max = (tmp[4] << 8) | tmp[3];
504 port->align = tmp[5];
506 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0;
507 pnp_register_port_resource(option, port);
511 * Add fixed port resource to resources list.
513 static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
516 unsigned char tmp[3];
517 struct pnp_port *port;
519 isapnp_peek(tmp, size);
520 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
523 port->min = port->max = (tmp[1] << 8) | tmp[0];
526 port->flags = PNP_PORT_FLAG_FIXED;
527 pnp_register_port_resource(option, port);
531 * Add memory resource to resources list.
533 static void __init isapnp_parse_mem_resource(struct pnp_option *option,
536 unsigned char tmp[9];
539 isapnp_peek(tmp, size);
540 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
543 mem->min = ((tmp[2] << 8) | tmp[1]) << 8;
544 mem->max = ((tmp[4] << 8) | tmp[3]) << 8;
545 mem->align = (tmp[6] << 8) | tmp[5];
546 mem->size = ((tmp[8] << 8) | tmp[7]) << 8;
548 pnp_register_mem_resource(option, mem);
552 * Add 32-bit memory resource to resources list.
554 static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
557 unsigned char tmp[17];
560 isapnp_peek(tmp, size);
561 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
564 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
565 mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
567 (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9];
569 (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
571 pnp_register_mem_resource(option, mem);
575 * Add 32-bit fixed memory resource to resources list.
577 static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
580 unsigned char tmp[9];
583 isapnp_peek(tmp, size);
584 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
587 mem->min = mem->max =
588 (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
589 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
592 pnp_register_mem_resource(option, mem);
596 * Parse card name for ISA PnP device.
599 isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size)
601 if (name[0] == '\0') {
602 unsigned short size1 =
603 *size >= name_max ? (name_max - 1) : *size;
604 isapnp_peek(name, size1);
608 /* clean whitespace from end of string */
609 while (size1 > 0 && name[--size1] == ' ')
615 * Parse resource map for logical device.
617 static int __init isapnp_create_device(struct pnp_card *card,
620 int number = 0, skip = 0, priority = 0, compat = 0;
621 unsigned char type, tmp[17];
622 struct pnp_option *option;
625 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
627 option = pnp_register_independent_option(dev);
632 pnp_add_card_device(card, dev);
635 if (isapnp_read_tag(&type, &size) < 0)
637 if (skip && type != _STAG_LOGDEVID && type != _STAG_END)
641 if (size >= 5 && size <= 6) {
643 isapnp_parse_device(card, size,
648 option = pnp_register_independent_option(dev);
653 pnp_add_card_device(card, dev);
660 case _STAG_COMPATDEVID:
661 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
663 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0],
664 (tmp[3] << 8) | tmp[2]);
670 if (size < 2 || size > 3)
672 isapnp_parse_irq_resource(option, size);
678 isapnp_parse_dma_resource(option, size);
684 priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE;
686 isapnp_peek(tmp, size);
687 priority = 0x100 | tmp[0];
690 option = pnp_register_dependent_option(dev, priority);
702 isapnp_parse_port_resource(option, size);
708 isapnp_parse_fixed_port_resource(option, size);
716 isapnp_parse_mem_resource(option, size);
720 isapnp_parse_name(dev->name, sizeof(dev->name), &size);
722 case _LTAG_UNICODESTR:
723 /* silently ignore */
724 /* who use unicode for hardware identification? */
728 case _LTAG_MEM32RANGE:
731 isapnp_parse_mem32_resource(option, size);
734 case _LTAG_FIXEDMEM32RANGE:
737 isapnp_parse_fixed_mem32_resource(option, size);
742 isapnp_skip_bytes(size);
746 "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n",
747 type, dev->number, card->number);
751 isapnp_skip_bytes(size);
757 * Parse resource map for ISA PnP card.
759 static void __init isapnp_parse_resource_map(struct pnp_card *card)
761 unsigned char type, tmp[17];
765 if (isapnp_read_tag(&type, &size) < 0)
772 card->pnpver = tmp[0];
773 card->productver = tmp[1];
777 if (size >= 5 && size <= 6) {
778 if (isapnp_create_device(card, size) == 1)
786 isapnp_parse_name(card->name, sizeof(card->name),
789 case _LTAG_UNICODESTR:
790 /* silently ignore */
791 /* who use unicode for hardware identification? */
797 isapnp_skip_bytes(size);
801 "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n",
806 isapnp_skip_bytes(size);
811 * Compute ISA PnP checksum for first eight bytes.
813 static unsigned char __init isapnp_checksum(unsigned char *data)
816 unsigned char checksum = 0x6a, bit, b;
818 for (i = 0; i < 8; i++) {
820 for (j = 0; j < 8; j++) {
825 ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7)
833 * Parse EISA id for ISA PnP card.
835 static void isapnp_parse_card_id(struct pnp_card *card, unsigned short vendor,
836 unsigned short device)
838 struct pnp_id *id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
842 sprintf(id->id, "%c%c%c%x%x%x%x",
843 'A' + ((vendor >> 2) & 0x3f) - 1,
844 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
845 'A' + ((vendor >> 8) & 0x1f) - 1,
846 (device >> 4) & 0x0f,
847 device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
848 pnp_add_card_id(id, card);
852 * Build device list for all present ISA PnP devices.
854 static int __init isapnp_build_device_list(void)
857 unsigned char header[9], checksum;
858 struct pnp_card *card;
862 for (csn = 1; csn <= isapnp_csn_count; csn++) {
864 isapnp_peek(header, 9);
865 checksum = isapnp_checksum(header);
868 "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
869 header[0], header[1], header[2], header[3], header[4],
870 header[5], header[6], header[7], header[8]);
871 printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
874 kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
878 INIT_LIST_HEAD(&card->devices);
879 isapnp_parse_card_id(card, (header[1] << 8) | header[0],
880 (header[3] << 8) | header[2]);
882 (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
884 isapnp_checksum_value = 0x00;
885 isapnp_parse_resource_map(card);
886 if (isapnp_checksum_value != 0x00)
888 "isapnp: checksum for device %i is not valid (0x%x)\n",
889 csn, isapnp_checksum_value);
890 card->checksum = isapnp_checksum_value;
891 card->protocol = &isapnp_protocol;
900 * Basic configuration routines.
903 int isapnp_present(void)
905 struct pnp_card *card;
907 pnp_for_each_card(card) {
908 if (card->protocol == &isapnp_protocol)
914 int isapnp_cfg_begin(int csn, int logdev)
916 if (csn < 1 || csn > isapnp_csn_count || logdev > 10)
918 mutex_lock(&isapnp_cfg_mutex);
923 /* to avoid malfunction when the isapnptools package is used */
924 /* we must set RDP to our value again */
925 /* it is possible to set RDP only in the isolation phase */
926 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
927 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
928 mdelay(2); /* is this necessary? */
929 isapnp_wake(csn); /* bring card into sleep state */
930 isapnp_wake(0); /* bring card into isolation state */
931 isapnp_set_rdp(); /* reset the RDP port */
932 udelay(1000); /* delay 1000us */
933 isapnp_write_byte(0x06, csn); /* reset CSN to previous value */
934 udelay(250); /* is this necessary? */
937 isapnp_device(logdev);
941 int isapnp_cfg_end(void)
944 mutex_unlock(&isapnp_cfg_mutex);
952 EXPORT_SYMBOL(isapnp_protocol);
953 EXPORT_SYMBOL(isapnp_present);
954 EXPORT_SYMBOL(isapnp_cfg_begin);
955 EXPORT_SYMBOL(isapnp_cfg_end);
956 EXPORT_SYMBOL(isapnp_write_byte);
958 static int isapnp_read_resources(struct pnp_dev *dev,
959 struct pnp_resource_table *res)
963 dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
965 for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
966 ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
969 res->port_resource[tmp].start = ret;
970 res->port_resource[tmp].flags = IORESOURCE_IO;
972 for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
974 isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
977 res->mem_resource[tmp].start = ret;
978 res->mem_resource[tmp].flags = IORESOURCE_MEM;
980 for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
982 (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >>
986 res->irq_resource[tmp].start =
987 res->irq_resource[tmp].end = ret;
988 res->irq_resource[tmp].flags = IORESOURCE_IRQ;
990 for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
991 ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
994 res->dma_resource[tmp].start =
995 res->dma_resource[tmp].end = ret;
996 res->dma_resource[tmp].flags = IORESOURCE_DMA;
1002 static int isapnp_get_resources(struct pnp_dev *dev,
1003 struct pnp_resource_table *res)
1007 pnp_init_resource_table(res);
1008 isapnp_cfg_begin(dev->card->number, dev->number);
1009 ret = isapnp_read_resources(dev, res);
1014 static int isapnp_set_resources(struct pnp_dev *dev,
1015 struct pnp_resource_table *res)
1019 isapnp_cfg_begin(dev->card->number, dev->number);
1022 tmp < ISAPNP_MAX_PORT
1023 && (res->port_resource[tmp].
1024 flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO;
1026 isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
1027 res->port_resource[tmp].start);
1029 tmp < ISAPNP_MAX_IRQ
1030 && (res->irq_resource[tmp].
1031 flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ;
1033 int irq = res->irq_resource[tmp].start;
1036 isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq);
1039 tmp < ISAPNP_MAX_DMA
1040 && (res->dma_resource[tmp].
1041 flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA;
1043 isapnp_write_byte(ISAPNP_CFG_DMA + tmp,
1044 res->dma_resource[tmp].start);
1046 tmp < ISAPNP_MAX_MEM
1047 && (res->mem_resource[tmp].
1048 flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM;
1050 isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
1051 (res->mem_resource[tmp].start >> 8) & 0xffff);
1052 /* FIXME: We aren't handling 32bit mems properly here */
1053 isapnp_activate(dev->number);
1058 static int isapnp_disable_resources(struct pnp_dev *dev)
1062 isapnp_cfg_begin(dev->card->number, dev->number);
1063 isapnp_deactivate(dev->number);
1069 struct pnp_protocol isapnp_protocol = {
1070 .name = "ISA Plug and Play",
1071 .get = isapnp_get_resources,
1072 .set = isapnp_set_resources,
1073 .disable = isapnp_disable_resources,
1076 static int __init isapnp_init(void)
1079 struct pnp_card *card;
1080 struct pnp_dev *dev;
1082 if (isapnp_disable) {
1083 printk(KERN_INFO "isapnp: ISA Plug & Play support disabled\n");
1086 #ifdef CONFIG_PPC_MERGE
1087 if (check_legacy_ioport(_PIDXR) || check_legacy_ioport(_PNPWRP))
1090 #ifdef ISAPNP_REGION_OK
1091 if (!request_region(_PIDXR, 1, "isapnp index")) {
1092 printk(KERN_ERR "isapnp: Index Register 0x%x already used\n",
1097 if (!request_region(_PNPWRP, 1, "isapnp write")) {
1099 "isapnp: Write Data Register 0x%x already used\n",
1101 #ifdef ISAPNP_REGION_OK
1102 release_region(_PIDXR, 1);
1107 if (pnp_register_protocol(&isapnp_protocol) < 0)
1111 * Print a message. The existing ISAPnP code is hanging machines
1112 * so let the user know where.
1115 printk(KERN_INFO "isapnp: Scanning for PnP cards...\n");
1116 if (isapnp_rdp >= 0x203 && isapnp_rdp <= 0x3ff) {
1118 if (!request_region(isapnp_rdp, 1, "isapnp read")) {
1120 "isapnp: Read Data Register 0x%x already used\n",
1122 #ifdef ISAPNP_REGION_OK
1123 release_region(_PIDXR, 1);
1125 release_region(_PNPWRP, 1);
1130 if (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff) {
1131 cards = isapnp_isolate();
1132 if (cards < 0 || (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff)) {
1133 #ifdef ISAPNP_REGION_OK
1134 release_region(_PIDXR, 1);
1136 release_region(_PNPWRP, 1);
1138 "isapnp: No Plug & Play device found\n");
1141 request_region(isapnp_rdp, 1, "isapnp read");
1143 isapnp_build_device_list();
1146 protocol_for_each_card(&isapnp_protocol, card) {
1148 if (isapnp_verbose) {
1149 printk(KERN_INFO "isapnp: Card '%s'\n",
1150 card->name[0] ? card->name : "Unknown");
1151 if (isapnp_verbose < 2)
1153 card_for_each_dev(card, dev) {
1154 printk(KERN_INFO "isapnp: Device '%s'\n",
1155 dev->name[0] ? dev->name : "Unknown");
1161 "isapnp: %i Plug & Play card%s detected total\n", cards,
1162 cards > 1 ? "s" : "");
1164 printk(KERN_INFO "isapnp: No Plug & Play card found\n");
1170 device_initcall(isapnp_init);
1172 /* format is: noisapnp */
1174 static int __init isapnp_setup_disable(char *str)
1180 __setup("noisapnp", isapnp_setup_disable);
1182 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1184 static int __init isapnp_setup_isapnp(char *str)
1186 (void)((get_option(&str, &isapnp_rdp) == 2) &&
1187 (get_option(&str, &isapnp_reset) == 2) &&
1188 (get_option(&str, &isapnp_verbose) == 2));
1192 __setup("isapnp=", isapnp_setup_isapnp);