blob: 2ec8ac97445c1491d73102808de25dcf8e2c26bc [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>
36#include <pcmcia/cs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <pcmcia/cistpl.h>
38#include <pcmcia/cisreg.h>
39#include <pcmcia/ds.h>
40#include "cs_internal.h"
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* Module parameters */
44
45MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
Dominik Brodowski33519dd2005-06-27 16:28:53 -070046MODULE_DESCRIPTION("Linux Kernel Card Services");
Linus Torvalds1da177e2005-04-16 15:20:36 -070047MODULE_LICENSE("GPL");
48
49#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
50
51INT_MODULE_PARM(setup_delay, 10); /* centiseconds */
52INT_MODULE_PARM(resume_delay, 20); /* centiseconds */
53INT_MODULE_PARM(shutdown_delay, 3); /* centiseconds */
54INT_MODULE_PARM(vcc_settle, 40); /* centiseconds */
55INT_MODULE_PARM(reset_time, 10); /* usecs */
56INT_MODULE_PARM(unreset_delay, 10); /* centiseconds */
57INT_MODULE_PARM(unreset_check, 10); /* centiseconds */
58INT_MODULE_PARM(unreset_limit, 30); /* unreset_check's */
59
60/* Access speed for attribute memory windows */
61INT_MODULE_PARM(cis_speed, 300); /* ns */
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64socket_state_t dead_socket = {
65 .csc_mask = SS_DETECT,
66};
Dominik Brodowski33519dd2005-06-27 16:28:53 -070067EXPORT_SYMBOL(dead_socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69
70/* List of all sockets, protected by a rwsem */
71LIST_HEAD(pcmcia_socket_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072EXPORT_SYMBOL(pcmcia_socket_list);
Dominik Brodowski33519dd2005-06-27 16:28:53 -070073
74DECLARE_RWSEM(pcmcia_socket_list_rwsem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
76
77
Dominik Brodowski9fea84f2009-12-07 22:11:45 +010078struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020080 struct device *dev = get_device(&skt->dev);
81 if (!dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return NULL;
Dominik Brodowski593f010b2010-01-02 22:59:15 +010083 return dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85EXPORT_SYMBOL(pcmcia_get_socket);
86
87
88void pcmcia_put_socket(struct pcmcia_socket *skt)
89{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020090 put_device(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92EXPORT_SYMBOL(pcmcia_put_socket);
93
94
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020095static void pcmcia_release_socket(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Greg Kroah-Hartman87373312006-09-12 17:00:10 +020097 struct pcmcia_socket *socket = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 complete(&socket->socket_released);
100}
101
102static int pccardd(void *__skt);
103
104/**
105 * pcmcia_register_socket - add a new pcmcia socket device
Randy Dunlap78187862007-12-10 15:49:22 -0800106 * @socket: the &socket to register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 */
108int pcmcia_register_socket(struct pcmcia_socket *socket)
109{
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500110 struct task_struct *tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 int ret;
112
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200113 if (!socket || !socket->ops || !socket->dev.parent || !socket->resource_ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return -EINVAL;
115
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200116 dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 /* try to obtain a socket number [yes, it gets ugly if we
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700119 * register more than 2^sizeof(unsigned int) pcmcia
120 * sockets... but the socket number is deprecated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 * anyways, so I don't care] */
122 down_write(&pcmcia_socket_list_rwsem);
123 if (list_empty(&pcmcia_socket_list))
124 socket->sock = 0;
125 else {
126 unsigned int found, i = 1;
127 struct pcmcia_socket *tmp;
128 do {
129 found = 1;
130 list_for_each_entry(tmp, &pcmcia_socket_list, socket_list) {
131 if (tmp->sock == i)
132 found = 0;
133 }
134 i++;
135 } while (!found);
136 socket->sock = i - 1;
137 }
138 list_add_tail(&socket->socket_list, &pcmcia_socket_list);
139 up_write(&pcmcia_socket_list_rwsem);
140
Russell King5bc6b682005-07-07 17:59:07 -0700141#ifndef CONFIG_CARDBUS
142 /*
143 * If we do not support Cardbus, ensure that
144 * the Cardbus socket capability is disabled.
145 */
146 socket->features &= ~SS_CAP_CARDBUS;
147#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 /* set proper values in socket->dev */
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200150 dev_set_drvdata(&socket->dev, socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 socket->dev.class = &pcmcia_socket_class;
Kay Sievers25096982008-11-01 11:46:06 +0100152 dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 /* base address = 0, map = 0 */
155 socket->cis_mem.flags = 0;
156 socket->cis_mem.speed = cis_speed;
157
158 INIT_LIST_HEAD(&socket->cis_cache);
159
160 init_completion(&socket->socket_released);
161 init_completion(&socket->thread_done);
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100162 mutex_init(&socket->skt_mutex);
Dominik Brodowski6b8e0872010-01-12 21:42:51 +0100163 mutex_init(&socket->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 spin_lock_init(&socket->thread_lock);
165
Dominik Brodowskib1769452008-11-09 21:47:47 +0100166 if (socket->resource_ops->init) {
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100167 mutex_lock(&socket->ops_mutex);
Dominik Brodowskib1769452008-11-09 21:47:47 +0100168 ret = socket->resource_ops->init(socket);
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100169 mutex_unlock(&socket->ops_mutex);
Dominik Brodowskib1769452008-11-09 21:47:47 +0100170 if (ret)
171 goto err;
172 }
173
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500174 tsk = kthread_run(pccardd, socket, "pccardd");
175 if (IS_ERR(tsk)) {
176 ret = PTR_ERR(tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 goto err;
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 wait_for_completion(&socket->thread_done);
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500181 if (!socket->thread) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200182 dev_printk(KERN_WARNING, &socket->dev,
183 "PCMCIA: warning: socket thread did not start\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return -EIO;
185 }
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 pcmcia_parse_events(socket, SS_DETECT);
188
Dominik Brodowski638bba52009-11-07 12:26:17 +0100189 /*
190 * Let's try to get the PCMCIA module for 16-bit PCMCIA support.
191 * If it fails, it doesn't matter -- we still have 32-bit CardBus
192 * support to offer, so this is not a failure mode.
193 */
194 request_module_nowait("pcmcia");
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 return 0;
197
198 err:
199 down_write(&pcmcia_socket_list_rwsem);
200 list_del(&socket->socket_list);
201 up_write(&pcmcia_socket_list_rwsem);
202 return ret;
203} /* pcmcia_register_socket */
204EXPORT_SYMBOL(pcmcia_register_socket);
205
206
207/**
208 * pcmcia_unregister_socket - remove a pcmcia socket device
Randy Dunlap78187862007-12-10 15:49:22 -0800209 * @socket: the &socket to unregister
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 */
211void pcmcia_unregister_socket(struct pcmcia_socket *socket)
212{
213 if (!socket)
214 return;
215
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200216 dev_dbg(&socket->dev, "pcmcia_unregister_socket(0x%p)\n", socket->ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Christoph Hellwig0b402092007-04-22 13:55:36 +0100218 if (socket->thread)
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500219 kthread_stop(socket->thread);
Christoph Hellwig0b402092007-04-22 13:55:36 +0100220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /* remove from our own list */
222 down_write(&pcmcia_socket_list_rwsem);
223 list_del(&socket->socket_list);
224 up_write(&pcmcia_socket_list_rwsem);
225
226 /* wait for sysfs to drop all references */
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100227 if (socket->resource_ops->exit) {
228 mutex_lock(&socket->ops_mutex);
Dominik Brodowski385ee872010-01-06 11:23:58 +0100229 socket->resource_ops->exit(socket);
Dominik Brodowskicfe5d802010-01-17 19:31:45 +0100230 mutex_unlock(&socket->ops_mutex);
231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 wait_for_completion(&socket->socket_released);
233} /* pcmcia_unregister_socket */
234EXPORT_SYMBOL(pcmcia_unregister_socket);
235
236
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100237struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 struct pcmcia_socket *s;
240
241 down_read(&pcmcia_socket_list_rwsem);
242 list_for_each_entry(s, &pcmcia_socket_list, socket_list)
243 if (s->sock == nr) {
244 up_read(&pcmcia_socket_list_rwsem);
245 return s;
246 }
247 up_read(&pcmcia_socket_list_rwsem);
248
249 return NULL;
250
251}
252EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254static int socket_reset(struct pcmcia_socket *skt)
255{
256 int status, i;
257
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200258 dev_dbg(&skt->dev, "reset\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 skt->socket.flags |= SS_OUTPUT_ENA | SS_RESET;
261 skt->ops->set_socket(skt, &skt->socket);
262 udelay((long)reset_time);
263
264 skt->socket.flags &= ~SS_RESET;
265 skt->ops->set_socket(skt, &skt->socket);
266
267 msleep(unreset_delay * 10);
268 for (i = 0; i < unreset_limit; i++) {
269 skt->ops->get_status(skt, &status);
270
271 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200272 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 if (status & SS_READY)
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200275 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 msleep(unreset_check * 10);
278 }
279
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200280 dev_printk(KERN_ERR, &skt->dev, "time out after reset.\n");
Dominik Brodowski85671422008-08-03 11:15:45 +0200281 return -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
Randy Dunlap78187862007-12-10 15:49:22 -0800284/*
Daniel Ritz6e493882005-12-30 15:12:35 +0100285 * socket_setup() and socket_shutdown() are called by the main event handler
286 * when card insertion and removal events are received.
287 * socket_setup() turns on socket power and resets the socket, in two stages.
288 * socket_shutdown() unconfigures a socket and turns off socket power.
289 */
290static void socket_shutdown(struct pcmcia_socket *s)
291{
292 int status;
293
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200294 dev_dbg(&s->dev, "shutdown\n");
Daniel Ritz6e493882005-12-30 15:12:35 +0100295
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200296 if (s->callback)
297 s->callback->remove(s);
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100298
299 mutex_lock(&s->ops_mutex);
Daniel Ritz6e493882005-12-30 15:12:35 +0100300 s->state &= SOCKET_INUSE | SOCKET_PRESENT;
301 msleep(shutdown_delay * 10);
302 s->state &= SOCKET_INUSE;
303
304 /* Blank out the socket state */
305 s->socket = dead_socket;
306 s->ops->init(s);
307 s->ops->set_socket(s, &s->socket);
Daniel Ritz6e493882005-12-30 15:12:35 +0100308 s->lock_count = 0;
Dominik Brodowski904e3772010-01-02 12:28:04 +0100309 kfree(s->fake_cis);
310 s->fake_cis = NULL;
Dominik Brodowskic3bfc962010-01-18 08:43:39 +0100311 s->functions = 0;
312
313 /* From here on we can be sure that only we (that is, the
314 * pccardd thread) accesses this socket, and all (16-bit)
315 * PCMCIA interactions are gone. Therefore, release
316 * ops_mutex so that we don't get a sysfs-related lockdep
317 * warning.
318 */
319 mutex_unlock(&s->ops_mutex);
320
Daniel Ritz6e493882005-12-30 15:12:35 +0100321#ifdef CONFIG_CARDBUS
322 cb_free(s);
323#endif
Daniel Ritz6e493882005-12-30 15:12:35 +0100324
Daniel Ritzafb2c162007-07-31 00:38:08 -0700325 /* give socket some time to power down */
326 msleep(100);
327
Daniel Ritz6e493882005-12-30 15:12:35 +0100328 s->ops->get_status(s, &status);
329 if (status & SS_POWERON) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200330 dev_printk(KERN_ERR, &s->dev,
331 "*** DANGER *** unable to remove socket power\n");
Daniel Ritz6e493882005-12-30 15:12:35 +0100332 }
333
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100334 s->state &= ~SOCKET_INUSE;
Daniel Ritz6e493882005-12-30 15:12:35 +0100335}
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
338{
339 int status, i;
340
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200341 dev_dbg(&skt->dev, "setup\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 skt->ops->get_status(skt, &status);
344 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200345 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 msleep(initial_delay * 10);
348
349 for (i = 0; i < 100; i++) {
350 skt->ops->get_status(skt, &status);
351 if (!(status & SS_DETECT))
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200352 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 if (!(status & SS_PENDING))
355 break;
356
357 msleep(100);
358 }
359
360 if (status & SS_PENDING) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200361 dev_printk(KERN_ERR, &skt->dev,
362 "voltage interrogation timed out.\n");
Dominik Brodowski85671422008-08-03 11:15:45 +0200363 return -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 }
365
366 if (status & SS_CARDBUS) {
Russell King5bc6b682005-07-07 17:59:07 -0700367 if (!(skt->features & SS_CAP_CARDBUS)) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200368 dev_printk(KERN_ERR, &skt->dev,
369 "cardbus cards are not supported.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200370 return -EINVAL;
Russell King5bc6b682005-07-07 17:59:07 -0700371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 skt->state |= SOCKET_CARDBUS;
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100373 } else
374 skt->state &= ~SOCKET_CARDBUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 /*
377 * Decode the card voltage requirements, and apply power to the card.
378 */
379 if (status & SS_3VCARD)
380 skt->socket.Vcc = skt->socket.Vpp = 33;
381 else if (!(status & SS_XVCARD))
382 skt->socket.Vcc = skt->socket.Vpp = 50;
383 else {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200384 dev_printk(KERN_ERR, &skt->dev, "unsupported voltage key.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200385 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 }
Daniel Ritzfa912bc2005-06-23 00:10:12 -0700387
388 if (skt->power_hook)
389 skt->power_hook(skt, HOOK_POWER_PRE);
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 skt->socket.flags = 0;
392 skt->ops->set_socket(skt, &skt->socket);
393
394 /*
395 * Wait "vcc_settle" for the supply to stabilise.
396 */
397 msleep(vcc_settle * 10);
398
399 skt->ops->get_status(skt, &status);
400 if (!(status & SS_POWERON)) {
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200401 dev_printk(KERN_ERR, &skt->dev, "unable to apply power.\n");
Dominik Brodowski610e2372008-08-03 11:58:53 +0200402 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404
Daniel Ritzfa912bc2005-06-23 00:10:12 -0700405 status = socket_reset(skt);
406
407 if (skt->power_hook)
408 skt->power_hook(skt, HOOK_POWER_POST);
409
410 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413/*
414 * Handle card insertion. Setup the socket, reset the card,
415 * and then tell the rest of PCMCIA that a card is present.
416 */
417static int socket_insert(struct pcmcia_socket *skt)
418{
419 int ret;
420
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200421 dev_dbg(&skt->dev, "insert\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100423 mutex_lock(&skt->ops_mutex);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100424 if (skt->state & SOCKET_INUSE) {
425 mutex_unlock(&skt->ops_mutex);
426 return -EINVAL;
427 }
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100428 skt->state |= SOCKET_INUSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 ret = socket_setup(skt, setup_delay);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200431 if (ret == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 skt->state |= SOCKET_PRESENT;
Dominik Brodowski807277c2005-11-12 23:34:06 +0100433
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200434 dev_printk(KERN_NOTICE, &skt->dev,
435 "pccard: %s card inserted into slot %d\n",
436 (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA",
437 skt->sock);
Dominik Brodowski807277c2005-11-12 23:34:06 +0100438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#ifdef CONFIG_CARDBUS
440 if (skt->state & SOCKET_CARDBUS) {
441 cb_alloc(skt);
442 skt->state |= SOCKET_CARDBUS_CONFIG;
443 }
444#endif
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200445 dev_dbg(&skt->dev, "insert done\n");
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100446 mutex_unlock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200448 if (!(skt->state & SOCKET_CARDBUS) && (skt->callback))
449 skt->callback->add(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 } else {
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100451 mutex_unlock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
455 return ret;
456}
457
458static int socket_suspend(struct pcmcia_socket *skt)
459{
460 if (skt->state & SOCKET_SUSPEND)
Dominik Brodowskif9580952008-08-03 11:40:19 +0200461 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100463 mutex_lock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100464 skt->suspended_state = skt->state;
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 skt->socket = dead_socket;
467 skt->ops->set_socket(skt, &skt->socket);
468 if (skt->ops->suspend)
469 skt->ops->suspend(skt);
470 skt->state |= SOCKET_SUSPEND;
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100471 mutex_unlock(&skt->ops_mutex);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200472 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100475static int socket_early_resume(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100477 mutex_lock(&skt->ops_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 skt->socket = dead_socket;
479 skt->ops->init(skt);
480 skt->ops->set_socket(skt, &skt->socket);
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100481 if (skt->state & SOCKET_PRESENT)
482 skt->resume_status = socket_setup(skt, resume_delay);
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100483 mutex_unlock(&skt->ops_mutex);
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100484 return 0;
485}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100487static int socket_late_resume(struct pcmcia_socket *skt)
488{
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100489 int ret;
490
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100491 mutex_lock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100492 skt->state &= ~SOCKET_SUSPEND;
Dominik Brodowski9e86749c2010-01-16 00:26:33 +0100493 mutex_unlock(&skt->ops_mutex);
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100494
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100495 if (!(skt->state & SOCKET_PRESENT)) {
496 ret = socket_insert(skt);
497 if (ret == -ENODEV)
498 ret = 0;
499 return ret;
500 }
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100501
502 if (skt->resume_status) {
503 socket_shutdown(skt);
504 return 0;
505 }
506
507 if (skt->suspended_state != skt->state) {
508 dev_dbg(&skt->dev,
509 "suspend state 0x%x != resume state 0x%x\n",
510 skt->suspended_state, skt->state);
511
512 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 return socket_insert(skt);
514 }
515
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100516#ifdef CONFIG_CARDBUS
517 if (skt->state & SOCKET_CARDBUS) {
518 /* We can't be sure the CardBus card is the same
519 * as the one previously inserted. Therefore, remove
520 * and re-add... */
521 cb_free(skt);
522 cb_alloc(skt);
523 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
Dominik Brodowski88b060d2010-01-02 14:14:23 +0100525#endif
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200526 if (!(skt->state & SOCKET_CARDBUS) && (skt->callback))
527 skt->callback->early_resume(skt);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200528 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529}
530
Rafael J. Wysocki9905d1b2009-11-03 10:54:58 +0100531/*
532 * Resume a socket. If a card is present, verify its CIS against
533 * our cached copy. If they are different, the card has been
534 * replaced, and we need to tell the drivers.
535 */
536static int socket_resume(struct pcmcia_socket *skt)
537{
538 if (!(skt->state & SOCKET_SUSPEND))
539 return -EBUSY;
540
541 socket_early_resume(skt);
542 return socket_late_resume(skt);
543}
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545static void socket_remove(struct pcmcia_socket *skt)
546{
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200547 dev_printk(KERN_NOTICE, &skt->dev,
548 "pccard: card ejected from slot %d\n", skt->sock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 socket_shutdown(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550}
551
552/*
553 * Process a socket card detect status change.
554 *
555 * If we don't have a card already present, delay the detect event for
556 * about 20ms (to be on the safe side) before reading the socket status.
557 *
558 * Some i82365-based systems send multiple SS_DETECT events during card
559 * insertion, and the "card present" status bit seems to bounce. This
560 * will probably be true with GPIO-based card detection systems after
561 * the product has aged.
562 */
563static void socket_detect_change(struct pcmcia_socket *skt)
564{
565 if (!(skt->state & SOCKET_SUSPEND)) {
566 int status;
567
568 if (!(skt->state & SOCKET_PRESENT))
569 msleep(20);
570
571 skt->ops->get_status(skt, &status);
572 if ((skt->state & SOCKET_PRESENT) &&
573 !(status & SS_DETECT))
574 socket_remove(skt);
575 if (!(skt->state & SOCKET_PRESENT) &&
576 (status & SS_DETECT))
577 socket_insert(skt);
578 }
579}
580
581static int pccardd(void *__skt)
582{
583 struct pcmcia_socket *skt = __skt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 int ret;
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 skt->thread = current;
587 skt->socket = dead_socket;
588 skt->ops->init(skt);
589 skt->ops->set_socket(skt, &skt->socket);
590
591 /* register with the device core */
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200592 ret = device_register(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (ret) {
Dominik Brodowski2e55bf62008-08-02 18:08:38 +0200594 dev_printk(KERN_WARNING, &skt->dev,
595 "PCMCIA: unable to register socket\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 skt->thread = NULL;
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500597 complete(&skt->thread_done);
598 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
David Brownell4356d732008-04-28 01:03:20 -0700600 ret = pccard_sysfs_add_socket(&skt->dev);
601 if (ret)
602 dev_warn(&skt->dev, "err %d adding socket attributes\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Daniel Ritzbf4de6f2005-09-09 13:03:23 -0700604 complete(&skt->thread_done);
605
Dominik Brodowskid801c1402010-02-17 11:02:22 +0100606 /* wait for userspace to catch up */
607 msleep(250);
608
Rafael J. Wysocki83144182007-07-17 04:03:35 -0700609 set_freezable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 for (;;) {
611 unsigned long flags;
612 unsigned int events;
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100613 unsigned int sysfs_events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 set_current_state(TASK_INTERRUPTIBLE);
616
617 spin_lock_irqsave(&skt->thread_lock, flags);
618 events = skt->thread_events;
619 skt->thread_events = 0;
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100620 sysfs_events = skt->sysfs_events;
621 skt->sysfs_events = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 spin_unlock_irqrestore(&skt->thread_lock, flags);
623
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100624 mutex_lock(&skt->skt_mutex);
Dominik Brodowski216d7cd2010-07-11 10:04:59 +0200625 if (events & SS_DETECT)
626 socket_detect_change(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100628 if (sysfs_events) {
629 if (sysfs_events & PCMCIA_UEVENT_EJECT)
630 socket_remove(skt);
631 if (sysfs_events & PCMCIA_UEVENT_INSERT)
632 socket_insert(skt);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100633 if ((sysfs_events & PCMCIA_UEVENT_SUSPEND) &&
634 !(skt->state & SOCKET_CARDBUS)) {
635 if (skt->callback)
636 ret = skt->callback->suspend(skt);
637 else
638 ret = 0;
Dominik Brodowski43821242010-05-03 15:10:09 +0200639 if (!ret) {
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100640 socket_suspend(skt);
Dominik Brodowski43821242010-05-03 15:10:09 +0200641 msleep(100);
642 }
643 }
644 if ((sysfs_events & PCMCIA_UEVENT_RESUME) &&
645 !(skt->state & SOCKET_CARDBUS)) {
646 ret = socket_resume(skt);
647 if (!ret && skt->callback)
648 skt->callback->resume(skt);
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100649 }
Dominik Brodowskiaf461fc2010-01-17 19:30:53 +0100650 if ((sysfs_events & PCMCIA_UEVENT_REQUERY) &&
651 !(skt->state & SOCKET_CARDBUS)) {
652 if (!ret && skt->callback)
653 skt->callback->requery(skt);
654 }
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100655 }
656 mutex_unlock(&skt->skt_mutex);
657
658 if (events || sysfs_events)
659 continue;
660
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500661 if (kthread_should_stop())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 break;
Daniel Ritzbf4de6f2005-09-09 13:03:23 -0700663
664 schedule();
665 try_to_freeze();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
Steven Rostedt220ec022005-10-10 11:13:17 -0400667 /* make sure we are running before we exit */
668 set_current_state(TASK_RUNNING);
669
Dominik Brodowski3970dd82010-01-02 23:19:45 +0100670 /* shut down socket, if a device is still present */
671 if (skt->state & SOCKET_PRESENT) {
672 mutex_lock(&skt->skt_mutex);
673 socket_remove(skt);
674 mutex_unlock(&skt->skt_mutex);
675 }
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /* remove from the device core */
David Brownell4356d732008-04-28 01:03:20 -0700678 pccard_sysfs_remove_socket(&skt->dev);
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200679 device_unregister(&skt->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Serge E. Hallyn1da9ab72006-06-14 08:01:26 -0500681 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682}
683
684/*
685 * Yenta (at least) probes interrupts before registering the socket and
686 * starting the handler thread.
687 */
688void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
689{
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200690 unsigned long flags;
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200691 dev_dbg(&s->dev, "parse_events: events %08x\n", events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 if (s->thread) {
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200693 spin_lock_irqsave(&s->thread_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 s->thread_events |= events;
Arjan van de Ven4b7a89a2006-06-30 10:31:13 +0200695 spin_unlock_irqrestore(&s->thread_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Christoph Hellwig0b402092007-04-22 13:55:36 +0100697 wake_up_process(s->thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 }
699} /* pcmcia_parse_events */
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700700EXPORT_SYMBOL(pcmcia_parse_events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100702/**
703 * pcmcia_parse_uevents() - tell pccardd to issue manual commands
704 * @s: the PCMCIA socket we wan't to command
705 * @events: events to pass to pccardd
706 *
707 * userspace-issued insert, eject, suspend and resume commands must be
708 * handled by pccardd to avoid any sysfs-related deadlocks. Valid events
709 * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert),
Dominik Brodowskiaf461fc2010-01-17 19:30:53 +0100710 * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend)
711 * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card).
Dominik Brodowskif971dbd2010-01-17 18:13:31 +0100712 */
713void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events)
714{
715 unsigned long flags;
716 dev_dbg(&s->dev, "parse_uevents: events %08x\n", events);
717 if (s->thread) {
718 spin_lock_irqsave(&s->thread_lock, flags);
719 s->sysfs_events |= events;
720 spin_unlock_irqrestore(&s->thread_lock, flags);
721
722 wake_up_process(s->thread);
723 }
724}
725EXPORT_SYMBOL(pcmcia_parse_uevents);
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728/* register pcmcia_callback */
729int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
730{
Dominik Brodowski9fea84f2009-12-07 22:11:45 +0100731 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100733 /* s->skt_mutex also protects s->callback */
734 mutex_lock(&s->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 if (c) {
737 /* registration */
738 if (s->callback) {
739 ret = -EBUSY;
740 goto err;
741 }
742
743 s->callback = c;
744
745 if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT)
Dominik Brodowski7b24e792010-07-11 10:26:53 +0200746 s->callback->add(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 } else
748 s->callback = NULL;
749 err:
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100750 mutex_unlock(&s->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 return ret;
753}
754EXPORT_SYMBOL(pccard_register_pcmcia);
755
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700757/* I'm not sure which "reset" function this is supposed to use,
758 * but for now, it uses the low-level interface's reset, not the
759 * CIS register.
760 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Dominik Brodowski994917f2008-08-31 15:20:26 +0200762int pcmcia_reset_card(struct pcmcia_socket *skt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763{
764 int ret;
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700765
Dominik Brodowskid50dbec2009-10-23 12:51:28 +0200766 dev_dbg(&skt->dev, "resetting socket\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100768 mutex_lock(&skt->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 do {
770 if (!(skt->state & SOCKET_PRESENT)) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200771 dev_dbg(&skt->dev, "can't reset, not present\n");
Dominik Brodowski3939c1ef2008-08-03 11:10:56 +0200772 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 break;
774 }
775 if (skt->state & SOCKET_SUSPEND) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200776 dev_dbg(&skt->dev, "can't reset, suspended\n");
Dominik Brodowskif9580952008-08-03 11:40:19 +0200777 ret = -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 break;
779 }
780 if (skt->state & SOCKET_CARDBUS) {
Dominik Brodowski6d9a2992009-10-24 12:20:18 +0200781 dev_dbg(&skt->dev, "can't reset, is cardbus\n");
Dominik Brodowskide6405e2008-08-03 10:47:59 +0200782 ret = -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 break;
784 }
785
Dominik Brodowski216d7cd2010-07-11 10:04:59 +0200786 if (skt->callback)
787 skt->callback->suspend(skt);
788 mutex_lock(&skt->ops_mutex);
789 ret = socket_reset(skt);
790 mutex_unlock(&skt->ops_mutex);
791 if ((ret == 0) && (skt->callback))
792 skt->callback->resume(skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200794 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 } while (0);
Dominik Brodowski7fe908d2006-01-10 21:20:36 +0100796 mutex_unlock(&skt->skt_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 return ret;
799} /* reset_card */
Dominik Brodowski994917f2008-08-31 15:20:26 +0200800EXPORT_SYMBOL(pcmcia_reset_card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Kay Sievers7eff2e72007-08-14 15:15:12 +0200803static int pcmcia_socket_uevent(struct device *dev,
804 struct kobj_uevent_env *env)
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700805{
806 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700807
Kay Sievers7eff2e72007-08-14 15:15:12 +0200808 if (add_uevent_var(env, "SOCKET_NO=%u", s->sock))
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700809 return -ENOMEM;
810
Dominik Brodowski3ee13932005-06-27 16:28:05 -0700811 return 0;
812}
813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700815static struct completion pcmcia_unload;
816
817static void pcmcia_release_socket_class(struct class *data)
818{
819 complete(&pcmcia_unload);
820}
821
822
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100823#ifdef CONFIG_PM
824
825static int __pcmcia_pm_op(struct device *dev,
826 int (*callback) (struct pcmcia_socket *skt))
827{
828 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
829 int ret;
830
831 mutex_lock(&s->skt_mutex);
832 ret = callback(s);
833 mutex_unlock(&s->skt_mutex);
834
835 return ret;
836}
837
838static int pcmcia_socket_dev_suspend_noirq(struct device *dev)
839{
840 return __pcmcia_pm_op(dev, socket_suspend);
841}
842
843static int pcmcia_socket_dev_resume_noirq(struct device *dev)
844{
845 return __pcmcia_pm_op(dev, socket_early_resume);
846}
847
848static int pcmcia_socket_dev_resume(struct device *dev)
849{
850 return __pcmcia_pm_op(dev, socket_late_resume);
851}
852
853static const struct dev_pm_ops pcmcia_socket_pm_ops = {
854 /* dev_resume may be called with IRQs enabled */
855 SET_SYSTEM_SLEEP_PM_OPS(NULL,
856 pcmcia_socket_dev_resume)
857
858 /* late suspend must be called with IRQs disabled */
859 .suspend_noirq = pcmcia_socket_dev_suspend_noirq,
860 .freeze_noirq = pcmcia_socket_dev_suspend_noirq,
861 .poweroff_noirq = pcmcia_socket_dev_suspend_noirq,
862
863 /* early resume must be called with IRQs disabled */
864 .resume_noirq = pcmcia_socket_dev_resume_noirq,
865 .thaw_noirq = pcmcia_socket_dev_resume_noirq,
866 .restore_noirq = pcmcia_socket_dev_resume_noirq,
867};
868
869#define PCMCIA_SOCKET_CLASS_PM_OPS (&pcmcia_socket_pm_ops)
870
871#else /* CONFIG_PM */
872
873#define PCMCIA_SOCKET_CLASS_PM_OPS NULL
874
875#endif /* CONFIG_PM */
876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877struct class pcmcia_socket_class = {
878 .name = "pcmcia_socket",
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200879 .dev_uevent = pcmcia_socket_uevent,
880 .dev_release = pcmcia_release_socket,
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700881 .class_release = pcmcia_release_socket_class,
Dominik Brodowskid7646f72010-03-15 21:46:34 +0100882 .pm = PCMCIA_SOCKET_CLASS_PM_OPS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883};
884EXPORT_SYMBOL(pcmcia_socket_class);
885
886
887static int __init init_pcmcia_cs(void)
888{
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700889 init_completion(&pcmcia_unload);
David Brownell4356d732008-04-28 01:03:20 -0700890 return class_register(&pcmcia_socket_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
893static void __exit exit_pcmcia_cs(void)
894{
Dominik Brodowski33519dd2005-06-27 16:28:53 -0700895 class_unregister(&pcmcia_socket_class);
Dominik Brodowski378a33a2005-06-27 16:28:54 -0700896 wait_for_completion(&pcmcia_unload);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897}
898
899subsys_initcall(init_pcmcia_cs);
900module_exit(exit_pcmcia_cs);
901