1 /* $Id: b1pcmcia.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
3 * Module for AVM B1/M1/M2 PCMCIA-card.
5 * Copyright 1999 by Carsten Paeth <calle@calle.de>
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/skbuff.h>
15 #include <linux/delay.h>
17 #include <linux/interrupt.h>
18 #include <linux/ioport.h>
19 #include <linux/init.h>
21 #include <linux/capi.h>
22 #include <linux/b1pcmcia.h>
23 #include <linux/isdn/capicmd.h>
24 #include <linux/isdn/capiutil.h>
25 #include <linux/isdn/capilli.h>
28 /* ------------------------------------------------------------- */
30 static char *revision
= "$Revision: 1.1.2.2 $";
32 /* ------------------------------------------------------------- */
34 MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM PCMCIA cards");
35 MODULE_AUTHOR("Carsten Paeth");
36 MODULE_LICENSE("GPL");
38 /* ------------------------------------------------------------- */
40 static void b1pcmcia_remove_ctr(struct capi_ctr
*ctrl
)
42 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
43 avmcard
*card
= cinfo
->card
;
44 unsigned int port
= card
->port
;
49 detach_capi_ctr(ctrl
);
50 free_irq(card
->irq
, card
);
54 /* ------------------------------------------------------------- */
56 static LIST_HEAD(cards
);
58 static char *b1pcmcia_procinfo(struct capi_ctr
*ctrl
);
60 static int b1pcmcia_add_card(unsigned int port
, unsigned irq
,
61 enum avmcardtype cardtype
)
68 card
= b1_alloc_card(1);
70 printk(KERN_WARNING
"b1pcmcia: no memory.\n");
74 cinfo
= card
->ctrlinfo
;
77 case avm_m1
: sprintf(card
->name
, "m1-%x", port
); break;
78 case avm_m2
: sprintf(card
->name
, "m2-%x", port
); break;
79 default: sprintf(card
->name
, "b1pcmcia-%x", port
); break;
83 card
->cardtype
= cardtype
;
85 retval
= request_irq(card
->irq
, b1_interrupt
, IRQF_SHARED
, card
->name
, card
);
87 printk(KERN_ERR
"b1pcmcia: unable to get IRQ %d.\n",
93 if ((retval
= b1_detect(card
->port
, card
->cardtype
)) != 0) {
94 printk(KERN_NOTICE
"b1pcmcia: NO card at 0x%x (%d)\n",
100 b1_getrevision(card
);
102 cinfo
->capi_ctrl
.owner
= THIS_MODULE
;
103 cinfo
->capi_ctrl
.driver_name
= "b1pcmcia";
104 cinfo
->capi_ctrl
.driverdata
= cinfo
;
105 cinfo
->capi_ctrl
.register_appl
= b1_register_appl
;
106 cinfo
->capi_ctrl
.release_appl
= b1_release_appl
;
107 cinfo
->capi_ctrl
.send_message
= b1_send_message
;
108 cinfo
->capi_ctrl
.load_firmware
= b1_load_firmware
;
109 cinfo
->capi_ctrl
.reset_ctr
= b1_reset_ctr
;
110 cinfo
->capi_ctrl
.procinfo
= b1pcmcia_procinfo
;
111 cinfo
->capi_ctrl
.proc_show
= b1_proc_show
;
112 strcpy(cinfo
->capi_ctrl
.name
, card
->name
);
114 retval
= attach_capi_ctr(&cinfo
->capi_ctrl
);
116 printk(KERN_ERR
"b1pcmcia: attach controller failed.\n");
120 case avm_m1
: cardname
= "M1"; break;
121 case avm_m2
: cardname
= "M2"; break;
122 default: cardname
= "B1 PCMCIA"; break;
125 printk(KERN_INFO
"b1pcmcia: AVM %s at i/o %#x, irq %d, revision %d\n",
126 cardname
, card
->port
, card
->irq
, card
->revision
);
128 list_add(&card
->list
, &cards
);
129 return cinfo
->capi_ctrl
.cnr
;
132 free_irq(card
->irq
, card
);
139 /* ------------------------------------------------------------- */
141 static char *b1pcmcia_procinfo(struct capi_ctr
*ctrl
)
143 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
147 sprintf(cinfo
->infobuf
, "%s %s 0x%x %d r%d",
148 cinfo
->cardname
[0] ? cinfo
->cardname
: "-",
149 cinfo
->version
[VER_DRIVER
] ? cinfo
->version
[VER_DRIVER
] : "-",
150 cinfo
->card
? cinfo
->card
->port
: 0x0,
151 cinfo
->card
? cinfo
->card
->irq
: 0,
152 cinfo
->card
? cinfo
->card
->revision
: 0
154 return cinfo
->infobuf
;
157 /* ------------------------------------------------------------- */
159 int b1pcmcia_addcard_b1(unsigned int port
, unsigned irq
)
161 return b1pcmcia_add_card(port
, irq
, avm_b1pcmcia
);
164 int b1pcmcia_addcard_m1(unsigned int port
, unsigned irq
)
166 return b1pcmcia_add_card(port
, irq
, avm_m1
);
169 int b1pcmcia_addcard_m2(unsigned int port
, unsigned irq
)
171 return b1pcmcia_add_card(port
, irq
, avm_m2
);
174 int b1pcmcia_delcard(unsigned int port
, unsigned irq
)
179 list_for_each(l
, &cards
) {
180 card
= list_entry(l
, avmcard
, list
);
181 if (card
->port
== port
&& card
->irq
== irq
) {
182 b1pcmcia_remove_ctr(&card
->ctrlinfo
[0].capi_ctrl
);
189 EXPORT_SYMBOL(b1pcmcia_addcard_b1
);
190 EXPORT_SYMBOL(b1pcmcia_addcard_m1
);
191 EXPORT_SYMBOL(b1pcmcia_addcard_m2
);
192 EXPORT_SYMBOL(b1pcmcia_delcard
);
194 static struct capi_driver capi_driver_b1pcmcia
= {
199 static int __init
b1pcmcia_init(void)
204 if ((p
= strchr(revision
, ':')) != NULL
&& p
[1]) {
205 strlcpy(rev
, p
+ 2, 32);
206 if ((p
= strchr(rev
, '$')) != NULL
&& p
> rev
)
211 strlcpy(capi_driver_b1pcmcia
.revision
, rev
, 32);
212 register_capi_driver(&capi_driver_b1pcmcia
);
213 printk(KERN_INFO
"b1pci: revision %s\n", rev
);
218 static void __exit
b1pcmcia_exit(void)
220 unregister_capi_driver(&capi_driver_b1pcmcia
);
223 module_init(b1pcmcia_init
);
224 module_exit(b1pcmcia_exit
);