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/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
54 int isapnp_disable
; /* Disable ISA PnP */
55 static int isapnp_rdp
; /* Read Data Port */
56 static int isapnp_reset
= 1; /* reset all PnP cards (deactivate) */
57 static 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 DEFINE_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 static unsigned short isapnp_read_word(unsigned char idx
)
128 val
= isapnp_read_byte(idx
);
129 val
= (val
<< 8) + isapnp_read_byte(idx
+ 1);
133 void isapnp_write_byte(unsigned char idx
, unsigned char val
)
139 static void isapnp_write_word(unsigned char idx
, unsigned short val
)
141 isapnp_write_byte(idx
, val
>> 8);
142 isapnp_write_byte(idx
+ 1, val
);
145 static void isapnp_key(void)
147 unsigned char code
= 0x6a, msb
;
156 for (i
= 1; i
< 32; i
++) {
157 msb
= ((code
& 0x01) ^ ((code
& 0x02) >> 1)) << 7;
158 code
= (code
>> 1) | msb
;
163 /* place all pnp cards in wait-for-key state */
164 static void isapnp_wait(void)
166 isapnp_write_byte(0x02, 0x02);
169 static void isapnp_wake(unsigned char csn
)
171 isapnp_write_byte(0x03, csn
);
174 static void isapnp_device(unsigned char logdev
)
176 isapnp_write_byte(0x07, logdev
);
179 static void isapnp_activate(unsigned char logdev
)
181 isapnp_device(logdev
);
182 isapnp_write_byte(ISAPNP_CFG_ACTIVATE
, 1);
186 static void isapnp_deactivate(unsigned char logdev
)
188 isapnp_device(logdev
);
189 isapnp_write_byte(ISAPNP_CFG_ACTIVATE
, 0);
193 static void __init
isapnp_peek(unsigned char *data
, int bytes
)
198 for (i
= 1; i
<= bytes
; i
++) {
199 for (j
= 0; j
< 20; j
++) {
200 d
= isapnp_read_byte(0x05);
210 d
= isapnp_read_byte(0x04); /* PRESDI */
211 isapnp_checksum_value
+= d
;
217 #define RDP_STEP 32 /* minimum is 4 */
219 static int isapnp_next_rdp(void)
221 int rdp
= isapnp_rdp
;
222 static int old_rdp
= 0;
225 release_region(old_rdp
, 1);
228 while (rdp
<= 0x3ff) {
230 * We cannot use NE2000 probe spaces for ISAPnP or we
231 * will lock up machines.
233 if ((rdp
< 0x280 || rdp
> 0x380)
234 && request_region(rdp
, 1, "ISAPnP")) {
244 /* Set read port address */
245 static inline void isapnp_set_rdp(void)
247 isapnp_write_byte(0x00, isapnp_rdp
>> 2);
252 * Perform an isolation. The port selection code now tries to avoid
253 * "dangerous to read" ports.
256 static int __init
isapnp_isolate_rdp_select(void)
261 /* Control: reset CSN and conditionally everything else too */
262 isapnp_write_byte(0x02, isapnp_reset
? 0x05 : 0x04);
269 if (isapnp_next_rdp() < 0) {
282 * Isolate (assign uniqued CSN) to all ISA PnP devices.
285 static int __init
isapnp_isolate(void)
287 unsigned char checksum
= 0x6a;
288 unsigned char chksum
= 0x00;
289 unsigned char bit
= 0x00;
296 if (isapnp_isolate_rdp_select() < 0)
300 for (i
= 1; i
<= 64; i
++) {
301 data
= read_data() << 8;
303 data
= data
| read_data();
308 ((((checksum
^ (checksum
>> 1)) & 0x01) ^ bit
) << 7)
312 for (i
= 65; i
<= 72; i
++) {
313 data
= read_data() << 8;
315 data
= data
| read_data();
318 chksum
|= (1 << (i
- 65));
320 if (checksum
!= 0x00 && checksum
== chksum
) {
323 isapnp_write_byte(0x06, csn
);
333 if (iteration
== 1) {
334 isapnp_rdp
+= RDP_STEP
;
335 if (isapnp_isolate_rdp_select() < 0)
337 } else if (iteration
> 1) {
348 isapnp_csn_count
= csn
;
353 * Read one tag from stream.
356 static int __init
isapnp_read_tag(unsigned char *type
, unsigned short *size
)
358 unsigned char tag
, tmp
[2];
360 isapnp_peek(&tag
, 1);
361 if (tag
== 0) /* invalid tag */
363 if (tag
& 0x80) { /* large item */
366 *size
= (tmp
[1] << 8) | tmp
[0];
368 *type
= (tag
>> 3) & 0x0f;
372 printk(KERN_DEBUG
"tag = 0x%x, type = 0x%x, size = %i\n", tag
, *type
,
375 if (*type
== 0xff && *size
== 0xffff) /* probably invalid data */
381 * Skip specified number of bytes from stream.
384 static void __init
isapnp_skip_bytes(int count
)
386 isapnp_peek(NULL
, count
);
393 static void isapnp_parse_id(struct pnp_dev
*dev
, unsigned short vendor
,
394 unsigned short device
)
399 id
= kzalloc(sizeof(struct pnp_id
), GFP_KERNEL
);
402 sprintf(id
->id
, "%c%c%c%x%x%x%x",
403 'A' + ((vendor
>> 2) & 0x3f) - 1,
404 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
405 'A' + ((vendor
>> 8) & 0x1f) - 1,
406 (device
>> 4) & 0x0f,
407 device
& 0x0f, (device
>> 12) & 0x0f, (device
>> 8) & 0x0f);
412 * 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.
444 static void __init
isapnp_parse_irq_resource(struct pnp_option
*option
,
447 unsigned char tmp
[3];
451 isapnp_peek(tmp
, size
);
452 irq
= kzalloc(sizeof(struct pnp_irq
), GFP_KERNEL
);
455 bits
= (tmp
[1] << 8) | tmp
[0];
456 bitmap_copy(irq
->map
, &bits
, 16);
460 irq
->flags
= IORESOURCE_IRQ_HIGHEDGE
;
461 pnp_register_irq_resource(option
, irq
);
466 * Add DMA resource to resources list.
469 static void __init
isapnp_parse_dma_resource(struct pnp_option
*option
,
472 unsigned char tmp
[2];
475 isapnp_peek(tmp
, size
);
476 dma
= kzalloc(sizeof(struct pnp_dma
), GFP_KERNEL
);
481 pnp_register_dma_resource(option
, dma
);
486 * Add port resource to resources list.
489 static void __init
isapnp_parse_port_resource(struct pnp_option
*option
,
492 unsigned char tmp
[7];
493 struct pnp_port
*port
;
495 isapnp_peek(tmp
, size
);
496 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
499 port
->min
= (tmp
[2] << 8) | tmp
[1];
500 port
->max
= (tmp
[4] << 8) | tmp
[3];
501 port
->align
= tmp
[5];
503 port
->flags
= tmp
[0] ? PNP_PORT_FLAG_16BITADDR
: 0;
504 pnp_register_port_resource(option
, port
);
509 * Add fixed port resource to resources list.
512 static void __init
isapnp_parse_fixed_port_resource(struct pnp_option
*option
,
515 unsigned char tmp
[3];
516 struct pnp_port
*port
;
518 isapnp_peek(tmp
, size
);
519 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
522 port
->min
= port
->max
= (tmp
[1] << 8) | tmp
[0];
525 port
->flags
= PNP_PORT_FLAG_FIXED
;
526 pnp_register_port_resource(option
, port
);
531 * Add memory resource to resources list.
534 static void __init
isapnp_parse_mem_resource(struct pnp_option
*option
,
537 unsigned char tmp
[9];
540 isapnp_peek(tmp
, size
);
541 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
544 mem
->min
= ((tmp
[2] << 8) | tmp
[1]) << 8;
545 mem
->max
= ((tmp
[4] << 8) | tmp
[3]) << 8;
546 mem
->align
= (tmp
[6] << 8) | tmp
[5];
547 mem
->size
= ((tmp
[8] << 8) | tmp
[7]) << 8;
549 pnp_register_mem_resource(option
, mem
);
554 * Add 32-bit memory resource to resources list.
557 static void __init
isapnp_parse_mem32_resource(struct pnp_option
*option
,
560 unsigned char tmp
[17];
563 isapnp_peek(tmp
, size
);
564 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
567 mem
->min
= (tmp
[4] << 24) | (tmp
[3] << 16) | (tmp
[2] << 8) | tmp
[1];
568 mem
->max
= (tmp
[8] << 24) | (tmp
[7] << 16) | (tmp
[6] << 8) | tmp
[5];
570 (tmp
[12] << 24) | (tmp
[11] << 16) | (tmp
[10] << 8) | tmp
[9];
572 (tmp
[16] << 24) | (tmp
[15] << 16) | (tmp
[14] << 8) | tmp
[13];
574 pnp_register_mem_resource(option
, mem
);
578 * Add 32-bit fixed memory resource to resources list.
581 static void __init
isapnp_parse_fixed_mem32_resource(struct pnp_option
*option
,
584 unsigned char tmp
[9];
587 isapnp_peek(tmp
, size
);
588 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
591 mem
->min
= mem
->max
=
592 (tmp
[4] << 24) | (tmp
[3] << 16) | (tmp
[2] << 8) | tmp
[1];
593 mem
->size
= (tmp
[8] << 24) | (tmp
[7] << 16) | (tmp
[6] << 8) | tmp
[5];
596 pnp_register_mem_resource(option
, mem
);
600 * Parse card name for ISA PnP device.
604 isapnp_parse_name(char *name
, unsigned int name_max
, unsigned short *size
)
606 if (name
[0] == '\0') {
607 unsigned short size1
=
608 *size
>= name_max
? (name_max
- 1) : *size
;
609 isapnp_peek(name
, size1
);
613 /* clean whitespace from end of string */
614 while (size1
> 0 && name
[--size1
] == ' ')
620 * Parse resource map for logical device.
623 static int __init
isapnp_create_device(struct pnp_card
*card
,
626 int number
= 0, skip
= 0, priority
= 0, compat
= 0;
627 unsigned char type
, tmp
[17];
628 struct pnp_option
*option
;
630 if ((dev
= isapnp_parse_device(card
, size
, number
++)) == NULL
)
632 option
= pnp_register_independent_option(dev
);
637 pnp_add_card_device(card
, dev
);
640 if (isapnp_read_tag(&type
, &size
) < 0)
642 if (skip
&& type
!= _STAG_LOGDEVID
&& type
!= _STAG_END
)
646 if (size
>= 5 && size
<= 6) {
648 isapnp_parse_device(card
, size
,
653 option
= pnp_register_independent_option(dev
);
658 pnp_add_card_device(card
, dev
);
665 case _STAG_COMPATDEVID
:
666 if (size
== 4 && compat
< DEVICE_COUNT_COMPATIBLE
) {
668 isapnp_parse_id(dev
, (tmp
[1] << 8) | tmp
[0],
669 (tmp
[3] << 8) | tmp
[2]);
675 if (size
< 2 || size
> 3)
677 isapnp_parse_irq_resource(option
, size
);
683 isapnp_parse_dma_resource(option
, size
);
689 priority
= 0x100 | PNP_RES_PRIORITY_ACCEPTABLE
;
691 isapnp_peek(tmp
, size
);
692 priority
= 0x100 | tmp
[0];
695 option
= pnp_register_dependent_option(dev
, priority
);
707 isapnp_parse_port_resource(option
, size
);
713 isapnp_parse_fixed_port_resource(option
, size
);
721 isapnp_parse_mem_resource(option
, size
);
725 isapnp_parse_name(dev
->name
, sizeof(dev
->name
), &size
);
727 case _LTAG_UNICODESTR
:
728 /* silently ignore */
729 /* who use unicode for hardware identification? */
733 case _LTAG_MEM32RANGE
:
736 isapnp_parse_mem32_resource(option
, size
);
739 case _LTAG_FIXEDMEM32RANGE
:
742 isapnp_parse_fixed_mem32_resource(option
, size
);
747 isapnp_skip_bytes(size
);
751 "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n",
752 type
, dev
->number
, card
->number
);
756 isapnp_skip_bytes(size
);
762 * Parse resource map for ISA PnP card.
765 static void __init
isapnp_parse_resource_map(struct pnp_card
*card
)
767 unsigned char type
, tmp
[17];
771 if (isapnp_read_tag(&type
, &size
) < 0)
778 card
->pnpver
= tmp
[0];
779 card
->productver
= tmp
[1];
783 if (size
>= 5 && size
<= 6) {
784 if (isapnp_create_device(card
, size
) == 1)
792 isapnp_parse_name(card
->name
, sizeof(card
->name
),
795 case _LTAG_UNICODESTR
:
796 /* silently ignore */
797 /* who use unicode for hardware identification? */
803 isapnp_skip_bytes(size
);
807 "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n",
812 isapnp_skip_bytes(size
);
817 * Compute ISA PnP checksum for first eight bytes.
820 static unsigned char __init
isapnp_checksum(unsigned char *data
)
823 unsigned char checksum
= 0x6a, bit
, b
;
825 for (i
= 0; i
< 8; i
++) {
827 for (j
= 0; j
< 8; j
++) {
832 ((((checksum
^ (checksum
>> 1)) & 0x01) ^ bit
) << 7)
840 * Parse EISA id for ISA PnP card.
843 static void isapnp_parse_card_id(struct pnp_card
*card
, unsigned short vendor
,
844 unsigned short device
)
846 struct pnp_id
*id
= kzalloc(sizeof(struct pnp_id
), GFP_KERNEL
);
849 sprintf(id
->id
, "%c%c%c%x%x%x%x",
850 'A' + ((vendor
>> 2) & 0x3f) - 1,
851 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
852 'A' + ((vendor
>> 8) & 0x1f) - 1,
853 (device
>> 4) & 0x0f,
854 device
& 0x0f, (device
>> 12) & 0x0f, (device
>> 8) & 0x0f);
855 pnp_add_card_id(id
, card
);
859 * Build device list for all present ISA PnP devices.
862 static int __init
isapnp_build_device_list(void)
865 unsigned char header
[9], checksum
;
866 struct pnp_card
*card
;
870 for (csn
= 1; csn
<= isapnp_csn_count
; csn
++) {
872 isapnp_peek(header
, 9);
873 checksum
= isapnp_checksum(header
);
876 "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
877 header
[0], header
[1], header
[2], header
[3], header
[4],
878 header
[5], header
[6], header
[7], header
[8]);
879 printk(KERN_DEBUG
"checksum = 0x%x\n", checksum
);
882 kzalloc(sizeof(struct pnp_card
), GFP_KERNEL
)) == NULL
)
886 INIT_LIST_HEAD(&card
->devices
);
887 isapnp_parse_card_id(card
, (header
[1] << 8) | header
[0],
888 (header
[3] << 8) | header
[2]);
890 (header
[7] << 24) | (header
[6] << 16) | (header
[5] << 8) |
892 isapnp_checksum_value
= 0x00;
893 isapnp_parse_resource_map(card
);
894 if (isapnp_checksum_value
!= 0x00)
896 "isapnp: checksum for device %i is not valid (0x%x)\n",
897 csn
, isapnp_checksum_value
);
898 card
->checksum
= isapnp_checksum_value
;
899 card
->protocol
= &isapnp_protocol
;
908 * Basic configuration routines.
911 int isapnp_present(void)
913 struct pnp_card
*card
;
914 pnp_for_each_card(card
) {
915 if (card
->protocol
== &isapnp_protocol
)
921 int isapnp_cfg_begin(int csn
, int logdev
)
923 if (csn
< 1 || csn
> isapnp_csn_count
|| logdev
> 10)
925 mutex_lock(&isapnp_cfg_mutex
);
930 /* to avoid malfunction when the isapnptools package is used */
931 /* we must set RDP to our value again */
932 /* it is possible to set RDP only in the isolation phase */
933 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
934 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
935 mdelay(2); /* is this necessary? */
936 isapnp_wake(csn
); /* bring card into sleep state */
937 isapnp_wake(0); /* bring card into isolation state */
938 isapnp_set_rdp(); /* reset the RDP port */
939 udelay(1000); /* delay 1000us */
940 isapnp_write_byte(0x06, csn
); /* reset CSN to previous value */
941 udelay(250); /* is this necessary? */
944 isapnp_device(logdev
);
948 int isapnp_cfg_end(void)
951 mutex_unlock(&isapnp_cfg_mutex
);
959 EXPORT_SYMBOL(isapnp_protocol
);
960 EXPORT_SYMBOL(isapnp_present
);
961 EXPORT_SYMBOL(isapnp_cfg_begin
);
962 EXPORT_SYMBOL(isapnp_cfg_end
);
964 EXPORT_SYMBOL(isapnp_read_byte
);
966 EXPORT_SYMBOL(isapnp_write_byte
);
968 static int isapnp_read_resources(struct pnp_dev
*dev
,
969 struct pnp_resource_table
*res
)
973 dev
->active
= isapnp_read_byte(ISAPNP_CFG_ACTIVATE
);
975 for (tmp
= 0; tmp
< PNP_MAX_PORT
; tmp
++) {
976 ret
= isapnp_read_word(ISAPNP_CFG_PORT
+ (tmp
<< 1));
979 res
->port_resource
[tmp
].start
= ret
;
980 res
->port_resource
[tmp
].flags
= IORESOURCE_IO
;
982 for (tmp
= 0; tmp
< PNP_MAX_MEM
; tmp
++) {
984 isapnp_read_word(ISAPNP_CFG_MEM
+ (tmp
<< 3)) << 8;
987 res
->mem_resource
[tmp
].start
= ret
;
988 res
->mem_resource
[tmp
].flags
= IORESOURCE_MEM
;
990 for (tmp
= 0; tmp
< PNP_MAX_IRQ
; tmp
++) {
992 (isapnp_read_word(ISAPNP_CFG_IRQ
+ (tmp
<< 1)) >>
996 res
->irq_resource
[tmp
].start
=
997 res
->irq_resource
[tmp
].end
= ret
;
998 res
->irq_resource
[tmp
].flags
= IORESOURCE_IRQ
;
1000 for (tmp
= 0; tmp
< PNP_MAX_DMA
; tmp
++) {
1001 ret
= isapnp_read_byte(ISAPNP_CFG_DMA
+ tmp
);
1004 res
->dma_resource
[tmp
].start
=
1005 res
->dma_resource
[tmp
].end
= ret
;
1006 res
->dma_resource
[tmp
].flags
= IORESOURCE_DMA
;
1012 static int isapnp_get_resources(struct pnp_dev
*dev
,
1013 struct pnp_resource_table
*res
)
1016 pnp_init_resource_table(res
);
1017 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1018 ret
= isapnp_read_resources(dev
, res
);
1023 static int isapnp_set_resources(struct pnp_dev
*dev
,
1024 struct pnp_resource_table
*res
)
1028 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1032 && (res
->port_resource
[tmp
].
1033 flags
& (IORESOURCE_IO
| IORESOURCE_UNSET
)) == IORESOURCE_IO
;
1035 isapnp_write_word(ISAPNP_CFG_PORT
+ (tmp
<< 1),
1036 res
->port_resource
[tmp
].start
);
1039 && (res
->irq_resource
[tmp
].
1040 flags
& (IORESOURCE_IRQ
| IORESOURCE_UNSET
)) == IORESOURCE_IRQ
;
1042 int irq
= res
->irq_resource
[tmp
].start
;
1045 isapnp_write_byte(ISAPNP_CFG_IRQ
+ (tmp
<< 1), irq
);
1049 && (res
->dma_resource
[tmp
].
1050 flags
& (IORESOURCE_DMA
| IORESOURCE_UNSET
)) == IORESOURCE_DMA
;
1052 isapnp_write_byte(ISAPNP_CFG_DMA
+ tmp
,
1053 res
->dma_resource
[tmp
].start
);
1056 && (res
->mem_resource
[tmp
].
1057 flags
& (IORESOURCE_MEM
| IORESOURCE_UNSET
)) == IORESOURCE_MEM
;
1059 isapnp_write_word(ISAPNP_CFG_MEM
+ (tmp
<< 3),
1060 (res
->mem_resource
[tmp
].start
>> 8) & 0xffff);
1061 /* FIXME: We aren't handling 32bit mems properly here */
1062 isapnp_activate(dev
->number
);
1067 static int isapnp_disable_resources(struct pnp_dev
*dev
)
1069 if (!dev
|| !dev
->active
)
1071 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1072 isapnp_deactivate(dev
->number
);
1078 struct pnp_protocol isapnp_protocol
= {
1079 .name
= "ISA Plug and Play",
1080 .get
= isapnp_get_resources
,
1081 .set
= isapnp_set_resources
,
1082 .disable
= isapnp_disable_resources
,
1085 static int __init
isapnp_init(void)
1088 struct pnp_card
*card
;
1089 struct pnp_dev
*dev
;
1091 if (isapnp_disable
) {
1092 isapnp_detected
= 0;
1093 printk(KERN_INFO
"isapnp: ISA Plug & Play support disabled\n");
1096 #ifdef CONFIG_PPC_MERGE
1097 if (check_legacy_ioport(_PIDXR
) || check_legacy_ioport(_PNPWRP
))
1100 #ifdef ISAPNP_REGION_OK
1101 if (!request_region(_PIDXR
, 1, "isapnp index")) {
1102 printk(KERN_ERR
"isapnp: Index Register 0x%x already used\n",
1107 if (!request_region(_PNPWRP
, 1, "isapnp write")) {
1109 "isapnp: Write Data Register 0x%x already used\n",
1111 #ifdef ISAPNP_REGION_OK
1112 release_region(_PIDXR
, 1);
1117 if (pnp_register_protocol(&isapnp_protocol
) < 0)
1121 * Print a message. The existing ISAPnP code is hanging machines
1122 * so let the user know where.
1125 printk(KERN_INFO
"isapnp: Scanning for PnP cards...\n");
1126 if (isapnp_rdp
>= 0x203 && isapnp_rdp
<= 0x3ff) {
1128 if (!request_region(isapnp_rdp
, 1, "isapnp read")) {
1130 "isapnp: Read Data Register 0x%x already used\n",
1132 #ifdef ISAPNP_REGION_OK
1133 release_region(_PIDXR
, 1);
1135 release_region(_PNPWRP
, 1);
1140 isapnp_detected
= 1;
1141 if (isapnp_rdp
< 0x203 || isapnp_rdp
> 0x3ff) {
1142 cards
= isapnp_isolate();
1143 if (cards
< 0 || (isapnp_rdp
< 0x203 || isapnp_rdp
> 0x3ff)) {
1144 #ifdef ISAPNP_REGION_OK
1145 release_region(_PIDXR
, 1);
1147 release_region(_PNPWRP
, 1);
1148 isapnp_detected
= 0;
1150 "isapnp: No Plug & Play device found\n");
1153 request_region(isapnp_rdp
, 1, "isapnp read");
1155 isapnp_build_device_list();
1158 protocol_for_each_card(&isapnp_protocol
, card
) {
1160 if (isapnp_verbose
) {
1161 printk(KERN_INFO
"isapnp: Card '%s'\n",
1162 card
->name
[0] ? card
->name
: "Unknown");
1163 if (isapnp_verbose
< 2)
1165 card_for_each_dev(card
, dev
) {
1166 printk(KERN_INFO
"isapnp: Device '%s'\n",
1167 dev
->name
[0] ? dev
->name
: "Unknown");
1173 "isapnp: %i Plug & Play card%s detected total\n", cards
,
1174 cards
> 1 ? "s" : "");
1176 printk(KERN_INFO
"isapnp: No Plug & Play card found\n");
1183 device_initcall(isapnp_init
);
1185 /* format is: noisapnp */
1187 static int __init
isapnp_setup_disable(char *str
)
1193 __setup("noisapnp", isapnp_setup_disable
);
1195 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1197 static int __init
isapnp_setup_isapnp(char *str
)
1199 (void)((get_option(&str
, &isapnp_rdp
) == 2) &&
1200 (get_option(&str
, &isapnp_reset
) == 2) &&
1201 (get_option(&str
, &isapnp_verbose
) == 2));
1205 __setup("isapnp=", isapnp_setup_isapnp
);