2 * $Id: b1pci.c,v 1.16 1999/08/11 21:01:07 keil Exp $
4 * Module for AVM B1 PCI-card.
6 * (c) Copyright 1999 by Carsten Paeth (calle@calle.in-berlin.de)
9 * Revision 1.16 1999/08/11 21:01:07 keil
12 * Revision 1.15 1999/08/10 16:02:27 calle
13 * struct pci_dev changed in 2.3.13. Made the necessary changes.
15 * Revision 1.14 1999/07/09 15:05:41 keil
16 * compat.h is now isdn_compat.h
18 * Revision 1.13 1999/07/05 15:09:50 calle
19 * - renamed "appl_release" to "appl_released".
20 * - version und profile data now cleared on controller reset
21 * - extended /proc interface, to allow driver and controller specific
22 * informations to include by driver hackers.
24 * Revision 1.12 1999/07/01 15:26:29 calle
25 * complete new version (I love it):
26 * + new hardware independed "capi_driver" interface that will make it easy to:
27 * - support other controllers with CAPI-2.0 (i.e. USB Controller)
28 * - write a CAPI-2.0 for the passive cards
29 * - support serial link CAPI-2.0 boxes.
30 * + wrote "capi_driver" for all supported cards.
31 * + "capi_driver" (supported cards) now have to be configured with
32 * make menuconfig, in the past all supported cards where included
34 * + new and better informations in /proc/capi/
35 * + new ioctl to switch trace of capi messages per controller
36 * using "avmcapictrl trace [contr] on|off|...."
37 * + complete testcircle with all supported cards and also the
38 * PCMCIA cards (now patch for pcmcia-cs-3.0.13 needed) done.
43 #include <linux/config.h>
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/skbuff.h>
47 #include <linux/delay.h>
49 #include <linux/interrupt.h>
50 #include <linux/ioport.h>
51 #include <linux/pci.h>
52 #include <linux/capi.h>
54 #include <linux/isdn_compat.h>
60 static char *revision
= "$Revision: 1.16 $";
62 /* ------------------------------------------------------------- */
64 #ifndef PCI_VENDOR_ID_AVM
65 #define PCI_VENDOR_ID_AVM 0x1244
68 #ifndef PCI_DEVICE_ID_AVM_B1
69 #define PCI_DEVICE_ID_AVM_B1 0x700
72 /* ------------------------------------------------------------- */
74 MODULE_AUTHOR("Carsten Paeth <calle@calle.in-berlin.de>");
76 /* ------------------------------------------------------------- */
78 static struct capi_driver_interface
*di
;
80 /* ------------------------------------------------------------- */
82 static void b1pci_interrupt(int interrupt
, void *devptr
, struct pt_regs
*regs
)
86 card
= (avmcard
*) devptr
;
89 printk(KERN_WARNING
"b1_interrupt: wrong device\n");
92 if (card
->interrupt
) {
93 printk(KERN_ERR
"b1_interrupt: reentering interrupt hander (%s)\n", card
->name
);
99 b1_handle_interrupt(card
);
103 /* ------------------------------------------------------------- */
105 static void b1pci_remove_ctr(struct capi_ctr
*ctrl
)
107 avmcard
*card
= (avmcard
*)(ctrl
->driverdata
);
108 unsigned int port
= card
->port
;
113 di
->detach_ctr(ctrl
);
114 free_irq(card
->irq
, card
);
115 release_region(card
->port
, AVMB1_PORTLEN
);
116 ctrl
->driverdata
= 0;
122 /* ------------------------------------------------------------- */
124 static char *b1pci_procinfo(struct capi_ctr
*ctrl
)
126 avmcard
*card
= (avmcard
*)(ctrl
->driverdata
);
129 sprintf(card
->infobuf
, "%s %s 0x%x %d",
130 card
->cardname
[0] ? card
->cardname
: "-",
131 card
->version
[VER_DRIVER
] ? card
->version
[VER_DRIVER
] : "-",
132 card
->port
, card
->irq
134 return card
->infobuf
;
137 /* ------------------------------------------------------------- */
139 static int b1pci_add_card(struct capi_driver
*driver
, struct capicardparams
*p
)
144 card
= (avmcard
*) kmalloc(sizeof(avmcard
), GFP_ATOMIC
);
147 printk(KERN_WARNING
"b1pci: no memory.\n");
150 memset(card
, 0, sizeof(avmcard
));
151 sprintf(card
->name
, "b1pci-%x", p
->port
);
152 card
->port
= p
->port
;
154 card
->cardtype
= avm_b1pci
;
156 if (check_region(card
->port
, AVMB1_PORTLEN
)) {
158 "b1pci: ports 0x%03x-0x%03x in use.\n",
159 card
->port
, card
->port
+ AVMB1_PORTLEN
);
163 b1_reset(card
->port
);
164 if ((retval
= b1_detect(card
->port
, card
->cardtype
)) != 0) {
165 printk(KERN_NOTICE
"b1pci: NO card at 0x%x (%d)\n",
170 b1_reset(card
->port
);
172 request_region(p
->port
, AVMB1_PORTLEN
, card
->name
);
174 retval
= request_irq(card
->irq
, b1pci_interrupt
, 0, card
->name
, card
);
176 printk(KERN_ERR
"b1pci: unable to get IRQ %d.\n", card
->irq
);
177 release_region(card
->port
, AVMB1_PORTLEN
);
182 card
->ctrl
= di
->attach_ctr(driver
, card
->name
, card
);
184 printk(KERN_ERR
"b1pci: attach controller failed.\n");
185 free_irq(card
->irq
, card
);
186 release_region(card
->port
, AVMB1_PORTLEN
);
196 /* ------------------------------------------------------------- */
198 static struct capi_driver b1pci_driver
= {
210 0, /* use standard driver_read_proc */
212 0, /* no add_card function */
216 #define b1pci_init init_module
217 void cleanup_module(void);
220 static int ncards
= 0;
224 struct capi_driver
*driver
= &b1pci_driver
;
225 struct pci_dev
*dev
= NULL
;
229 if ((p
= strchr(revision
, ':'))) {
230 strncpy(driver
->revision
, p
+ 1, sizeof(driver
->revision
));
231 p
= strchr(driver
->revision
, '$');
235 printk(KERN_INFO
"%s: revision %s\n", driver
->name
, driver
->revision
);
237 di
= attach_capi_driver(driver
);
240 printk(KERN_ERR
"%s: failed to attach capi_driver\n",
246 if (!pci_present()) {
247 printk(KERN_ERR
"%s: no PCI bus present\n", driver
->name
);
248 detach_capi_driver(driver
);
252 while ((dev
= pci_find_device(PCI_VENDOR_ID_AVM
, PCI_DEVICE_ID_AVM_B1
, dev
))) {
253 struct capicardparams param
;
255 param
.port
= get_pcibase(dev
, 1) & PCI_BASE_ADDRESS_IO_MASK
;
256 param
.irq
= dev
->irq
;
258 "%s: PCI BIOS reports AVM-B1 at i/o %#x, irq %d\n",
259 driver
->name
, param
.port
, param
.irq
);
260 retval
= b1pci_add_card(driver
, ¶m
);
263 "%s: no AVM-B1 at i/o %#x, irq %d detected\n",
264 driver
->name
, param
.port
, param
.irq
);
273 printk(KERN_INFO
"%s: %d B1-PCI card(s) detected\n",
274 driver
->name
, ncards
);
277 printk(KERN_ERR
"%s: NO B1-PCI card detected\n", driver
->name
);
280 printk(KERN_ERR
"b1pci: kernel not compiled with PCI.\n");
286 void cleanup_module(void)
288 detach_capi_driver(&b1pci_driver
);