pcmcia: convert pcmcia_request_configuration to pcmcia_enable_device
[deliverable/linux.git] / drivers / isdn / hisax / avma1_cs.c
CommitLineData
1da177e4
LT
1/*
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>
1da177e4
LT
17#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
1da177e4
LT
23#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
1da177e4
LT
31
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
a465870a 51static int avma1cs_config(struct pcmcia_device *link) __devinit ;
fba395ee 52static void avma1cs_release(struct pcmcia_device *link);
1da177e4
LT
53
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
a465870a 60static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
1da177e4 61
1da177e4 62
1da177e4
LT
63/*======================================================================
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
a465870a 75static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
1da177e4 76{
e773cfe1 77 dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
1da177e4 78
1da177e4 79 /* The io structure describes IO port mapping */
90abdc3b
DB
80 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;
1da177e4 84
1da177e4 85 /* General socket configuration */
1ac71e5a 86 p_dev->config_flags |= CONF_ENABLE_IRQ;
7feabb64
DB
87 p_dev->config_index = 1;
88 p_dev->config_regs = PRESENT_OPTION;
f8cfa618 89
15b99ac1 90 return avma1cs_config(p_dev);
1da177e4
LT
91} /* 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
a465870a 102static void __devexit avma1cs_detach(struct pcmcia_device *link)
1da177e4 103{
e773cfe1 104 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
e2d40963
DB
105 avma1cs_release(link);
106 kfree(link->priv);
1da177e4
LT
107} /* 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
5fcd4da0 117static int avma1cs_configcheck(struct pcmcia_device *p_dev,
8e2fc39d
DB
118 cistpl_cftable_entry_t *cf,
119 cistpl_cftable_entry_t *dflt,
ad913c11 120 unsigned int vcc,
8e2fc39d 121 void *priv_data)
1da177e4 122{
5fcd4da0
DB
123 if (cf->io.nwin <= 0)
124 return -ENODEV;
125
90abdc3b
DB
126 p_dev->resource[0]->start = cf->io.win[0].base;
127 p_dev->resource[0]->end = cf->io.win[0].len;
128 p_dev->io_lines = 5;
129 return pcmcia_request_io(p_dev);
1da177e4
LT
130}
131
1da177e4 132
a465870a 133static int __devinit avma1cs_config(struct pcmcia_device *link)
1da177e4 134{
eb14120f 135 int i = -1;
1da177e4
LT
136 char devname[128];
137 IsdnCard_t icard;
138 int busy = 0;
fba395ee 139
e773cfe1 140 dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
1da177e4 141
5fcd4da0
DB
142 devname[0] = 0;
143 if (link->prod_id[1])
144 strlcpy(devname, link->prod_id[1], sizeof(devname));
a9606fd3 145
5fcd4da0
DB
146 if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
147 return -ENODEV;
1da177e4 148
5fcd4da0 149 do {
1da177e4
LT
150 /*
151 * allocate an interrupt line
152 */
eb14120f 153 if (!link->irq) {
50db3fdb 154 /* undo */
fba395ee 155 pcmcia_disable_device(link);
1da177e4
LT
156 break;
157 }
50db3fdb 158
1da177e4
LT
159 /*
160 * configure the PCMCIA socket
161 */
1ac71e5a 162 i = pcmcia_enable_device(link);
4c89e88b 163 if (i != 0) {
fba395ee 164 pcmcia_disable_device(link);
1da177e4
LT
165 break;
166 }
167
168 } while (0);
169
1da177e4
LT
170 /* If any step failed, release any partially configured state */
171 if (i != 0) {
172 avma1cs_release(link);
15b99ac1 173 return -ENODEV;
1da177e4
LT
174 }
175
176 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
9a017a91 177 (unsigned int) link->resource[0]->start, link->irq);
1da177e4 178
eb14120f 179 icard.para[0] = link->irq;
9a017a91 180 icard.para[1] = link->resource[0]->start;
1da177e4
LT
181 icard.protocol = isdnprot;
182 icard.typ = ISDN_CTYPE_A1_PCMCIA;
183
184 i = hisax_init_pcmcia(link, &busy, &icard);
185 if (i < 0) {
9a017a91
DB
186 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 "
187 "PCMCIA %d at i/o %#x\n", i,
188 (unsigned int) link->resource[0]->start);
1da177e4 189 avma1cs_release(link);
15b99ac1 190 return -ENODEV;
1da177e4 191 }
b498ada6 192 link->priv = (void *) (unsigned long) i;
1da177e4 193
15b99ac1 194 return 0;
1da177e4
LT
195} /* avma1cs_config */
196
197/*======================================================================
198
199 After a card is removed, avma1cs_release() will unregister the net
200 device, and release the PCMCIA configuration. If the device is
201 still open, this will be postponed until it is closed.
202
203======================================================================*/
204
fba395ee 205static void avma1cs_release(struct pcmcia_device *link)
1da177e4 206{
b498ada6 207 unsigned long minor = (unsigned long) link->priv;
1da177e4 208
e773cfe1 209 dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
1da177e4 210
5f2a71fc 211 /* now unregister function with hisax */
b498ada6 212 HiSax_closecard(minor);
1da177e4 213
fba395ee 214 pcmcia_disable_device(link);
1da177e4
LT
215} /* avma1cs_release */
216
1da177e4 217
c594c12c
DB
218static struct pcmcia_device_id avma1cs_ids[] = {
219 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
220 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
221 PCMCIA_DEVICE_NULL
222};
223MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
224
1da177e4
LT
225static struct pcmcia_driver avma1cs_driver = {
226 .owner = THIS_MODULE,
227 .drv = {
228 .name = "avma1_cs",
229 },
15b99ac1 230 .probe = avma1cs_probe,
a465870a 231 .remove = __devexit_p(avma1cs_detach),
c594c12c 232 .id_table = avma1cs_ids,
1da177e4 233};
8661bb5b 234
1da177e4
LT
235/*====================================================================*/
236
237static int __init init_avma1_cs(void)
238{
239 return(pcmcia_register_driver(&avma1cs_driver));
240}
241
242static void __exit exit_avma1_cs(void)
243{
244 pcmcia_unregister_driver(&avma1cs_driver);
1da177e4
LT
245}
246
247module_init(init_avma1_cs);
248module_exit(exit_avma1_cs);
This page took 0.594986 seconds and 5 git commands to generate.