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 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 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 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_alloc(long size
)
149 result
= kmalloc(size
, GFP_KERNEL
);
152 memset(result
, 0, size
);
156 static void isapnp_key(void)
158 unsigned char code
= 0x6a, msb
;
167 for (i
= 1; i
< 32; i
++) {
168 msb
= ((code
& 0x01) ^ ((code
& 0x02) >> 1)) << 7;
169 code
= (code
>> 1) | msb
;
174 /* place all pnp cards in wait-for-key state */
175 static void isapnp_wait(void)
177 isapnp_write_byte(0x02, 0x02);
180 static void isapnp_wake(unsigned char csn
)
182 isapnp_write_byte(0x03, csn
);
185 static void isapnp_device(unsigned char logdev
)
187 isapnp_write_byte(0x07, logdev
);
190 static void isapnp_activate(unsigned char logdev
)
192 isapnp_device(logdev
);
193 isapnp_write_byte(ISAPNP_CFG_ACTIVATE
, 1);
197 static void isapnp_deactivate(unsigned char logdev
)
199 isapnp_device(logdev
);
200 isapnp_write_byte(ISAPNP_CFG_ACTIVATE
, 0);
204 static void __init
isapnp_peek(unsigned char *data
, int bytes
)
209 for (i
= 1; i
<= bytes
; i
++) {
210 for (j
= 0; j
< 20; j
++) {
211 d
= isapnp_read_byte(0x05);
221 d
= isapnp_read_byte(0x04); /* PRESDI */
222 isapnp_checksum_value
+= d
;
228 #define RDP_STEP 32 /* minimum is 4 */
230 static int isapnp_next_rdp(void)
232 int rdp
= isapnp_rdp
;
233 static int old_rdp
= 0;
237 release_region(old_rdp
, 1);
240 while (rdp
<= 0x3ff) {
242 * We cannot use NE2000 probe spaces for ISAPnP or we
243 * will lock up machines.
245 if ((rdp
< 0x280 || rdp
> 0x380) && request_region(rdp
, 1, "ISAPnP"))
256 /* Set read port address */
257 static inline void isapnp_set_rdp(void)
259 isapnp_write_byte(0x00, isapnp_rdp
>> 2);
264 * Perform an isolation. The port selection code now tries to avoid
265 * "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.
297 static int __init
isapnp_isolate(void)
299 unsigned char checksum
= 0x6a;
300 unsigned char chksum
= 0x00;
301 unsigned char bit
= 0x00;
308 if (isapnp_isolate_rdp_select() < 0)
312 for (i
= 1; i
<= 64; i
++) {
313 data
= read_data() << 8;
315 data
= data
| read_data();
319 checksum
= ((((checksum
^ (checksum
>> 1)) & 0x01) ^ bit
) << 7) | (checksum
>> 1);
322 for (i
= 65; i
<= 72; i
++) {
323 data
= read_data() << 8;
325 data
= data
| read_data();
328 chksum
|= (1 << (i
- 65));
330 if (checksum
!= 0x00 && checksum
== chksum
) {
333 isapnp_write_byte(0x06, csn
);
343 if (iteration
== 1) {
344 isapnp_rdp
+= RDP_STEP
;
345 if (isapnp_isolate_rdp_select() < 0)
347 } else if (iteration
> 1) {
358 isapnp_csn_count
= csn
;
363 * 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
, *size
);
384 if (type
== 0) /* wrong type */
386 if (*type
== 0xff && *size
== 0xffff) /* probably invalid data */
392 * Skip specified number of bytes from stream.
395 static void __init
isapnp_skip_bytes(int count
)
397 isapnp_peek(NULL
, count
);
404 static void isapnp_parse_id(struct pnp_dev
* dev
, unsigned short vendor
, unsigned short device
)
409 id
= isapnp_alloc(sizeof(struct pnp_id
));
412 sprintf(id
->id
, "%c%c%c%x%x%x%x",
413 'A' + ((vendor
>> 2) & 0x3f) - 1,
414 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
415 'A' + ((vendor
>> 8) & 0x1f) - 1,
416 (device
>> 4) & 0x0f,
418 (device
>> 12) & 0x0f,
419 (device
>> 8) & 0x0f);
424 * Parse logical device tag.
427 static struct pnp_dev
* __init
isapnp_parse_device(struct pnp_card
*card
, int size
, int number
)
429 unsigned char tmp
[6];
432 isapnp_peek(tmp
, size
);
433 dev
= isapnp_alloc(sizeof(struct pnp_dev
));
436 dev
->number
= number
;
437 isapnp_parse_id(dev
, (tmp
[1] << 8) | tmp
[0], (tmp
[3] << 8) | tmp
[2]);
441 dev
->regs
|= tmp
[5] << 8;
442 dev
->protocol
= &isapnp_protocol
;
443 dev
->capabilities
|= PNP_CONFIGURABLE
;
444 dev
->capabilities
|= PNP_READ
;
445 dev
->capabilities
|= PNP_WRITE
;
446 dev
->capabilities
|= PNP_DISABLE
;
447 pnp_init_resource_table(&dev
->res
);
453 * Add IRQ resource to resources list.
456 static void __init
isapnp_parse_irq_resource(struct pnp_option
*option
,
459 unsigned char tmp
[3];
463 isapnp_peek(tmp
, size
);
464 irq
= isapnp_alloc(sizeof(struct pnp_irq
));
467 bits
= (tmp
[1] << 8) | tmp
[0];
468 bitmap_copy(irq
->map
, &bits
, 16);
472 irq
->flags
= IORESOURCE_IRQ_HIGHEDGE
;
473 pnp_register_irq_resource(option
, irq
);
478 * Add DMA resource to resources list.
481 static void __init
isapnp_parse_dma_resource(struct pnp_option
*option
,
484 unsigned char tmp
[2];
487 isapnp_peek(tmp
, size
);
488 dma
= isapnp_alloc(sizeof(struct pnp_dma
));
493 pnp_register_dma_resource(option
, dma
);
498 * Add port resource to resources list.
501 static void __init
isapnp_parse_port_resource(struct pnp_option
*option
,
504 unsigned char tmp
[7];
505 struct pnp_port
*port
;
507 isapnp_peek(tmp
, size
);
508 port
= isapnp_alloc(sizeof(struct pnp_port
));
511 port
->min
= (tmp
[2] << 8) | tmp
[1];
512 port
->max
= (tmp
[4] << 8) | tmp
[3];
513 port
->align
= tmp
[5];
515 port
->flags
= tmp
[0] ? PNP_PORT_FLAG_16BITADDR
: 0;
516 pnp_register_port_resource(option
,port
);
521 * Add fixed port resource to resources list.
524 static void __init
isapnp_parse_fixed_port_resource(struct pnp_option
*option
,
527 unsigned char tmp
[3];
528 struct pnp_port
*port
;
530 isapnp_peek(tmp
, size
);
531 port
= isapnp_alloc(sizeof(struct pnp_port
));
534 port
->min
= port
->max
= (tmp
[1] << 8) | tmp
[0];
537 port
->flags
= PNP_PORT_FLAG_FIXED
;
538 pnp_register_port_resource(option
,port
);
543 * Add memory resource to resources list.
546 static void __init
isapnp_parse_mem_resource(struct pnp_option
*option
,
549 unsigned char tmp
[9];
552 isapnp_peek(tmp
, size
);
553 mem
= isapnp_alloc(sizeof(struct pnp_mem
));
556 mem
->min
= ((tmp
[2] << 8) | tmp
[1]) << 8;
557 mem
->max
= ((tmp
[4] << 8) | tmp
[3]) << 8;
558 mem
->align
= (tmp
[6] << 8) | tmp
[5];
559 mem
->size
= ((tmp
[8] << 8) | tmp
[7]) << 8;
561 pnp_register_mem_resource(option
,mem
);
566 * Add 32-bit memory resource to resources list.
569 static void __init
isapnp_parse_mem32_resource(struct pnp_option
*option
,
572 unsigned char tmp
[17];
575 isapnp_peek(tmp
, size
);
576 mem
= isapnp_alloc(sizeof(struct pnp_mem
));
579 mem
->min
= (tmp
[4] << 24) | (tmp
[3] << 16) | (tmp
[2] << 8) | tmp
[1];
580 mem
->max
= (tmp
[8] << 24) | (tmp
[7] << 16) | (tmp
[6] << 8) | tmp
[5];
581 mem
->align
= (tmp
[12] << 24) | (tmp
[11] << 16) | (tmp
[10] << 8) | tmp
[9];
582 mem
->size
= (tmp
[16] << 24) | (tmp
[15] << 16) | (tmp
[14] << 8) | tmp
[13];
584 pnp_register_mem_resource(option
,mem
);
588 * Add 32-bit fixed memory resource to resources list.
591 static void __init
isapnp_parse_fixed_mem32_resource(struct pnp_option
*option
,
594 unsigned char tmp
[9];
597 isapnp_peek(tmp
, size
);
598 mem
= isapnp_alloc(sizeof(struct pnp_mem
));
601 mem
->min
= mem
->max
= (tmp
[4] << 24) | (tmp
[3] << 16) | (tmp
[2] << 8) | tmp
[1];
602 mem
->size
= (tmp
[8] << 24) | (tmp
[7] << 16) | (tmp
[6] << 8) | tmp
[5];
605 pnp_register_mem_resource(option
,mem
);
609 * Parse card name for ISA PnP device.
613 isapnp_parse_name(char *name
, unsigned int name_max
, unsigned short *size
)
615 if (name
[0] == '\0') {
616 unsigned short size1
= *size
>= name_max
? (name_max
- 1) : *size
;
617 isapnp_peek(name
, size1
);
621 /* clean whitespace from end of string */
622 while (size1
> 0 && name
[--size1
] == ' ')
628 * Parse resource map for logical device.
631 static int __init
isapnp_create_device(struct pnp_card
*card
,
634 int number
= 0, skip
= 0, priority
= 0, compat
= 0;
635 unsigned char type
, tmp
[17];
636 struct pnp_option
*option
;
638 if ((dev
= isapnp_parse_device(card
, size
, number
++)) == NULL
)
640 option
= pnp_register_independent_option(dev
);
645 pnp_add_card_device(card
,dev
);
648 if (isapnp_read_tag(&type
, &size
)<0)
650 if (skip
&& type
!= _STAG_LOGDEVID
&& type
!= _STAG_END
)
654 if (size
>= 5 && size
<= 6) {
655 if ((dev
= isapnp_parse_device(card
, size
, number
++)) == NULL
)
659 option
= pnp_register_independent_option(dev
);
662 pnp_add_card_device(card
,dev
);
669 case _STAG_COMPATDEVID
:
670 if (size
== 4 && compat
< DEVICE_COUNT_COMPATIBLE
) {
672 isapnp_parse_id(dev
,(tmp
[1] << 8) | tmp
[0], (tmp
[3] << 8) | tmp
[2]);
678 if (size
< 2 || size
> 3)
680 isapnp_parse_irq_resource(option
, size
);
686 isapnp_parse_dma_resource(option
, size
);
692 priority
= 0x100 | PNP_RES_PRIORITY_ACCEPTABLE
;
694 isapnp_peek(tmp
, size
);
695 priority
= 0x100 | tmp
[0];
698 option
= pnp_register_dependent_option(dev
,priority
);
710 isapnp_parse_port_resource(option
, size
);
716 isapnp_parse_fixed_port_resource(option
, size
);
724 isapnp_parse_mem_resource(option
, size
);
728 isapnp_parse_name(dev
->name
, sizeof(dev
->name
), &size
);
730 case _LTAG_UNICODESTR
:
731 /* silently ignore */
732 /* who use unicode for hardware identification? */
736 case _LTAG_MEM32RANGE
:
739 isapnp_parse_mem32_resource(option
, size
);
742 case _LTAG_FIXEDMEM32RANGE
:
745 isapnp_parse_fixed_mem32_resource(option
, size
);
750 isapnp_skip_bytes(size
);
753 printk(KERN_ERR
"isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n", type
, dev
->number
, card
->number
);
757 isapnp_skip_bytes(size
);
763 * Parse resource map for ISA PnP card.
766 static void __init
isapnp_parse_resource_map(struct pnp_card
*card
)
768 unsigned char type
, tmp
[17];
772 if (isapnp_read_tag(&type
, &size
)<0)
779 card
->pnpver
= tmp
[0];
780 card
->productver
= tmp
[1];
784 if (size
>= 5 && size
<= 6) {
785 if (isapnp_create_device(card
, size
)==1)
793 isapnp_parse_name(card
->name
, sizeof(card
->name
), &size
);
795 case _LTAG_UNICODESTR
:
796 /* silently ignore */
797 /* who use unicode for hardware identification? */
803 isapnp_skip_bytes(size
);
806 printk(KERN_ERR
"isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n", type
, card
->number
);
810 isapnp_skip_bytes(size
);
815 * Compute ISA PnP checksum for first eight bytes.
818 static unsigned char __init
isapnp_checksum(unsigned char *data
)
821 unsigned char checksum
= 0x6a, bit
, b
;
823 for (i
= 0; i
< 8; i
++) {
825 for (j
= 0; j
< 8; j
++) {
829 checksum
= ((((checksum
^ (checksum
>> 1)) & 0x01) ^ bit
) << 7) | (checksum
>> 1);
836 * Parse EISA id for ISA PnP card.
839 static void isapnp_parse_card_id(struct pnp_card
* card
, unsigned short vendor
, unsigned short device
)
841 struct pnp_id
* id
= isapnp_alloc(sizeof(struct pnp_id
));
844 sprintf(id
->id
, "%c%c%c%x%x%x%x",
845 'A' + ((vendor
>> 2) & 0x3f) - 1,
846 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
847 'A' + ((vendor
>> 8) & 0x1f) - 1,
848 (device
>> 4) & 0x0f,
850 (device
>> 12) & 0x0f,
851 (device
>> 8) & 0x0f);
852 pnp_add_card_id(id
,card
);
856 * Build device list for all present ISA PnP devices.
859 static int __init
isapnp_build_device_list(void)
862 unsigned char header
[9], checksum
;
863 struct pnp_card
*card
;
867 for (csn
= 1; csn
<= isapnp_csn_count
; csn
++) {
869 isapnp_peek(header
, 9);
870 checksum
= isapnp_checksum(header
);
872 printk(KERN_DEBUG
"vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
873 header
[0], header
[1], header
[2], header
[3],
874 header
[4], header
[5], header
[6], header
[7], header
[8]);
875 printk(KERN_DEBUG
"checksum = 0x%x\n", checksum
);
877 if ((card
= isapnp_alloc(sizeof(struct pnp_card
))) == NULL
)
881 INIT_LIST_HEAD(&card
->devices
);
882 isapnp_parse_card_id(card
, (header
[1] << 8) | header
[0], (header
[3] << 8) | header
[2]);
883 card
->serial
= (header
[7] << 24) | (header
[6] << 16) | (header
[5] << 8) | header
[4];
884 isapnp_checksum_value
= 0x00;
885 isapnp_parse_resource_map(card
);
886 if (isapnp_checksum_value
!= 0x00)
887 printk(KERN_ERR
"isapnp: checksum for device %i is not valid (0x%x)\n", csn
, isapnp_checksum_value
);
888 card
->checksum
= isapnp_checksum_value
;
889 card
->protocol
= &isapnp_protocol
;
898 * Basic configuration routines.
901 int isapnp_present(void)
903 struct pnp_card
*card
;
904 pnp_for_each_card(card
) {
905 if (card
->protocol
== &isapnp_protocol
)
911 int isapnp_cfg_begin(int csn
, int logdev
)
913 if (csn
< 1 || csn
> isapnp_csn_count
|| logdev
> 10)
915 down(&isapnp_cfg_mutex
);
920 /* to avoid malfunction when the isapnptools package is used */
921 /* we must set RDP to our value again */
922 /* it is possible to set RDP only in the isolation phase */
923 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
924 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
925 mdelay(2); /* is this necessary? */
926 isapnp_wake(csn
); /* bring card into sleep state */
927 isapnp_wake(0); /* bring card into isolation state */
928 isapnp_set_rdp(); /* reset the RDP port */
929 udelay(1000); /* delay 1000us */
930 isapnp_write_byte(0x06, csn
); /* reset CSN to previous value */
931 udelay(250); /* is this necessary? */
934 isapnp_device(logdev
);
938 int isapnp_cfg_end(void)
941 up(&isapnp_cfg_mutex
);
951 EXPORT_SYMBOL(isapnp_protocol
);
952 EXPORT_SYMBOL(isapnp_present
);
953 EXPORT_SYMBOL(isapnp_cfg_begin
);
954 EXPORT_SYMBOL(isapnp_cfg_end
);
955 EXPORT_SYMBOL(isapnp_read_byte
);
956 EXPORT_SYMBOL(isapnp_write_byte
);
958 static int isapnp_read_resources(struct pnp_dev
*dev
, struct pnp_resource_table
*res
)
962 dev
->active
= isapnp_read_byte(ISAPNP_CFG_ACTIVATE
);
964 for (tmp
= 0; tmp
< PNP_MAX_PORT
; tmp
++) {
965 ret
= isapnp_read_word(ISAPNP_CFG_PORT
+ (tmp
<< 1));
968 res
->port_resource
[tmp
].start
= ret
;
969 res
->port_resource
[tmp
].flags
= IORESOURCE_IO
;
971 for (tmp
= 0; tmp
< PNP_MAX_MEM
; tmp
++) {
972 ret
= isapnp_read_word(ISAPNP_CFG_MEM
+ (tmp
<< 3)) << 8;
975 res
->mem_resource
[tmp
].start
= ret
;
976 res
->mem_resource
[tmp
].flags
= IORESOURCE_MEM
;
978 for (tmp
= 0; tmp
< PNP_MAX_IRQ
; tmp
++) {
979 ret
= (isapnp_read_word(ISAPNP_CFG_IRQ
+ (tmp
<< 1)) >> 8);
982 res
->irq_resource
[tmp
].start
= res
->irq_resource
[tmp
].end
= ret
;
983 res
->irq_resource
[tmp
].flags
= IORESOURCE_IRQ
;
985 for (tmp
= 0; tmp
< PNP_MAX_DMA
; tmp
++) {
986 ret
= isapnp_read_byte(ISAPNP_CFG_DMA
+ tmp
);
989 res
->dma_resource
[tmp
].start
= res
->dma_resource
[tmp
].end
= ret
;
990 res
->dma_resource
[tmp
].flags
= IORESOURCE_DMA
;
996 static int isapnp_get_resources(struct pnp_dev
*dev
, 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
, struct pnp_resource_table
* res
)
1010 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1012 for (tmp
= 0; tmp
< PNP_MAX_PORT
&& (res
->port_resource
[tmp
].flags
& (IORESOURCE_IO
| IORESOURCE_UNSET
)) == IORESOURCE_IO
; tmp
++)
1013 isapnp_write_word(ISAPNP_CFG_PORT
+(tmp
<<1), res
->port_resource
[tmp
].start
);
1014 for (tmp
= 0; tmp
< PNP_MAX_IRQ
&& (res
->irq_resource
[tmp
].flags
& (IORESOURCE_IRQ
| IORESOURCE_UNSET
)) == IORESOURCE_IRQ
; tmp
++) {
1015 int irq
= res
->irq_resource
[tmp
].start
;
1018 isapnp_write_byte(ISAPNP_CFG_IRQ
+(tmp
<<1), irq
);
1020 for (tmp
= 0; tmp
< PNP_MAX_DMA
&& (res
->dma_resource
[tmp
].flags
& (IORESOURCE_DMA
| IORESOURCE_UNSET
)) == IORESOURCE_DMA
; tmp
++)
1021 isapnp_write_byte(ISAPNP_CFG_DMA
+tmp
, res
->dma_resource
[tmp
].start
);
1022 for (tmp
= 0; tmp
< PNP_MAX_MEM
&& (res
->mem_resource
[tmp
].flags
& (IORESOURCE_MEM
| IORESOURCE_UNSET
)) == IORESOURCE_MEM
; tmp
++)
1023 isapnp_write_word(ISAPNP_CFG_MEM
+(tmp
<<3), (res
->mem_resource
[tmp
].start
>> 8) & 0xffff);
1024 /* FIXME: We aren't handling 32bit mems properly here */
1025 isapnp_activate(dev
->number
);
1030 static int isapnp_disable_resources(struct pnp_dev
*dev
)
1032 if (!dev
|| !dev
->active
)
1034 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1035 isapnp_deactivate(dev
->number
);
1041 struct pnp_protocol isapnp_protocol
= {
1042 .name
= "ISA Plug and Play",
1043 .get
= isapnp_get_resources
,
1044 .set
= isapnp_set_resources
,
1045 .disable
= isapnp_disable_resources
,
1048 static int __init
isapnp_init(void)
1051 struct pnp_card
*card
;
1052 struct pnp_dev
*dev
;
1054 if (isapnp_disable
) {
1055 isapnp_detected
= 0;
1056 printk(KERN_INFO
"isapnp: ISA Plug & Play support disabled\n");
1059 #ifdef ISAPNP_REGION_OK
1060 if (!request_region(_PIDXR
, 1, "isapnp index")) {
1061 printk(KERN_ERR
"isapnp: Index Register 0x%x already used\n", _PIDXR
);
1065 if (!request_region(_PNPWRP
, 1, "isapnp write")) {
1066 printk(KERN_ERR
"isapnp: Write Data Register 0x%x already used\n", _PNPWRP
);
1067 #ifdef ISAPNP_REGION_OK
1068 release_region(_PIDXR
, 1);
1073 if(pnp_register_protocol(&isapnp_protocol
)<0)
1077 * Print a message. The existing ISAPnP code is hanging machines
1078 * so let the user know where.
1081 printk(KERN_INFO
"isapnp: Scanning for PnP cards...\n");
1082 if (isapnp_rdp
>= 0x203 && isapnp_rdp
<= 0x3ff) {
1084 if (!request_region(isapnp_rdp
, 1, "isapnp read")) {
1085 printk(KERN_ERR
"isapnp: Read Data Register 0x%x already used\n", isapnp_rdp
);
1086 #ifdef ISAPNP_REGION_OK
1087 release_region(_PIDXR
, 1);
1089 release_region(_PNPWRP
, 1);
1094 isapnp_detected
= 1;
1095 if (isapnp_rdp
< 0x203 || isapnp_rdp
> 0x3ff) {
1096 cards
= isapnp_isolate();
1098 (isapnp_rdp
< 0x203 || isapnp_rdp
> 0x3ff)) {
1099 #ifdef ISAPNP_REGION_OK
1100 release_region(_PIDXR
, 1);
1102 release_region(_PNPWRP
, 1);
1103 isapnp_detected
= 0;
1104 printk(KERN_INFO
"isapnp: No Plug & Play device found\n");
1107 request_region(isapnp_rdp
, 1, "isapnp read");
1109 isapnp_build_device_list();
1112 protocol_for_each_card(&isapnp_protocol
,card
) {
1114 if (isapnp_verbose
) {
1115 printk(KERN_INFO
"isapnp: Card '%s'\n", card
->name
[0]?card
->name
:"Unknown");
1116 if (isapnp_verbose
< 2)
1118 card_for_each_dev(card
,dev
) {
1119 printk(KERN_INFO
"isapnp: Device '%s'\n", dev
->name
[0]?dev
->name
:"Unknown");
1124 printk(KERN_INFO
"isapnp: %i Plug & Play card%s detected total\n", cards
, cards
>1?"s":"");
1126 printk(KERN_INFO
"isapnp: No Plug & Play card found\n");
1133 device_initcall(isapnp_init
);
1135 /* format is: noisapnp */
1137 static int __init
isapnp_setup_disable(char *str
)
1143 __setup("noisapnp", isapnp_setup_disable
);
1145 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1147 static int __init
isapnp_setup_isapnp(char *str
)
1149 (void)((get_option(&str
,&isapnp_rdp
) == 2) &&
1150 (get_option(&str
,&isapnp_reset
) == 2) &&
1151 (get_option(&str
,&isapnp_verbose
) == 2));
1155 __setup("isapnp=", isapnp_setup_isapnp
);