2 * $Id: b1isa.c,v 1.10.6.2 2001/02/16 16:43:23 kai Exp $
4 * Module for AVM B1 ISA-card.
6 * (c) Copyright 1999 by Carsten Paeth (calle@calle.in-berlin.de)
9 * Revision 1.10.6.2 2001/02/16 16:43:23 kai
10 * Changes from -ac16, little bug fixes, typos and the like
12 * Revision 1.10.6.1 2001/02/13 11:43:29 kai
13 * more compatility changes for 2.2.19
15 * Revision 1.10 2000/11/23 20:45:14 kai
16 * fixed module_init/exit stuff
17 * Note: compiled-in kernel doesn't work pre 2.2.18 anymore.
19 * Revision 1.9 2000/11/01 14:05:02 calle
20 * - use module_init/module_exit from linux/init.h.
21 * - all static struct variables are initialized with "membername:" now.
22 * - avm_cs.c, let it work with newer pcmcia-cs.
24 * Revision 1.8 2000/04/03 13:29:24 calle
25 * make Tim Waugh happy (module unload races in 2.3.99-pre3).
26 * no real problem there, but now it is much cleaner ...
28 * Revision 1.7 2000/02/02 18:36:03 calle
29 * - Modules are now locked while init_module is running
30 * - fixed problem with memory mapping if address is not aligned
32 * Revision 1.6 2000/01/25 14:37:39 calle
33 * new message after successful detection including card revision and
36 * Revision 1.5 1999/11/05 16:38:01 calle
37 * Cleanups before kernel 2.4:
38 * - Changed all messages to use card->name or driver->name instead of
40 * - Moved some data from struct avmcard into new struct avmctrl_info.
41 * Changed all lowlevel capi driver to match the new structur.
43 * Revision 1.4 1999/08/22 20:26:24 calle
44 * backported changes from kernel 2.3.14:
45 * - several #include "config.h" gone, others come.
46 * - "struct device" changed to "struct net_device" in 2.3.14, added a
47 * define in isdn_compat.h for older kernel versions.
49 * Revision 1.3 1999/07/09 15:05:40 keil
50 * compat.h is now isdn_compat.h
52 * Revision 1.2 1999/07/05 15:09:49 calle
53 * - renamed "appl_release" to "appl_released".
54 * - version und profile data now cleared on controller reset
55 * - extended /proc interface, to allow driver and controller specific
56 * informations to include by driver hackers.
58 * Revision 1.1 1999/07/01 15:26:27 calle
59 * complete new version (I love it):
60 * + new hardware independed "capi_driver" interface that will make it easy to:
61 * - support other controllers with CAPI-2.0 (i.e. USB Controller)
62 * - write a CAPI-2.0 for the passive cards
63 * - support serial link CAPI-2.0 boxes.
64 * + wrote "capi_driver" for all supported cards.
65 * + "capi_driver" (supported cards) now have to be configured with
66 * make menuconfig, in the past all supported cards where included
68 * + new and better informations in /proc/capi/
69 * + new ioctl to switch trace of capi messages per controller
70 * using "avmcapictrl trace [contr] on|off|...."
71 * + complete testcircle with all supported cards and also the
72 * PCMCIA cards (now patch for pcmcia-cs-3.0.13 needed) done.
77 #include <linux/module.h>
78 #include <linux/kernel.h>
79 #include <linux/skbuff.h>
80 #include <linux/delay.h>
82 #include <linux/interrupt.h>
83 #include <linux/ioport.h>
84 #include <linux/capi.h>
85 #include <linux/init.h>
92 static char *revision = "$Revision: 1.10.6.2 $";
94 /* ------------------------------------------------------------- */
96 MODULE_AUTHOR("Carsten Paeth <calle@calle.in-berlin.de>");
98 /* ------------------------------------------------------------- */
100 static void b1isa_interrupt(int interrupt, void *devptr, struct pt_regs *regs)
104 card = (avmcard *) devptr;
107 printk(KERN_WARNING "b1_interrupt: wrong device\n");
110 if (card->interrupt) {
111 printk(KERN_ERR "b1_interrupt: reentering interrupt hander (%s)\n", card->name);
117 b1_handle_interrupt(card);
121 /* ------------------------------------------------------------- */
123 static struct capi_driver_interface *di;
125 /* ------------------------------------------------------------- */
127 static void b1isa_remove_ctr(struct capi_ctr *ctrl)
129 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
130 avmcard *card = cinfo->card;
131 unsigned int port = card->port;
136 di->detach_ctr(ctrl);
137 free_irq(card->irq, card);
138 release_region(card->port, AVMB1_PORTLEN);
139 kfree(card->ctrlinfo);
145 /* ------------------------------------------------------------- */
147 static int b1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
155 card = (avmcard *) kmalloc(sizeof(avmcard), GFP_ATOMIC);
158 printk(KERN_WARNING "b1isa: no memory.\n");
162 memset(card, 0, sizeof(avmcard));
163 cinfo = (avmctrl_info *) kmalloc(sizeof(avmctrl_info), GFP_ATOMIC);
165 printk(KERN_WARNING "b1isa: no memory.\n");
170 memset(cinfo, 0, sizeof(avmctrl_info));
171 card->ctrlinfo = cinfo;
173 sprintf(card->name, "b1isa-%x", p->port);
174 card->port = p->port;
176 card->cardtype = avm_b1isa;
178 if (check_region(card->port, AVMB1_PORTLEN)) {
180 "b1isa: ports 0x%03x-0x%03x in use.\n",
181 card->port, card->port + AVMB1_PORTLEN);
182 kfree(card->ctrlinfo);
187 if (b1_irq_table[card->irq & 0xf] == 0) {
188 printk(KERN_WARNING "b1isa: irq %d not valid.\n", card->irq);
189 kfree(card->ctrlinfo);
194 if ( card->port != 0x150 && card->port != 0x250
195 && card->port != 0x300 && card->port != 0x340) {
196 printk(KERN_WARNING "b1isa: illegal port 0x%x.\n", card->port);
197 kfree(card->ctrlinfo);
202 b1_reset(card->port);
203 if ((retval = b1_detect(card->port, card->cardtype)) != 0) {
204 printk(KERN_NOTICE "b1isa: NO card at 0x%x (%d)\n",
206 kfree(card->ctrlinfo);
211 b1_reset(card->port);
212 b1_getrevision(card);
214 request_region(p->port, AVMB1_PORTLEN, card->name);
216 retval = request_irq(card->irq, b1isa_interrupt, 0, card->name, card);
218 printk(KERN_ERR "b1isa: unable to get IRQ %d.\n", card->irq);
219 release_region(card->port, AVMB1_PORTLEN);
220 kfree(card->ctrlinfo);
226 cinfo->capi_ctrl = di->attach_ctr(driver, card->name, cinfo);
227 if (!cinfo->capi_ctrl) {
228 printk(KERN_ERR "b1isa: attach controller failed.\n");
229 free_irq(card->irq, card);
230 release_region(card->port, AVMB1_PORTLEN);
231 kfree(card->ctrlinfo);
238 "%s: AVM B1 ISA at i/o %#x, irq %d, revision %d\n",
239 driver->name, card->port, card->irq, card->revision);
244 static char *b1isa_procinfo(struct capi_ctr *ctrl)
246 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
250 sprintf(cinfo->infobuf, "%s %s 0x%x %d r%d",
251 cinfo->cardname[0] ? cinfo->cardname : "-",
252 cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
253 cinfo->card ? cinfo->card->port : 0x0,
254 cinfo->card ? cinfo->card->irq : 0,
255 cinfo->card ? cinfo->card->revision : 0
257 return cinfo->infobuf;
260 /* ------------------------------------------------------------- */
262 static struct capi_driver b1isa_driver = {
265 load_firmware: b1_load_firmware,
266 reset_ctr: b1_reset_ctr,
267 remove_ctr: b1isa_remove_ctr,
268 register_appl: b1_register_appl,
269 release_appl: b1_release_appl,
270 send_message: b1_send_message,
272 procinfo: b1isa_procinfo,
273 ctr_read_proc: b1ctl_read_proc,
274 driver_read_proc: 0, /* use standard driver_read_proc */
276 add_card: b1isa_add_card,
279 static int __init b1isa_init(void)
281 struct capi_driver *driver = &b1isa_driver;
287 if ((p = strchr(revision, ':'))) {
288 strncpy(driver->revision, p + 1, sizeof(driver->revision));
289 p = strchr(driver->revision, '$');
293 printk(KERN_INFO "%s: revision %s\n", driver->name, driver->revision);
295 di = attach_capi_driver(driver);
298 printk(KERN_ERR "%s: failed to attach capi_driver\n",
306 static void __exit b1isa_exit(void)
308 detach_capi_driver(&b1isa_driver);
311 module_init(b1isa_init);
312 module_exit(b1isa_exit);