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/cistpl.h>
24 #include <pcmcia/ds.h>
25 #include "hisax_cfg.h"
27 MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards");
28 MODULE_AUTHOR("Carsten Paeth");
29 MODULE_LICENSE("GPL");
32 /*====================================================================*/
34 /* Parameters that can be set with 'insmod' */
36 static int isdnprot = 2;
38 module_param(isdnprot, int, 0);
40 /*====================================================================*/
43 The event() function is this driver's Card Services event handler.
44 It will be called by Card Services when an appropriate card status
45 event is received. The config() and release() entry points are
46 used to configure or release a socket, in response to card insertion
47 and ejection events. They are invoked from the skeleton event
51 static int avma1cs_config(struct pcmcia_device *link) __devinit ;
52 static void avma1cs_release(struct pcmcia_device *link);
55 The attach() and detach() entry points are used to create and destroy
56 "instances" of the driver, where each instance represents everything
57 needed to manage one actual PCMCIA card.
60 static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
63 /*======================================================================
65 avma1cs_attach() creates an "instance" of the driver, allocating
66 local data structures for one device. The device is registered
69 The dev_link structure is initialized, but we don't actually
70 configure the card at this point -- we wait until we receive a
73 ======================================================================*/
75 static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
77 dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
79 /* General socket configuration */
80 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
81 p_dev->config_index = 1;
82 p_dev->config_regs = PRESENT_OPTION;
84 return avma1cs_config(p_dev);
85 } /* avma1cs_attach */
87 /*======================================================================
89 This deletes a driver "instance". The device is de-registered
90 with Card Services. If it has been released, all local data
91 structures are freed. Otherwise, the structures will be freed
92 when the device is released.
94 ======================================================================*/
96 static void __devexit avma1cs_detach(struct pcmcia_device *link)
98 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
99 avma1cs_release(link);
101 } /* avma1cs_detach */
103 /*======================================================================
105 avma1cs_config() is scheduled to run after a CARD_INSERTION event
106 is received, to configure the PCMCIA socket, and to make the
107 ethernet device available to the system.
109 ======================================================================*/
111 static int avma1cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
113 p_dev->resource[0]->end = 16;
114 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
115 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
118 return pcmcia_request_io(p_dev);
122 static int __devinit avma1cs_config(struct pcmcia_device *link)
129 dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
132 if (link->prod_id[1])
133 strlcpy(devname, link->prod_id[1], sizeof(devname));
135 if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
140 * allocate an interrupt line
144 pcmcia_disable_device(link);
149 * configure the PCMCIA socket
151 i = pcmcia_enable_device(link);
153 pcmcia_disable_device(link);
159 /* If any step failed, release any partially configured state */
161 avma1cs_release(link);
165 icard.para[0] = link->irq;
166 icard.para[1] = link->resource[0]->start;
167 icard.protocol = isdnprot;
168 icard.typ = ISDN_CTYPE_A1_PCMCIA;
170 i = hisax_init_pcmcia(link, &busy, &icard);
172 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 "
173 "PCMCIA %d at i/o %#x\n", i,
174 (unsigned int) link->resource[0]->start);
175 avma1cs_release(link);
178 link->priv = (void *) (unsigned long) i;
181 } /* avma1cs_config */
183 /*======================================================================
185 After a card is removed, avma1cs_release() will unregister the net
186 device, and release the PCMCIA configuration. If the device is
187 still open, this will be postponed until it is closed.
189 ======================================================================*/
191 static void avma1cs_release(struct pcmcia_device *link)
193 unsigned long minor = (unsigned long) link->priv;
195 dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
197 /* now unregister function with hisax */
198 HiSax_closecard(minor);
200 pcmcia_disable_device(link);
201 } /* avma1cs_release */
204 static struct pcmcia_device_id avma1cs_ids[] = {
205 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
206 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
209 MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
211 static struct pcmcia_driver avma1cs_driver = {
212 .owner = THIS_MODULE,
214 .probe = avma1cs_probe,
215 .remove = __devexit_p(avma1cs_detach),
216 .id_table = avma1cs_ids,
219 /*====================================================================*/
221 static int __init init_avma1_cs(void)
223 return pcmcia_register_driver(&avma1cs_driver);
226 static void __exit exit_avma1_cs(void)
228 pcmcia_unregister_driver(&avma1cs_driver);
231 module_init(init_avma1_cs);
232 module_exit(exit_avma1_cs);