2 * $Id: t1pci.c,v 1.9 2000/05/19 15:43:22 calle Exp $
4 * Module for AVM T1 PCI-card.
6 * (c) Copyright 1999 by Carsten Paeth (calle@calle.in-berlin.de)
9 * Revision 1.9 2000/05/19 15:43:22 calle
10 * added calls to pci_device_start().
12 * Revision 1.8 2000/05/06 00:52:36 kai
13 * merged changes from kernel tree
14 * fixed timer and net_device->name breakage
16 * Revision 1.7 2000/04/07 15:26:55 calle
17 * better error message if cabel not connected or T1 has no power.
19 * Revision 1.6 2000/04/03 13:29:25 calle
20 * make Tim Waugh happy (module unload races in 2.3.99-pre3).
21 * no real problem there, but now it is much cleaner ...
23 * Revision 1.5 2000/02/02 18:36:04 calle
24 * - Modules are now locked while init_module is running
25 * - fixed problem with memory mapping if address is not aligned
27 * Revision 1.4 2000/01/25 14:33:38 calle
28 * - Added Support AVM B1 PCI V4.0 (tested with prototype)
29 * - splitted up t1pci.c into b1dma.c for common function with b1pciv4
30 * - support for revision register
32 * Revision 1.3 1999/11/13 21:27:16 keil
33 * remove KERNELVERSION
35 * Revision 1.2 1999/11/05 16:38:02 calle
36 * Cleanups before kernel 2.4:
37 * - Changed all messages to use card->name or driver->name instead of
39 * - Moved some data from struct avmcard into new struct avmctrl_info.
40 * Changed all lowlevel capi driver to match the new structur.
42 * Revision 1.1 1999/10/26 15:31:42 calle
43 * Added driver for T1-PCI card.
48 #include <linux/config.h>
49 #include <linux/module.h>
50 #include <linux/kernel.h>
51 #include <linux/skbuff.h>
52 #include <linux/delay.h>
54 #include <linux/interrupt.h>
55 #include <linux/ioport.h>
56 #include <linux/pci.h>
57 #include <linux/capi.h>
59 #include <linux/isdn.h>
65 static char *revision
= "$Revision: 1.9 $";
67 #undef CONFIG_T1PCI_DEBUG
68 #undef CONFIG_T1PCI_POLLDEBUG
70 /* ------------------------------------------------------------- */
72 #ifndef PCI_VENDOR_ID_AVM
73 #define PCI_VENDOR_ID_AVM 0x1244
76 #ifndef PCI_DEVICE_ID_AVM_T1
77 #define PCI_DEVICE_ID_AVM_T1 0x1200
80 /* ------------------------------------------------------------- */
82 MODULE_AUTHOR("Carsten Paeth <calle@calle.in-berlin.de>");
84 /* ------------------------------------------------------------- */
86 static struct capi_driver_interface
*di
;
88 /* ------------------------------------------------------------- */
90 static void t1pci_remove_ctr(struct capi_ctr
*ctrl
)
92 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
93 avmcard
*card
= cinfo
->card
;
98 free_irq(card
->irq
, card
);
99 iounmap((void *) (((unsigned long) card
->mbase
) & PAGE_MASK
));
100 release_region(card
->port
, AVMB1_PORTLEN
);
101 ctrl
->driverdata
= 0;
102 kfree(card
->ctrlinfo
);
109 /* ------------------------------------------------------------- */
111 static int t1pci_add_card(struct capi_driver
*driver
, struct capicardparams
*p
)
113 unsigned long base
, page_offset
;
120 card
= (avmcard
*) kmalloc(sizeof(avmcard
), GFP_ATOMIC
);
123 printk(KERN_WARNING
"%s: no memory.\n", driver
->name
);
127 memset(card
, 0, sizeof(avmcard
));
128 card
->dma
= (avmcard_dmainfo
*) kmalloc(sizeof(avmcard_dmainfo
), GFP_ATOMIC
);
130 printk(KERN_WARNING
"%s: no memory.\n", driver
->name
);
135 memset(card
->dma
, 0, sizeof(avmcard_dmainfo
));
136 cinfo
= (avmctrl_info
*) kmalloc(sizeof(avmctrl_info
), GFP_ATOMIC
);
138 printk(KERN_WARNING
"%s: no memory.\n", driver
->name
);
144 memset(cinfo
, 0, sizeof(avmctrl_info
));
145 card
->ctrlinfo
= cinfo
;
147 sprintf(card
->name
, "t1pci-%x", p
->port
);
148 card
->port
= p
->port
;
150 card
->membase
= p
->membase
;
151 card
->cardtype
= avm_t1pci
;
153 if (check_region(card
->port
, AVMB1_PORTLEN
)) {
155 "%s: ports 0x%03x-0x%03x in use.\n",
156 driver
->name
, card
->port
, card
->port
+ AVMB1_PORTLEN
);
157 kfree(card
->ctrlinfo
);
164 base
= card
->membase
& PAGE_MASK
;
165 page_offset
= card
->membase
- base
;
166 card
->mbase
= ioremap_nocache(base
, page_offset
+ 64);
168 card
->mbase
+= page_offset
;
170 printk(KERN_NOTICE
"%s: can't remap memory at 0x%lx\n",
171 driver
->name
, card
->membase
);
172 kfree(card
->ctrlinfo
);
181 if ((retval
= t1pci_detect(card
)) != 0) {
183 printk(KERN_NOTICE
"%s: NO card at 0x%x (%d)\n",
184 driver
->name
, card
->port
, retval
);
186 printk(KERN_NOTICE
"%s: card at 0x%x, but cabel not connected or T1 has no power (%d)\n",
187 driver
->name
, card
->port
, retval
);
188 iounmap((void *) (((unsigned long) card
->mbase
) & PAGE_MASK
));
189 kfree(card
->ctrlinfo
);
197 request_region(p
->port
, AVMB1_PORTLEN
, card
->name
);
199 retval
= request_irq(card
->irq
, b1dma_interrupt
, SA_SHIRQ
, card
->name
, card
);
201 printk(KERN_ERR
"%s: unable to get IRQ %d.\n",
202 driver
->name
, card
->irq
);
203 iounmap((void *) (((unsigned long) card
->mbase
) & PAGE_MASK
));
204 release_region(card
->port
, AVMB1_PORTLEN
);
205 kfree(card
->ctrlinfo
);
212 cinfo
->capi_ctrl
= di
->attach_ctr(driver
, card
->name
, cinfo
);
213 if (!cinfo
->capi_ctrl
) {
214 printk(KERN_ERR
"%s: attach controller failed.\n", driver
->name
);
215 iounmap((void *) (((unsigned long) card
->mbase
) & PAGE_MASK
));
216 free_irq(card
->irq
, card
);
217 release_region(card
->port
, AVMB1_PORTLEN
);
218 kfree(card
->ctrlinfo
);
224 card
->cardnr
= cinfo
->capi_ctrl
->cnr
;
226 skb_queue_head_init(&card
->dma
->send_queue
);
229 "%s: AVM T1 PCI at i/o %#x, irq %d, mem %#lx\n",
230 driver
->name
, card
->port
, card
->irq
, card
->membase
);
235 /* ------------------------------------------------------------- */
237 static char *t1pci_procinfo(struct capi_ctr
*ctrl
)
239 avmctrl_info
*cinfo
= (avmctrl_info
*)(ctrl
->driverdata
);
243 sprintf(cinfo
->infobuf
, "%s %s 0x%x %d 0x%lx",
244 cinfo
->cardname
[0] ? cinfo
->cardname
: "-",
245 cinfo
->version
[VER_DRIVER
] ? cinfo
->version
[VER_DRIVER
] : "-",
246 cinfo
->card
? cinfo
->card
->port
: 0x0,
247 cinfo
->card
? cinfo
->card
->irq
: 0,
248 cinfo
->card
? cinfo
->card
->membase
: 0
250 return cinfo
->infobuf
;
253 /* ------------------------------------------------------------- */
255 static struct capi_driver t1pci_driver
= {
267 0, /* use standard driver_read_proc */
269 0, /* no add_card function */
273 #define t1pci_init init_module
274 void cleanup_module(void);
277 static int ncards
= 0;
281 struct capi_driver
*driver
= &t1pci_driver
;
282 struct pci_dev
*dev
= NULL
;
288 if ((p
= strchr(revision
, ':'))) {
289 strncpy(driver
->revision
, p
+ 1, sizeof(driver
->revision
));
290 p
= strchr(driver
->revision
, '$');
294 printk(KERN_INFO
"%s: revision %s\n", driver
->name
, driver
->revision
);
296 di
= attach_capi_driver(driver
);
299 printk(KERN_ERR
"%s: failed to attach capi_driver\n",
306 if (!pci_present()) {
307 printk(KERN_ERR
"%s: no PCI bus present\n", driver
->name
);
308 detach_capi_driver(driver
);
313 while ((dev
= pci_find_device(PCI_VENDOR_ID_AVM
, PCI_DEVICE_ID_AVM_T1
, dev
))) {
314 struct capicardparams param
;
316 param
.port
= pci_resource_start(dev
, 1);
317 param
.irq
= dev
->irq
;
318 param
.membase
= pci_resource_start(dev
, 0);
320 retval
= pci_enable_device (dev
);
323 "%s: failed to enable AVM-T1-PCI at i/o %#x, irq %d, mem %#x err=%d\n",
324 driver
->name
, param
.port
, param
.irq
, param
.membase
, retval
);
333 "%s: PCI BIOS reports AVM-T1-PCI at i/o %#x, irq %d, mem %#x\n",
334 driver
->name
, param
.port
, param
.irq
, param
.membase
);
335 retval
= t1pci_add_card(driver
, ¶m
);
338 "%s: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n",
339 driver
->name
, param
.port
, param
.irq
, param
.membase
);
349 printk(KERN_INFO
"%s: %d T1-PCI card(s) detected\n",
350 driver
->name
, ncards
);
354 printk(KERN_ERR
"%s: NO T1-PCI card detected\n", driver
->name
);
358 printk(KERN_ERR
"%s: kernel not compiled with PCI.\n", driver
->name
);
365 void cleanup_module(void)
367 detach_capi_driver(&t1pci_driver
);