blob: efa30b84a75aba2032c1c25141b39ce44432bed2 [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/cs_types.h>
36#include <pcmcia/ss.h>
37#include <pcmcia/cs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <pcmcia/cistpl.h>
39#include <pcmcia/cisreg.h>
40#include <pcmcia/ds.h>
41#include "cs_internal.h"
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/* Module parameters */
45
46MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
Dominik Brodowski33519dd2005-06-27 16:28:53 -070047MODULE_DESCRIPTION("Linux Kernel Card Services");
Linus Torvalds1da177e2005-04-16 15:20:36 -070048MODULE_LICENSE("GPL");
49
50#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
51
52INT_MODULE_PARM(setup_delay, 10); /* centiseconds */
53INT_MODULE_PARM(resume_delay, 20); /* centiseconds */
54INT_MODULE_PARM(shutdown_delay, 3); /* centiseconds */
55INT_MODULE_PARM(vcc_settle, 40); /* centiseconds */
56INT_MODULE_PARM(reset_time, 10); /* usecs */
57INT_MODULE_PARM(unreset_delay, 10); /* centiseconds */
58INT_MODULE_PARM(unreset_check, 10); /* centiseconds */
59INT_MODULE_PARM(unreset_limit, 30); /* unreset_check's */
60
61/* Access speed for attribute memory windows */
62INT_MODULE_PARM(cis_speed, 300); /* ns */
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65socket_state_t dead_socket = {
66 .csc_mask = SS_DETECT,
67};
Dominik Brodowski33519dd2005-06-27 16:28:53 -070068EXPORT_SYMBOL(dead_socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70
71/* List of all sockets, protected by a rwsem */
72LIST_HEAD(pcmcia_socket_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073EXPORT_SYMBOL(pcmcia_socket_list);
Dominik Brodowski33519dd2005-06-27 16:28:53 -070074
75DECLARE_RWSEM(pcmcia_socket_list_rwsem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
77
78
Dominik Brodowski9fea84f2009-12-07 22:11:45 +010079struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020081 struct device *dev = get_device(&skt->dev);
82 if (!dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 return NULL;
Dominik Brodowski593f010b2010-01-02 22:59:15 +010084 return dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86EXPORT_SYMBOL(pcmcia_get_socket);
87
88
89void pcmcia_put_socket(struct pcmcia_socket *skt)
90{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020091 put_device(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93EXPORT_SYMBOL(pcmcia_put_socket);
94
95
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020096static void pcmcia_release_socket(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020098 struct pcmcia_socket *socket = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 complete(&socket->socket_released);
101}
102
103static int pccardd(void *__skt);
104
105/**
106 * pcmcia_register_socket - add a new pcmcia socket device
Randy Dunlap78187862007-12-10 15:49:22 -0800107 * @socket: the &socket to register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 */
109int pcmcia_register_socket(struct pcmcia_socket *socket)
110{
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500111 struct task_struct *tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 int ret;
113
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200114 if (!socket || !socket->ops || !socket->dev.parent || !socket->resource_ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return -EINVAL;
116
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200117 dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 /* try to obtain a socket number [yes, it gets ugly if we
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700120 * register more than 2^sizeof(unsigned int) pcmcia
121 * sockets... but the socket number is deprecated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 * anyways, so I don't care] */
123 down_write(&pcmcia_socket_list_rwsem);
124 if (list_empty(&pcmcia_socket_list))
125 socket->sock = 0;
126 else {
127 unsigned int found, i = 1;
128 struct pcmcia_socket *tmp;
129 do {
130 found = 1;
131 list_for_each_entry(tmp, &pcmcia_socket_list, socket_list) {
132 if (tmp->sock == i)
133 found = 0;
134 }
135 i++;
136 } while (!found);
137 socket->sock = i - 1;
138 }
139 list_add_tail(&socket->socket_list, &pcmcia_socket_list);
140 up_write(&pcmcia_socket_list_rwsem);
141
Russell King5bc6b682005-07-07 17:59:07 -0700142#ifndef CONFIG_CARDBUS
143 /*
144 * If we do not support Cardbus, ensure that
145 * the Cardbus socket capability is disabled.
146 */
147 socket->features &= ~SS_CAP_CARDBUS;
148#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 /* set proper values in socket->dev */
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200151 dev_set_drvdata(&socket->dev, socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 socket->dev.class = &pcmcia_socket_class;
Kay Sievers25096982008-11-01 11:46:06 +0100153 dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 /* base address = 0, map = 0 */
156 socket->cis_mem.flags = 0;
157 socket->cis_mem.speed = cis_speed;
158
159 INIT_LIST_HEAD(&socket->cis_cache);
160
161 init_completion(&socket->socket_released);
162 init_completion(&socket->thread_done);
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100163 mutex_init(&socket->skt_mutex);
Dominik Brodowski6b8e0872010-01-12 21:42:51 +0100164 mutex_init(&socket->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 spin_lock_init(&socket->thread_lock);
166
Dominik Brodowskib1769452008-11-09 21:47:47 +0100167 if (socket->resource_ops->init) {
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100168 mutex_lock(&socket->ops_mutex);
Dominik Brodowskib1769452008-11-09 21:47:47 +0100169 ret = socket->resource_ops->init(socket);
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100170 mutex_unlock(&socket->ops_mutex);
Dominik Brodowskib1769452008-11-09 21:47:47 +0100171 if (ret)
172 goto err;
173 }
174
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500175 tsk = kthread_run(pccardd, socket, "pccardd");
176 if (IS_ERR(tsk)) {
177 ret = PTR_ERR(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 goto err;
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 wait_for_completion(&socket->thread_done);
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500182 if (!socket->thread) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200183 dev_printk(KERN_WARNING, &socket->dev,
184 "PCMCIA: warning: socket thread did not start\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return -EIO;
186 }
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 pcmcia_parse_events(socket, SS_DETECT);
189
Dominik Brodowski638bba52009-11-07 12:26:17 +0100190 /*
191 * Let's try to get the PCMCIA module for 16-bit PCMCIA support.
192 * If it fails, it doesn't matter -- we still have 32-bit CardBus
193 * support to offer, so this is not a failure mode.
194 */
195 request_module_nowait("pcmcia");
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 return 0;
198
199 err:
200 down_write(&pcmcia_socket_list_rwsem);
201 list_del(&socket->socket_list);
202 up_write(&pcmcia_socket_list_rwsem);
203 return ret;
204} /* pcmcia_register_socket */
205EXPORT_SYMBOL(pcmcia_register_socket);
206
207
208/**
209 * pcmcia_unregister_socket - remove a pcmcia socket device
Randy Dunlap78187862007-12-10 15:49:22 -0800210 * @socket: the &socket to unregister
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 */
212void pcmcia_unregister_socket(struct pcmcia_socket *socket)
213{
214 if (!socket)
215 return;
216
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200217 dev_dbg(&socket->dev, "pcmcia_unregister_socket(0x%p)\n", socket->ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Christoph Hellwig0b402092007-04-22 13:55:36 +0100219 if (socket->thread)
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500220 kthread_stop(socket->thread);
Christoph Hellwig0b402092007-04-22 13:55:36 +0100221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 /* remove from our own list */
223 down_write(&pcmcia_socket_list_rwsem);
224 list_del(&socket->socket_list);
225 up_write(&pcmcia_socket_list_rwsem);
226
227 /* wait for sysfs to drop all references */
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100228 if (socket->resource_ops->exit) {
229 mutex_lock(&socket->ops_mutex);
Dominik Brodowski385ee872010-01-06 11:23:58 +0100230 socket->resource_ops->exit(socket);
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100231 mutex_unlock(&socket->ops_mutex);
232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 wait_for_completion(&socket->socket_released);
234} /* pcmcia_unregister_socket */
235EXPORT_SYMBOL(pcmcia_unregister_socket);
236
237
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100238struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
240 struct pcmcia_socket *s;
241
242 down_read(&pcmcia_socket_list_rwsem);
243 list_for_each_entry(s, &pcmcia_socket_list, socket_list)
244 if (s->sock == nr) {
245 up_read(&pcmcia_socket_list_rwsem);
246 return s;
247 }
248 up_read(&pcmcia_socket_list_rwsem);
249
250 return NULL;
251
252}
253EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255static int socket_reset(struct pcmcia_socket *skt)
256{
257 int status, i;
258
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200259 dev_dbg(&skt->dev, "reset\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 skt->socket.flags |= SS_OUTPUT_ENA | SS_RESET;
262 skt->ops->set_socket(skt, &skt->socket);
263 udelay((long)reset_time);
264
265 skt->socket.flags &= ~SS_RESET;
266 skt->ops->set_socket(skt, &skt->socket);
267
268 msleep(unreset_delay * 10);
269 for (i = 0; i < unreset_limit; i++) {
270 skt->ops->get_status(skt, &status);
271
272 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200273 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 if (status & SS_READY)
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200276 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 msleep(unreset_check * 10);
279 }
280
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200281 dev_printk(KERN_ERR, &skt->dev, "time out after reset.\n");
Dominik Brodowski85671422008-08-03 11:15:45 +0200282 return -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Randy Dunlap78187862007-12-10 15:49:22 -0800285/*
Daniel Ritz6e493882005-12-30 15:12:35 +0100286 * socket_setup() and socket_shutdown() are called by the main event handler
287 * when card insertion and removal events are received.
288 * socket_setup() turns on socket power and resets the socket, in two stages.
289 * socket_shutdown() unconfigures a socket and turns off socket power.
290 */
291static void socket_shutdown(struct pcmcia_socket *s)
292{
293 int status;
294
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200295 dev_dbg(&s->dev, "shutdown\n");
Daniel Ritz6e493882005-12-30 15:12:35 +0100296
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200297 if (s->callback)
298 s->callback->remove(s);
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100299
300 mutex_lock(&s->ops_mutex);
Daniel Ritz6e493882005-12-30 15:12:35 +0100301 s->state &= SOCKET_INUSE | SOCKET_PRESENT;
302 msleep(shutdown_delay * 10);
303 s->state &= SOCKET_INUSE;
304
305 /* Blank out the socket state */
306 s->socket = dead_socket;
307 s->ops->init(s);
308 s->ops->set_socket(s, &s->socket);
Daniel Ritz6e493882005-12-30 15:12:35 +0100309 s->lock_count = 0;
Dominik Brodowski904e3772010-01-02 12:28:04 +0100310 kfree(s->fake_cis);
311 s->fake_cis = NULL;
Dominik Brodowskic3bfc962010-01-18 08:43:39 +0100312 s->functions = 0;
313
314 /* From here on we can be sure that only we (that is, the
315 * pccardd thread) accesses this socket, and all (16-bit)
316 * PCMCIA interactions are gone. Therefore, release
317 * ops_mutex so that we don't get a sysfs-related lockdep
318 * warning.
319 */
320 mutex_unlock(&s->ops_mutex);
321
Daniel Ritz6e493882005-12-30 15:12:35 +0100322#ifdef CONFIG_CARDBUS
323 cb_free(s);
324#endif
Daniel Ritz6e493882005-12-30 15:12:35 +0100325
Daniel Ritzafb2c162007-07-31 00:38:08 -0700326 /* give socket some time to power down */
327 msleep(100);
328
Daniel Ritz6e493882005-12-30 15:12:35 +0100329 s->ops->get_status(s, &status);
330 if (status & SS_POWERON) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200331 dev_printk(KERN_ERR, &s->dev,
332 "*** DANGER *** unable to remove socket power\n");
Daniel Ritz6e493882005-12-30 15:12:35 +0100333 }
334
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100335 s->state &= ~SOCKET_INUSE;
Daniel Ritz6e493882005-12-30 15:12:35 +0100336}
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
339{
340 int status, i;
341
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200342 dev_dbg(&skt->dev, "setup\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 skt->ops->get_status(skt, &status);
345 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200346 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 msleep(initial_delay * 10);
349
350 for (i = 0; i < 100; i++) {
351 skt->ops->get_status(skt, &status);
352 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200353 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 if (!(status & SS_PENDING))
356 break;
357
358 msleep(100);
359 }
360
361 if (status & SS_PENDING) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200362 dev_printk(KERN_ERR, &skt->dev,
363 "voltage interrogation timed out.\n");
Dominik Brodowski85671422008-08-03 11:15:45 +0200364 return -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366
367 if (status & SS_CARDBUS) {
Russell King5bc6b682005-07-07 17:59:07 -0700368 if (!(skt->features & SS_CAP_CARDBUS)) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200369 dev_printk(KERN_ERR, &skt->dev,
370 "cardbus cards are not supported.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200371 return -EINVAL;
Russell King5bc6b682005-07-07 17:59:07 -0700372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 skt->state |= SOCKET_CARDBUS;
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100374 } else
375 skt->state &= ~SOCKET_CARDBUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 /*
378 * Decode the card voltage requirements, and apply power to the card.
379 */
380 if (status & SS_3VCARD)
381 skt->socket.Vcc = skt->socket.Vpp = 33;
382 else if (!(status & SS_XVCARD))
383 skt->socket.Vcc = skt->socket.Vpp = 50;
384 else {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200385 dev_printk(KERN_ERR, &skt->dev, "unsupported voltage key.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200386 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
Daniel Ritzfa912bc2005-06-23 00:10:12 -0700388
389 if (skt->power_hook)
390 skt->power_hook(skt, HOOK_POWER_PRE);
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 skt->socket.flags = 0;
393 skt->ops->set_socket(skt, &skt->socket);
394
395 /*
396 * Wait "vcc_settle" for the supply to stabilise.
397 */
398 msleep(vcc_settle * 10);
399
400 skt->ops->get_status(skt, &status);
401 if (!(status & SS_POWERON)) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200402 dev_printk(KERN_ERR, &skt->dev, "unable to apply power.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200403 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405
Daniel Ritzfa912bc2005-06-23 00:10:12 -0700406 status = socket_reset(skt);
407
408 if (skt->power_hook)
409 skt->power_hook(skt, HOOK_POWER_POST);
410
411 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414/*
415 * Handle card insertion. Setup the socket, reset the card,
416 * and then tell the rest of PCMCIA that a card is present.
417 */
418static int socket_insert(struct pcmcia_socket *skt)
419{
420 int ret;
421
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200422 dev_dbg(&skt->dev, "insert\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100424 mutex_lock(&skt->ops_mutex);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100425 if (skt->state & SOCKET_INUSE) {
426 mutex_unlock(&skt->ops_mutex);
427 return -EINVAL;
428 }
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100429 skt->state |= SOCKET_INUSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 ret = socket_setup(skt, setup_delay);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200432 if (ret == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 skt->state |= SOCKET_PRESENT;
Dominik Brodowski807277c2005-11-12 23:34:06 +0100434
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200435 dev_printk(KERN_NOTICE, &skt->dev,
436 "pccard: %s card inserted into slot %d\n",
437 (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA",
438 skt->sock);
Dominik Brodowski807277c2005-11-12 23:34:06 +0100439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#ifdef CONFIG_CARDBUS
441 if (skt->state & SOCKET_CARDBUS) {
442 cb_alloc(skt);
443 skt->state |= SOCKET_CARDBUS_CONFIG;
444 }
445#endif
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200446 dev_dbg(&skt->dev, "insert done\n");
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100447 mutex_unlock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200449 if (!(skt->state & SOCKET_CARDBUS) && (skt->callback))
450 skt->callback->add(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 } else {
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100452 mutex_unlock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
456 return ret;
457}
458
459static int socket_suspend(struct pcmcia_socket *skt)
460{
461 if (skt->state & SOCKET_SUSPEND)
Dominik Brodowskif9580952008-08-03 11:40:19 +0200462 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100464 mutex_lock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100465 skt->suspended_state = skt->state;
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 skt->socket = dead_socket;
468 skt->ops->set_socket(skt, &skt->socket);
469 if (skt->ops->suspend)
470 skt->ops->suspend(skt);
471 skt->state |= SOCKET_SUSPEND;
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100472 mutex_unlock(&skt->ops_mutex);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200473 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100476static int socket_early_resume(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100478 mutex_lock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 skt->socket = dead_socket;
480 skt->ops->init(skt);
481 skt->ops->set_socket(skt, &skt->socket);
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100482 if (skt->state & SOCKET_PRESENT)
483 skt->resume_status = socket_setup(skt, resume_delay);
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100484 mutex_unlock(&skt->ops_mutex);
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100485 return 0;
486}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100488static int socket_late_resume(struct pcmcia_socket *skt)
489{
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100490 int ret;
491
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100492 mutex_lock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100493 skt->state &= ~SOCKET_SUSPEND;
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100494 mutex_unlock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100495
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100496 if (!(skt->state & SOCKET_PRESENT)) {
497 ret = socket_insert(skt);
498 if (ret == -ENODEV)
499 ret = 0;
500 return ret;
501 }
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100502
503 if (skt->resume_status) {
504 socket_shutdown(skt);
505 return 0;
506 }
507
508 if (skt->suspended_state != skt->state) {
509 dev_dbg(&skt->dev,
510 "suspend state 0x%x != resume state 0x%x\n",
511 skt->suspended_state, skt->state);
512
513 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return socket_insert(skt);
515 }
516
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100517#ifdef CONFIG_CARDBUS
518 if (skt->state & SOCKET_CARDBUS) {
519 /* We can't be sure the CardBus card is the same
520 * as the one previously inserted. Therefore, remove
521 * and re-add... */
522 cb_free(skt);
523 cb_alloc(skt);
524 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100526#endif
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200527 if (!(skt->state & SOCKET_CARDBUS) && (skt->callback))
528 skt->callback->early_resume(skt);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200529 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530}
531
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100532/*
533 * Resume a socket. If a card is present, verify its CIS against
534 * our cached copy. If they are different, the card has been
535 * replaced, and we need to tell the drivers.
536 */
537static int socket_resume(struct pcmcia_socket *skt)
538{
539 if (!(skt->state & SOCKET_SUSPEND))
540 return -EBUSY;
541
542 socket_early_resume(skt);
543 return socket_late_resume(skt);
544}
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546static void socket_remove(struct pcmcia_socket *skt)
547{
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200548 dev_printk(KERN_NOTICE, &skt->dev,
549 "pccard: card ejected from slot %d\n", skt->sock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
553/*
554 * Process a socket card detect status change.
555 *
556 * If we don't have a card already present, delay the detect event for
557 * about 20ms (to be on the safe side) before reading the socket status.
558 *
559 * Some i82365-based systems send multiple SS_DETECT events during card
560 * insertion, and the "card present" status bit seems to bounce. This
561 * will probably be true with GPIO-based card detection systems after
562 * the product has aged.
563 */
564static void socket_detect_change(struct pcmcia_socket *skt)
565{
566 if (!(skt->state & SOCKET_SUSPEND)) {
567 int status;
568
569 if (!(skt->state & SOCKET_PRESENT))
570 msleep(20);
571
572 skt->ops->get_status(skt, &status);
573 if ((skt->state & SOCKET_PRESENT) &&
574 !(status & SS_DETECT))
575 socket_remove(skt);
576 if (!(skt->state & SOCKET_PRESENT) &&
577 (status & SS_DETECT))
578 socket_insert(skt);
579 }
580}
581
582static int pccardd(void *__skt)
583{
584 struct pcmcia_socket *skt = __skt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 int ret;
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 skt->thread = current;
588 skt->socket = dead_socket;
589 skt->ops->init(skt);
590 skt->ops->set_socket(skt, &skt->socket);
591
592 /* register with the device core */
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200593 ret = device_register(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (ret) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200595 dev_printk(KERN_WARNING, &skt->dev,
596 "PCMCIA: unable to register socket\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 skt->thread = NULL;
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500598 complete(&skt->thread_done);
599 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
David Brownell4356d732008-04-28 01:03:20 -0700601 ret = pccard_sysfs_add_socket(&skt->dev);
602 if (ret)
603 dev_warn(&skt->dev, "err %d adding socket attributes\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Daniel Ritzbf4de6f2005-09-09 13:03:23 -0700605 complete(&skt->thread_done);
606
Dominik Brodowskid801c1402010-02-17 11:02:22 +0100607 /* wait for userspace to catch up */
608 msleep(250);
609
Rafael J. Wysocki83144182007-07-17 04:03:35 -0700610 set_freezable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 for (;;) {
612 unsigned long flags;
613 unsigned int events;
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100614 unsigned int sysfs_events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 set_current_state(TASK_INTERRUPTIBLE);
617
618 spin_lock_irqsave(&skt->thread_lock, flags);
619 events = skt->thread_events;
620 skt->thread_events = 0;
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100621 sysfs_events = skt->sysfs_events;
622 skt->sysfs_events = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 spin_unlock_irqrestore(&skt->thread_lock, flags);
624
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100625 mutex_lock(&skt->skt_mutex);
Dominik Brodowski216d7cd2010-07-11 10:04:59 +0200626 if (events & SS_DETECT)
627 socket_detect_change(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100629 if (sysfs_events) {
630 if (sysfs_events & PCMCIA_UEVENT_EJECT)
631 socket_remove(skt);
632 if (sysfs_events & PCMCIA_UEVENT_INSERT)
633 socket_insert(skt);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100634 if ((sysfs_events & PCMCIA_UEVENT_SUSPEND) &&
635 !(skt->state & SOCKET_CARDBUS)) {
636 if (skt->callback)
637 ret = skt->callback->suspend(skt);
638 else
639 ret = 0;
Dominik Brodowski43821242010-05-03 15:10:09 +0200640 if (!ret) {
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100641 socket_suspend(skt);
Dominik Brodowski43821242010-05-03 15:10:09 +0200642 msleep(100);
643 }
644 }
645 if ((sysfs_events & PCMCIA_UEVENT_RESUME) &&
646 !(skt->state & SOCKET_CARDBUS)) {
647 ret = socket_resume(skt);
648 if (!ret && skt->callback)
649 skt->callback->resume(skt);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100650 }
Dominik Brodowskiaf461fc2010-01-17 19:30:53 +0100651 if ((sysfs_events & PCMCIA_UEVENT_REQUERY) &&
652 !(skt->state & SOCKET_CARDBUS)) {
653 if (!ret && skt->callback)
654 skt->callback->requery(skt);
655 }
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100656 }
657 mutex_unlock(&skt->skt_mutex);
658
659 if (events || sysfs_events)
660 continue;
661
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500662 if (kthread_should_stop())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 break;
Daniel Ritzbf4de6f2005-09-09 13:03:23 -0700664
665 schedule();
666 try_to_freeze();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
Steven Rostedt220ec022005-10-10 11:13:17 -0400668 /* make sure we are running before we exit */
669 set_current_state(TASK_RUNNING);
670
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100671 /* shut down socket, if a device is still present */
672 if (skt->state & SOCKET_PRESENT) {
673 mutex_lock(&skt->skt_mutex);
674 socket_remove(skt);
675 mutex_unlock(&skt->skt_mutex);
676 }
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 /* remove from the device core */
David Brownell4356d732008-04-28 01:03:20 -0700679 pccard_sysfs_remove_socket(&skt->dev);
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200680 device_unregister(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500682 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
685/*
686 * Yenta (at least) probes interrupts before registering the socket and
687 * starting the handler thread.
688 */
689void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
690{
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200691 unsigned long flags;
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200692 dev_dbg(&s->dev, "parse_events: events %08x\n", events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 if (s->thread) {
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200694 spin_lock_irqsave(&s->thread_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 s->thread_events |= events;
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200696 spin_unlock_irqrestore(&s->thread_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Christoph Hellwig0b402092007-04-22 13:55:36 +0100698 wake_up_process(s->thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700} /* pcmcia_parse_events */
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700701EXPORT_SYMBOL(pcmcia_parse_events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100703/**
704 * pcmcia_parse_uevents() - tell pccardd to issue manual commands
705 * @s: the PCMCIA socket we wan't to command
706 * @events: events to pass to pccardd
707 *
708 * userspace-issued insert, eject, suspend and resume commands must be
709 * handled by pccardd to avoid any sysfs-related deadlocks. Valid events
710 * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert),
Dominik Brodowskiaf461fc2010-01-17 19:30:53 +0100711 * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend)
712 * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card).
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100713 */
714void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events)
715{
716 unsigned long flags;
717 dev_dbg(&s->dev, "parse_uevents: events %08x\n", events);
718 if (s->thread) {
719 spin_lock_irqsave(&s->thread_lock, flags);
720 s->sysfs_events |= events;
721 spin_unlock_irqrestore(&s->thread_lock, flags);
722
723 wake_up_process(s->thread);
724 }
725}
726EXPORT_SYMBOL(pcmcia_parse_uevents);
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729/* register pcmcia_callback */
730int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
731{
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100732 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100734 /* s->skt_mutex also protects s->callback */
735 mutex_lock(&s->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 if (c) {
738 /* registration */
739 if (s->callback) {
740 ret = -EBUSY;
741 goto err;
742 }
743
744 s->callback = c;
745
746 if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT)
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200747 s->callback->add(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 } else
749 s->callback = NULL;
750 err:
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100751 mutex_unlock(&s->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 return ret;
754}
755EXPORT_SYMBOL(pccard_register_pcmcia);
756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700758/* I'm not sure which "reset" function this is supposed to use,
759 * but for now, it uses the low-level interface's reset, not the
760 * CIS register.
761 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Dominik Brodowski994917f2008-08-31 15:20:26 +0200763int pcmcia_reset_card(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764{
765 int ret;
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700766
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200767 dev_dbg(&skt->dev, "resetting socket\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100769 mutex_lock(&skt->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 do {
771 if (!(skt->state & SOCKET_PRESENT)) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200772 dev_dbg(&skt->dev, "can't reset, not present\n");
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200773 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 break;
775 }
776 if (skt->state & SOCKET_SUSPEND) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200777 dev_dbg(&skt->dev, "can't reset, suspended\n");
Dominik Brodowskif9580952008-08-03 11:40:19 +0200778 ret = -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 break;
780 }
781 if (skt->state & SOCKET_CARDBUS) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200782 dev_dbg(&skt->dev, "can't reset, is cardbus\n");
Dominik Brodowskide6405e2008-08-03 10:47:59 +0200783 ret = -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 break;
785 }
786
Dominik Brodowski216d7cd2010-07-11 10:04:59 +0200787 if (skt->callback)
788 skt->callback->suspend(skt);
789 mutex_lock(&skt->ops_mutex);
790 ret = socket_reset(skt);
791 mutex_unlock(&skt->ops_mutex);
792 if ((ret == 0) && (skt->callback))
793 skt->callback->resume(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200795 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 } while (0);
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100797 mutex_unlock(&skt->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 return ret;
800} /* reset_card */
Dominik Brodowski994917f2008-08-31 15:20:26 +0200801EXPORT_SYMBOL(pcmcia_reset_card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Kay Sievers7eff2e72007-08-14 15:15:12 +0200804static int pcmcia_socket_uevent(struct device *dev,
805 struct kobj_uevent_env *env)
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700806{
807 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700808
Kay Sievers7eff2e72007-08-14 15:15:12 +0200809 if (add_uevent_var(env, "SOCKET_NO=%u", s->sock))
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700810 return -ENOMEM;
811
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700812 return 0;
813}
814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700816static struct completion pcmcia_unload;
817
818static void pcmcia_release_socket_class(struct class *data)
819{
820 complete(&pcmcia_unload);
821}
822
823
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100824#ifdef CONFIG_PM
825
826static int __pcmcia_pm_op(struct device *dev,
827 int (*callback) (struct pcmcia_socket *skt))
828{
829 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
830 int ret;
831
832 mutex_lock(&s->skt_mutex);
833 ret = callback(s);
834 mutex_unlock(&s->skt_mutex);
835
836 return ret;
837}
838
839static int pcmcia_socket_dev_suspend_noirq(struct device *dev)
840{
841 return __pcmcia_pm_op(dev, socket_suspend);
842}
843
844static int pcmcia_socket_dev_resume_noirq(struct device *dev)
845{
846 return __pcmcia_pm_op(dev, socket_early_resume);
847}
848
849static int pcmcia_socket_dev_resume(struct device *dev)
850{
851 return __pcmcia_pm_op(dev, socket_late_resume);
852}
853
854static const struct dev_pm_ops pcmcia_socket_pm_ops = {
855 /* dev_resume may be called with IRQs enabled */
856 SET_SYSTEM_SLEEP_PM_OPS(NULL,
857 pcmcia_socket_dev_resume)
858
859 /* late suspend must be called with IRQs disabled */
860 .suspend_noirq = pcmcia_socket_dev_suspend_noirq,
861 .freeze_noirq = pcmcia_socket_dev_suspend_noirq,
862 .poweroff_noirq = pcmcia_socket_dev_suspend_noirq,
863
864 /* early resume must be called with IRQs disabled */
865 .resume_noirq = pcmcia_socket_dev_resume_noirq,
866 .thaw_noirq = pcmcia_socket_dev_resume_noirq,
867 .restore_noirq = pcmcia_socket_dev_resume_noirq,
868};
869
870#define PCMCIA_SOCKET_CLASS_PM_OPS (&pcmcia_socket_pm_ops)
871
872#else /* CONFIG_PM */
873
874#define PCMCIA_SOCKET_CLASS_PM_OPS NULL
875
876#endif /* CONFIG_PM */
877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878struct class pcmcia_socket_class = {
879 .name = "pcmcia_socket",
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200880 .dev_uevent = pcmcia_socket_uevent,
881 .dev_release = pcmcia_release_socket,
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700882 .class_release = pcmcia_release_socket_class,
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100883 .pm = PCMCIA_SOCKET_CLASS_PM_OPS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884};
885EXPORT_SYMBOL(pcmcia_socket_class);
886
887
888static int __init init_pcmcia_cs(void)
889{
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700890 init_completion(&pcmcia_unload);
David Brownell4356d732008-04-28 01:03:20 -0700891 return class_register(&pcmcia_socket_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892}
893
894static void __exit exit_pcmcia_cs(void)
895{
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700896 class_unregister(&pcmcia_socket_class);
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700897 wait_for_completion(&pcmcia_unload);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898}
899
900subsys_initcall(init_pcmcia_cs);
901module_exit(exit_pcmcia_cs);
902