1 /* $Id: t1pci.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
3 * Module for AVM T1 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>
22 #include <linux/init.h>
24 #include <linux/isdn/capicmd.h>
25 #include <linux/isdn/capiutil.h>
26 #include <linux/isdn/capilli.h>
29 #undef CONFIG_T1PCI_DEBUG
30 #undef CONFIG_T1PCI_POLLDEBUG
32 /* ------------------------------------------------------------- */
33 static char *revision
= "$Revision: 1.1.2.2 $";
34 /* ------------------------------------------------------------- */
36 static struct pci_device_id t1pci_pci_tbl
[] = {
37 { PCI_VENDOR_ID_AVM
, PCI_DEVICE_ID_AVM_T1
, PCI_ANY_ID
, PCI_ANY_ID
},
38 { } /* Terminating entry */
41 MODULE_DEVICE_TABLE(pci
, t1pci_pci_tbl
);
42 MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM T1 PCI card");
43 MODULE_AUTHOR("Carsten Paeth");
44 MODULE_LICENSE("GPL");
46 /* ------------------------------------------------------------- */
48 static char *t1pci_procinfo(struct capi_ctr
*ctrl
);
50 static int t1pci_add_card(struct capicardparams
*p
, struct pci_dev
*pdev
)
56 card
= b1_alloc_card(1);
58 printk(KERN_WARNING
"t1pci: no memory.\n");
63 card
->dma
= avmcard_dma_alloc("t1pci", pdev
, 2048+128, 2048+128);
65 printk(KERN_WARNING
"t1pci: no memory.\n");
70 cinfo
= card
->ctrlinfo
;
71 sprintf(card
->name
, "t1pci-%x", p
->port
);
74 card
->membase
= p
->membase
;
75 card
->cardtype
= avm_t1pci
;
77 if (!request_region(card
->port
, AVMB1_PORTLEN
, card
->name
)) {
78 printk(KERN_WARNING
"t1pci: ports 0x%03x-0x%03x in use.\n",
79 card
->port
, card
->port
+ AVMB1_PORTLEN
);
84 card
->mbase
= ioremap(card
->membase
, 64);
86 printk(KERN_NOTICE
"t1pci: can't remap memory at 0x%lx\n",
89 goto err_release_region
;
94 retval
= t1pci_detect(card
);
97 printk(KERN_NOTICE
"t1pci: NO card at 0x%x (%d)\n",
100 printk(KERN_NOTICE
"t1pci: card at 0x%x, but cable not connected or T1 has no power (%d)\n",
107 retval
= request_irq(card
->irq
, b1dma_interrupt
, SA_SHIRQ
, card
->name
, card
);
109 printk(KERN_ERR
"t1pci: unable to get IRQ %d.\n", card
->irq
);
114 cinfo
->capi_ctrl
.owner
= THIS_MODULE
;
115 cinfo
->capi_ctrl
.driver_name
= "t1pci";
116 cinfo
->capi_ctrl
.driverdata
= cinfo
;
117 cinfo
->capi_ctrl
.register_appl
= b1dma_register_appl
;
118 cinfo
->capi_ctrl
.release_appl
= b1dma_release_appl
;
119 cinfo
->capi_ctrl
.send_message
= b1dma_send_message
;
120 cinfo
->capi_ctrl
.load_firmware
= b1dma_load_firmware
;
121 cinfo
->capi_ctrl
.reset_ctr
= b1dma_reset_ctr
;
122 cinfo
->capi_ctrl
.procinfo
= t1pci_procinfo
;
123 cinfo
->capi_ctrl
.ctr_read_proc
= b1dmactl_read_proc
;
124 strcpy(cinfo
->capi_ctrl
.name
, card
->name
);
126 retval
= attach_capi_ctr(&cinfo
->capi_ctrl
);
128 printk(KERN_ERR
"t1pci: attach controller failed.\n");
132 card
->cardnr
= cinfo
->capi_ctrl
.cnr
;
134 printk(KERN_INFO
"t1pci: AVM T1 PCI at i/o %#x, irq %d, mem %#lx\n",
135 card
->port
, card
->irq
, card
->membase
);
137 pci_set_drvdata(pdev
, card
);
141 free_irq(card
->irq
, card
);
143 iounmap(card
->mbase
);
145 release_region(card
->port
, AVMB1_PORTLEN
);
147 avmcard_dma_free(card
->dma
);
154 /* ------------------------------------------------------------- */
156 static void t1pci_remove(struct pci_dev
*pdev
)
158 avmcard
*card
= pci_get_drvdata(pdev
);
159 avmctrl_info
*cinfo
= card
->ctrlinfo
;
163 detach_capi_ctr(&cinfo
->capi_ctrl
);
164 free_irq(card
->irq
, card
);
165 iounmap(card
->mbase
);
166 release_region(card
->port
, AVMB1_PORTLEN
);
167 avmcard_dma_free(card
->dma
);
171 /* ------------------------------------------------------------- */
173 static char *t1pci_procinfo(struct capi_ctr
*ctrl
)
175 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
179 sprintf(cinfo
->infobuf
, "%s %s 0x%x %d 0x%lx",
180 cinfo
->cardname
[0] ? cinfo
->cardname
: "-",
181 cinfo
->version
[VER_DRIVER
] ? cinfo
->version
[VER_DRIVER
] : "-",
182 cinfo
->card
? cinfo
->card
->port
: 0x0,
183 cinfo
->card
? cinfo
->card
->irq
: 0,
184 cinfo
->card
? cinfo
->card
->membase
: 0
186 return cinfo
->infobuf
;
189 /* ------------------------------------------------------------- */
191 static int __devinit
t1pci_probe(struct pci_dev
*dev
,
192 const struct pci_device_id
*ent
)
194 struct capicardparams param
;
197 if (pci_enable_device(dev
) < 0) {
198 printk(KERN_ERR
"t1pci: failed to enable AVM-T1-PCI\n");
203 param
.port
= pci_resource_start(dev
, 1);
204 param
.irq
= dev
->irq
;
205 param
.membase
= pci_resource_start(dev
, 0);
207 printk(KERN_INFO
"t1pci: PCI BIOS reports AVM-T1-PCI at i/o %#x, irq %d, mem %#x\n",
208 param
.port
, param
.irq
, param
.membase
);
210 retval
= t1pci_add_card(¶m
, dev
);
212 printk(KERN_ERR
"t1pci: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n",
213 param
.port
, param
.irq
, param
.membase
);
219 static struct pci_driver t1pci_pci_driver
= {
221 .id_table
= t1pci_pci_tbl
,
222 .probe
= t1pci_probe
,
223 .remove
= t1pci_remove
,
226 static struct capi_driver capi_driver_t1pci
= {
231 static int __init
t1pci_init(void)
237 if ((p
= strchr(revision
, ':')) != 0 && p
[1]) {
238 strlcpy(rev
, p
+ 2, 32);
239 if ((p
= strchr(rev
, '$')) != 0 && p
> rev
)
244 err
= pci_register_driver(&t1pci_pci_driver
);
246 strlcpy(capi_driver_t1pci
.revision
, rev
, 32);
247 register_capi_driver(&capi_driver_t1pci
);
248 printk(KERN_INFO
"t1pci: revision %s\n", rev
);
253 static void __exit
t1pci_exit(void)
255 unregister_capi_driver(&capi_driver_t1pci
);
256 pci_unregister_driver(&t1pci_pci_driver
);
259 module_init(t1pci_init
);
260 module_exit(t1pci_exit
);