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
92 * Sizes of ISAPNP logical device configuration register sets.
93 * See PNP-ISA-v1.0a.pdf, Appendix A.
95 #define ISAPNP_MAX_MEM 4
96 #define ISAPNP_MAX_PORT 8
97 #define ISAPNP_MAX_IRQ 2
98 #define ISAPNP_MAX_DMA 2
100 static unsigned char isapnp_checksum_value;
101 static DEFINE_MUTEX(isapnp_cfg_mutex);
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 static unsigned short isapnp_read_word(unsigned char idx)
133 val = isapnp_read_byte(idx);
134 val = (val << 8) + isapnp_read_byte(idx + 1);
138 void isapnp_write_byte(unsigned char idx, unsigned char val)
144 static void isapnp_write_word(unsigned char idx, unsigned short val)
146 isapnp_write_byte(idx, val >> 8);
147 isapnp_write_byte(idx + 1, val);
150 static void isapnp_key(void)
152 unsigned char code = 0x6a, msb;
161 for (i = 1; i < 32; i++) {
162 msb = ((code & 0x01) ^ ((code & 0x02) >> 1)) << 7;
163 code = (code >> 1) | msb;
168 /* place all pnp cards in wait-for-key state */
169 static void isapnp_wait(void)
171 isapnp_write_byte(0x02, 0x02);
174 static void isapnp_wake(unsigned char csn)
176 isapnp_write_byte(0x03, csn);
179 static void isapnp_device(unsigned char logdev)
181 isapnp_write_byte(0x07, logdev);
184 static void isapnp_activate(unsigned char logdev)
186 isapnp_device(logdev);
187 isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 1);
191 static void isapnp_deactivate(unsigned char logdev)
193 isapnp_device(logdev);
194 isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 0);
198 static void __init isapnp_peek(unsigned char *data, int bytes)
203 for (i = 1; i <= bytes; i++) {
204 for (j = 0; j < 20; j++) {
205 d = isapnp_read_byte(0x05);
215 d = isapnp_read_byte(0x04); /* PRESDI */
216 isapnp_checksum_value += d;
222 #define RDP_STEP 32 /* minimum is 4 */
224 static int isapnp_next_rdp(void)
226 int rdp = isapnp_rdp;
227 static int old_rdp = 0;
230 release_region(old_rdp, 1);
233 while (rdp <= 0x3ff) {
235 * We cannot use NE2000 probe spaces for ISAPnP or we
236 * will lock up machines.
238 if ((rdp < 0x280 || rdp > 0x380)
239 && request_region(rdp, 1, "ISAPnP")) {
249 /* Set read port address */
250 static inline void isapnp_set_rdp(void)
252 isapnp_write_byte(0x00, isapnp_rdp >> 2);
257 * Perform an isolation. The port selection code now tries to avoid
258 * "dangerous to read" ports.
260 static int __init isapnp_isolate_rdp_select(void)
265 /* Control: reset CSN and conditionally everything else too */
266 isapnp_write_byte(0x02, isapnp_reset ? 0x05 : 0x04);
273 if (isapnp_next_rdp() < 0) {
286 * Isolate (assign uniqued CSN) to all ISA PnP devices.
288 static int __init isapnp_isolate(void)
290 unsigned char checksum = 0x6a;
291 unsigned char chksum = 0x00;
292 unsigned char bit = 0x00;
299 if (isapnp_isolate_rdp_select() < 0)
303 for (i = 1; i <= 64; i++) {
304 data = read_data() << 8;
306 data = data | read_data();
311 ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7)
315 for (i = 65; i <= 72; i++) {
316 data = read_data() << 8;
318 data = data | read_data();
321 chksum |= (1 << (i - 65));
323 if (checksum != 0x00 && checksum == chksum) {
326 isapnp_write_byte(0x06, csn);
336 if (iteration == 1) {
337 isapnp_rdp += RDP_STEP;
338 if (isapnp_isolate_rdp_select() < 0)
340 } else if (iteration > 1) {
351 isapnp_csn_count = csn;
356 * Read one tag from stream.
358 static int __init isapnp_read_tag(unsigned char *type, unsigned short *size)
360 unsigned char tag, tmp[2];
362 isapnp_peek(&tag, 1);
363 if (tag == 0) /* invalid tag */
365 if (tag & 0x80) { /* large item */
368 *size = (tmp[1] << 8) | tmp[0];
370 *type = (tag >> 3) & 0x0f;
374 printk(KERN_DEBUG "tag = 0x%x, type = 0x%x, size = %i\n", tag, *type,
377 if (*type == 0xff && *size == 0xffff) /* probably invalid data */
383 * Skip specified number of bytes from stream.
385 static void __init isapnp_skip_bytes(int count)
387 isapnp_peek(NULL, count);
393 static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
394 unsigned short device)
400 id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
403 sprintf(id->id, "%c%c%c%x%x%x%x",
404 'A' + ((vendor >> 2) & 0x3f) - 1,
405 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
406 'A' + ((vendor >> 8) & 0x1f) - 1,
407 (device >> 4) & 0x0f,
408 device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
413 * Parse logical device tag.
415 static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
416 int size, int number)
418 unsigned char tmp[6];
421 isapnp_peek(tmp, size);
422 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
425 dev->number = number;
426 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
430 dev->regs |= tmp[5] << 8;
431 dev->protocol = &isapnp_protocol;
432 dev->capabilities |= PNP_CONFIGURABLE;
433 dev->capabilities |= PNP_READ;
434 dev->capabilities |= PNP_WRITE;
435 dev->capabilities |= PNP_DISABLE;
436 pnp_init_resource_table(&dev->res);
441 * Add IRQ resource to resources list.
443 static void __init isapnp_parse_irq_resource(struct pnp_option *option,
446 unsigned char tmp[3];
450 isapnp_peek(tmp, size);
451 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
454 bits = (tmp[1] << 8) | tmp[0];
455 bitmap_copy(irq->map, &bits, 16);
459 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
460 pnp_register_irq_resource(option, irq);
464 * Add DMA resource to resources list.
466 static void __init isapnp_parse_dma_resource(struct pnp_option *option,
469 unsigned char tmp[2];
472 isapnp_peek(tmp, size);
473 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
478 pnp_register_dma_resource(option, dma);
482 * Add port resource to resources list.
484 static void __init isapnp_parse_port_resource(struct pnp_option *option,
487 unsigned char tmp[7];
488 struct pnp_port *port;
490 isapnp_peek(tmp, size);
491 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
494 port->min = (tmp[2] << 8) | tmp[1];
495 port->max = (tmp[4] << 8) | tmp[3];
496 port->align = tmp[5];
498 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0;
499 pnp_register_port_resource(option, port);
503 * Add fixed port resource to resources list.
505 static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
508 unsigned char tmp[3];
509 struct pnp_port *port;
511 isapnp_peek(tmp, size);
512 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
515 port->min = port->max = (tmp[1] << 8) | tmp[0];
518 port->flags = PNP_PORT_FLAG_FIXED;
519 pnp_register_port_resource(option, port);
523 * Add memory resource to resources list.
525 static void __init isapnp_parse_mem_resource(struct pnp_option *option,
528 unsigned char tmp[9];
531 isapnp_peek(tmp, size);
532 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
535 mem->min = ((tmp[2] << 8) | tmp[1]) << 8;
536 mem->max = ((tmp[4] << 8) | tmp[3]) << 8;
537 mem->align = (tmp[6] << 8) | tmp[5];
538 mem->size = ((tmp[8] << 8) | tmp[7]) << 8;
540 pnp_register_mem_resource(option, mem);
544 * Add 32-bit memory resource to resources list.
546 static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
549 unsigned char tmp[17];
552 isapnp_peek(tmp, size);
553 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
556 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
557 mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
559 (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9];
561 (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
563 pnp_register_mem_resource(option, mem);
567 * Add 32-bit fixed memory resource to resources list.
569 static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
572 unsigned char tmp[9];
575 isapnp_peek(tmp, size);
576 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
579 mem->min = mem->max =
580 (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
581 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
584 pnp_register_mem_resource(option, mem);
588 * Parse card name for ISA PnP device.
591 isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size)
593 if (name[0] == '\0') {
594 unsigned short size1 =
595 *size >= name_max ? (name_max - 1) : *size;
596 isapnp_peek(name, size1);
600 /* clean whitespace from end of string */
601 while (size1 > 0 && name[--size1] == ' ')
607 * Parse resource map for logical device.
609 static int __init isapnp_create_device(struct pnp_card *card,
612 int number = 0, skip = 0, priority = 0, compat = 0;
613 unsigned char type, tmp[17];
614 struct pnp_option *option;
617 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
619 option = pnp_register_independent_option(dev);
624 pnp_add_card_device(card, dev);
627 if (isapnp_read_tag(&type, &size) < 0)
629 if (skip && type != _STAG_LOGDEVID && type != _STAG_END)
633 if (size >= 5 && size <= 6) {
635 isapnp_parse_device(card, size,
640 option = pnp_register_independent_option(dev);
645 pnp_add_card_device(card, dev);
652 case _STAG_COMPATDEVID:
653 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
655 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0],
656 (tmp[3] << 8) | tmp[2]);
662 if (size < 2 || size > 3)
664 isapnp_parse_irq_resource(option, size);
670 isapnp_parse_dma_resource(option, size);
676 priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE;
678 isapnp_peek(tmp, size);
679 priority = 0x100 | tmp[0];
682 option = pnp_register_dependent_option(dev, priority);
694 isapnp_parse_port_resource(option, size);
700 isapnp_parse_fixed_port_resource(option, size);
708 isapnp_parse_mem_resource(option, size);
712 isapnp_parse_name(dev->name, sizeof(dev->name), &size);
714 case _LTAG_UNICODESTR:
715 /* silently ignore */
716 /* who use unicode for hardware identification? */
720 case _LTAG_MEM32RANGE:
723 isapnp_parse_mem32_resource(option, size);
726 case _LTAG_FIXEDMEM32RANGE:
729 isapnp_parse_fixed_mem32_resource(option, size);
734 isapnp_skip_bytes(size);
738 "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n",
739 type, dev->number, card->number);
743 isapnp_skip_bytes(size);
749 * Parse resource map for ISA PnP card.
751 static void __init isapnp_parse_resource_map(struct pnp_card *card)
753 unsigned char type, tmp[17];
757 if (isapnp_read_tag(&type, &size) < 0)
764 card->pnpver = tmp[0];
765 card->productver = tmp[1];
769 if (size >= 5 && size <= 6) {
770 if (isapnp_create_device(card, size) == 1)
778 isapnp_parse_name(card->name, sizeof(card->name),
781 case _LTAG_UNICODESTR:
782 /* silently ignore */
783 /* who use unicode for hardware identification? */
789 isapnp_skip_bytes(size);
793 "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n",
798 isapnp_skip_bytes(size);
803 * Compute ISA PnP checksum for first eight bytes.
805 static unsigned char __init isapnp_checksum(unsigned char *data)
808 unsigned char checksum = 0x6a, bit, b;
810 for (i = 0; i < 8; i++) {
812 for (j = 0; j < 8; j++) {
817 ((((checksum ^ (checksum >> 1)) & 0x01) ^ bit) << 7)
825 * Parse EISA id for ISA PnP card.
827 static void isapnp_parse_card_id(struct pnp_card *card, unsigned short vendor,
828 unsigned short device)
830 struct pnp_id *id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
834 sprintf(id->id, "%c%c%c%x%x%x%x",
835 'A' + ((vendor >> 2) & 0x3f) - 1,
836 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
837 'A' + ((vendor >> 8) & 0x1f) - 1,
838 (device >> 4) & 0x0f,
839 device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
840 pnp_add_card_id(id, card);
844 * Build device list for all present ISA PnP devices.
846 static int __init isapnp_build_device_list(void)
849 unsigned char header[9], checksum;
850 struct pnp_card *card;
854 for (csn = 1; csn <= isapnp_csn_count; csn++) {
856 isapnp_peek(header, 9);
857 checksum = isapnp_checksum(header);
860 "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
861 header[0], header[1], header[2], header[3], header[4],
862 header[5], header[6], header[7], header[8]);
863 printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
866 kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
870 INIT_LIST_HEAD(&card->devices);
871 isapnp_parse_card_id(card, (header[1] << 8) | header[0],
872 (header[3] << 8) | header[2]);
874 (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
876 isapnp_checksum_value = 0x00;
877 isapnp_parse_resource_map(card);
878 if (isapnp_checksum_value != 0x00)
880 "isapnp: checksum for device %i is not valid (0x%x)\n",
881 csn, isapnp_checksum_value);
882 card->checksum = isapnp_checksum_value;
883 card->protocol = &isapnp_protocol;
892 * Basic configuration routines.
895 int isapnp_present(void)
897 struct pnp_card *card;
899 pnp_for_each_card(card) {
900 if (card->protocol == &isapnp_protocol)
906 int isapnp_cfg_begin(int csn, int logdev)
908 if (csn < 1 || csn > isapnp_csn_count || logdev > 10)
910 mutex_lock(&isapnp_cfg_mutex);
915 /* to avoid malfunction when the isapnptools package is used */
916 /* we must set RDP to our value again */
917 /* it is possible to set RDP only in the isolation phase */
918 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
919 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
920 mdelay(2); /* is this necessary? */
921 isapnp_wake(csn); /* bring card into sleep state */
922 isapnp_wake(0); /* bring card into isolation state */
923 isapnp_set_rdp(); /* reset the RDP port */
924 udelay(1000); /* delay 1000us */
925 isapnp_write_byte(0x06, csn); /* reset CSN to previous value */
926 udelay(250); /* is this necessary? */
929 isapnp_device(logdev);
933 int isapnp_cfg_end(void)
936 mutex_unlock(&isapnp_cfg_mutex);
944 EXPORT_SYMBOL(isapnp_protocol);
945 EXPORT_SYMBOL(isapnp_present);
946 EXPORT_SYMBOL(isapnp_cfg_begin);
947 EXPORT_SYMBOL(isapnp_cfg_end);
948 EXPORT_SYMBOL(isapnp_write_byte);
950 static int isapnp_read_resources(struct pnp_dev *dev,
951 struct pnp_resource_table *res)
955 dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
957 for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
958 ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
961 res->port_resource[tmp].start = ret;
962 res->port_resource[tmp].flags = IORESOURCE_IO;
964 for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
966 isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
969 res->mem_resource[tmp].start = ret;
970 res->mem_resource[tmp].flags = IORESOURCE_MEM;
972 for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
974 (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >>
978 res->irq_resource[tmp].start =
979 res->irq_resource[tmp].end = ret;
980 res->irq_resource[tmp].flags = IORESOURCE_IRQ;
982 for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
983 ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);
986 res->dma_resource[tmp].start =
987 res->dma_resource[tmp].end = ret;
988 res->dma_resource[tmp].flags = IORESOURCE_DMA;
994 static int isapnp_get_resources(struct pnp_dev *dev,
995 struct pnp_resource_table *res)
999 pnp_init_resource_table(res);
1000 isapnp_cfg_begin(dev->card->number, dev->number);
1001 ret = isapnp_read_resources(dev, res);
1006 static int isapnp_set_resources(struct pnp_dev *dev,
1007 struct pnp_resource_table *res)
1011 isapnp_cfg_begin(dev->card->number, dev->number);
1014 tmp < ISAPNP_MAX_PORT
1015 && (res->port_resource[tmp].
1016 flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO;
1018 isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
1019 res->port_resource[tmp].start);
1021 tmp < ISAPNP_MAX_IRQ
1022 && (res->irq_resource[tmp].
1023 flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ;
1025 int irq = res->irq_resource[tmp].start;
1028 isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq);
1031 tmp < ISAPNP_MAX_DMA
1032 && (res->dma_resource[tmp].
1033 flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA;
1035 isapnp_write_byte(ISAPNP_CFG_DMA + tmp,
1036 res->dma_resource[tmp].start);
1038 tmp < ISAPNP_MAX_MEM
1039 && (res->mem_resource[tmp].
1040 flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM;
1042 isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
1043 (res->mem_resource[tmp].start >> 8) & 0xffff);
1044 /* FIXME: We aren't handling 32bit mems properly here */
1045 isapnp_activate(dev->number);
1050 static int isapnp_disable_resources(struct pnp_dev *dev)
1054 isapnp_cfg_begin(dev->card->number, dev->number);
1055 isapnp_deactivate(dev->number);
1061 struct pnp_protocol isapnp_protocol = {
1062 .name = "ISA Plug and Play",
1063 .get = isapnp_get_resources,
1064 .set = isapnp_set_resources,
1065 .disable = isapnp_disable_resources,
1068 static int __init isapnp_init(void)
1071 struct pnp_card *card;
1072 struct pnp_dev *dev;
1074 if (isapnp_disable) {
1075 printk(KERN_INFO "isapnp: ISA Plug & Play support disabled\n");
1078 #ifdef CONFIG_PPC_MERGE
1079 if (check_legacy_ioport(_PIDXR) || check_legacy_ioport(_PNPWRP))
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",
1089 if (!request_region(_PNPWRP, 1, "isapnp write")) {
1091 "isapnp: Write Data Register 0x%x already used\n",
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")) {
1112 "isapnp: Read Data Register 0x%x already used\n",
1114 #ifdef ISAPNP_REGION_OK
1115 release_region(_PIDXR, 1);
1117 release_region(_PNPWRP, 1);
1122 if (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff) {
1123 cards = isapnp_isolate();
1124 if (cards < 0 || (isapnp_rdp < 0x203 || isapnp_rdp > 0x3ff)) {
1125 #ifdef ISAPNP_REGION_OK
1126 release_region(_PIDXR, 1);
1128 release_region(_PNPWRP, 1);
1130 "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",
1142 card->name[0] ? card->name : "Unknown");
1143 if (isapnp_verbose < 2)
1145 card_for_each_dev(card, dev) {
1146 printk(KERN_INFO "isapnp: Device '%s'\n",
1147 dev->name[0] ? dev->name : "Unknown");
1153 "isapnp: %i Plug & Play card%s detected total\n", cards,
1154 cards > 1 ? "s" : "");
1156 printk(KERN_INFO "isapnp: No Plug & Play card found\n");
1162 device_initcall(isapnp_init);
1164 /* format is: noisapnp */
1166 static int __init isapnp_setup_disable(char *str)
1172 __setup("noisapnp", isapnp_setup_disable);
1174 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1176 static int __init isapnp_setup_isapnp(char *str)
1178 (void)((get_option(&str, &isapnp_rdp) == 2) &&
1179 (get_option(&str, &isapnp_reset) == 2) &&
1180 (get_option(&str, &isapnp_verbose) == 2));
1184 __setup("isapnp=", isapnp_setup_isapnp);