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/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/pci.h>
20 #include <linux/capi.h>
22 #include <linux/init.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 static struct pci_device_id b1pci_pci_tbl
[] = {
35 { PCI_VENDOR_ID_AVM
, PCI_DEVICE_ID_AVM_B1
, PCI_ANY_ID
, PCI_ANY_ID
},
36 { } /* Terminating entry */
39 MODULE_DEVICE_TABLE(pci
, b1pci_pci_tbl
);
40 MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM B1 PCI card");
41 MODULE_AUTHOR("Carsten Paeth");
42 MODULE_LICENSE("GPL");
44 /* ------------------------------------------------------------- */
46 static char *b1pci_procinfo(struct capi_ctr
*ctrl
)
48 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
52 sprintf(cinfo
->infobuf
, "%s %s 0x%x %d r%d",
53 cinfo
->cardname
[0] ? cinfo
->cardname
: "-",
54 cinfo
->version
[VER_DRIVER
] ? cinfo
->version
[VER_DRIVER
] : "-",
55 cinfo
->card
? cinfo
->card
->port
: 0x0,
56 cinfo
->card
? cinfo
->card
->irq
: 0,
57 cinfo
->card
? cinfo
->card
->revision
: 0
59 return cinfo
->infobuf
;
62 /* ------------------------------------------------------------- */
64 static int b1pci_probe(struct capicardparams
*p
, struct pci_dev
*pdev
)
70 card
= b1_alloc_card(1);
72 printk(KERN_WARNING
"b1pci: no memory.\n");
77 cinfo
= card
->ctrlinfo
;
78 sprintf(card
->name
, "b1pci-%x", p
->port
);
81 card
->cardtype
= avm_b1pci
;
83 if (!request_region(card
->port
, AVMB1_PORTLEN
, card
->name
)) {
84 printk(KERN_WARNING
"b1pci: ports 0x%03x-0x%03x in use.\n",
85 card
->port
, card
->port
+ AVMB1_PORTLEN
);
90 retval
= b1_detect(card
->port
, card
->cardtype
);
92 printk(KERN_NOTICE
"b1pci: NO card at 0x%x (%d)\n",
95 goto err_release_region
;
100 retval
= request_irq(card
->irq
, b1_interrupt
, IRQF_SHARED
, card
->name
, card
);
102 printk(KERN_ERR
"b1pci: unable to get IRQ %d.\n", card
->irq
);
104 goto err_release_region
;
107 cinfo
->capi_ctrl
.driver_name
= "b1pci";
108 cinfo
->capi_ctrl
.driverdata
= cinfo
;
109 cinfo
->capi_ctrl
.register_appl
= b1_register_appl
;
110 cinfo
->capi_ctrl
.release_appl
= b1_release_appl
;
111 cinfo
->capi_ctrl
.send_message
= b1_send_message
;
112 cinfo
->capi_ctrl
.load_firmware
= b1_load_firmware
;
113 cinfo
->capi_ctrl
.reset_ctr
= b1_reset_ctr
;
114 cinfo
->capi_ctrl
.procinfo
= b1pci_procinfo
;
115 cinfo
->capi_ctrl
.ctr_read_proc
= b1ctl_read_proc
;
116 strcpy(cinfo
->capi_ctrl
.name
, card
->name
);
117 cinfo
->capi_ctrl
.owner
= THIS_MODULE
;
119 retval
= attach_capi_ctr(&cinfo
->capi_ctrl
);
121 printk(KERN_ERR
"b1pci: attach controller failed.\n");
125 if (card
->revision
>= 4) {
126 printk(KERN_INFO
"b1pci: AVM B1 PCI V4 at i/o %#x, irq %d, revision %d (no dma)\n",
127 card
->port
, card
->irq
, card
->revision
);
129 printk(KERN_INFO
"b1pci: AVM B1 PCI at i/o %#x, irq %d, revision %d\n",
130 card
->port
, card
->irq
, card
->revision
);
133 pci_set_drvdata(pdev
, card
);
137 free_irq(card
->irq
, card
);
139 release_region(card
->port
, AVMB1_PORTLEN
);
146 static void b1pci_remove(struct pci_dev
*pdev
)
148 avmcard
*card
= pci_get_drvdata(pdev
);
149 avmctrl_info
*cinfo
= card
->ctrlinfo
;
150 unsigned int port
= card
->port
;
155 detach_capi_ctr(&cinfo
->capi_ctrl
);
156 free_irq(card
->irq
, card
);
157 release_region(card
->port
, AVMB1_PORTLEN
);
161 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
162 /* ------------------------------------------------------------- */
164 static char *b1pciv4_procinfo(struct capi_ctr
*ctrl
)
166 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
170 sprintf(cinfo
->infobuf
, "%s %s 0x%x %d 0x%lx r%d",
171 cinfo
->cardname
[0] ? cinfo
->cardname
: "-",
172 cinfo
->version
[VER_DRIVER
] ? cinfo
->version
[VER_DRIVER
] : "-",
173 cinfo
->card
? cinfo
->card
->port
: 0x0,
174 cinfo
->card
? cinfo
->card
->irq
: 0,
175 cinfo
->card
? cinfo
->card
->membase
: 0,
176 cinfo
->card
? cinfo
->card
->revision
: 0
178 return cinfo
->infobuf
;
181 /* ------------------------------------------------------------- */
183 static int b1pciv4_probe(struct capicardparams
*p
, struct pci_dev
*pdev
)
189 card
= b1_alloc_card(1);
191 printk(KERN_WARNING
"b1pci: no memory.\n");
196 card
->dma
= avmcard_dma_alloc("b1pci", pdev
, 2048+128, 2048+128);
198 printk(KERN_WARNING
"b1pci: dma alloc.\n");
203 cinfo
= card
->ctrlinfo
;
204 sprintf(card
->name
, "b1pciv4-%x", p
->port
);
205 card
->port
= p
->port
;
207 card
->membase
= p
->membase
;
208 card
->cardtype
= avm_b1pci
;
210 if (!request_region(card
->port
, AVMB1_PORTLEN
, card
->name
)) {
211 printk(KERN_WARNING
"b1pci: ports 0x%03x-0x%03x in use.\n",
212 card
->port
, card
->port
+ AVMB1_PORTLEN
);
217 card
->mbase
= ioremap(card
->membase
, 64);
219 printk(KERN_NOTICE
"b1pci: can't remap memory at 0x%lx\n",
222 goto err_release_region
;
227 retval
= b1pciv4_detect(card
);
229 printk(KERN_NOTICE
"b1pci: NO card at 0x%x (%d)\n",
235 b1_getrevision(card
);
237 retval
= request_irq(card
->irq
, b1dma_interrupt
, IRQF_SHARED
, card
->name
, card
);
239 printk(KERN_ERR
"b1pci: unable to get IRQ %d.\n",
245 cinfo
->capi_ctrl
.owner
= THIS_MODULE
;
246 cinfo
->capi_ctrl
.driver_name
= "b1pciv4";
247 cinfo
->capi_ctrl
.driverdata
= cinfo
;
248 cinfo
->capi_ctrl
.register_appl
= b1dma_register_appl
;
249 cinfo
->capi_ctrl
.release_appl
= b1dma_release_appl
;
250 cinfo
->capi_ctrl
.send_message
= b1dma_send_message
;
251 cinfo
->capi_ctrl
.load_firmware
= b1dma_load_firmware
;
252 cinfo
->capi_ctrl
.reset_ctr
= b1dma_reset_ctr
;
253 cinfo
->capi_ctrl
.procinfo
= b1pciv4_procinfo
;
254 cinfo
->capi_ctrl
.ctr_read_proc
= b1dmactl_read_proc
;
255 strcpy(cinfo
->capi_ctrl
.name
, card
->name
);
257 retval
= attach_capi_ctr(&cinfo
->capi_ctrl
);
259 printk(KERN_ERR
"b1pci: attach controller failed.\n");
262 card
->cardnr
= cinfo
->capi_ctrl
.cnr
;
264 printk(KERN_INFO
"b1pci: AVM B1 PCI V4 at i/o %#x, irq %d, mem %#lx, revision %d (dma)\n",
265 card
->port
, card
->irq
, card
->membase
, card
->revision
);
267 pci_set_drvdata(pdev
, card
);
271 free_irq(card
->irq
, card
);
273 iounmap(card
->mbase
);
275 release_region(card
->port
, AVMB1_PORTLEN
);
277 avmcard_dma_free(card
->dma
);
285 static void b1pciv4_remove(struct pci_dev
*pdev
)
287 avmcard
*card
= pci_get_drvdata(pdev
);
288 avmctrl_info
*cinfo
= card
->ctrlinfo
;
292 detach_capi_ctr(&cinfo
->capi_ctrl
);
293 free_irq(card
->irq
, card
);
294 iounmap(card
->mbase
);
295 release_region(card
->port
, AVMB1_PORTLEN
);
296 avmcard_dma_free(card
->dma
);
300 #endif /* CONFIG_ISDN_DRV_AVMB1_B1PCIV4 */
302 static int __devinit
b1pci_pci_probe(struct pci_dev
*pdev
,
303 const struct pci_device_id
*ent
)
305 struct capicardparams param
;
308 if (pci_enable_device(pdev
) < 0) {
309 printk(KERN_ERR
"b1pci: failed to enable AVM-B1\n");
312 param
.irq
= pdev
->irq
;
314 if (pci_resource_start(pdev
, 2)) { /* B1 PCI V4 */
315 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
316 pci_set_master(pdev
);
318 param
.membase
= pci_resource_start(pdev
, 0);
319 param
.port
= pci_resource_start(pdev
, 2);
321 printk(KERN_INFO
"b1pci: PCI BIOS reports AVM-B1 V4 at i/o %#x, irq %d, mem %#x\n",
322 param
.port
, param
.irq
, param
.membase
);
323 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
324 retval
= b1pciv4_probe(¶m
, pdev
);
326 retval
= b1pci_probe(¶m
, pdev
);
329 printk(KERN_ERR
"b1pci: no AVM-B1 V4 at i/o %#x, irq %d, mem %#x detected\n",
330 param
.port
, param
.irq
, param
.membase
);
334 param
.port
= pci_resource_start(pdev
, 1);
336 printk(KERN_INFO
"b1pci: PCI BIOS reports AVM-B1 at i/o %#x, irq %d\n",
337 param
.port
, param
.irq
);
338 retval
= b1pci_probe(¶m
, pdev
);
340 printk(KERN_ERR
"b1pci: no AVM-B1 at i/o %#x, irq %d detected\n",
341 param
.port
, param
.irq
);
347 static void __devexit
b1pci_pci_remove(struct pci_dev
*pdev
)
349 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
350 avmcard
*card
= pci_get_drvdata(pdev
);
353 b1pciv4_remove(pdev
);
361 static struct pci_driver b1pci_pci_driver
= {
363 .id_table
= b1pci_pci_tbl
,
364 .probe
= b1pci_pci_probe
,
365 .remove
= __devexit_p(b1pci_pci_remove
),
368 static struct capi_driver capi_driver_b1pci
= {
372 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
373 static struct capi_driver capi_driver_b1pciv4
= {
379 static int __init
b1pci_init(void)
385 if ((p
= strchr(revision
, ':')) != 0 && p
[1]) {
386 strlcpy(rev
, p
+ 2, 32);
387 if ((p
= strchr(rev
, '$')) != 0 && p
> rev
)
393 err
= pci_register_driver(&b1pci_pci_driver
);
395 strlcpy(capi_driver_b1pci
.revision
, rev
, 32);
396 register_capi_driver(&capi_driver_b1pci
);
397 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
398 strlcpy(capi_driver_b1pciv4
.revision
, rev
, 32);
399 register_capi_driver(&capi_driver_b1pciv4
);
401 printk(KERN_INFO
"b1pci: revision %s\n", rev
);
406 static void __exit
b1pci_exit(void)
408 unregister_capi_driver(&capi_driver_b1pci
);
409 #ifdef CONFIG_ISDN_DRV_AVMB1_B1PCIV4
410 unregister_capi_driver(&capi_driver_b1pciv4
);
412 pci_unregister_driver(&b1pci_pci_driver
);
415 module_init(b1pci_init
);
416 module_exit(b1pci_exit
);