1 /* $Id: b1pci.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
3 * Module for AVM B1 PCI-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/config.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/delay.h>
18 #include <linux/interrupt.h>
19 #include <linux/ioport.h>
20 #include <linux/pci.h>
21 #include <linux/capi.h>
23 #include <linux/init.h>
24 #include <linux/isdn/capicmd.h>
25 #include <linux/isdn/capiutil.h>
26 #include <linux/isdn/capilli.h>
29 /* ------------------------------------------------------------- */
31 static char *revision
= "$Revision: 1.1.2.2 $";
33 /* ------------------------------------------------------------- */
35 static struct pci_device_id b1pci_pci_tbl
[] = {
36 { PCI_VENDOR_ID_AVM
, PCI_DEVICE_ID_AVM_B1
, PCI_ANY_ID
, PCI_ANY_ID
},
37 { } /* Terminating entry */
40 MODULE_DEVICE_TABLE(pci
, b1pci_pci_tbl
);
41 MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM B1 PCI card");
42 MODULE_AUTHOR("Carsten Paeth");
43 MODULE_LICENSE("GPL");
45 /* ------------------------------------------------------------- */
47 static char *b1pci_procinfo(struct capi_ctr
*ctrl
)
49 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
53 sprintf(cinfo
->infobuf
, "%s %s 0x%x %d r%d",
54 cinfo
->cardname
[0] ? cinfo
->cardname
: "-",
55 cinfo
->version
[VER_DRIVER
] ? cinfo
->version
[VER_DRIVER
] : "-",
56 cinfo
->card
? cinfo
->card
->port
: 0x0,
57 cinfo
->card
? cinfo
->card
->irq
: 0,
58 cinfo
->card
? cinfo
->card
->revision
: 0
60 return cinfo
->infobuf
;
63 /* ------------------------------------------------------------- */
65 static int b1pci_probe(struct capicardparams
*p
, struct pci_dev
*pdev
)
71 card
= b1_alloc_card(1);
73 printk(KERN_WARNING
"b1pci: no memory.\n");
78 cinfo
= card
->ctrlinfo
;
79 sprintf(card
->name
, "b1pci-%x", p
->port
);
82 card
->cardtype
= avm_b1pci
;
84 if (!request_region(card
->port
, AVMB1_PORTLEN
, card
->name
)) {
85 printk(KERN_WARNING
"b1pci: ports 0x%03x-0x%03x in use.\n",
86 card
->port
, card
->port
+ AVMB1_PORTLEN
);
91 retval
= b1_detect(card
->port
, card
->cardtype
);
93 printk(KERN_NOTICE
"b1pci: NO card at 0x%x (%d)\n",
96 goto err_release_region
;
101 retval
= request_irq(card
->irq
, b1_interrupt
, SA_SHIRQ
, card
->name
, card
);
103 printk(KERN_ERR
"b1pci: unable to get IRQ %d.\n", card
->irq
);
105 goto err_release_region
;
108 cinfo
->capi_ctrl
.driver_name
= "b1pci";
109 cinfo
->capi_ctrl
.driverdata
= cinfo
;
110 cinfo
->capi_ctrl
.register_appl
= b1_register_appl
;
111 cinfo
->capi_ctrl
.release_appl
= b1_release_appl
;
112 cinfo
->capi_ctrl
.send_message
= b1_send_message
;
113 cinfo
->capi_ctrl
.load_firmware
= b1_load_firmware
;
114 cinfo
->capi_ctrl
.reset_ctr
= b1_reset_ctr
;
115 cinfo
->capi_ctrl
.procinfo
= b1pci_procinfo
;
116 cinfo
->capi_ctrl
.ctr_read_proc
= b1ctl_read_proc
;
117 strcpy(cinfo
->capi_ctrl
.name
, card
->name
);
118 cinfo
->capi_ctrl
.owner
= THIS_MODULE
;
120 retval
= attach_capi_ctr(&cinfo
->capi_ctrl
);
122 printk(KERN_ERR
"b1pci: attach controller failed.\n");
126 if (card
->revision
>= 4) {
127 printk(KERN_INFO
"b1pci: AVM B1 PCI V4 at i/o %#x, irq %d, revision %d (no dma)\n",
128 card
->port
, card
->irq
, card
->revision
);
130 printk(KERN_INFO
"b1pci: AVM B1 PCI at i/o %#x, irq %d, revision %d\n",
131 card
->port
, card
->irq
, card
->revision
);
134 pci_set_drvdata(pdev
, card
);
138 free_irq(card
->irq
, card
);
140 release_region(card
->port
, AVMB1_PORTLEN
);
147 static void b1pci_remove(struct pci_dev
*pdev
)
149 avmcard
*card
= pci_get_drvdata(pdev
);
150 avmctrl_info
*cinfo
= card
->ctrlinfo
;
151 unsigned int port
= card
->port
;
156 detach_capi_ctr(&cinfo
->capi_ctrl
);
157 free_irq(card
->irq
, card
);
158 release_region(card
->port
, AVMB1_PORTLEN
);
162 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
163 /* ------------------------------------------------------------- */
165 static char *b1pciv4_procinfo(struct capi_ctr
*ctrl
)
167 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
171 sprintf(cinfo
->infobuf
, "%s %s 0x%x %d 0x%lx r%d",
172 cinfo
->cardname
[0] ? cinfo
->cardname
: "-",
173 cinfo
->version
[VER_DRIVER
] ? cinfo
->version
[VER_DRIVER
] : "-",
174 cinfo
->card
? cinfo
->card
->port
: 0x0,
175 cinfo
->card
? cinfo
->card
->irq
: 0,
176 cinfo
->card
? cinfo
->card
->membase
: 0,
177 cinfo
->card
? cinfo
->card
->revision
: 0
179 return cinfo
->infobuf
;
182 /* ------------------------------------------------------------- */
184 static int b1pciv4_probe(struct capicardparams
*p
, struct pci_dev
*pdev
)
190 card
= b1_alloc_card(1);
192 printk(KERN_WARNING
"b1pci: no memory.\n");
197 card
->dma
= avmcard_dma_alloc("b1pci", pdev
, 2048+128, 2048+128);
199 printk(KERN_WARNING
"b1pci: dma alloc.\n");
204 cinfo
= card
->ctrlinfo
;
205 sprintf(card
->name
, "b1pciv4-%x", p
->port
);
206 card
->port
= p
->port
;
208 card
->membase
= p
->membase
;
209 card
->cardtype
= avm_b1pci
;
211 if (!request_region(card
->port
, AVMB1_PORTLEN
, card
->name
)) {
212 printk(KERN_WARNING
"b1pci: ports 0x%03x-0x%03x in use.\n",
213 card
->port
, card
->port
+ AVMB1_PORTLEN
);
218 card
->mbase
= ioremap(card
->membase
, 64);
220 printk(KERN_NOTICE
"b1pci: can't remap memory at 0x%lx\n",
223 goto err_release_region
;
228 retval
= b1pciv4_detect(card
);
230 printk(KERN_NOTICE
"b1pci: NO card at 0x%x (%d)\n",
236 b1_getrevision(card
);
238 retval
= request_irq(card
->irq
, b1dma_interrupt
, SA_SHIRQ
, card
->name
, card
);
240 printk(KERN_ERR
"b1pci: unable to get IRQ %d.\n",
246 cinfo
->capi_ctrl
.owner
= THIS_MODULE
;
247 cinfo
->capi_ctrl
.driver_name
= "b1pciv4";
248 cinfo
->capi_ctrl
.driverdata
= cinfo
;
249 cinfo
->capi_ctrl
.register_appl
= b1dma_register_appl
;
250 cinfo
->capi_ctrl
.release_appl
= b1dma_release_appl
;
251 cinfo
->capi_ctrl
.send_message
= b1dma_send_message
;
252 cinfo
->capi_ctrl
.load_firmware
= b1dma_load_firmware
;
253 cinfo
->capi_ctrl
.reset_ctr
= b1dma_reset_ctr
;
254 cinfo
->capi_ctrl
.procinfo
= b1pciv4_procinfo
;
255 cinfo
->capi_ctrl
.ctr_read_proc
= b1dmactl_read_proc
;
256 strcpy(cinfo
->capi_ctrl
.name
, card
->name
);
258 retval
= attach_capi_ctr(&cinfo
->capi_ctrl
);
260 printk(KERN_ERR
"b1pci: attach controller failed.\n");
263 card
->cardnr
= cinfo
->capi_ctrl
.cnr
;
265 printk(KERN_INFO
"b1pci: AVM B1 PCI V4 at i/o %#x, irq %d, mem %#lx, revision %d (dma)\n",
266 card
->port
, card
->irq
, card
->membase
, card
->revision
);
268 pci_set_drvdata(pdev
, card
);
272 free_irq(card
->irq
, card
);
274 iounmap(card
->mbase
);
276 release_region(card
->port
, AVMB1_PORTLEN
);
278 avmcard_dma_free(card
->dma
);
286 static void b1pciv4_remove(struct pci_dev
*pdev
)
288 avmcard
*card
= pci_get_drvdata(pdev
);
289 avmctrl_info
*cinfo
= card
->ctrlinfo
;
293 detach_capi_ctr(&cinfo
->capi_ctrl
);
294 free_irq(card
->irq
, card
);
295 iounmap(card
->mbase
);
296 release_region(card
->port
, AVMB1_PORTLEN
);
297 avmcard_dma_free(card
->dma
);
301 #endif /* CONFIG_ISDN_DRV_AVMB1_B1PCIV4 */
303 static int __devinit
b1pci_pci_probe(struct pci_dev
*pdev
,
304 const struct pci_device_id
*ent
)
306 struct capicardparams param
;
309 if (pci_enable_device(pdev
) < 0) {
310 printk(KERN_ERR
"b1pci: failed to enable AVM-B1\n");
313 param
.irq
= pdev
->irq
;
315 if (pci_resource_start(pdev
, 2)) { /* B1 PCI V4 */
316 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
317 pci_set_master(pdev
);
319 param
.membase
= pci_resource_start(pdev
, 0);
320 param
.port
= pci_resource_start(pdev
, 2);
322 printk(KERN_INFO
"b1pci: PCI BIOS reports AVM-B1 V4 at i/o %#x, irq %d, mem %#x\n",
323 param
.port
, param
.irq
, param
.membase
);
324 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
325 retval
= b1pciv4_probe(¶m
, pdev
);
327 retval
= b1pci_probe(¶m
, pdev
);
330 printk(KERN_ERR
"b1pci: no AVM-B1 V4 at i/o %#x, irq %d, mem %#x detected\n",
331 param
.port
, param
.irq
, param
.membase
);
335 param
.port
= pci_resource_start(pdev
, 1);
337 printk(KERN_INFO
"b1pci: PCI BIOS reports AVM-B1 at i/o %#x, irq %d\n",
338 param
.port
, param
.irq
);
339 retval
= b1pci_probe(¶m
, pdev
);
341 printk(KERN_ERR
"b1pci: no AVM-B1 at i/o %#x, irq %d detected\n",
342 param
.port
, param
.irq
);
348 static void __devexit
b1pci_pci_remove(struct pci_dev
*pdev
)
350 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
351 avmcard
*card
= pci_get_drvdata(pdev
);
354 b1pciv4_remove(pdev
);
362 static struct pci_driver b1pci_pci_driver
= {
364 .id_table
= b1pci_pci_tbl
,
365 .probe
= b1pci_pci_probe
,
366 .remove
= __devexit_p(b1pci_pci_remove
),
369 static struct capi_driver capi_driver_b1pci
= {
373 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
374 static struct capi_driver capi_driver_b1pciv4
= {
380 static int __init
b1pci_init(void)
386 if ((p
= strchr(revision
, ':')) != 0 && p
[1]) {
387 strlcpy(rev
, p
+ 2, 32);
388 if ((p
= strchr(rev
, '$')) != 0 && p
> rev
)
394 err
= pci_register_driver(&b1pci_pci_driver
);
396 strlcpy(capi_driver_b1pci
.revision
, rev
, 32);
397 register_capi_driver(&capi_driver_b1pci
);
398 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
399 strlcpy(capi_driver_b1pciv4
.revision
, rev
, 32);
400 register_capi_driver(&capi_driver_b1pciv4
);
402 printk(KERN_INFO
"b1pci: revision %s\n", rev
);
407 static void __exit
b1pci_exit(void)
409 unregister_capi_driver(&capi_driver_b1pci
);
410 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
411 unregister_capi_driver(&capi_driver_b1pciv4
);
413 pci_unregister_driver(&b1pci_pci_driver
);
416 module_init(b1pci_init
);
417 module_exit(b1pci_exit
);