OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / isdn / hardware / avm / b1pcmcia.c
blobd6391e0afeeaf76425a70ded1b4aa1d167c3aaaa
1 /* $Id: b1pcmcia.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
2 *
3 * Module for AVM B1/M1/M2 PCMCIA-card.
4 *
5 * Copyright 1999 by Carsten Paeth <calle@calle.de>
6 *
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>
16 #include <linux/mm.h>
17 #include <linux/interrupt.h>
18 #include <linux/ioport.h>
19 #include <linux/init.h>
20 #include <asm/io.h>
21 #include <linux/capi.h>
22 #include <linux/b1pcmcia.h>
23 #include <linux/isdn/capicmd.h>
24 #include <linux/isdn/capiutil.h>
25 #include <linux/isdn/capilli.h>
26 #include "avmcard.h"
28 /* ------------------------------------------------------------- */
30 static char *revision = "$Revision: 1.1.2.2 $";
32 /* ------------------------------------------------------------- */
34 MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM PCMCIA cards");
35 MODULE_AUTHOR("Carsten Paeth");
36 MODULE_LICENSE("GPL");
38 /* ------------------------------------------------------------- */
40 static void b1pcmcia_remove_ctr(struct capi_ctr *ctrl)
42 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
43 avmcard *card = cinfo->card;
44 unsigned int port = card->port;
46 b1_reset(port);
47 b1_reset(port);
49 detach_capi_ctr(ctrl);
50 free_irq(card->irq, card);
51 b1_free_card(card);
54 /* ------------------------------------------------------------- */
56 static LIST_HEAD(cards);
58 static char *b1pcmcia_procinfo(struct capi_ctr *ctrl);
60 static int b1pcmcia_add_card(unsigned int port, unsigned irq,
61 enum avmcardtype cardtype)
63 avmctrl_info *cinfo;
64 avmcard *card;
65 char *cardname;
66 int retval;
68 card = b1_alloc_card(1);
69 if (!card) {
70 printk(KERN_WARNING "b1pcmcia: no memory.\n");
71 retval = -ENOMEM;
72 goto err;
74 cinfo = card->ctrlinfo;
76 switch (cardtype) {
77 case avm_m1: sprintf(card->name, "m1-%x", port); break;
78 case avm_m2: sprintf(card->name, "m2-%x", port); break;
79 default: sprintf(card->name, "b1pcmcia-%x", port); break;
81 card->port = port;
82 card->irq = irq;
83 card->cardtype = cardtype;
85 retval = request_irq(card->irq, b1_interrupt, IRQF_SHARED, card->name, card);
86 if (retval) {
87 printk(KERN_ERR "b1pcmcia: unable to get IRQ %d.\n",
88 card->irq);
89 retval = -EBUSY;
90 goto err_free;
92 b1_reset(card->port);
93 if ((retval = b1_detect(card->port, card->cardtype)) != 0) {
94 printk(KERN_NOTICE "b1pcmcia: NO card at 0x%x (%d)\n",
95 card->port, retval);
96 retval = -ENODEV;
97 goto err_free_irq;
99 b1_reset(card->port);
100 b1_getrevision(card);
102 cinfo->capi_ctrl.owner = THIS_MODULE;
103 cinfo->capi_ctrl.driver_name = "b1pcmcia";
104 cinfo->capi_ctrl.driverdata = cinfo;
105 cinfo->capi_ctrl.register_appl = b1_register_appl;
106 cinfo->capi_ctrl.release_appl = b1_release_appl;
107 cinfo->capi_ctrl.send_message = b1_send_message;
108 cinfo->capi_ctrl.load_firmware = b1_load_firmware;
109 cinfo->capi_ctrl.reset_ctr = b1_reset_ctr;
110 cinfo->capi_ctrl.procinfo = b1pcmcia_procinfo;
111 cinfo->capi_ctrl.proc_fops = &b1ctl_proc_fops;
112 strcpy(cinfo->capi_ctrl.name, card->name);
114 retval = attach_capi_ctr(&cinfo->capi_ctrl);
115 if (retval) {
116 printk(KERN_ERR "b1pcmcia: attach controller failed.\n");
117 goto err_free_irq;
119 switch (cardtype) {
120 case avm_m1: cardname = "M1"; break;
121 case avm_m2: cardname = "M2"; break;
122 default : cardname = "B1 PCMCIA"; break;
125 printk(KERN_INFO "b1pcmcia: AVM %s at i/o %#x, irq %d, revision %d\n",
126 cardname, card->port, card->irq, card->revision);
128 list_add(&card->list, &cards);
129 return cinfo->capi_ctrl.cnr;
131 err_free_irq:
132 free_irq(card->irq, card);
133 err_free:
134 b1_free_card(card);
135 err:
136 return retval;
139 /* ------------------------------------------------------------- */
141 static char *b1pcmcia_procinfo(struct capi_ctr *ctrl)
143 avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
145 if (!cinfo)
146 return "";
147 sprintf(cinfo->infobuf, "%s %s 0x%x %d r%d",
148 cinfo->cardname[0] ? cinfo->cardname : "-",
149 cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
150 cinfo->card ? cinfo->card->port : 0x0,
151 cinfo->card ? cinfo->card->irq : 0,
152 cinfo->card ? cinfo->card->revision : 0
154 return cinfo->infobuf;
157 /* ------------------------------------------------------------- */
159 int b1pcmcia_addcard_b1(unsigned int port, unsigned irq)
161 return b1pcmcia_add_card(port, irq, avm_b1pcmcia);
164 int b1pcmcia_addcard_m1(unsigned int port, unsigned irq)
166 return b1pcmcia_add_card(port, irq, avm_m1);
169 int b1pcmcia_addcard_m2(unsigned int port, unsigned irq)
171 return b1pcmcia_add_card(port, irq, avm_m2);
174 int b1pcmcia_delcard(unsigned int port, unsigned irq)
176 struct list_head *l;
177 avmcard *card;
179 list_for_each(l, &cards) {
180 card = list_entry(l, avmcard, list);
181 if (card->port == port && card->irq == irq) {
182 b1pcmcia_remove_ctr(&card->ctrlinfo[0].capi_ctrl);
183 return 0;
186 return -ESRCH;
189 EXPORT_SYMBOL(b1pcmcia_addcard_b1);
190 EXPORT_SYMBOL(b1pcmcia_addcard_m1);
191 EXPORT_SYMBOL(b1pcmcia_addcard_m2);
192 EXPORT_SYMBOL(b1pcmcia_delcard);
194 static struct capi_driver capi_driver_b1pcmcia = {
195 .name = "b1pcmcia",
196 .revision = "1.0",
199 static int __init b1pcmcia_init(void)
201 char *p;
202 char rev[32];
204 if ((p = strchr(revision, ':')) != NULL && p[1]) {
205 strlcpy(rev, p + 2, 32);
206 if ((p = strchr(rev, '$')) != NULL && p > rev)
207 *(p-1) = 0;
208 } else
209 strcpy(rev, "1.0");
211 strlcpy(capi_driver_b1pcmcia.revision, rev, 32);
212 register_capi_driver(&capi_driver_b1pcmcia);
213 printk(KERN_INFO "b1pci: revision %s\n", rev);
215 return 0;
218 static void __exit b1pcmcia_exit(void)
220 unregister_capi_driver(&capi_driver_b1pcmcia);
223 module_init(b1pcmcia_init);
224 module_exit(b1pcmcia_exit);