blob: d9ea192c4001ed9e315d21bac96b2ab37361376f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * cs.c -- Kernel Card Services - core services
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * The initial developer of the original code is David A. Hinds
9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 *
12 * (C) 1999 David A. Hinds
13 */
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/string.h>
20#include <linux/major.h>
21#include <linux/errno.h>
22#include <linux/slab.h>
23#include <linux/mm.h>
24#include <linux/interrupt.h>
25#include <linux/timer.h>
26#include <linux/ioport.h>
27#include <linux/delay.h>
28#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/device.h>
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -050030#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080031#include <linux/freezer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/system.h>
33#include <asm/irq.h>
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <pcmcia/ss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <pcmcia/cistpl.h>
37#include <pcmcia/cisreg.h>
38#include <pcmcia/ds.h>
39#include "cs_internal.h"
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/* Module parameters */
43
44MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
Dominik Brodowski33519dd2005-06-27 16:28:53 -070045MODULE_DESCRIPTION("Linux Kernel Card Services");
Linus Torvalds1da177e2005-04-16 15:20:36 -070046MODULE_LICENSE("GPL");
47
48#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
49
50INT_MODULE_PARM(setup_delay, 10); /* centiseconds */
51INT_MODULE_PARM(resume_delay, 20); /* centiseconds */
52INT_MODULE_PARM(shutdown_delay, 3); /* centiseconds */
53INT_MODULE_PARM(vcc_settle, 40); /* centiseconds */
54INT_MODULE_PARM(reset_time, 10); /* usecs */
55INT_MODULE_PARM(unreset_delay, 10); /* centiseconds */
56INT_MODULE_PARM(unreset_check, 10); /* centiseconds */
57INT_MODULE_PARM(unreset_limit, 30); /* unreset_check's */
58
59/* Access speed for attribute memory windows */
60INT_MODULE_PARM(cis_speed, 300); /* ns */
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63socket_state_t dead_socket = {
64 .csc_mask = SS_DETECT,
65};
Dominik Brodowski33519dd2005-06-27 16:28:53 -070066EXPORT_SYMBOL(dead_socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68
69/* List of all sockets, protected by a rwsem */
70LIST_HEAD(pcmcia_socket_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071EXPORT_SYMBOL(pcmcia_socket_list);
Dominik Brodowski33519dd2005-06-27 16:28:53 -070072
73DECLARE_RWSEM(pcmcia_socket_list_rwsem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
75
76
Dominik Brodowski9fea84f2009-12-07 22:11:45 +010077struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020079 struct device *dev = get_device(&skt->dev);
80 if (!dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return NULL;
Dominik Brodowski593f010b2010-01-02 22:59:15 +010082 return dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84EXPORT_SYMBOL(pcmcia_get_socket);
85
86
87void pcmcia_put_socket(struct pcmcia_socket *skt)
88{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020089 put_device(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91EXPORT_SYMBOL(pcmcia_put_socket);
92
93
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020094static void pcmcia_release_socket(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020096 struct pcmcia_socket *socket = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 complete(&socket->socket_released);
99}
100
101static int pccardd(void *__skt);
102
103/**
104 * pcmcia_register_socket - add a new pcmcia socket device
Randy Dunlap78187862007-12-10 15:49:22 -0800105 * @socket: the &socket to register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
107int pcmcia_register_socket(struct pcmcia_socket *socket)
108{
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500109 struct task_struct *tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 int ret;
111
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200112 if (!socket || !socket->ops || !socket->dev.parent || !socket->resource_ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return -EINVAL;
114
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200115 dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 /* try to obtain a socket number [yes, it gets ugly if we
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700118 * register more than 2^sizeof(unsigned int) pcmcia
119 * sockets... but the socket number is deprecated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 * anyways, so I don't care] */
121 down_write(&pcmcia_socket_list_rwsem);
122 if (list_empty(&pcmcia_socket_list))
123 socket->sock = 0;
124 else {
125 unsigned int found, i = 1;
126 struct pcmcia_socket *tmp;
127 do {
128 found = 1;
129 list_for_each_entry(tmp, &pcmcia_socket_list, socket_list) {
130 if (tmp->sock == i)
131 found = 0;
132 }
133 i++;
134 } while (!found);
135 socket->sock = i - 1;
136 }
137 list_add_tail(&socket->socket_list, &pcmcia_socket_list);
138 up_write(&pcmcia_socket_list_rwsem);
139
Russell King5bc6b682005-07-07 17:59:07 -0700140#ifndef CONFIG_CARDBUS
141 /*
142 * If we do not support Cardbus, ensure that
143 * the Cardbus socket capability is disabled.
144 */
145 socket->features &= ~SS_CAP_CARDBUS;
146#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* set proper values in socket->dev */
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200149 dev_set_drvdata(&socket->dev, socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 socket->dev.class = &pcmcia_socket_class;
Kay Sievers25096982008-11-01 11:46:06 +0100151 dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* base address = 0, map = 0 */
154 socket->cis_mem.flags = 0;
155 socket->cis_mem.speed = cis_speed;
156
157 INIT_LIST_HEAD(&socket->cis_cache);
158
159 init_completion(&socket->socket_released);
160 init_completion(&socket->thread_done);
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100161 mutex_init(&socket->skt_mutex);
Dominik Brodowski6b8e0872010-01-12 21:42:51 +0100162 mutex_init(&socket->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 spin_lock_init(&socket->thread_lock);
164
Dominik Brodowskib1769452008-11-09 21:47:47 +0100165 if (socket->resource_ops->init) {
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100166 mutex_lock(&socket->ops_mutex);
Dominik Brodowskib1769452008-11-09 21:47:47 +0100167 ret = socket->resource_ops->init(socket);
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100168 mutex_unlock(&socket->ops_mutex);
Dominik Brodowskib1769452008-11-09 21:47:47 +0100169 if (ret)
170 goto err;
171 }
172
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500173 tsk = kthread_run(pccardd, socket, "pccardd");
174 if (IS_ERR(tsk)) {
175 ret = PTR_ERR(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 goto err;
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 wait_for_completion(&socket->thread_done);
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500180 if (!socket->thread) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200181 dev_printk(KERN_WARNING, &socket->dev,
182 "PCMCIA: warning: socket thread did not start\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return -EIO;
184 }
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 pcmcia_parse_events(socket, SS_DETECT);
187
Dominik Brodowski638bba52009-11-07 12:26:17 +0100188 /*
189 * Let's try to get the PCMCIA module for 16-bit PCMCIA support.
190 * If it fails, it doesn't matter -- we still have 32-bit CardBus
191 * support to offer, so this is not a failure mode.
192 */
193 request_module_nowait("pcmcia");
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 return 0;
196
197 err:
198 down_write(&pcmcia_socket_list_rwsem);
199 list_del(&socket->socket_list);
200 up_write(&pcmcia_socket_list_rwsem);
201 return ret;
202} /* pcmcia_register_socket */
203EXPORT_SYMBOL(pcmcia_register_socket);
204
205
206/**
207 * pcmcia_unregister_socket - remove a pcmcia socket device
Randy Dunlap78187862007-12-10 15:49:22 -0800208 * @socket: the &socket to unregister
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 */
210void pcmcia_unregister_socket(struct pcmcia_socket *socket)
211{
212 if (!socket)
213 return;
214
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200215 dev_dbg(&socket->dev, "pcmcia_unregister_socket(0x%p)\n", socket->ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Christoph Hellwig0b402092007-04-22 13:55:36 +0100217 if (socket->thread)
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500218 kthread_stop(socket->thread);
Christoph Hellwig0b402092007-04-22 13:55:36 +0100219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 /* remove from our own list */
221 down_write(&pcmcia_socket_list_rwsem);
222 list_del(&socket->socket_list);
223 up_write(&pcmcia_socket_list_rwsem);
224
225 /* wait for sysfs to drop all references */
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100226 if (socket->resource_ops->exit) {
227 mutex_lock(&socket->ops_mutex);
Dominik Brodowski385ee872010-01-06 11:23:58 +0100228 socket->resource_ops->exit(socket);
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100229 mutex_unlock(&socket->ops_mutex);
230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 wait_for_completion(&socket->socket_released);
232} /* pcmcia_unregister_socket */
233EXPORT_SYMBOL(pcmcia_unregister_socket);
234
235
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100236struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 struct pcmcia_socket *s;
239
240 down_read(&pcmcia_socket_list_rwsem);
241 list_for_each_entry(s, &pcmcia_socket_list, socket_list)
242 if (s->sock == nr) {
243 up_read(&pcmcia_socket_list_rwsem);
244 return s;
245 }
246 up_read(&pcmcia_socket_list_rwsem);
247
248 return NULL;
249
250}
251EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static int socket_reset(struct pcmcia_socket *skt)
254{
255 int status, i;
256
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200257 dev_dbg(&skt->dev, "reset\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 skt->socket.flags |= SS_OUTPUT_ENA | SS_RESET;
260 skt->ops->set_socket(skt, &skt->socket);
261 udelay((long)reset_time);
262
263 skt->socket.flags &= ~SS_RESET;
264 skt->ops->set_socket(skt, &skt->socket);
265
266 msleep(unreset_delay * 10);
267 for (i = 0; i < unreset_limit; i++) {
268 skt->ops->get_status(skt, &status);
269
270 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200271 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273 if (status & SS_READY)
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200274 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 msleep(unreset_check * 10);
277 }
278
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200279 dev_printk(KERN_ERR, &skt->dev, "time out after reset.\n");
Dominik Brodowski85671422008-08-03 11:15:45 +0200280 return -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
Randy Dunlap78187862007-12-10 15:49:22 -0800283/*
Daniel Ritz6e493882005-12-30 15:12:35 +0100284 * socket_setup() and socket_shutdown() are called by the main event handler
285 * when card insertion and removal events are received.
286 * socket_setup() turns on socket power and resets the socket, in two stages.
287 * socket_shutdown() unconfigures a socket and turns off socket power.
288 */
289static void socket_shutdown(struct pcmcia_socket *s)
290{
291 int status;
292
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200293 dev_dbg(&s->dev, "shutdown\n");
Daniel Ritz6e493882005-12-30 15:12:35 +0100294
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200295 if (s->callback)
296 s->callback->remove(s);
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100297
298 mutex_lock(&s->ops_mutex);
Daniel Ritz6e493882005-12-30 15:12:35 +0100299 s->state &= SOCKET_INUSE | SOCKET_PRESENT;
300 msleep(shutdown_delay * 10);
301 s->state &= SOCKET_INUSE;
302
303 /* Blank out the socket state */
304 s->socket = dead_socket;
305 s->ops->init(s);
306 s->ops->set_socket(s, &s->socket);
Daniel Ritz6e493882005-12-30 15:12:35 +0100307 s->lock_count = 0;
Dominik Brodowski904e3772010-01-02 12:28:04 +0100308 kfree(s->fake_cis);
309 s->fake_cis = NULL;
Dominik Brodowskic3bfc962010-01-18 08:43:39 +0100310 s->functions = 0;
311
312 /* From here on we can be sure that only we (that is, the
313 * pccardd thread) accesses this socket, and all (16-bit)
314 * PCMCIA interactions are gone. Therefore, release
315 * ops_mutex so that we don't get a sysfs-related lockdep
316 * warning.
317 */
318 mutex_unlock(&s->ops_mutex);
319
Daniel Ritz6e493882005-12-30 15:12:35 +0100320#ifdef CONFIG_CARDBUS
321 cb_free(s);
322#endif
Daniel Ritz6e493882005-12-30 15:12:35 +0100323
Daniel Ritzafb2c162007-07-31 00:38:08 -0700324 /* give socket some time to power down */
325 msleep(100);
326
Daniel Ritz6e493882005-12-30 15:12:35 +0100327 s->ops->get_status(s, &status);
328 if (status & SS_POWERON) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200329 dev_printk(KERN_ERR, &s->dev,
330 "*** DANGER *** unable to remove socket power\n");
Daniel Ritz6e493882005-12-30 15:12:35 +0100331 }
332
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100333 s->state &= ~SOCKET_INUSE;
Daniel Ritz6e493882005-12-30 15:12:35 +0100334}
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
337{
338 int status, i;
339
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200340 dev_dbg(&skt->dev, "setup\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 skt->ops->get_status(skt, &status);
343 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200344 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 msleep(initial_delay * 10);
347
348 for (i = 0; i < 100; i++) {
349 skt->ops->get_status(skt, &status);
350 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200351 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 if (!(status & SS_PENDING))
354 break;
355
356 msleep(100);
357 }
358
359 if (status & SS_PENDING) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200360 dev_printk(KERN_ERR, &skt->dev,
361 "voltage interrogation timed out.\n");
Dominik Brodowski85671422008-08-03 11:15:45 +0200362 return -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364
365 if (status & SS_CARDBUS) {
Russell King5bc6b682005-07-07 17:59:07 -0700366 if (!(skt->features & SS_CAP_CARDBUS)) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200367 dev_printk(KERN_ERR, &skt->dev,
368 "cardbus cards are not supported.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200369 return -EINVAL;
Russell King5bc6b682005-07-07 17:59:07 -0700370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 skt->state |= SOCKET_CARDBUS;
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100372 } else
373 skt->state &= ~SOCKET_CARDBUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 /*
376 * Decode the card voltage requirements, and apply power to the card.
377 */
378 if (status & SS_3VCARD)
379 skt->socket.Vcc = skt->socket.Vpp = 33;
380 else if (!(status & SS_XVCARD))
381 skt->socket.Vcc = skt->socket.Vpp = 50;
382 else {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200383 dev_printk(KERN_ERR, &skt->dev, "unsupported voltage key.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200384 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 }
Daniel Ritzfa912bc2005-06-23 00:10:12 -0700386
387 if (skt->power_hook)
388 skt->power_hook(skt, HOOK_POWER_PRE);
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 skt->socket.flags = 0;
391 skt->ops->set_socket(skt, &skt->socket);
392
393 /*
394 * Wait "vcc_settle" for the supply to stabilise.
395 */
396 msleep(vcc_settle * 10);
397
398 skt->ops->get_status(skt, &status);
399 if (!(status & SS_POWERON)) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200400 dev_printk(KERN_ERR, &skt->dev, "unable to apply power.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200401 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403
Daniel Ritzfa912bc2005-06-23 00:10:12 -0700404 status = socket_reset(skt);
405
406 if (skt->power_hook)
407 skt->power_hook(skt, HOOK_POWER_POST);
408
409 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
412/*
413 * Handle card insertion. Setup the socket, reset the card,
414 * and then tell the rest of PCMCIA that a card is present.
415 */
416static int socket_insert(struct pcmcia_socket *skt)
417{
418 int ret;
419
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200420 dev_dbg(&skt->dev, "insert\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100422 mutex_lock(&skt->ops_mutex);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100423 if (skt->state & SOCKET_INUSE) {
424 mutex_unlock(&skt->ops_mutex);
425 return -EINVAL;
426 }
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100427 skt->state |= SOCKET_INUSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 ret = socket_setup(skt, setup_delay);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200430 if (ret == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 skt->state |= SOCKET_PRESENT;
Dominik Brodowski807277c2005-11-12 23:34:06 +0100432
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200433 dev_printk(KERN_NOTICE, &skt->dev,
434 "pccard: %s card inserted into slot %d\n",
435 (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA",
436 skt->sock);
Dominik Brodowski807277c2005-11-12 23:34:06 +0100437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#ifdef CONFIG_CARDBUS
439 if (skt->state & SOCKET_CARDBUS) {
440 cb_alloc(skt);
441 skt->state |= SOCKET_CARDBUS_CONFIG;
442 }
443#endif
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200444 dev_dbg(&skt->dev, "insert done\n");
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100445 mutex_unlock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200447 if (!(skt->state & SOCKET_CARDBUS) && (skt->callback))
448 skt->callback->add(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 } else {
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100450 mutex_unlock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
453
454 return ret;
455}
456
457static int socket_suspend(struct pcmcia_socket *skt)
458{
459 if (skt->state & SOCKET_SUSPEND)
Dominik Brodowskif9580952008-08-03 11:40:19 +0200460 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100462 mutex_lock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100463 skt->suspended_state = skt->state;
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 skt->socket = dead_socket;
466 skt->ops->set_socket(skt, &skt->socket);
467 if (skt->ops->suspend)
468 skt->ops->suspend(skt);
469 skt->state |= SOCKET_SUSPEND;
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100470 mutex_unlock(&skt->ops_mutex);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200471 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100474static int socket_early_resume(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100476 mutex_lock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 skt->socket = dead_socket;
478 skt->ops->init(skt);
479 skt->ops->set_socket(skt, &skt->socket);
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100480 if (skt->state & SOCKET_PRESENT)
481 skt->resume_status = socket_setup(skt, resume_delay);
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100482 mutex_unlock(&skt->ops_mutex);
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100483 return 0;
484}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100486static int socket_late_resume(struct pcmcia_socket *skt)
487{
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100488 int ret;
489
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100490 mutex_lock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100491 skt->state &= ~SOCKET_SUSPEND;
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100492 mutex_unlock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100493
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100494 if (!(skt->state & SOCKET_PRESENT)) {
495 ret = socket_insert(skt);
496 if (ret == -ENODEV)
497 ret = 0;
498 return ret;
499 }
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100500
501 if (skt->resume_status) {
502 socket_shutdown(skt);
503 return 0;
504 }
505
506 if (skt->suspended_state != skt->state) {
507 dev_dbg(&skt->dev,
508 "suspend state 0x%x != resume state 0x%x\n",
509 skt->suspended_state, skt->state);
510
511 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 return socket_insert(skt);
513 }
514
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100515#ifdef CONFIG_CARDBUS
516 if (skt->state & SOCKET_CARDBUS) {
517 /* We can't be sure the CardBus card is the same
518 * as the one previously inserted. Therefore, remove
519 * and re-add... */
520 cb_free(skt);
521 cb_alloc(skt);
522 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100524#endif
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200525 if (!(skt->state & SOCKET_CARDBUS) && (skt->callback))
526 skt->callback->early_resume(skt);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200527 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528}
529
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100530/*
531 * Resume a socket. If a card is present, verify its CIS against
532 * our cached copy. If they are different, the card has been
533 * replaced, and we need to tell the drivers.
534 */
535static int socket_resume(struct pcmcia_socket *skt)
536{
537 if (!(skt->state & SOCKET_SUSPEND))
538 return -EBUSY;
539
540 socket_early_resume(skt);
541 return socket_late_resume(skt);
542}
543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544static void socket_remove(struct pcmcia_socket *skt)
545{
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200546 dev_printk(KERN_NOTICE, &skt->dev,
547 "pccard: card ejected from slot %d\n", skt->sock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549}
550
551/*
552 * Process a socket card detect status change.
553 *
554 * If we don't have a card already present, delay the detect event for
555 * about 20ms (to be on the safe side) before reading the socket status.
556 *
557 * Some i82365-based systems send multiple SS_DETECT events during card
558 * insertion, and the "card present" status bit seems to bounce. This
559 * will probably be true with GPIO-based card detection systems after
560 * the product has aged.
561 */
562static void socket_detect_change(struct pcmcia_socket *skt)
563{
564 if (!(skt->state & SOCKET_SUSPEND)) {
565 int status;
566
567 if (!(skt->state & SOCKET_PRESENT))
568 msleep(20);
569
570 skt->ops->get_status(skt, &status);
571 if ((skt->state & SOCKET_PRESENT) &&
572 !(status & SS_DETECT))
573 socket_remove(skt);
574 if (!(skt->state & SOCKET_PRESENT) &&
575 (status & SS_DETECT))
576 socket_insert(skt);
577 }
578}
579
580static int pccardd(void *__skt)
581{
582 struct pcmcia_socket *skt = __skt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 int ret;
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 skt->thread = current;
586 skt->socket = dead_socket;
587 skt->ops->init(skt);
588 skt->ops->set_socket(skt, &skt->socket);
589
590 /* register with the device core */
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200591 ret = device_register(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if (ret) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200593 dev_printk(KERN_WARNING, &skt->dev,
594 "PCMCIA: unable to register socket\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 skt->thread = NULL;
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500596 complete(&skt->thread_done);
597 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
David Brownell4356d732008-04-28 01:03:20 -0700599 ret = pccard_sysfs_add_socket(&skt->dev);
600 if (ret)
601 dev_warn(&skt->dev, "err %d adding socket attributes\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Daniel Ritzbf4de6f2005-09-09 13:03:23 -0700603 complete(&skt->thread_done);
604
Dominik Brodowskid801c142010-02-17 11:02:22 +0100605 /* wait for userspace to catch up */
606 msleep(250);
607
Rafael J. Wysocki83144182007-07-17 04:03:35 -0700608 set_freezable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 for (;;) {
610 unsigned long flags;
611 unsigned int events;
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100612 unsigned int sysfs_events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 set_current_state(TASK_INTERRUPTIBLE);
615
616 spin_lock_irqsave(&skt->thread_lock, flags);
617 events = skt->thread_events;
618 skt->thread_events = 0;
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100619 sysfs_events = skt->sysfs_events;
620 skt->sysfs_events = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 spin_unlock_irqrestore(&skt->thread_lock, flags);
622
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100623 mutex_lock(&skt->skt_mutex);
Dominik Brodowski216d7cd2010-07-11 10:04:59 +0200624 if (events & SS_DETECT)
625 socket_detect_change(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100627 if (sysfs_events) {
628 if (sysfs_events & PCMCIA_UEVENT_EJECT)
629 socket_remove(skt);
630 if (sysfs_events & PCMCIA_UEVENT_INSERT)
631 socket_insert(skt);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100632 if ((sysfs_events & PCMCIA_UEVENT_SUSPEND) &&
633 !(skt->state & SOCKET_CARDBUS)) {
634 if (skt->callback)
635 ret = skt->callback->suspend(skt);
636 else
637 ret = 0;
Dominik Brodowski43821242010-05-03 15:10:09 +0200638 if (!ret) {
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100639 socket_suspend(skt);
Dominik Brodowski43821242010-05-03 15:10:09 +0200640 msleep(100);
641 }
642 }
643 if ((sysfs_events & PCMCIA_UEVENT_RESUME) &&
644 !(skt->state & SOCKET_CARDBUS)) {
645 ret = socket_resume(skt);
646 if (!ret && skt->callback)
647 skt->callback->resume(skt);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100648 }
Dominik Brodowskiaf461fc2010-01-17 19:30:53 +0100649 if ((sysfs_events & PCMCIA_UEVENT_REQUERY) &&
650 !(skt->state & SOCKET_CARDBUS)) {
651 if (!ret && skt->callback)
652 skt->callback->requery(skt);
653 }
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100654 }
655 mutex_unlock(&skt->skt_mutex);
656
657 if (events || sysfs_events)
658 continue;
659
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500660 if (kthread_should_stop())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 break;
Daniel Ritzbf4de6f2005-09-09 13:03:23 -0700662
663 schedule();
664 try_to_freeze();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
Steven Rostedt220ec022005-10-10 11:13:17 -0400666 /* make sure we are running before we exit */
667 set_current_state(TASK_RUNNING);
668
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100669 /* shut down socket, if a device is still present */
670 if (skt->state & SOCKET_PRESENT) {
671 mutex_lock(&skt->skt_mutex);
672 socket_remove(skt);
673 mutex_unlock(&skt->skt_mutex);
674 }
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 /* remove from the device core */
David Brownell4356d732008-04-28 01:03:20 -0700677 pccard_sysfs_remove_socket(&skt->dev);
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200678 device_unregister(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
683/*
684 * Yenta (at least) probes interrupts before registering the socket and
685 * starting the handler thread.
686 */
687void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
688{
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200689 unsigned long flags;
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200690 dev_dbg(&s->dev, "parse_events: events %08x\n", events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 if (s->thread) {
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200692 spin_lock_irqsave(&s->thread_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 s->thread_events |= events;
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200694 spin_unlock_irqrestore(&s->thread_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Christoph Hellwig0b402092007-04-22 13:55:36 +0100696 wake_up_process(s->thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 }
698} /* pcmcia_parse_events */
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700699EXPORT_SYMBOL(pcmcia_parse_events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100701/**
702 * pcmcia_parse_uevents() - tell pccardd to issue manual commands
703 * @s: the PCMCIA socket we wan't to command
704 * @events: events to pass to pccardd
705 *
706 * userspace-issued insert, eject, suspend and resume commands must be
707 * handled by pccardd to avoid any sysfs-related deadlocks. Valid events
708 * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert),
Dominik Brodowskiaf461fc2010-01-17 19:30:53 +0100709 * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend)
710 * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card).
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100711 */
712void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events)
713{
714 unsigned long flags;
715 dev_dbg(&s->dev, "parse_uevents: events %08x\n", events);
716 if (s->thread) {
717 spin_lock_irqsave(&s->thread_lock, flags);
718 s->sysfs_events |= events;
719 spin_unlock_irqrestore(&s->thread_lock, flags);
720
721 wake_up_process(s->thread);
722 }
723}
724EXPORT_SYMBOL(pcmcia_parse_uevents);
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
727/* register pcmcia_callback */
728int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
729{
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100730 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100732 /* s->skt_mutex also protects s->callback */
733 mutex_lock(&s->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 if (c) {
736 /* registration */
737 if (s->callback) {
738 ret = -EBUSY;
739 goto err;
740 }
741
742 s->callback = c;
743
744 if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT)
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200745 s->callback->add(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 } else
747 s->callback = NULL;
748 err:
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100749 mutex_unlock(&s->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 return ret;
752}
753EXPORT_SYMBOL(pccard_register_pcmcia);
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700756/* I'm not sure which "reset" function this is supposed to use,
757 * but for now, it uses the low-level interface's reset, not the
758 * CIS register.
759 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Dominik Brodowski994917f2008-08-31 15:20:26 +0200761int pcmcia_reset_card(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
763 int ret;
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700764
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200765 dev_dbg(&skt->dev, "resetting socket\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100767 mutex_lock(&skt->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 do {
769 if (!(skt->state & SOCKET_PRESENT)) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200770 dev_dbg(&skt->dev, "can't reset, not present\n");
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200771 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 break;
773 }
774 if (skt->state & SOCKET_SUSPEND) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200775 dev_dbg(&skt->dev, "can't reset, suspended\n");
Dominik Brodowskif9580952008-08-03 11:40:19 +0200776 ret = -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 break;
778 }
779 if (skt->state & SOCKET_CARDBUS) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200780 dev_dbg(&skt->dev, "can't reset, is cardbus\n");
Dominik Brodowskide6405e2008-08-03 10:47:59 +0200781 ret = -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 break;
783 }
784
Dominik Brodowski216d7cd2010-07-11 10:04:59 +0200785 if (skt->callback)
786 skt->callback->suspend(skt);
787 mutex_lock(&skt->ops_mutex);
788 ret = socket_reset(skt);
789 mutex_unlock(&skt->ops_mutex);
790 if ((ret == 0) && (skt->callback))
791 skt->callback->resume(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200793 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 } while (0);
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100795 mutex_unlock(&skt->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 return ret;
798} /* reset_card */
Dominik Brodowski994917f2008-08-31 15:20:26 +0200799EXPORT_SYMBOL(pcmcia_reset_card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Kay Sievers7eff2e72007-08-14 15:15:12 +0200802static int pcmcia_socket_uevent(struct device *dev,
803 struct kobj_uevent_env *env)
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700804{
805 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700806
Kay Sievers7eff2e72007-08-14 15:15:12 +0200807 if (add_uevent_var(env, "SOCKET_NO=%u", s->sock))
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700808 return -ENOMEM;
809
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700810 return 0;
811}
812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700814static struct completion pcmcia_unload;
815
816static void pcmcia_release_socket_class(struct class *data)
817{
818 complete(&pcmcia_unload);
819}
820
821
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100822#ifdef CONFIG_PM
823
824static int __pcmcia_pm_op(struct device *dev,
825 int (*callback) (struct pcmcia_socket *skt))
826{
827 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
828 int ret;
829
830 mutex_lock(&s->skt_mutex);
831 ret = callback(s);
832 mutex_unlock(&s->skt_mutex);
833
834 return ret;
835}
836
837static int pcmcia_socket_dev_suspend_noirq(struct device *dev)
838{
839 return __pcmcia_pm_op(dev, socket_suspend);
840}
841
842static int pcmcia_socket_dev_resume_noirq(struct device *dev)
843{
844 return __pcmcia_pm_op(dev, socket_early_resume);
845}
846
Maciej Żenczykowski3c7d2b72010-10-13 21:47:14 -0700847static int __used pcmcia_socket_dev_resume(struct device *dev)
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100848{
849 return __pcmcia_pm_op(dev, socket_late_resume);
850}
851
852static const struct dev_pm_ops pcmcia_socket_pm_ops = {
853 /* dev_resume may be called with IRQs enabled */
854 SET_SYSTEM_SLEEP_PM_OPS(NULL,
855 pcmcia_socket_dev_resume)
856
857 /* late suspend must be called with IRQs disabled */
858 .suspend_noirq = pcmcia_socket_dev_suspend_noirq,
859 .freeze_noirq = pcmcia_socket_dev_suspend_noirq,
860 .poweroff_noirq = pcmcia_socket_dev_suspend_noirq,
861
862 /* early resume must be called with IRQs disabled */
863 .resume_noirq = pcmcia_socket_dev_resume_noirq,
864 .thaw_noirq = pcmcia_socket_dev_resume_noirq,
865 .restore_noirq = pcmcia_socket_dev_resume_noirq,
866};
867
868#define PCMCIA_SOCKET_CLASS_PM_OPS (&pcmcia_socket_pm_ops)
869
870#else /* CONFIG_PM */
871
872#define PCMCIA_SOCKET_CLASS_PM_OPS NULL
873
874#endif /* CONFIG_PM */
875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876struct class pcmcia_socket_class = {
877 .name = "pcmcia_socket",
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200878 .dev_uevent = pcmcia_socket_uevent,
879 .dev_release = pcmcia_release_socket,
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700880 .class_release = pcmcia_release_socket_class,
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100881 .pm = PCMCIA_SOCKET_CLASS_PM_OPS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882};
883EXPORT_SYMBOL(pcmcia_socket_class);
884
885
886static int __init init_pcmcia_cs(void)
887{
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700888 init_completion(&pcmcia_unload);
David Brownell4356d732008-04-28 01:03:20 -0700889 return class_register(&pcmcia_socket_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
891
892static void __exit exit_pcmcia_cs(void)
893{
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700894 class_unregister(&pcmcia_socket_class);
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700895 wait_for_completion(&pcmcia_unload);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
897
898subsys_initcall(init_pcmcia_cs);
899module_exit(exit_pcmcia_cs);
900