blob: 2f2b0005f07b79dd7a8c759a30a719f13e5093f3 [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/cistpl.h>
24#include <pcmcia/ds.h>
25#include "hisax_cfg.h"
26
27MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for AVM A1/Fritz!PCMCIA cards");
28MODULE_AUTHOR("Carsten Paeth");
29MODULE_LICENSE("GPL");
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/*====================================================================*/
33
34/* Parameters that can be set with 'insmod' */
35
36static int isdnprot = 2;
37
38module_param(isdnprot, int, 0);
39
40/*====================================================================*/
41
42/*
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
48 handler.
49*/
50
Hennea4658702010-03-25 12:05:31 +000051static int avma1cs_config(struct pcmcia_device *link) __devinit ;
Dominik Brodowskifba395e2006-03-31 17:21:06 +020052static void avma1cs_release(struct pcmcia_device *link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*
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.
58*/
59
Hennea4658702010-03-25 12:05:31 +000060static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*======================================================================
64
65 avma1cs_attach() creates an "instance" of the driver, allocating
66 local data structures for one device. The device is registered
67 with Card Services.
68
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
71 card insertion event.
72
73======================================================================*/
74
Hennea4658702010-03-25 12:05:31 +000075static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Dominik Brodowskie773cfe2009-10-24 15:50:13 +020077 dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /* The io structure describes IO port mapping */
Dominik Brodowski90abdc32010-07-24 17:23:51 +020080 p_dev->resource[0]->end = 16;
81 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
82 p_dev->resource[1]->end = 16;
83 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_16;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 /* General socket configuration */
Dominik Brodowski1ac71e52010-07-29 19:27:09 +020086 p_dev->config_flags |= CONF_ENABLE_IRQ;
Dominik Brodowski7feabb62010-07-29 18:35:47 +020087 p_dev->config_index = 1;
88 p_dev->config_regs = PRESENT_OPTION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020090 return avma1cs_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091} /* avma1cs_attach */
92
93/*======================================================================
94
95 This deletes a driver "instance". The device is de-registered
96 with Card Services. If it has been released, all local data
97 structures are freed. Otherwise, the structures will be freed
98 when the device is released.
99
100======================================================================*/
101
Hennea4658702010-03-25 12:05:31 +0000102static void __devexit avma1cs_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Dominik Brodowskie773cfe2009-10-24 15:50:13 +0200104 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100105 avma1cs_release(link);
106 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107} /* avma1cs_detach */
108
109/*======================================================================
110
111 avma1cs_config() is scheduled to run after a CARD_INSERTION event
112 is received, to configure the PCMCIA socket, and to make the
113 ethernet device available to the system.
114
115======================================================================*/
116
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200117static int avma1cs_configcheck(struct pcmcia_device *p_dev,
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200118 cistpl_cftable_entry_t *cf,
119 cistpl_cftable_entry_t *dflt,
120 void *priv_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200122 if (cf->io.nwin <= 0)
123 return -ENODEV;
124
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200125 p_dev->resource[0]->start = cf->io.win[0].base;
126 p_dev->resource[0]->end = cf->io.win[0].len;
127 p_dev->io_lines = 5;
128 return pcmcia_request_io(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Hennea4658702010-03-25 12:05:31 +0000132static int __devinit avma1cs_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Dominik Brodowskieb141202010-03-07 12:21:16 +0100134 int i = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 char devname[128];
136 IsdnCard_t icard;
137 int busy = 0;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200138
Dominik Brodowskie773cfe2009-10-24 15:50:13 +0200139 dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200141 devname[0] = 0;
142 if (link->prod_id[1])
143 strlcpy(devname, link->prod_id[1], sizeof(devname));
144
145 if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
146 return -ENODEV;
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 /*
150 * allocate an interrupt line
151 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100152 if (!link->irq) {
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100153 /* undo */
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200154 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 break;
156 }
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 /*
159 * configure the PCMCIA socket
160 */
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200161 i = pcmcia_enable_device(link);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200162 if (i != 0) {
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200163 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 break;
165 }
166
167 } while (0);
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 /* If any step failed, release any partially configured state */
170 if (i != 0) {
171 avma1cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200172 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
175 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200176 (unsigned int) link->resource[0]->start, link->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Dominik Brodowskieb141202010-03-07 12:21:16 +0100178 icard.para[0] = link->irq;
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200179 icard.para[1] = link->resource[0]->start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 icard.protocol = isdnprot;
181 icard.typ = ISDN_CTYPE_A1_PCMCIA;
182
183 i = hisax_init_pcmcia(link, &busy, &icard);
184 if (i < 0) {
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200185 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 "
186 "PCMCIA %d at i/o %#x\n", i,
187 (unsigned int) link->resource[0]->start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 avma1cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200189 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100191 link->priv = (void *) (unsigned long) i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194} /* avma1cs_config */
195
196/*======================================================================
197
198 After a card is removed, avma1cs_release() will unregister the net
199 device, and release the PCMCIA configuration. If the device is
200 still open, this will be postponed until it is closed.
201
202======================================================================*/
203
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200204static void avma1cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100206 unsigned long minor = (unsigned long) link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Dominik Brodowskie773cfe2009-10-24 15:50:13 +0200208 dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Dominik Brodowski5f2a71f2006-01-15 09:32:39 +0100210 /* now unregister function with hisax */
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100211 HiSax_closecard(minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200213 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214} /* avma1cs_release */
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Dominik Brodowskic594c122005-06-27 16:28:34 -0700217static struct pcmcia_device_id avma1cs_ids[] = {
218 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
219 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
220 PCMCIA_DEVICE_NULL
221};
222MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224static struct pcmcia_driver avma1cs_driver = {
225 .owner = THIS_MODULE,
226 .drv = {
227 .name = "avma1_cs",
228 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200229 .probe = avma1cs_probe,
Hennea4658702010-03-25 12:05:31 +0000230 .remove = __devexit_p(avma1cs_detach),
Dominik Brodowskic594c122005-06-27 16:28:34 -0700231 .id_table = avma1cs_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234/*====================================================================*/
235
236static int __init init_avma1_cs(void)
237{
238 return(pcmcia_register_driver(&avma1cs_driver));
239}
240
241static void __exit exit_avma1_cs(void)
242{
243 pcmcia_unregister_driver(&avma1cs_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
246module_init(init_avma1_cs);
247module_exit(exit_avma1_cs);