blob: a80a7617f16fb19ba72483983959c3ffe1fe96a1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * PCMCIA client driver for AVM A1 / Fritz!PCMCIA
3 *
4 * Author Carsten Paeth
5 * Copyright 1998-2001 by Carsten Paeth <calle@calle.in-berlin.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.
9 *
10 */
11
12#include <linux/module.h>
13
14
15#include <linux/kernel.h>
16#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/ptrace.h>
18#include <linux/slab.h>
19#include <linux/string.h>
20#include <asm/io.h>
21#include <asm/system.h>
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <pcmcia/cs_types.h>
24#include <pcmcia/cs.h>
25#include <pcmcia/cistpl.h>
26#include <pcmcia/ds.h>
27#include "hisax_cfg.h"
28
29MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards");
30MODULE_AUTHOR("Carsten Paeth");
31MODULE_LICENSE("GPL");
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34/*====================================================================*/
35
36/* Parameters that can be set with 'insmod' */
37
38static int isdnprot = 2;
39
40module_param(isdnprot, int, 0);
41
42/*====================================================================*/
43
44/*
45 The event() function is this driver's Card Services event handler.
46 It will be called by Card Services when an appropriate card status
47 event is received. The config() and release() entry points are
48 used to configure or release a socket, in response to card insertion
49 and ejection events. They are invoked from the skeleton event
50 handler.
51*/
52
Hennea4658702010-03-25 12:05:31 +000053static int avma1cs_config(struct pcmcia_device *link) __devinit ;
Dominik Brodowskifba395e2006-03-31 17:21:06 +020054static void avma1cs_release(struct pcmcia_device *link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/*
57 The attach() and detach() entry points are used to create and destroy
58 "instances" of the driver, where each instance represents everything
59 needed to manage one actual PCMCIA card.
60*/
61
Hennea4658702010-03-25 12:05:31 +000062static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/*======================================================================
66
67 avma1cs_attach() creates an "instance" of the driver, allocating
68 local data structures for one device. The device is registered
69 with Card Services.
70
71 The dev_link structure is initialized, but we don't actually
72 configure the card at this point -- we wait until we receive a
73 card insertion event.
74
75======================================================================*/
76
Hennea4658702010-03-25 12:05:31 +000077static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Dominik Brodowskie773cfe2009-10-24 15:50:13 +020079 dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 /* The io structure describes IO port mapping */
Dominik Brodowskifd238232006-03-05 10:45:09 +010082 p_dev->io.NumPorts1 = 16;
83 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
84 p_dev->io.NumPorts2 = 16;
85 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
86 p_dev->io.IOAddrLines = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* General socket configuration */
Dominik Brodowskifd238232006-03-05 10:45:09 +010089 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
90 p_dev->conf.IntType = INT_MEMORY_AND_IO;
91 p_dev->conf.ConfigIndex = 1;
92 p_dev->conf.Present = PRESENT_OPTION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020094 return avma1cs_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095} /* avma1cs_attach */
96
97/*======================================================================
98
99 This deletes a driver "instance". The device is de-registered
100 with Card Services. If it has been released, all local data
101 structures are freed. Otherwise, the structures will be freed
102 when the device is released.
103
104======================================================================*/
105
Hennea4658702010-03-25 12:05:31 +0000106static void __devexit avma1cs_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Dominik Brodowskie773cfe2009-10-24 15:50:13 +0200108 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100109 avma1cs_release(link);
110 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111} /* avma1cs_detach */
112
113/*======================================================================
114
115 avma1cs_config() is scheduled to run after a CARD_INSERTION event
116 is received, to configure the PCMCIA socket, and to make the
117 ethernet device available to the system.
118
119======================================================================*/
120
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200121static int avma1cs_configcheck(struct pcmcia_device *p_dev,
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200122 cistpl_cftable_entry_t *cf,
123 cistpl_cftable_entry_t *dflt,
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200124 unsigned int vcc,
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200125 void *priv_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200127 if (cf->io.nwin <= 0)
128 return -ENODEV;
129
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200130 p_dev->io.BasePort1 = cf->io.win[0].base;
131 p_dev->io.NumPorts1 = cf->io.win[0].len;
132 p_dev->io.NumPorts2 = 0;
133 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
134 p_dev->io.BasePort1,
135 p_dev->io.BasePort1+p_dev->io.NumPorts1-1);
136 return pcmcia_request_io(p_dev, &p_dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Hennea4658702010-03-25 12:05:31 +0000140static int __devinit avma1cs_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Dominik Brodowskieb141202010-03-07 12:21:16 +0100142 int i = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 char devname[128];
144 IsdnCard_t icard;
145 int busy = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200146
Dominik Brodowskie773cfe2009-10-24 15:50:13 +0200147 dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200149 devname[0] = 0;
150 if (link->prod_id[1])
151 strlcpy(devname, link->prod_id[1], sizeof(devname));
152
153 if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
154 return -ENODEV;
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /*
158 * allocate an interrupt line
159 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100160 if (!link->irq) {
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100161 /* undo */
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200162 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 break;
164 }
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /*
167 * configure the PCMCIA socket
168 */
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200169 i = pcmcia_request_configuration(link, &link->conf);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200170 if (i != 0) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200171 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 break;
173 }
174
175 } while (0);
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /* If any step failed, release any partially configured state */
178 if (i != 0) {
179 avma1cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200180 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
182
183 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
Dominik Brodowskieb141202010-03-07 12:21:16 +0100184 link->io.BasePort1, link->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Dominik Brodowskieb141202010-03-07 12:21:16 +0100186 icard.para[0] = link->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 icard.para[1] = link->io.BasePort1;
188 icard.protocol = isdnprot;
189 icard.typ = ISDN_CTYPE_A1_PCMCIA;
190
191 i = hisax_init_pcmcia(link, &busy, &icard);
192 if (i < 0) {
193 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1);
194 avma1cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200195 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100197 link->priv = (void *) (unsigned long) i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200199 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200} /* avma1cs_config */
201
202/*======================================================================
203
204 After a card is removed, avma1cs_release() will unregister the net
205 device, and release the PCMCIA configuration. If the device is
206 still open, this will be postponed until it is closed.
207
208======================================================================*/
209
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200210static void avma1cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100212 unsigned long minor = (unsigned long) link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Dominik Brodowskie773cfe2009-10-24 15:50:13 +0200214 dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100216 /* now unregister function with hisax */
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100217 HiSax_closecard(minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200219 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220} /* avma1cs_release */
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Dominik Brodowskic594c122005-06-27 16:28:34 -0700223static struct pcmcia_device_id avma1cs_ids[] = {
224 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
225 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
226 PCMCIA_DEVICE_NULL
227};
228MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static struct pcmcia_driver avma1cs_driver = {
231 .owner = THIS_MODULE,
232 .drv = {
233 .name = "avma1_cs",
234 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200235 .probe = avma1cs_probe,
Hennea4658702010-03-25 12:05:31 +0000236 .remove = __devexit_p(avma1cs_detach),
Dominik Brodowskic594c122005-06-27 16:28:34 -0700237 .id_table = avma1cs_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238};
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/*====================================================================*/
241
242static int __init init_avma1_cs(void)
243{
244 return(pcmcia_register_driver(&avma1cs_driver));
245}
246
247static void __exit exit_avma1_cs(void)
248{
249 pcmcia_unregister_driver(&avma1cs_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
252module_init(init_avma1_cs);
253module_exit(exit_avma1_cs);