2 * PCMCIA client driver for AVM A1 / Fritz!PCMCIA
5 * Copyright 1998-2001 by Carsten Paeth <calle@calle.in-berlin.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>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/ptrace.h>
18 #include <linux/slab.h>
19 #include <linux/string.h>
21 #include <asm/system.h>
23 #include <pcmcia/cs.h>
24 #include <pcmcia/cistpl.h>
25 #include <pcmcia/ds.h>
26 #include "hisax_cfg.h"
28 MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards");
29 MODULE_AUTHOR("Carsten Paeth");
30 MODULE_LICENSE("GPL");
33 /*====================================================================*/
35 /* Parameters that can be set with 'insmod' */
37 static int isdnprot = 2;
39 module_param(isdnprot, int, 0);
41 /*====================================================================*/
44 The event() function is this driver's Card Services event handler.
45 It will be called by Card Services when an appropriate card status
46 event is received. The config() and release() entry points are
47 used to configure or release a socket, in response to card insertion
48 and ejection events. They are invoked from the skeleton event
52 static int avma1cs_config(struct pcmcia_device *link) __devinit ;
53 static void avma1cs_release(struct pcmcia_device *link);
56 The attach() and detach() entry points are used to create and destroy
57 "instances" of the driver, where each instance represents everything
58 needed to manage one actual PCMCIA card.
61 static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
64 /*======================================================================
66 avma1cs_attach() creates an "instance" of the driver, allocating
67 local data structures for one device. The device is registered
70 The dev_link structure is initialized, but we don't actually
71 configure the card at this point -- we wait until we receive a
74 ======================================================================*/
76 static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
78 dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
80 /* The io structure describes IO port mapping */
81 p_dev->resource[0]->end = 16;
82 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
83 p_dev->resource[1]->end = 16;
84 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_16;
86 /* General socket configuration */
87 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
88 p_dev->conf.IntType = INT_MEMORY_AND_IO;
89 p_dev->conf.ConfigIndex = 1;
90 p_dev->conf.Present = PRESENT_OPTION;
92 return avma1cs_config(p_dev);
93 } /* avma1cs_attach */
95 /*======================================================================
97 This deletes a driver "instance". The device is de-registered
98 with Card Services. If it has been released, all local data
99 structures are freed. Otherwise, the structures will be freed
100 when the device is released.
102 ======================================================================*/
104 static void __devexit avma1cs_detach(struct pcmcia_device *link)
106 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
107 avma1cs_release(link);
109 } /* avma1cs_detach */
111 /*======================================================================
113 avma1cs_config() is scheduled to run after a CARD_INSERTION event
114 is received, to configure the PCMCIA socket, and to make the
115 ethernet device available to the system.
117 ======================================================================*/
119 static int avma1cs_configcheck(struct pcmcia_device *p_dev,
120 cistpl_cftable_entry_t *cf,
121 cistpl_cftable_entry_t *dflt,
125 if (cf->io.nwin <= 0)
128 p_dev->resource[0]->start = cf->io.win[0].base;
129 p_dev->resource[0]->end = cf->io.win[0].len;
131 return pcmcia_request_io(p_dev);
135 static int __devinit avma1cs_config(struct pcmcia_device *link)
142 dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
145 if (link->prod_id[1])
146 strlcpy(devname, link->prod_id[1], sizeof(devname));
148 if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
153 * allocate an interrupt line
157 pcmcia_disable_device(link);
162 * configure the PCMCIA socket
164 i = pcmcia_request_configuration(link, &link->conf);
166 pcmcia_disable_device(link);
172 /* If any step failed, release any partially configured state */
174 avma1cs_release(link);
178 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
179 (unsigned int) link->resource[0]->start, link->irq);
181 icard.para[0] = link->irq;
182 icard.para[1] = link->resource[0]->start;
183 icard.protocol = isdnprot;
184 icard.typ = ISDN_CTYPE_A1_PCMCIA;
186 i = hisax_init_pcmcia(link, &busy, &icard);
188 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 "
189 "PCMCIA %d at i/o %#x\n", i,
190 (unsigned int) link->resource[0]->start);
191 avma1cs_release(link);
194 link->priv = (void *) (unsigned long) i;
197 } /* avma1cs_config */
199 /*======================================================================
201 After a card is removed, avma1cs_release() will unregister the net
202 device, and release the PCMCIA configuration. If the device is
203 still open, this will be postponed until it is closed.
205 ======================================================================*/
207 static void avma1cs_release(struct pcmcia_device *link)
209 unsigned long minor = (unsigned long) link->priv;
211 dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
213 /* now unregister function with hisax */
214 HiSax_closecard(minor);
216 pcmcia_disable_device(link);
217 } /* avma1cs_release */
220 static struct pcmcia_device_id avma1cs_ids[] = {
221 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
222 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
225 MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
227 static struct pcmcia_driver avma1cs_driver = {
228 .owner = THIS_MODULE,
232 .probe = avma1cs_probe,
233 .remove = __devexit_p(avma1cs_detach),
234 .id_table = avma1cs_ids,
237 /*====================================================================*/
239 static int __init init_avma1_cs(void)
241 return(pcmcia_register_driver(&avma1cs_driver));
244 static void __exit exit_avma1_cs(void)
246 pcmcia_unregister_driver(&avma1cs_driver);
249 module_init(init_avma1_cs);
250 module_exit(exit_avma1_cs);