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>
45 #include <linux/mutex.h>
49 #define ISAPNP_REGION_OK
55 int isapnp_disable
; /* Disable ISA PnP */
56 static int isapnp_rdp
; /* Read Data Port */
57 static int isapnp_reset
= 1; /* reset all PnP cards (deactivate) */
58 static int isapnp_verbose
= 1; /* verbose mode */
60 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
61 MODULE_DESCRIPTION("Generic ISA Plug & Play support");
62 module_param(isapnp_disable
, int, 0);
63 MODULE_PARM_DESC(isapnp_disable
, "ISA Plug & Play disable");
64 module_param(isapnp_rdp
, int, 0);
65 MODULE_PARM_DESC(isapnp_rdp
, "ISA Plug & Play read data port");
66 module_param(isapnp_reset
, int, 0);
67 MODULE_PARM_DESC(isapnp_reset
, "ISA Plug & Play reset all cards");
68 module_param(isapnp_verbose
, int, 0);
69 MODULE_PARM_DESC(isapnp_verbose
, "ISA Plug & Play verbose mode");
70 MODULE_LICENSE("GPL");
76 #define _STAG_PNPVERNO 0x01
77 #define _STAG_LOGDEVID 0x02
78 #define _STAG_COMPATDEVID 0x03
79 #define _STAG_IRQ 0x04
80 #define _STAG_DMA 0x05
81 #define _STAG_STARTDEP 0x06
82 #define _STAG_ENDDEP 0x07
83 #define _STAG_IOPORT 0x08
84 #define _STAG_FIXEDIO 0x09
85 #define _STAG_VENDOR 0x0e
86 #define _STAG_END 0x0f
88 #define _LTAG_MEMRANGE 0x81
89 #define _LTAG_ANSISTR 0x82
90 #define _LTAG_UNICODESTR 0x83
91 #define _LTAG_VENDOR 0x84
92 #define _LTAG_MEM32RANGE 0x85
93 #define _LTAG_FIXEDMEM32RANGE 0x86
95 static unsigned char isapnp_checksum_value
;
96 static DEFINE_MUTEX(isapnp_cfg_mutex
);
97 static int isapnp_detected
;
98 static int isapnp_csn_count
;
100 /* some prototypes */
102 static inline void write_data(unsigned char x
)
107 static inline void write_address(unsigned char x
)
113 static inline unsigned char read_data(void)
115 unsigned char val
= inb(isapnp_rdp
);
119 unsigned char isapnp_read_byte(unsigned char idx
)
125 static unsigned short isapnp_read_word(unsigned char idx
)
129 val
= isapnp_read_byte(idx
);
130 val
= (val
<< 8) + isapnp_read_byte(idx
+1);
134 void isapnp_write_byte(unsigned char idx
, unsigned char val
)
140 static void isapnp_write_word(unsigned char idx
, unsigned short val
)
142 isapnp_write_byte(idx
, val
>> 8);
143 isapnp_write_byte(idx
+1, val
);
146 static void isapnp_key(void)
148 unsigned char code
= 0x6a, msb
;
157 for (i
= 1; i
< 32; i
++) {
158 msb
= ((code
& 0x01) ^ ((code
& 0x02) >> 1)) << 7;
159 code
= (code
>> 1) | msb
;
164 /* place all pnp cards in wait-for-key state */
165 static void isapnp_wait(void)
167 isapnp_write_byte(0x02, 0x02);
170 static void isapnp_wake(unsigned char csn
)
172 isapnp_write_byte(0x03, csn
);
175 static void isapnp_device(unsigned char logdev
)
177 isapnp_write_byte(0x07, logdev
);
180 static void isapnp_activate(unsigned char logdev
)
182 isapnp_device(logdev
);
183 isapnp_write_byte(ISAPNP_CFG_ACTIVATE
, 1);
187 static void isapnp_deactivate(unsigned char logdev
)
189 isapnp_device(logdev
);
190 isapnp_write_byte(ISAPNP_CFG_ACTIVATE
, 0);
194 static void __init
isapnp_peek(unsigned char *data
, int bytes
)
199 for (i
= 1; i
<= bytes
; i
++) {
200 for (j
= 0; j
< 20; j
++) {
201 d
= isapnp_read_byte(0x05);
211 d
= isapnp_read_byte(0x04); /* PRESDI */
212 isapnp_checksum_value
+= d
;
218 #define RDP_STEP 32 /* minimum is 4 */
220 static int isapnp_next_rdp(void)
222 int rdp
= isapnp_rdp
;
223 static int old_rdp
= 0;
227 release_region(old_rdp
, 1);
230 while (rdp
<= 0x3ff) {
232 * We cannot use NE2000 probe spaces for ISAPnP or we
233 * will lock up machines.
235 if ((rdp
< 0x280 || rdp
> 0x380) && request_region(rdp
, 1, "ISAPnP"))
246 /* Set read port address */
247 static inline void isapnp_set_rdp(void)
249 isapnp_write_byte(0x00, isapnp_rdp
>> 2);
254 * Perform an isolation. The port selection code now tries to avoid
255 * "dangerous to read" ports.
258 static int __init
isapnp_isolate_rdp_select(void)
263 /* Control: reset CSN and conditionally everything else too */
264 isapnp_write_byte(0x02, isapnp_reset
? 0x05 : 0x04);
271 if (isapnp_next_rdp() < 0) {
284 * Isolate (assign uniqued CSN) to all ISA PnP devices.
287 static int __init
isapnp_isolate(void)
289 unsigned char checksum
= 0x6a;
290 unsigned char chksum
= 0x00;
291 unsigned char bit
= 0x00;
298 if (isapnp_isolate_rdp_select() < 0)
302 for (i
= 1; i
<= 64; i
++) {
303 data
= read_data() << 8;
305 data
= data
| read_data();
309 checksum
= ((((checksum
^ (checksum
>> 1)) & 0x01) ^ bit
) << 7) | (checksum
>> 1);
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
, *size
);
374 if (type
== 0) /* wrong type */
376 if (*type
== 0xff && *size
== 0xffff) /* probably invalid data */
382 * Skip specified number of bytes from stream.
385 static void __init
isapnp_skip_bytes(int count
)
387 isapnp_peek(NULL
, count
);
394 static void isapnp_parse_id(struct pnp_dev
* dev
, unsigned short vendor
, unsigned short device
)
399 id
= kcalloc(1, 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,
408 (device
>> 12) & 0x0f,
409 (device
>> 8) & 0x0f);
414 * Parse logical device tag.
417 static struct pnp_dev
* __init
isapnp_parse_device(struct pnp_card
*card
, int size
, int number
)
419 unsigned char tmp
[6];
422 isapnp_peek(tmp
, size
);
423 dev
= kcalloc(1, sizeof(struct pnp_dev
), GFP_KERNEL
);
426 dev
->number
= number
;
427 isapnp_parse_id(dev
, (tmp
[1] << 8) | tmp
[0], (tmp
[3] << 8) | tmp
[2]);
431 dev
->regs
|= tmp
[5] << 8;
432 dev
->protocol
= &isapnp_protocol
;
433 dev
->capabilities
|= PNP_CONFIGURABLE
;
434 dev
->capabilities
|= PNP_READ
;
435 dev
->capabilities
|= PNP_WRITE
;
436 dev
->capabilities
|= PNP_DISABLE
;
437 pnp_init_resource_table(&dev
->res
);
443 * Add IRQ resource to resources list.
446 static void __init
isapnp_parse_irq_resource(struct pnp_option
*option
,
449 unsigned char tmp
[3];
453 isapnp_peek(tmp
, size
);
454 irq
= kcalloc(1, sizeof(struct pnp_irq
), GFP_KERNEL
);
457 bits
= (tmp
[1] << 8) | tmp
[0];
458 bitmap_copy(irq
->map
, &bits
, 16);
462 irq
->flags
= IORESOURCE_IRQ_HIGHEDGE
;
463 pnp_register_irq_resource(option
, irq
);
468 * Add DMA resource to resources list.
471 static void __init
isapnp_parse_dma_resource(struct pnp_option
*option
,
474 unsigned char tmp
[2];
477 isapnp_peek(tmp
, size
);
478 dma
= kcalloc(1, sizeof(struct pnp_dma
), GFP_KERNEL
);
483 pnp_register_dma_resource(option
, dma
);
488 * Add port resource to resources list.
491 static void __init
isapnp_parse_port_resource(struct pnp_option
*option
,
494 unsigned char tmp
[7];
495 struct pnp_port
*port
;
497 isapnp_peek(tmp
, size
);
498 port
= kcalloc(1, sizeof(struct pnp_port
), GFP_KERNEL
);
501 port
->min
= (tmp
[2] << 8) | tmp
[1];
502 port
->max
= (tmp
[4] << 8) | tmp
[3];
503 port
->align
= tmp
[5];
505 port
->flags
= tmp
[0] ? PNP_PORT_FLAG_16BITADDR
: 0;
506 pnp_register_port_resource(option
,port
);
511 * Add fixed port resource to resources list.
514 static void __init
isapnp_parse_fixed_port_resource(struct pnp_option
*option
,
517 unsigned char tmp
[3];
518 struct pnp_port
*port
;
520 isapnp_peek(tmp
, size
);
521 port
= kcalloc(1, sizeof(struct pnp_port
), GFP_KERNEL
);
524 port
->min
= port
->max
= (tmp
[1] << 8) | tmp
[0];
527 port
->flags
= PNP_PORT_FLAG_FIXED
;
528 pnp_register_port_resource(option
,port
);
533 * Add memory resource to resources list.
536 static void __init
isapnp_parse_mem_resource(struct pnp_option
*option
,
539 unsigned char tmp
[9];
542 isapnp_peek(tmp
, size
);
543 mem
= kcalloc(1, sizeof(struct pnp_mem
), GFP_KERNEL
);
546 mem
->min
= ((tmp
[2] << 8) | tmp
[1]) << 8;
547 mem
->max
= ((tmp
[4] << 8) | tmp
[3]) << 8;
548 mem
->align
= (tmp
[6] << 8) | tmp
[5];
549 mem
->size
= ((tmp
[8] << 8) | tmp
[7]) << 8;
551 pnp_register_mem_resource(option
,mem
);
556 * Add 32-bit memory resource to resources list.
559 static void __init
isapnp_parse_mem32_resource(struct pnp_option
*option
,
562 unsigned char tmp
[17];
565 isapnp_peek(tmp
, size
);
566 mem
= kcalloc(1, sizeof(struct pnp_mem
), GFP_KERNEL
);
569 mem
->min
= (tmp
[4] << 24) | (tmp
[3] << 16) | (tmp
[2] << 8) | tmp
[1];
570 mem
->max
= (tmp
[8] << 24) | (tmp
[7] << 16) | (tmp
[6] << 8) | tmp
[5];
571 mem
->align
= (tmp
[12] << 24) | (tmp
[11] << 16) | (tmp
[10] << 8) | tmp
[9];
572 mem
->size
= (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
= kcalloc(1, sizeof(struct pnp_mem
), GFP_KERNEL
);
591 mem
->min
= mem
->max
= (tmp
[4] << 24) | (tmp
[3] << 16) | (tmp
[2] << 8) | tmp
[1];
592 mem
->size
= (tmp
[8] << 24) | (tmp
[7] << 16) | (tmp
[6] << 8) | tmp
[5];
595 pnp_register_mem_resource(option
,mem
);
599 * Parse card name for ISA PnP device.
603 isapnp_parse_name(char *name
, unsigned int name_max
, unsigned short *size
)
605 if (name
[0] == '\0') {
606 unsigned short size1
= *size
>= name_max
? (name_max
- 1) : *size
;
607 isapnp_peek(name
, size1
);
611 /* clean whitespace from end of string */
612 while (size1
> 0 && name
[--size1
] == ' ')
618 * Parse resource map for logical device.
621 static int __init
isapnp_create_device(struct pnp_card
*card
,
624 int number
= 0, skip
= 0, priority
= 0, compat
= 0;
625 unsigned char type
, tmp
[17];
626 struct pnp_option
*option
;
628 if ((dev
= isapnp_parse_device(card
, size
, number
++)) == NULL
)
630 option
= pnp_register_independent_option(dev
);
635 pnp_add_card_device(card
,dev
);
638 if (isapnp_read_tag(&type
, &size
)<0)
640 if (skip
&& type
!= _STAG_LOGDEVID
&& type
!= _STAG_END
)
644 if (size
>= 5 && size
<= 6) {
645 if ((dev
= isapnp_parse_device(card
, size
, number
++)) == NULL
)
649 option
= pnp_register_independent_option(dev
);
654 pnp_add_card_device(card
,dev
);
661 case _STAG_COMPATDEVID
:
662 if (size
== 4 && compat
< DEVICE_COUNT_COMPATIBLE
) {
664 isapnp_parse_id(dev
,(tmp
[1] << 8) | tmp
[0], (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
);
745 printk(KERN_ERR
"isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n", type
, dev
->number
, card
->number
);
749 isapnp_skip_bytes(size
);
755 * Parse resource map for ISA PnP card.
758 static void __init
isapnp_parse_resource_map(struct pnp_card
*card
)
760 unsigned char type
, tmp
[17];
764 if (isapnp_read_tag(&type
, &size
)<0)
771 card
->pnpver
= tmp
[0];
772 card
->productver
= tmp
[1];
776 if (size
>= 5 && size
<= 6) {
777 if (isapnp_create_device(card
, size
)==1)
785 isapnp_parse_name(card
->name
, sizeof(card
->name
), &size
);
787 case _LTAG_UNICODESTR
:
788 /* silently ignore */
789 /* who use unicode for hardware identification? */
795 isapnp_skip_bytes(size
);
798 printk(KERN_ERR
"isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n", type
, card
->number
);
802 isapnp_skip_bytes(size
);
807 * Compute ISA PnP checksum for first eight bytes.
810 static unsigned char __init
isapnp_checksum(unsigned char *data
)
813 unsigned char checksum
= 0x6a, bit
, b
;
815 for (i
= 0; i
< 8; i
++) {
817 for (j
= 0; j
< 8; j
++) {
821 checksum
= ((((checksum
^ (checksum
>> 1)) & 0x01) ^ bit
) << 7) | (checksum
>> 1);
828 * Parse EISA id for ISA PnP card.
831 static void isapnp_parse_card_id(struct pnp_card
* card
, unsigned short vendor
, unsigned short device
)
833 struct pnp_id
* id
= kcalloc(1, sizeof(struct pnp_id
), GFP_KERNEL
);
836 sprintf(id
->id
, "%c%c%c%x%x%x%x",
837 'A' + ((vendor
>> 2) & 0x3f) - 1,
838 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
839 'A' + ((vendor
>> 8) & 0x1f) - 1,
840 (device
>> 4) & 0x0f,
842 (device
>> 12) & 0x0f,
843 (device
>> 8) & 0x0f);
844 pnp_add_card_id(id
,card
);
848 * Build device list for all present ISA PnP devices.
851 static int __init
isapnp_build_device_list(void)
854 unsigned char header
[9], checksum
;
855 struct pnp_card
*card
;
859 for (csn
= 1; csn
<= isapnp_csn_count
; csn
++) {
861 isapnp_peek(header
, 9);
862 checksum
= isapnp_checksum(header
);
864 printk(KERN_DEBUG
"vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
865 header
[0], header
[1], header
[2], header
[3],
866 header
[4], header
[5], header
[6], header
[7], header
[8]);
867 printk(KERN_DEBUG
"checksum = 0x%x\n", checksum
);
869 if ((card
= kcalloc(1, sizeof(struct pnp_card
), GFP_KERNEL
)) == NULL
)
873 INIT_LIST_HEAD(&card
->devices
);
874 isapnp_parse_card_id(card
, (header
[1] << 8) | header
[0], (header
[3] << 8) | header
[2]);
875 card
->serial
= (header
[7] << 24) | (header
[6] << 16) | (header
[5] << 8) | header
[4];
876 isapnp_checksum_value
= 0x00;
877 isapnp_parse_resource_map(card
);
878 if (isapnp_checksum_value
!= 0x00)
879 printk(KERN_ERR
"isapnp: checksum for device %i is not valid (0x%x)\n", csn
, isapnp_checksum_value
);
880 card
->checksum
= isapnp_checksum_value
;
881 card
->protocol
= &isapnp_protocol
;
890 * Basic configuration routines.
893 int isapnp_present(void)
895 struct pnp_card
*card
;
896 pnp_for_each_card(card
) {
897 if (card
->protocol
== &isapnp_protocol
)
903 int isapnp_cfg_begin(int csn
, int logdev
)
905 if (csn
< 1 || csn
> isapnp_csn_count
|| logdev
> 10)
907 mutex_lock(&isapnp_cfg_mutex
);
912 /* to avoid malfunction when the isapnptools package is used */
913 /* we must set RDP to our value again */
914 /* it is possible to set RDP only in the isolation phase */
915 /* Jens Thoms Toerring <Jens.Toerring@physik.fu-berlin.de> */
916 isapnp_write_byte(0x02, 0x04); /* clear CSN of card */
917 mdelay(2); /* is this necessary? */
918 isapnp_wake(csn
); /* bring card into sleep state */
919 isapnp_wake(0); /* bring card into isolation state */
920 isapnp_set_rdp(); /* reset the RDP port */
921 udelay(1000); /* delay 1000us */
922 isapnp_write_byte(0x06, csn
); /* reset CSN to previous value */
923 udelay(250); /* is this necessary? */
926 isapnp_device(logdev
);
930 int isapnp_cfg_end(void)
933 mutex_unlock(&isapnp_cfg_mutex
);
943 EXPORT_SYMBOL(isapnp_protocol
);
944 EXPORT_SYMBOL(isapnp_present
);
945 EXPORT_SYMBOL(isapnp_cfg_begin
);
946 EXPORT_SYMBOL(isapnp_cfg_end
);
948 EXPORT_SYMBOL(isapnp_read_byte
);
950 EXPORT_SYMBOL(isapnp_write_byte
);
952 static int isapnp_read_resources(struct pnp_dev
*dev
, struct pnp_resource_table
*res
)
956 dev
->active
= isapnp_read_byte(ISAPNP_CFG_ACTIVATE
);
958 for (tmp
= 0; tmp
< PNP_MAX_PORT
; tmp
++) {
959 ret
= isapnp_read_word(ISAPNP_CFG_PORT
+ (tmp
<< 1));
962 res
->port_resource
[tmp
].start
= ret
;
963 res
->port_resource
[tmp
].flags
= IORESOURCE_IO
;
965 for (tmp
= 0; tmp
< PNP_MAX_MEM
; tmp
++) {
966 ret
= 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
< PNP_MAX_IRQ
; tmp
++) {
973 ret
= (isapnp_read_word(ISAPNP_CFG_IRQ
+ (tmp
<< 1)) >> 8);
976 res
->irq_resource
[tmp
].start
= res
->irq_resource
[tmp
].end
= ret
;
977 res
->irq_resource
[tmp
].flags
= IORESOURCE_IRQ
;
979 for (tmp
= 0; tmp
< PNP_MAX_DMA
; tmp
++) {
980 ret
= isapnp_read_byte(ISAPNP_CFG_DMA
+ tmp
);
983 res
->dma_resource
[tmp
].start
= res
->dma_resource
[tmp
].end
= ret
;
984 res
->dma_resource
[tmp
].flags
= IORESOURCE_DMA
;
990 static int isapnp_get_resources(struct pnp_dev
*dev
, struct pnp_resource_table
* res
)
993 pnp_init_resource_table(res
);
994 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
995 ret
= isapnp_read_resources(dev
, res
);
1000 static int isapnp_set_resources(struct pnp_dev
*dev
, struct pnp_resource_table
* res
)
1004 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1006 for (tmp
= 0; tmp
< PNP_MAX_PORT
&& (res
->port_resource
[tmp
].flags
& (IORESOURCE_IO
| IORESOURCE_UNSET
)) == IORESOURCE_IO
; tmp
++)
1007 isapnp_write_word(ISAPNP_CFG_PORT
+(tmp
<<1), res
->port_resource
[tmp
].start
);
1008 for (tmp
= 0; tmp
< PNP_MAX_IRQ
&& (res
->irq_resource
[tmp
].flags
& (IORESOURCE_IRQ
| IORESOURCE_UNSET
)) == IORESOURCE_IRQ
; tmp
++) {
1009 int irq
= res
->irq_resource
[tmp
].start
;
1012 isapnp_write_byte(ISAPNP_CFG_IRQ
+(tmp
<<1), irq
);
1014 for (tmp
= 0; tmp
< PNP_MAX_DMA
&& (res
->dma_resource
[tmp
].flags
& (IORESOURCE_DMA
| IORESOURCE_UNSET
)) == IORESOURCE_DMA
; tmp
++)
1015 isapnp_write_byte(ISAPNP_CFG_DMA
+tmp
, res
->dma_resource
[tmp
].start
);
1016 for (tmp
= 0; tmp
< PNP_MAX_MEM
&& (res
->mem_resource
[tmp
].flags
& (IORESOURCE_MEM
| IORESOURCE_UNSET
)) == IORESOURCE_MEM
; tmp
++)
1017 isapnp_write_word(ISAPNP_CFG_MEM
+(tmp
<<3), (res
->mem_resource
[tmp
].start
>> 8) & 0xffff);
1018 /* FIXME: We aren't handling 32bit mems properly here */
1019 isapnp_activate(dev
->number
);
1024 static int isapnp_disable_resources(struct pnp_dev
*dev
)
1026 if (!dev
|| !dev
->active
)
1028 isapnp_cfg_begin(dev
->card
->number
, dev
->number
);
1029 isapnp_deactivate(dev
->number
);
1035 struct pnp_protocol isapnp_protocol
= {
1036 .name
= "ISA Plug and Play",
1037 .get
= isapnp_get_resources
,
1038 .set
= isapnp_set_resources
,
1039 .disable
= isapnp_disable_resources
,
1042 static int __init
isapnp_init(void)
1045 struct pnp_card
*card
;
1046 struct pnp_dev
*dev
;
1048 if (isapnp_disable
) {
1049 isapnp_detected
= 0;
1050 printk(KERN_INFO
"isapnp: ISA Plug & Play support disabled\n");
1053 #ifdef ISAPNP_REGION_OK
1054 if (!request_region(_PIDXR
, 1, "isapnp index")) {
1055 printk(KERN_ERR
"isapnp: Index Register 0x%x already used\n", _PIDXR
);
1059 if (!request_region(_PNPWRP
, 1, "isapnp write")) {
1060 printk(KERN_ERR
"isapnp: Write Data Register 0x%x already used\n", _PNPWRP
);
1061 #ifdef ISAPNP_REGION_OK
1062 release_region(_PIDXR
, 1);
1067 if(pnp_register_protocol(&isapnp_protocol
)<0)
1071 * Print a message. The existing ISAPnP code is hanging machines
1072 * so let the user know where.
1075 printk(KERN_INFO
"isapnp: Scanning for PnP cards...\n");
1076 if (isapnp_rdp
>= 0x203 && isapnp_rdp
<= 0x3ff) {
1078 if (!request_region(isapnp_rdp
, 1, "isapnp read")) {
1079 printk(KERN_ERR
"isapnp: Read Data Register 0x%x already used\n", isapnp_rdp
);
1080 #ifdef ISAPNP_REGION_OK
1081 release_region(_PIDXR
, 1);
1083 release_region(_PNPWRP
, 1);
1088 isapnp_detected
= 1;
1089 if (isapnp_rdp
< 0x203 || isapnp_rdp
> 0x3ff) {
1090 cards
= isapnp_isolate();
1092 (isapnp_rdp
< 0x203 || isapnp_rdp
> 0x3ff)) {
1093 #ifdef ISAPNP_REGION_OK
1094 release_region(_PIDXR
, 1);
1096 release_region(_PNPWRP
, 1);
1097 isapnp_detected
= 0;
1098 printk(KERN_INFO
"isapnp: No Plug & Play device found\n");
1101 request_region(isapnp_rdp
, 1, "isapnp read");
1103 isapnp_build_device_list();
1106 protocol_for_each_card(&isapnp_protocol
,card
) {
1108 if (isapnp_verbose
) {
1109 printk(KERN_INFO
"isapnp: Card '%s'\n", card
->name
[0]?card
->name
:"Unknown");
1110 if (isapnp_verbose
< 2)
1112 card_for_each_dev(card
,dev
) {
1113 printk(KERN_INFO
"isapnp: Device '%s'\n", dev
->name
[0]?dev
->name
:"Unknown");
1118 printk(KERN_INFO
"isapnp: %i Plug & Play card%s detected total\n", cards
, cards
>1?"s":"");
1120 printk(KERN_INFO
"isapnp: No Plug & Play card found\n");
1127 device_initcall(isapnp_init
);
1129 /* format is: noisapnp */
1131 static int __init
isapnp_setup_disable(char *str
)
1137 __setup("noisapnp", isapnp_setup_disable
);
1139 /* format is: isapnp=rdp,reset,skip_pci_scan,verbose */
1141 static int __init
isapnp_setup_isapnp(char *str
)
1143 (void)((get_option(&str
,&isapnp_rdp
) == 2) &&
1144 (get_option(&str
,&isapnp_reset
) == 2) &&
1145 (get_option(&str
,&isapnp_verbose
) == 2));
1149 __setup("isapnp=", isapnp_setup_isapnp
);