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/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>
21 #include <linux/init.h>
23 #include <linux/isdn/capicmd.h>
24 #include <linux/isdn/capiutil.h>
25 #include <linux/isdn/capilli.h>
28 #undef CONFIG_T1PCI_DEBUG
29 #undef CONFIG_T1PCI_POLLDEBUG
31 /* ------------------------------------------------------------- */
32 static char *revision
= "$Revision: 1.1.2.2 $";
33 /* ------------------------------------------------------------- */
35 static struct pci_device_id t1pci_pci_tbl
[] = {
36 { PCI_VENDOR_ID_AVM
, PCI_DEVICE_ID_AVM_T1
, PCI_ANY_ID
, PCI_ANY_ID
},
37 { } /* Terminating entry */
40 MODULE_DEVICE_TABLE(pci
, t1pci_pci_tbl
);
41 MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM T1 PCI card");
42 MODULE_AUTHOR("Carsten Paeth");
43 MODULE_LICENSE("GPL");
45 /* ------------------------------------------------------------- */
47 static char *t1pci_procinfo(struct capi_ctr
*ctrl
);
49 static int t1pci_add_card(struct capicardparams
*p
, struct pci_dev
*pdev
)
55 card
= b1_alloc_card(1);
57 printk(KERN_WARNING
"t1pci: no memory.\n");
62 card
->dma
= avmcard_dma_alloc("t1pci", pdev
, 2048+128, 2048+128);
64 printk(KERN_WARNING
"t1pci: no memory.\n");
69 cinfo
= card
->ctrlinfo
;
70 sprintf(card
->name
, "t1pci-%x", p
->port
);
73 card
->membase
= p
->membase
;
74 card
->cardtype
= avm_t1pci
;
76 if (!request_region(card
->port
, AVMB1_PORTLEN
, card
->name
)) {
77 printk(KERN_WARNING
"t1pci: ports 0x%03x-0x%03x in use.\n",
78 card
->port
, card
->port
+ AVMB1_PORTLEN
);
83 card
->mbase
= ioremap(card
->membase
, 64);
85 printk(KERN_NOTICE
"t1pci: can't remap memory at 0x%lx\n",
88 goto err_release_region
;
93 retval
= t1pci_detect(card
);
96 printk(KERN_NOTICE
"t1pci: NO card at 0x%x (%d)\n",
99 printk(KERN_NOTICE
"t1pci: card at 0x%x, but cable not connected or T1 has no power (%d)\n",
106 retval
= request_irq(card
->irq
, b1dma_interrupt
, IRQF_SHARED
, card
->name
, card
);
108 printk(KERN_ERR
"t1pci: unable to get IRQ %d.\n", card
->irq
);
113 cinfo
->capi_ctrl
.owner
= THIS_MODULE
;
114 cinfo
->capi_ctrl
.driver_name
= "t1pci";
115 cinfo
->capi_ctrl
.driverdata
= cinfo
;
116 cinfo
->capi_ctrl
.register_appl
= b1dma_register_appl
;
117 cinfo
->capi_ctrl
.release_appl
= b1dma_release_appl
;
118 cinfo
->capi_ctrl
.send_message
= b1dma_send_message
;
119 cinfo
->capi_ctrl
.load_firmware
= b1dma_load_firmware
;
120 cinfo
->capi_ctrl
.reset_ctr
= b1dma_reset_ctr
;
121 cinfo
->capi_ctrl
.procinfo
= t1pci_procinfo
;
122 cinfo
->capi_ctrl
.ctr_read_proc
= b1dmactl_read_proc
;
123 strcpy(cinfo
->capi_ctrl
.name
, card
->name
);
125 retval
= attach_capi_ctr(&cinfo
->capi_ctrl
);
127 printk(KERN_ERR
"t1pci: attach controller failed.\n");
131 card
->cardnr
= cinfo
->capi_ctrl
.cnr
;
133 printk(KERN_INFO
"t1pci: AVM T1 PCI at i/o %#x, irq %d, mem %#lx\n",
134 card
->port
, card
->irq
, card
->membase
);
136 pci_set_drvdata(pdev
, card
);
140 free_irq(card
->irq
, card
);
142 iounmap(card
->mbase
);
144 release_region(card
->port
, AVMB1_PORTLEN
);
146 avmcard_dma_free(card
->dma
);
153 /* ------------------------------------------------------------- */
155 static void t1pci_remove(struct pci_dev
*pdev
)
157 avmcard
*card
= pci_get_drvdata(pdev
);
158 avmctrl_info
*cinfo
= card
->ctrlinfo
;
162 detach_capi_ctr(&cinfo
->capi_ctrl
);
163 free_irq(card
->irq
, card
);
164 iounmap(card
->mbase
);
165 release_region(card
->port
, AVMB1_PORTLEN
);
166 avmcard_dma_free(card
->dma
);
170 /* ------------------------------------------------------------- */
172 static char *t1pci_procinfo(struct capi_ctr
*ctrl
)
174 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
178 sprintf(cinfo
->infobuf
, "%s %s 0x%x %d 0x%lx",
179 cinfo
->cardname
[0] ? cinfo
->cardname
: "-",
180 cinfo
->version
[VER_DRIVER
] ? cinfo
->version
[VER_DRIVER
] : "-",
181 cinfo
->card
? cinfo
->card
->port
: 0x0,
182 cinfo
->card
? cinfo
->card
->irq
: 0,
183 cinfo
->card
? cinfo
->card
->membase
: 0
185 return cinfo
->infobuf
;
188 /* ------------------------------------------------------------- */
190 static int __devinit
t1pci_probe(struct pci_dev
*dev
,
191 const struct pci_device_id
*ent
)
193 struct capicardparams param
;
196 if (pci_enable_device(dev
) < 0) {
197 printk(KERN_ERR
"t1pci: failed to enable AVM-T1-PCI\n");
202 param
.port
= pci_resource_start(dev
, 1);
203 param
.irq
= dev
->irq
;
204 param
.membase
= pci_resource_start(dev
, 0);
206 printk(KERN_INFO
"t1pci: PCI BIOS reports AVM-T1-PCI at i/o %#x, irq %d, mem %#x\n",
207 param
.port
, param
.irq
, param
.membase
);
209 retval
= t1pci_add_card(¶m
, dev
);
211 printk(KERN_ERR
"t1pci: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n",
212 param
.port
, param
.irq
, param
.membase
);
218 static struct pci_driver t1pci_pci_driver
= {
220 .id_table
= t1pci_pci_tbl
,
221 .probe
= t1pci_probe
,
222 .remove
= t1pci_remove
,
225 static struct capi_driver capi_driver_t1pci
= {
230 static int __init
t1pci_init(void)
236 if ((p
= strchr(revision
, ':')) != NULL
&& p
[1]) {
237 strlcpy(rev
, p
+ 2, 32);
238 if ((p
= strchr(rev
, '$')) != NULL
&& p
> rev
)
243 err
= pci_register_driver(&t1pci_pci_driver
);
245 strlcpy(capi_driver_t1pci
.revision
, rev
, 32);
246 register_capi_driver(&capi_driver_t1pci
);
247 printk(KERN_INFO
"t1pci: revision %s\n", rev
);
252 static void __exit
t1pci_exit(void)
254 unregister_capi_driver(&capi_driver_t1pci
);
255 pci_unregister_driver(&t1pci_pci_driver
);
258 module_init(t1pci_init
);
259 module_exit(t1pci_exit
);