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 static unsigned char isapnp_checksum_value
;
92 static DEFINE_MUTEX(isapnp_cfg_mutex
);
93 static int isapnp_csn_count
;
97 static inline void write_data(unsigned char x
)
102 static inline void write_address(unsigned char x
)
108 static inline unsigned char read_data(void)
110 unsigned char val
= inb(isapnp_rdp
);
114 unsigned char isapnp_read_byte(unsigned char idx
)
120 static unsigned short isapnp_read_word(unsigned char idx
)
124 val
= isapnp_read_byte(idx
);
125 val
= (val
<< 8) + isapnp_read_byte(idx
+ 1);
129 void isapnp_write_byte(unsigned char idx
, unsigned char val
)
135 static void isapnp_write_word(unsigned char idx
, unsigned short val
)
137 isapnp_write_byte(idx
, val
>> 8);
138 isapnp_write_byte(idx
+ 1, val
);
141 static void isapnp_key(void)
143 unsigned char code
= 0x6a, msb
;
152 for (i
= 1; i
< 32; i
++) {
153 msb
= ((code
& 0x01) ^ ((code
& 0x02) >> 1)) << 7;
154 code
= (code
>> 1) | msb
;
159 /* place all pnp cards in wait-for-key state */
160 static void isapnp_wait(void)
162 isapnp_write_byte(0x02, 0x02);
165 static void isapnp_wake(unsigned char csn
)
167 isapnp_write_byte(0x03, csn
);
170 static void isapnp_device(unsigned char logdev
)
172 isapnp_write_byte(0x07, logdev
);
175 static void isapnp_activate(unsigned char logdev
)
177 isapnp_device(logdev
);
178 isapnp_write_byte(ISAPNP_CFG_ACTIVATE
, 1);
182 static void isapnp_deactivate(unsigned char logdev
)
184 isapnp_device(logdev
);
185 isapnp_write_byte(ISAPNP_CFG_ACTIVATE
, 0);
189 static void __init
isapnp_peek(unsigned char *data
, int bytes
)
194 for (i
= 1; i
<= bytes
; i
++) {
195 for (j
= 0; j
< 20; j
++) {
196 d
= isapnp_read_byte(0x05);
206 d
= isapnp_read_byte(0x04); /* PRESDI */
207 isapnp_checksum_value
+= d
;
213 #define RDP_STEP 32 /* minimum is 4 */
215 static int isapnp_next_rdp(void)
217 int rdp
= isapnp_rdp
;
218 static int old_rdp
= 0;
221 release_region(old_rdp
, 1);
224 while (rdp
<= 0x3ff) {
226 * We cannot use NE2000 probe spaces for ISAPnP or we
227 * will lock up machines.
229 if ((rdp
< 0x280 || rdp
> 0x380)
230 && request_region(rdp
, 1, "ISAPnP")) {
240 /* Set read port address */
241 static inline void isapnp_set_rdp(void)
243 isapnp_write_byte(0x00, isapnp_rdp
>> 2);
248 * Perform an isolation. The port selection code now tries to avoid
249 * "dangerous to read" ports.
251 static int __init
isapnp_isolate_rdp_select(void)
256 /* Control: reset CSN and conditionally everything else too */
257 isapnp_write_byte(0x02, isapnp_reset
? 0x05 : 0x04);
264 if (isapnp_next_rdp() < 0) {
277 * Isolate (assign uniqued CSN) to all ISA PnP devices.
279 static int __init
isapnp_isolate(void)
281 unsigned char checksum
= 0x6a;
282 unsigned char chksum
= 0x00;
283 unsigned char bit
= 0x00;
290 if (isapnp_isolate_rdp_select() < 0)
294 for (i
= 1; i
<= 64; i
++) {
295 data
= read_data() << 8;
297 data
= data
| read_data();
302 ((((checksum
^ (checksum
>> 1)) & 0x01) ^ bit
) << 7)
306 for (i
= 65; i
<= 72; i
++) {
307 data
= read_data() << 8;
309 data
= data
| read_data();
312 chksum
|= (1 << (i
- 65));
314 if (checksum
!= 0x00 && checksum
== chksum
) {
317 isapnp_write_byte(0x06, csn
);
327 if (iteration
== 1) {
328 isapnp_rdp
+= RDP_STEP
;
329 if (isapnp_isolate_rdp_select() < 0)
331 } else if (iteration
> 1) {
342 isapnp_csn_count
= csn
;
347 * Read one tag from stream.
349 static int __init
isapnp_read_tag(unsigned char *type
, unsigned short *size
)
351 unsigned char tag
, tmp
[2];
353 isapnp_peek(&tag
, 1);
354 if (tag
== 0) /* invalid tag */
356 if (tag
& 0x80) { /* large item */
359 *size
= (tmp
[1] << 8) | tmp
[0];
361 *type
= (tag
>> 3) & 0x0f;
365 printk(KERN_DEBUG
"tag = 0x%x, type = 0x%x, size = %i\n", tag
, *type
,
368 if (*type
== 0xff && *size
== 0xffff) /* probably invalid data */
374 * Skip specified number of bytes from stream.
376 static void __init
isapnp_skip_bytes(int count
)
378 isapnp_peek(NULL
, count
);
384 static void isapnp_parse_id(struct pnp_dev
*dev
, unsigned short vendor
,
385 unsigned short device
)
391 id
= kzalloc(sizeof(struct pnp_id
), GFP_KERNEL
);
394 sprintf(id
->id
, "%c%c%c%x%x%x%x",
395 'A' + ((vendor
>> 2) & 0x3f) - 1,
396 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
397 'A' + ((vendor
>> 8) & 0x1f) - 1,
398 (device
>> 4) & 0x0f,
399 device
& 0x0f, (device
>> 12) & 0x0f, (device
>> 8) & 0x0f);
404 * Parse logical device tag.
406 static struct pnp_dev
*__init
isapnp_parse_device(struct pnp_card
*card
,
407 int size
, int number
)
409 unsigned char tmp
[6];
412 isapnp_peek(tmp
, size
);
413 dev
= kzalloc(sizeof(struct pnp_dev
), GFP_KERNEL
);
416 dev
->number
= number
;
417 isapnp_parse_id(dev
, (tmp
[1] << 8) | tmp
[0], (tmp
[3] << 8) | tmp
[2]);
421 dev
->regs
|= tmp
[5] << 8;
422 dev
->protocol
= &isapnp_protocol
;
423 dev
->capabilities
|= PNP_CONFIGURABLE
;
424 dev
->capabilities
|= PNP_READ
;
425 dev
->capabilities
|= PNP_WRITE
;
426 dev
->capabilities
|= PNP_DISABLE
;
427 pnp_init_resource_table(&dev
->res
);
432 * Add IRQ resource to resources list.
434 static void __init
isapnp_parse_irq_resource(struct pnp_option
*option
,
437 unsigned char tmp
[3];
441 isapnp_peek(tmp
, size
);
442 irq
= kzalloc(sizeof(struct pnp_irq
), GFP_KERNEL
);
445 bits
= (tmp
[1] << 8) | tmp
[0];
446 bitmap_copy(irq
->map
, &bits
, 16);
450 irq
->flags
= IORESOURCE_IRQ_HIGHEDGE
;
451 pnp_register_irq_resource(option
, irq
);
455 * Add DMA resource to resources list.
457 static void __init
isapnp_parse_dma_resource(struct pnp_option
*option
,
460 unsigned char tmp
[2];
463 isapnp_peek(tmp
, size
);
464 dma
= kzalloc(sizeof(struct pnp_dma
), GFP_KERNEL
);
469 pnp_register_dma_resource(option
, dma
);
473 * Add port resource to resources list.
475 static void __init
isapnp_parse_port_resource(struct pnp_option
*option
,
478 unsigned char tmp
[7];
479 struct pnp_port
*port
;
481 isapnp_peek(tmp
, size
);
482 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
485 port
->min
= (tmp
[2] << 8) | tmp
[1];
486 port
->max
= (tmp
[4] << 8) | tmp
[3];
487 port
->align
= tmp
[5];
489 port
->flags
= tmp
[0] ? PNP_PORT_FLAG_16BITADDR
: 0;
490 pnp_register_port_resource(option
, port
);
494 * Add fixed port resource to resources list.
496 static void __init
isapnp_parse_fixed_port_resource(struct pnp_option
*option
,
499 unsigned char tmp
[3];
500 struct pnp_port
*port
;
502 isapnp_peek(tmp
, size
);
503 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
506 port
->min
= port
->max
= (tmp
[1] << 8) | tmp
[0];
509 port
->flags
= PNP_PORT_FLAG_FIXED
;
510 pnp_register_port_resource(option
, port
);
514 * Add memory resource to resources list.
516 static void __init
isapnp_parse_mem_resource(struct pnp_option
*option
,
519 unsigned char tmp
[9];
522 isapnp_peek(tmp
, size
);
523 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
526 mem
->min
= ((tmp
[2] << 8) | tmp
[1]) << 8;
527 mem
->max
= ((tmp
[4] << 8) | tmp
[3]) << 8;
528 mem
->align
= (tmp
[6] << 8) | tmp
[5];
529 mem
->size
= ((tmp
[8] << 8) | tmp
[7]) << 8;
531 pnp_register_mem_resource(option
, mem
);
535 * Add 32-bit memory resource to resources list.
537 static void __init
isapnp_parse_mem32_resource(struct pnp_option
*option
,
540 unsigned char tmp
[17];
543 isapnp_peek(tmp
, size
);
544 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
547 mem
->min
= (tmp
[4] << 24) | (tmp
[3] << 16) | (tmp
[2] << 8) | tmp
[1];
548 mem
->max
= (tmp
[8] << 24) | (tmp
[7] << 16) | (tmp
[6] << 8) | tmp
[5];
550 (tmp
[12] << 24) | (tmp
[11] << 16) | (tmp
[10] << 8) | tmp
[9];
552 (tmp
[16] << 24) | (tmp
[15] << 16) | (tmp
[14] << 8) | tmp
[13];
554 pnp_register_mem_resource(option
, mem
);
558 * Add 32-bit fixed memory resource to resources list.
560 static void __init
isapnp_parse_fixed_mem32_resource(struct pnp_option
*option
,
563 unsigned char tmp
[9];
566 isapnp_peek(tmp
, size
);
567 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
570 mem
->min
= mem
->max
=
571 (tmp
[4] << 24) | (tmp
[3] << 16) | (tmp
[2] << 8) | tmp
[1];
572 mem
->size
= (tmp
[8] << 24) | (tmp
[7] << 16) | (tmp
[6] << 8) | tmp
[5];
575 pnp_register_mem_resource(option
, mem
);
579 * Parse card name for ISA PnP device.
582 isapnp_parse_name(char *name
, unsigned int name_max
, unsigned short *size
)
584 if (name
[0] == '\0') {
585 unsigned short size1
=
586 *size
>= name_max
? (name_max
- 1) : *size
;
587 isapnp_peek(name
, size1
);
591 /* clean whitespace from end of string */
592 while (size1
> 0 && name
[--size1
] == ' ')
598 * Parse resource map for logical device.
600 static int __init
isapnp_create_device(struct pnp_card
*card
,
603 int number
= 0, skip
= 0, priority
= 0, compat
= 0;
604 unsigned char type
, tmp
[17];
605 struct pnp_option
*option
;
608 if ((dev
= isapnp_parse_device(card
, size
, number
++)) == NULL
)
610 option
= pnp_register_independent_option(dev
);
615 pnp_add_card_device(card
, dev
);
618 if (isapnp_read_tag(&type
, &size
) < 0)
620 if (skip
&& type
!= _STAG_LOGDEVID
&& type
!= _STAG_END
)
624 if (size
>= 5 && size
<= 6) {
626 isapnp_parse_device(card
, size
,
631 option
= pnp_register_independent_option(dev
);
636 pnp_add_card_device(card
, dev
);
643 case _STAG_COMPATDEVID
:
644 if (size
== 4 && compat
< DEVICE_COUNT_COMPATIBLE
) {
646 isapnp_parse_id(dev
, (tmp
[1] << 8) | tmp
[0],
647 (tmp
[3] << 8) | tmp
[2]);
653 if (size
< 2 || size
> 3)
655 isapnp_parse_irq_resource(option
, size
);
661 isapnp_parse_dma_resource(option
, size
);
667 priority
= 0x100 | PNP_RES_PRIORITY_ACCEPTABLE
;
669 isapnp_peek(tmp
, size
);
670 priority
= 0x100 | tmp
[0];
673 option
= pnp_register_dependent_option(dev
, priority
);
685 isapnp_parse_port_resource(option
, size
);
691 isapnp_parse_fixed_port_resource(option
, size
);
699 isapnp_parse_mem_resource(option
, size
);
703 isapnp_parse_name(dev
->name
, sizeof(dev
->name
), &size
);
705 case _LTAG_UNICODESTR
:
706 /* silently ignore */
707 /* who use unicode for hardware identification? */
711 case _LTAG_MEM32RANGE
:
714 isapnp_parse_mem32_resource(option
, size
);
717 case _LTAG_FIXEDMEM32RANGE
:
720 isapnp_parse_fixed_mem32_resource(option
, size
);
725 isapnp_skip_bytes(size
);
729 "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n",
730 type
, dev
->number
, card
->number
);
734 isapnp_skip_bytes(size
);
740 * Parse resource map for ISA PnP card.
742 static void __init
isapnp_parse_resource_map(struct pnp_card
*card
)
744 unsigned char type
, tmp
[17];
748 if (isapnp_read_tag(&type
, &size
) < 0)
755 card
->pnpver
= tmp
[0];
756 card
->productver
= tmp
[1];
760 if (size
>= 5 && size
<= 6) {
761 if (isapnp_create_device(card
, size
) == 1)
769 isapnp_parse_name(card
->name
, sizeof(card
->name
),
772 case _LTAG_UNICODESTR
:
773 /* silently ignore */
774 /* who use unicode for hardware identification? */
780 isapnp_skip_bytes(size
);
784 "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n",
789 isapnp_skip_bytes(size
);
794 * Compute ISA PnP checksum for first eight bytes.
796 static unsigned char __init
isapnp_checksum(unsigned char *data
)
799 unsigned char checksum
= 0x6a, bit
, b
;
801 for (i
= 0; i
< 8; i
++) {
803 for (j
= 0; j
< 8; j
++) {
808 ((((checksum
^ (checksum
>> 1)) & 0x01) ^ bit
) << 7)
816 * Parse EISA id for ISA PnP card.
818 static void isapnp_parse_card_id(struct pnp_card
*card
, unsigned short vendor
,
819 unsigned short device
)
821 struct pnp_id
*id
= kzalloc(sizeof(struct pnp_id
), GFP_KERNEL
);
825 sprintf(id
->id
, "%c%c%c%x%x%x%x",
826 'A' + ((vendor
>> 2) & 0x3f) - 1,
827 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
828 'A' + ((vendor
>> 8) & 0x1f) - 1,
829 (device
>> 4) & 0x0f,
830 device
& 0x0f, (device
>> 12) & 0x0f, (device
>> 8) & 0x0f);
831 pnp_add_card_id(id
, card
);
835 * Build device list for all present ISA PnP devices.
837 static int __init
isapnp_build_device_list(void)
840 unsigned char header
[9], checksum
;
841 struct pnp_card
*card
;
845 for (csn
= 1; csn
<= isapnp_csn_count
; csn
++) {
847 isapnp_peek(header
, 9);
848 checksum
= isapnp_checksum(header
);
851 "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
852 header
[0], header
[1], header
[2], header
[3], header
[4],
853 header
[5], header
[6], header
[7], header
[8]);
854 printk(KERN_DEBUG
"checksum = 0x%x\n", checksum
);
857 kzalloc(sizeof(struct pnp_card
), GFP_KERNEL
)) == NULL
)
861 INIT_LIST_HEAD(&card
->devices
);
862 isapnp_parse_card_id(card
, (header
[1] << 8) | header
[0],
863 (header
[3] << 8) | header
[2]);
865 (header
[7] << 24) | (header
[6] << 16) | (header
[5] << 8) |
867 isapnp_checksum_value
= 0x00;
868 isapnp_parse_resource_map(card
);
869 if (isapnp_checksum_value
!= 0x00)
871 "isapnp: checksum for device %i is not valid (0x%x)\n",
872 csn
, isapnp_checksum_value
);
873 card
->checksum
= isapnp_checksum_value
;
874 card
->protocol
= &isapnp_protocol
;
883 * Basic configuration routines.
886 int isapnp_present(void)
888 struct pnp_card
*card
;
890 pnp_for_each_card(card
) {
891 if (card
->protocol
== &isapnp_protocol
)
897 int isapnp_cfg_begin(int csn
, int logdev
)
899 if (csn
< 1 || csn
> isapnp_csn_count
|| logdev
> 10)
901 mutex_lock(&isapnp_cfg_mutex
);
906 /* to avoid malfunction when the isapnptools package is used */
907 /* we must set RDP to our value again */
908 /* it is possible to set RDP only in the isolation phase */
909 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
910 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
911 mdelay(2); /* is this necessary? */
912 isapnp_wake(csn
); /* bring card into sleep state */
913 isapnp_wake(0); /* bring card into isolation state */
914 isapnp_set_rdp(); /* reset the RDP port */
915 udelay(1000); /* delay 1000us */
916 isapnp_write_byte(0x06, csn
); /* reset CSN to previous value */
917 udelay(250); /* is this necessary? */
920 isapnp_device(logdev
);
924 int isapnp_cfg_end(void)
927 mutex_unlock(&isapnp_cfg_mutex
);
935 EXPORT_SYMBOL(isapnp_protocol
);
936 EXPORT_SYMBOL(isapnp_present
);
937 EXPORT_SYMBOL(isapnp_cfg_begin
);
938 EXPORT_SYMBOL(isapnp_cfg_end
);
939 EXPORT_SYMBOL(isapnp_write_byte
);
941 static int isapnp_read_resources(struct pnp_dev
*dev
,
942 struct pnp_resource_table
*res
)
946 dev
->active
= isapnp_read_byte(ISAPNP_CFG_ACTIVATE
);
948 for (tmp
= 0; tmp
< PNP_MAX_PORT
; tmp
++) {
949 ret
= isapnp_read_word(ISAPNP_CFG_PORT
+ (tmp
<< 1));
952 res
->port_resource
[tmp
].start
= ret
;
953 res
->port_resource
[tmp
].flags
= IORESOURCE_IO
;
955 for (tmp
= 0; tmp
< PNP_MAX_MEM
; tmp
++) {
957 isapnp_read_word(ISAPNP_CFG_MEM
+ (tmp
<< 3)) << 8;
960 res
->mem_resource
[tmp
].start
= ret
;
961 res
->mem_resource
[tmp
].flags
= IORESOURCE_MEM
;
963 for (tmp
= 0; tmp
< PNP_MAX_IRQ
; tmp
++) {
965 (isapnp_read_word(ISAPNP_CFG_IRQ
+ (tmp
<< 1)) >>
969 res
->irq_resource
[tmp
].start
=
970 res
->irq_resource
[tmp
].end
= ret
;
971 res
->irq_resource
[tmp
].flags
= IORESOURCE_IRQ
;
973 for (tmp
= 0; tmp
< PNP_MAX_DMA
; tmp
++) {
974 ret
= isapnp_read_byte(ISAPNP_CFG_DMA
+ tmp
);
977 res
->dma_resource
[tmp
].start
=
978 res
->dma_resource
[tmp
].end
= ret
;
979 res
->dma_resource
[tmp
].flags
= IORESOURCE_DMA
;
985 static int isapnp_get_resources(struct pnp_dev
*dev
,
986 struct pnp_resource_table
*res
)
990 pnp_init_resource_table(res
);
991 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
992 ret
= isapnp_read_resources(dev
, res
);
997 static int isapnp_set_resources(struct pnp_dev
*dev
,
998 struct pnp_resource_table
*res
)
1002 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1006 && (res
->port_resource
[tmp
].
1007 flags
& (IORESOURCE_IO
| IORESOURCE_UNSET
)) == IORESOURCE_IO
;
1009 isapnp_write_word(ISAPNP_CFG_PORT
+ (tmp
<< 1),
1010 res
->port_resource
[tmp
].start
);
1013 && (res
->irq_resource
[tmp
].
1014 flags
& (IORESOURCE_IRQ
| IORESOURCE_UNSET
)) == IORESOURCE_IRQ
;
1016 int irq
= res
->irq_resource
[tmp
].start
;
1019 isapnp_write_byte(ISAPNP_CFG_IRQ
+ (tmp
<< 1), irq
);
1023 && (res
->dma_resource
[tmp
].
1024 flags
& (IORESOURCE_DMA
| IORESOURCE_UNSET
)) == IORESOURCE_DMA
;
1026 isapnp_write_byte(ISAPNP_CFG_DMA
+ tmp
,
1027 res
->dma_resource
[tmp
].start
);
1030 && (res
->mem_resource
[tmp
].
1031 flags
& (IORESOURCE_MEM
| IORESOURCE_UNSET
)) == IORESOURCE_MEM
;
1033 isapnp_write_word(ISAPNP_CFG_MEM
+ (tmp
<< 3),
1034 (res
->mem_resource
[tmp
].start
>> 8) & 0xffff);
1035 /* FIXME: We aren't handling 32bit mems properly here */
1036 isapnp_activate(dev
->number
);
1041 static int isapnp_disable_resources(struct pnp_dev
*dev
)
1045 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1046 isapnp_deactivate(dev
->number
);
1052 struct pnp_protocol isapnp_protocol
= {
1053 .name
= "ISA Plug and Play",
1054 .get
= isapnp_get_resources
,
1055 .set
= isapnp_set_resources
,
1056 .disable
= isapnp_disable_resources
,
1059 static int __init
isapnp_init(void)
1062 struct pnp_card
*card
;
1063 struct pnp_dev
*dev
;
1065 if (isapnp_disable
) {
1066 printk(KERN_INFO
"isapnp: ISA Plug & Play support disabled\n");
1069 #ifdef CONFIG_PPC_MERGE
1070 if (check_legacy_ioport(_PIDXR
) || check_legacy_ioport(_PNPWRP
))
1073 #ifdef ISAPNP_REGION_OK
1074 if (!request_region(_PIDXR
, 1, "isapnp index")) {
1075 printk(KERN_ERR
"isapnp: Index Register 0x%x already used\n",
1080 if (!request_region(_PNPWRP
, 1, "isapnp write")) {
1082 "isapnp: Write Data Register 0x%x already used\n",
1084 #ifdef ISAPNP_REGION_OK
1085 release_region(_PIDXR
, 1);
1090 if (pnp_register_protocol(&isapnp_protocol
) < 0)
1094 * Print a message. The existing ISAPnP code is hanging machines
1095 * so let the user know where.
1098 printk(KERN_INFO
"isapnp: Scanning for PnP cards...\n");
1099 if (isapnp_rdp
>= 0x203 && isapnp_rdp
<= 0x3ff) {
1101 if (!request_region(isapnp_rdp
, 1, "isapnp read")) {
1103 "isapnp: Read Data Register 0x%x already used\n",
1105 #ifdef ISAPNP_REGION_OK
1106 release_region(_PIDXR
, 1);
1108 release_region(_PNPWRP
, 1);
1113 if (isapnp_rdp
< 0x203 || isapnp_rdp
> 0x3ff) {
1114 cards
= isapnp_isolate();
1115 if (cards
< 0 || (isapnp_rdp
< 0x203 || isapnp_rdp
> 0x3ff)) {
1116 #ifdef ISAPNP_REGION_OK
1117 release_region(_PIDXR
, 1);
1119 release_region(_PNPWRP
, 1);
1121 "isapnp: No Plug & Play device found\n");
1124 request_region(isapnp_rdp
, 1, "isapnp read");
1126 isapnp_build_device_list();
1129 protocol_for_each_card(&isapnp_protocol
, card
) {
1131 if (isapnp_verbose
) {
1132 printk(KERN_INFO
"isapnp: Card '%s'\n",
1133 card
->name
[0] ? card
->name
: "Unknown");
1134 if (isapnp_verbose
< 2)
1136 card_for_each_dev(card
, dev
) {
1137 printk(KERN_INFO
"isapnp: Device '%s'\n",
1138 dev
->name
[0] ? dev
->name
: "Unknown");
1144 "isapnp: %i Plug & Play card%s detected total\n", cards
,
1145 cards
> 1 ? "s" : "");
1147 printk(KERN_INFO
"isapnp: No Plug & Play card found\n");
1153 device_initcall(isapnp_init
);
1155 /* format is: noisapnp */
1157 static int __init
isapnp_setup_disable(char *str
)
1163 __setup("noisapnp", isapnp_setup_disable
);
1165 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1167 static int __init
isapnp_setup_isapnp(char *str
)
1169 (void)((get_option(&str
, &isapnp_rdp
) == 2) &&
1170 (get_option(&str
, &isapnp_reset
) == 2) &&
1171 (get_option(&str
, &isapnp_verbose
) == 2));
1175 __setup("isapnp=", isapnp_setup_isapnp
);