* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / isdn / avmb1 / b1isa.c
blob9ab1984323eea0b885aa24e5c60f5dcec94d12e7
1 /*
2 * $Id: b1isa.c,v 1.4 1999/08/22 20:26:24 calle Exp $
3 *
4 * Module for AVM B1 ISA-card.
5 *
6 * (c) Copyright 1999 by Carsten Paeth (calle@calle.in-berlin.de)
7 *
8 * $Log: b1isa.c,v $
9 * Revision 1.4 1999/08/22 20:26:24 calle
10 * backported changes from kernel 2.3.14:
11 * - several #include "config.h" gone, others come.
12 * - "struct device" changed to "struct net_device" in 2.3.14, added a
13 * define in isdn_compat.h for older kernel versions.
15 * Revision 1.3 1999/07/09 15:05:40 keil
16 * compat.h is now isdn_compat.h
18 * Revision 1.2 1999/07/05 15:09:49 calle
19 * - renamed "appl_release" to "appl_released".
20 * - version und profile data now cleared on controller reset
21 * - extended /proc interface, to allow driver and controller specific
22 * informations to include by driver hackers.
24 * Revision 1.1 1999/07/01 15:26:27 calle
25 * complete new version (I love it):
26 * + new hardware independed "capi_driver" interface that will make it easy to:
27 * - support other controllers with CAPI-2.0 (i.e. USB Controller)
28 * - write a CAPI-2.0 for the passive cards
29 * - support serial link CAPI-2.0 boxes.
30 * + wrote "capi_driver" for all supported cards.
31 * + "capi_driver" (supported cards) now have to be configured with
32 * make menuconfig, in the past all supported cards where included
33 * at once.
34 * + new and better informations in /proc/capi/
35 * + new ioctl to switch trace of capi messages per controller
36 * using "avmcapictrl trace [contr] on|off|...."
37 * + complete testcircle with all supported cards and also the
38 * PCMCIA cards (now patch for pcmcia-cs-3.0.13 needed) done.
43 #include <linux/module.h>
44 #include <linux/kernel.h>
45 #include <linux/skbuff.h>
46 #include <linux/delay.h>
47 #include <linux/mm.h>
48 #include <linux/interrupt.h>
49 #include <linux/ioport.h>
50 #include <linux/capi.h>
51 #include <asm/io.h>
52 #include <linux/isdn_compat.h>
53 #include "capicmd.h"
54 #include "capiutil.h"
55 #include "capilli.h"
56 #include "avmcard.h"
58 static char *revision = "$Revision: 1.4 $";
60 /* ------------------------------------------------------------- */
62 MODULE_AUTHOR("Carsten Paeth <calle@calle.in-berlin.de>");
64 /* ------------------------------------------------------------- */
66 static struct capi_driver_interface *di;
68 /* ------------------------------------------------------------- */
70 static void b1isa_interrupt(int interrupt, void *devptr, struct pt_regs *regs)
72 avmcard *card;
74 card = (avmcard *) devptr;
76 if (!card) {
77 printk(KERN_WARNING "b1_interrupt: wrong device\n");
78 return;
80 if (card->interrupt) {
81 printk(KERN_ERR "b1_interrupt: reentering interrupt hander (%s)\n", card->name);
82 return;
85 card->interrupt = 1;
87 b1_handle_interrupt(card);
89 card->interrupt = 0;
91 /* ------------------------------------------------------------- */
93 static void b1isa_remove_ctr(struct capi_ctr *ctrl)
95 avmcard *card = (avmcard *)(ctrl->driverdata);
96 unsigned int port = card->port;
98 b1_reset(port);
99 b1_reset(port);
101 di->detach_ctr(ctrl);
102 free_irq(card->irq, card);
103 release_region(card->port, AVMB1_PORTLEN);
104 kfree(card);
106 MOD_DEC_USE_COUNT;
109 /* ------------------------------------------------------------- */
111 static int b1isa_add_card(struct capi_driver *driver, struct capicardparams *p)
113 avmcard *card;
114 int retval;
116 card = (avmcard *) kmalloc(sizeof(avmcard), GFP_ATOMIC);
118 if (!card) {
119 printk(KERN_WARNING "b1isa: no memory.\n");
120 return -ENOMEM;
122 memset(card, 0, sizeof(avmcard));
123 sprintf(card->name, "b1isa-%x", p->port);
124 card->port = p->port;
125 card->irq = p->irq;
126 card->cardtype = avm_b1isa;
128 if (check_region(card->port, AVMB1_PORTLEN)) {
129 printk(KERN_WARNING
130 "b1isa: ports 0x%03x-0x%03x in use.\n",
131 card->port, card->port + AVMB1_PORTLEN);
132 kfree(card);
133 return -EBUSY;
135 if (b1_irq_table[card->irq & 0xf] == 0) {
136 printk(KERN_WARNING "b1isa: irq %d not valid.\n", card->irq);
137 kfree(card);
138 return -EINVAL;
140 if ( card->port != 0x150 && card->port != 0x250
141 && card->port != 0x300 && card->port != 0x340) {
142 printk(KERN_WARNING "b1isa: illegal port 0x%x.\n", card->port);
143 kfree(card);
144 return -EINVAL;
146 b1_reset(card->port);
147 if ((retval = b1_detect(card->port, card->cardtype)) != 0) {
148 printk(KERN_NOTICE "b1isa: NO card at 0x%x (%d)\n",
149 card->port, retval);
150 kfree(card);
151 return -EIO;
153 b1_reset(card->port);
155 request_region(p->port, AVMB1_PORTLEN, card->name);
157 retval = request_irq(card->irq, b1isa_interrupt, 0, card->name, card);
158 if (retval) {
159 printk(KERN_ERR "b1isa: unable to get IRQ %d.\n", card->irq);
160 release_region(card->port, AVMB1_PORTLEN);
161 kfree(card);
162 return -EBUSY;
165 card->ctrl = di->attach_ctr(driver, card->name, card);
166 if (!card->ctrl) {
167 printk(KERN_ERR "b1isa: attach controller failed.\n");
168 free_irq(card->irq, card);
169 release_region(card->port, AVMB1_PORTLEN);
170 kfree(card);
171 return -EBUSY;
174 MOD_INC_USE_COUNT;
175 return 0;
178 static char *b1isa_procinfo(struct capi_ctr *ctrl)
180 avmcard *card = (avmcard *)(ctrl->driverdata);
181 if (!card)
182 return "";
183 sprintf(card->infobuf, "%s %s 0x%x %d",
184 card->cardname[0] ? card->cardname : "-",
185 card->version[VER_DRIVER] ? card->version[VER_DRIVER] : "-",
186 card->port, card->irq
188 return card->infobuf;
191 /* ------------------------------------------------------------- */
193 static struct capi_driver b1isa_driver = {
194 "b1isa",
195 "0.0",
196 b1_load_firmware,
197 b1_reset_ctr,
198 b1isa_remove_ctr,
199 b1_register_appl,
200 b1_release_appl,
201 b1_send_message,
203 b1isa_procinfo,
204 b1ctl_read_proc,
205 0, /* use standard driver_read_proc */
207 b1isa_add_card,
210 #ifdef MODULE
211 #define b1isa_init init_module
212 void cleanup_module(void);
213 #endif
215 int b1isa_init(void)
217 struct capi_driver *driver = &b1isa_driver;
218 char *p;
220 if ((p = strchr(revision, ':'))) {
221 strncpy(driver->revision, p + 1, sizeof(driver->revision));
222 p = strchr(driver->revision, '$');
223 *p = 0;
226 printk(KERN_INFO "%s: revision %s\n", driver->name, driver->revision);
228 di = attach_capi_driver(driver);
230 if (!di) {
231 printk(KERN_ERR "%s: failed to attach capi_driver\n",
232 driver->name);
233 return -EIO;
235 return 0;
238 #ifdef MODULE
239 void cleanup_module(void)
241 detach_capi_driver(&b1isa_driver);
243 #endif