2 * cs.c -- Kernel Card Services - core services
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.
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.
12 * (C) 1999 David A. Hinds
15 #include <linux/module.h>
16 #include <linux/moduleparam.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/major.h>
21 #include <linux/errno.h>
22 #include <linux/slab.h>
24 #include <linux/interrupt.h>
25 #include <linux/timer.h>
26 #include <linux/ioport.h>
27 #include <linux/delay.h>
29 #include <linux/device.h>
30 #include <linux/kthread.h>
31 #include <linux/freezer.h>
32 #include <asm/system.h>
35 #include <pcmcia/cs_types.h>
36 #include <pcmcia/ss.h>
37 #include <pcmcia/cs.h>
38 #include <pcmcia/cistpl.h>
39 #include <pcmcia/cisreg.h>
40 #include <pcmcia/ds.h>
41 #include "cs_internal.h"
44 /* Module parameters */
46 MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
47 MODULE_DESCRIPTION("Linux Kernel Card Services");
48 MODULE_LICENSE("GPL");
50 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
52 INT_MODULE_PARM(setup_delay
, 10); /* centiseconds */
53 INT_MODULE_PARM(resume_delay
, 20); /* centiseconds */
54 INT_MODULE_PARM(shutdown_delay
, 3); /* centiseconds */
55 INT_MODULE_PARM(vcc_settle
, 40); /* centiseconds */
56 INT_MODULE_PARM(reset_time
, 10); /* usecs */
57 INT_MODULE_PARM(unreset_delay
, 10); /* centiseconds */
58 INT_MODULE_PARM(unreset_check
, 10); /* centiseconds */
59 INT_MODULE_PARM(unreset_limit
, 30); /* unreset_check's */
61 /* Access speed for attribute memory windows */
62 INT_MODULE_PARM(cis_speed
, 300); /* ns */
65 socket_state_t dead_socket
= {
66 .csc_mask
= SS_DETECT
,
68 EXPORT_SYMBOL(dead_socket
);
71 /* List of all sockets, protected by a rwsem */
72 LIST_HEAD(pcmcia_socket_list
);
73 EXPORT_SYMBOL(pcmcia_socket_list
);
75 DECLARE_RWSEM(pcmcia_socket_list_rwsem
);
76 EXPORT_SYMBOL(pcmcia_socket_list_rwsem
);
79 struct pcmcia_socket
*pcmcia_get_socket(struct pcmcia_socket
*skt
)
81 struct device
*dev
= get_device(&skt
->dev
);
84 return dev_get_drvdata(dev
);
86 EXPORT_SYMBOL(pcmcia_get_socket
);
89 void pcmcia_put_socket(struct pcmcia_socket
*skt
)
91 put_device(&skt
->dev
);
93 EXPORT_SYMBOL(pcmcia_put_socket
);
96 static void pcmcia_release_socket(struct device
*dev
)
98 struct pcmcia_socket
*socket
= dev_get_drvdata(dev
);
100 complete(&socket
->socket_released
);
103 static int pccardd(void *__skt
);
106 * pcmcia_register_socket - add a new pcmcia socket device
107 * @socket: the &socket to register
109 int pcmcia_register_socket(struct pcmcia_socket
*socket
)
111 struct task_struct
*tsk
;
114 if (!socket
|| !socket
->ops
|| !socket
->dev
.parent
|| !socket
->resource_ops
)
117 dev_dbg(&socket
->dev
, "pcmcia_register_socket(0x%p)\n", socket
->ops
);
119 /* try to obtain a socket number [yes, it gets ugly if we
120 * register more than 2^sizeof(unsigned int) pcmcia
121 * sockets... but the socket number is deprecated
122 * anyways, so I don't care] */
123 down_write(&pcmcia_socket_list_rwsem
);
124 if (list_empty(&pcmcia_socket_list
))
127 unsigned int found
, i
= 1;
128 struct pcmcia_socket
*tmp
;
131 list_for_each_entry(tmp
, &pcmcia_socket_list
, socket_list
) {
137 socket
->sock
= i
- 1;
139 list_add_tail(&socket
->socket_list
, &pcmcia_socket_list
);
140 up_write(&pcmcia_socket_list_rwsem
);
142 #ifndef CONFIG_CARDBUS
144 * If we do not support Cardbus, ensure that
145 * the Cardbus socket capability is disabled.
147 socket
->features
&= ~SS_CAP_CARDBUS
;
150 /* set proper values in socket->dev */
151 dev_set_drvdata(&socket
->dev
, socket
);
152 socket
->dev
.class = &pcmcia_socket_class
;
153 dev_set_name(&socket
->dev
, "pcmcia_socket%u", socket
->sock
);
155 /* base address = 0, map = 0 */
156 socket
->cis_mem
.flags
= 0;
157 socket
->cis_mem
.speed
= cis_speed
;
159 INIT_LIST_HEAD(&socket
->cis_cache
);
161 init_completion(&socket
->socket_released
);
162 init_completion(&socket
->thread_done
);
163 mutex_init(&socket
->skt_mutex
);
164 mutex_init(&socket
->ops_mutex
);
165 spin_lock_init(&socket
->thread_lock
);
167 if (socket
->resource_ops
->init
) {
168 mutex_lock(&socket
->ops_mutex
);
169 ret
= socket
->resource_ops
->init(socket
);
170 mutex_unlock(&socket
->ops_mutex
);
175 tsk
= kthread_run(pccardd
, socket
, "pccardd");
181 wait_for_completion(&socket
->thread_done
);
182 if (!socket
->thread
) {
183 dev_printk(KERN_WARNING
, &socket
->dev
,
184 "PCMCIA: warning: socket thread did not start\n");
188 pcmcia_parse_events(socket
, SS_DETECT
);
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.
195 request_module_nowait("pcmcia");
200 down_write(&pcmcia_socket_list_rwsem
);
201 list_del(&socket
->socket_list
);
202 up_write(&pcmcia_socket_list_rwsem
);
204 } /* pcmcia_register_socket */
205 EXPORT_SYMBOL(pcmcia_register_socket
);
209 * pcmcia_unregister_socket - remove a pcmcia socket device
210 * @socket: the &socket to unregister
212 void pcmcia_unregister_socket(struct pcmcia_socket
*socket
)
217 dev_dbg(&socket
->dev
, "pcmcia_unregister_socket(0x%p)\n", socket
->ops
);
220 kthread_stop(socket
->thread
);
222 /* 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
);
227 /* wait for sysfs to drop all references */
228 if (socket
->resource_ops
->exit
) {
229 mutex_lock(&socket
->ops_mutex
);
230 socket
->resource_ops
->exit(socket
);
231 mutex_unlock(&socket
->ops_mutex
);
233 wait_for_completion(&socket
->socket_released
);
234 } /* pcmcia_unregister_socket */
235 EXPORT_SYMBOL(pcmcia_unregister_socket
);
238 struct pcmcia_socket
*pcmcia_get_socket_by_nr(unsigned int nr
)
240 struct pcmcia_socket
*s
;
242 down_read(&pcmcia_socket_list_rwsem
);
243 list_for_each_entry(s
, &pcmcia_socket_list
, socket_list
)
245 up_read(&pcmcia_socket_list_rwsem
);
248 up_read(&pcmcia_socket_list_rwsem
);
253 EXPORT_SYMBOL(pcmcia_get_socket_by_nr
);
256 * The central event handler. Send_event() sends an event to the
257 * 16-bit subsystem, which then calls the relevant device drivers.
258 * Parse_events() interprets the event bits from
259 * a card status change report. Do_shutdown() handles the high
260 * priority stuff associated with a card removal.
263 /* NOTE: send_event needs to be called with skt->sem held. */
265 static int send_event(struct pcmcia_socket
*s
, event_t event
, int priority
)
269 if ((s
->state
& SOCKET_CARDBUS
) && (event
!= CS_EVENT_CARD_REMOVAL
))
272 dev_dbg(&s
->dev
, "send_event(event %d, pri %d, callback 0x%p)\n",
273 event
, priority
, s
->callback
);
277 if (!try_module_get(s
->callback
->owner
))
280 ret
= s
->callback
->event(s
, event
, priority
);
282 module_put(s
->callback
->owner
);
287 static int socket_reset(struct pcmcia_socket
*skt
)
291 dev_dbg(&skt
->dev
, "reset\n");
293 skt
->socket
.flags
|= SS_OUTPUT_ENA
| SS_RESET
;
294 skt
->ops
->set_socket(skt
, &skt
->socket
);
295 udelay((long)reset_time
);
297 skt
->socket
.flags
&= ~SS_RESET
;
298 skt
->ops
->set_socket(skt
, &skt
->socket
);
300 msleep(unreset_delay
* 10);
301 for (i
= 0; i
< unreset_limit
; i
++) {
302 skt
->ops
->get_status(skt
, &status
);
304 if (!(status
& SS_DETECT
))
307 if (status
& SS_READY
)
310 msleep(unreset_check
* 10);
313 dev_printk(KERN_ERR
, &skt
->dev
, "time out after reset.\n");
318 * socket_setup() and socket_shutdown() are called by the main event handler
319 * when card insertion and removal events are received.
320 * socket_setup() turns on socket power and resets the socket, in two stages.
321 * socket_shutdown() unconfigures a socket and turns off socket power.
323 static void socket_shutdown(struct pcmcia_socket
*s
)
327 dev_dbg(&s
->dev
, "shutdown\n");
329 send_event(s
, CS_EVENT_CARD_REMOVAL
, CS_EVENT_PRI_HIGH
);
331 mutex_lock(&s
->ops_mutex
);
332 s
->state
&= SOCKET_INUSE
| SOCKET_PRESENT
;
333 msleep(shutdown_delay
* 10);
334 s
->state
&= SOCKET_INUSE
;
336 /* Blank out the socket state */
337 s
->socket
= dead_socket
;
339 s
->ops
->set_socket(s
, &s
->socket
);
345 /* From here on we can be sure that only we (that is, the
346 * pccardd thread) accesses this socket, and all (16-bit)
347 * PCMCIA interactions are gone. Therefore, release
348 * ops_mutex so that we don't get a sysfs-related lockdep
351 mutex_unlock(&s
->ops_mutex
);
353 #ifdef CONFIG_CARDBUS
357 /* give socket some time to power down */
360 s
->ops
->get_status(s
, &status
);
361 if (status
& SS_POWERON
) {
362 dev_printk(KERN_ERR
, &s
->dev
,
363 "*** DANGER *** unable to remove socket power\n");
366 s
->state
&= ~SOCKET_INUSE
;
369 static int socket_setup(struct pcmcia_socket
*skt
, int initial_delay
)
373 dev_dbg(&skt
->dev
, "setup\n");
375 skt
->ops
->get_status(skt
, &status
);
376 if (!(status
& SS_DETECT
))
379 msleep(initial_delay
* 10);
381 for (i
= 0; i
< 100; i
++) {
382 skt
->ops
->get_status(skt
, &status
);
383 if (!(status
& SS_DETECT
))
386 if (!(status
& SS_PENDING
))
392 if (status
& SS_PENDING
) {
393 dev_printk(KERN_ERR
, &skt
->dev
,
394 "voltage interrogation timed out.\n");
398 if (status
& SS_CARDBUS
) {
399 if (!(skt
->features
& SS_CAP_CARDBUS
)) {
400 dev_printk(KERN_ERR
, &skt
->dev
,
401 "cardbus cards are not supported.\n");
404 skt
->state
|= SOCKET_CARDBUS
;
406 skt
->state
&= ~SOCKET_CARDBUS
;
409 * Decode the card voltage requirements, and apply power to the card.
411 if (status
& SS_3VCARD
)
412 skt
->socket
.Vcc
= skt
->socket
.Vpp
= 33;
413 else if (!(status
& SS_XVCARD
))
414 skt
->socket
.Vcc
= skt
->socket
.Vpp
= 50;
416 dev_printk(KERN_ERR
, &skt
->dev
, "unsupported voltage key.\n");
421 skt
->power_hook(skt
, HOOK_POWER_PRE
);
423 skt
->socket
.flags
= 0;
424 skt
->ops
->set_socket(skt
, &skt
->socket
);
427 * Wait "vcc_settle" for the supply to stabilise.
429 msleep(vcc_settle
* 10);
431 skt
->ops
->get_status(skt
, &status
);
432 if (!(status
& SS_POWERON
)) {
433 dev_printk(KERN_ERR
, &skt
->dev
, "unable to apply power.\n");
437 status
= socket_reset(skt
);
440 skt
->power_hook(skt
, HOOK_POWER_POST
);
446 * Handle card insertion. Setup the socket, reset the card,
447 * and then tell the rest of PCMCIA that a card is present.
449 static int socket_insert(struct pcmcia_socket
*skt
)
453 dev_dbg(&skt
->dev
, "insert\n");
455 mutex_lock(&skt
->ops_mutex
);
456 if (skt
->state
& SOCKET_INUSE
) {
457 mutex_unlock(&skt
->ops_mutex
);
460 skt
->state
|= SOCKET_INUSE
;
462 ret
= socket_setup(skt
, setup_delay
);
464 skt
->state
|= SOCKET_PRESENT
;
466 dev_printk(KERN_NOTICE
, &skt
->dev
,
467 "pccard: %s card inserted into slot %d\n",
468 (skt
->state
& SOCKET_CARDBUS
) ? "CardBus" : "PCMCIA",
471 #ifdef CONFIG_CARDBUS
472 if (skt
->state
& SOCKET_CARDBUS
) {
474 skt
->state
|= SOCKET_CARDBUS_CONFIG
;
477 dev_dbg(&skt
->dev
, "insert done\n");
478 mutex_unlock(&skt
->ops_mutex
);
480 send_event(skt
, CS_EVENT_CARD_INSERTION
, CS_EVENT_PRI_LOW
);
482 mutex_unlock(&skt
->ops_mutex
);
483 socket_shutdown(skt
);
489 static int socket_suspend(struct pcmcia_socket
*skt
)
491 if (skt
->state
& SOCKET_SUSPEND
)
494 mutex_lock(&skt
->ops_mutex
);
495 skt
->suspended_state
= skt
->state
;
497 send_event(skt
, CS_EVENT_PM_SUSPEND
, CS_EVENT_PRI_LOW
);
498 skt
->socket
= dead_socket
;
499 skt
->ops
->set_socket(skt
, &skt
->socket
);
500 if (skt
->ops
->suspend
)
501 skt
->ops
->suspend(skt
);
502 skt
->state
|= SOCKET_SUSPEND
;
503 mutex_unlock(&skt
->ops_mutex
);
507 static int socket_early_resume(struct pcmcia_socket
*skt
)
509 mutex_lock(&skt
->ops_mutex
);
510 skt
->socket
= dead_socket
;
512 skt
->ops
->set_socket(skt
, &skt
->socket
);
513 if (skt
->state
& SOCKET_PRESENT
)
514 skt
->resume_status
= socket_setup(skt
, resume_delay
);
515 mutex_unlock(&skt
->ops_mutex
);
519 static int socket_late_resume(struct pcmcia_socket
*skt
)
523 mutex_lock(&skt
->ops_mutex
);
524 skt
->state
&= ~SOCKET_SUSPEND
;
525 mutex_unlock(&skt
->ops_mutex
);
527 if (!(skt
->state
& SOCKET_PRESENT
)) {
528 ret
= socket_insert(skt
);
534 if (skt
->resume_status
) {
535 socket_shutdown(skt
);
539 if (skt
->suspended_state
!= skt
->state
) {
541 "suspend state 0x%x != resume state 0x%x\n",
542 skt
->suspended_state
, skt
->state
);
544 socket_shutdown(skt
);
545 return socket_insert(skt
);
548 #ifdef CONFIG_CARDBUS
549 if (skt
->state
& SOCKET_CARDBUS
) {
550 /* We can't be sure the CardBus card is the same
551 * as the one previously inserted. Therefore, remove
559 send_event(skt
, CS_EVENT_PM_RESUME
, CS_EVENT_PRI_LOW
);
564 * Resume a socket. If a card is present, verify its CIS against
565 * our cached copy. If they are different, the card has been
566 * replaced, and we need to tell the drivers.
568 static int socket_resume(struct pcmcia_socket
*skt
)
570 if (!(skt
->state
& SOCKET_SUSPEND
))
573 socket_early_resume(skt
);
574 return socket_late_resume(skt
);
577 static void socket_remove(struct pcmcia_socket
*skt
)
579 dev_printk(KERN_NOTICE
, &skt
->dev
,
580 "pccard: card ejected from slot %d\n", skt
->sock
);
581 socket_shutdown(skt
);
585 * Process a socket card detect status change.
587 * If we don't have a card already present, delay the detect event for
588 * about 20ms (to be on the safe side) before reading the socket status.
590 * Some i82365-based systems send multiple SS_DETECT events during card
591 * insertion, and the "card present" status bit seems to bounce. This
592 * will probably be true with GPIO-based card detection systems after
593 * the product has aged.
595 static void socket_detect_change(struct pcmcia_socket
*skt
)
597 if (!(skt
->state
& SOCKET_SUSPEND
)) {
600 if (!(skt
->state
& SOCKET_PRESENT
))
603 skt
->ops
->get_status(skt
, &status
);
604 if ((skt
->state
& SOCKET_PRESENT
) &&
605 !(status
& SS_DETECT
))
607 if (!(skt
->state
& SOCKET_PRESENT
) &&
608 (status
& SS_DETECT
))
613 static int pccardd(void *__skt
)
615 struct pcmcia_socket
*skt
= __skt
;
618 skt
->thread
= current
;
619 skt
->socket
= dead_socket
;
621 skt
->ops
->set_socket(skt
, &skt
->socket
);
623 /* register with the device core */
624 ret
= device_register(&skt
->dev
);
626 dev_printk(KERN_WARNING
, &skt
->dev
,
627 "PCMCIA: unable to register socket\n");
629 complete(&skt
->thread_done
);
632 ret
= pccard_sysfs_add_socket(&skt
->dev
);
634 dev_warn(&skt
->dev
, "err %d adding socket attributes\n", ret
);
636 complete(&skt
->thread_done
);
638 /* wait for userspace to catch up */
645 unsigned int sysfs_events
;
647 set_current_state(TASK_INTERRUPTIBLE
);
649 spin_lock_irqsave(&skt
->thread_lock
, flags
);
650 events
= skt
->thread_events
;
651 skt
->thread_events
= 0;
652 sysfs_events
= skt
->sysfs_events
;
653 skt
->sysfs_events
= 0;
654 spin_unlock_irqrestore(&skt
->thread_lock
, flags
);
656 mutex_lock(&skt
->skt_mutex
);
658 if (events
& SS_DETECT
)
659 socket_detect_change(skt
);
660 if (events
& SS_BATDEAD
)
661 send_event(skt
, CS_EVENT_BATTERY_DEAD
, CS_EVENT_PRI_LOW
);
662 if (events
& SS_BATWARN
)
663 send_event(skt
, CS_EVENT_BATTERY_LOW
, CS_EVENT_PRI_LOW
);
664 if (events
& SS_READY
)
665 send_event(skt
, CS_EVENT_READY_CHANGE
, CS_EVENT_PRI_LOW
);
669 if (sysfs_events
& PCMCIA_UEVENT_EJECT
)
671 if (sysfs_events
& PCMCIA_UEVENT_INSERT
)
673 if ((sysfs_events
& PCMCIA_UEVENT_SUSPEND
) &&
674 !(skt
->state
& SOCKET_CARDBUS
)) {
676 ret
= skt
->callback
->suspend(skt
);
684 if ((sysfs_events
& PCMCIA_UEVENT_RESUME
) &&
685 !(skt
->state
& SOCKET_CARDBUS
)) {
686 ret
= socket_resume(skt
);
687 if (!ret
&& skt
->callback
)
688 skt
->callback
->resume(skt
);
690 if ((sysfs_events
& PCMCIA_UEVENT_REQUERY
) &&
691 !(skt
->state
& SOCKET_CARDBUS
)) {
692 if (!ret
&& skt
->callback
)
693 skt
->callback
->requery(skt
);
696 mutex_unlock(&skt
->skt_mutex
);
698 if (events
|| sysfs_events
)
701 if (kthread_should_stop())
707 /* make sure we are running before we exit */
708 set_current_state(TASK_RUNNING
);
710 /* shut down socket, if a device is still present */
711 if (skt
->state
& SOCKET_PRESENT
) {
712 mutex_lock(&skt
->skt_mutex
);
714 mutex_unlock(&skt
->skt_mutex
);
717 /* remove from the device core */
718 pccard_sysfs_remove_socket(&skt
->dev
);
719 device_unregister(&skt
->dev
);
725 * Yenta (at least) probes interrupts before registering the socket and
726 * starting the handler thread.
728 void pcmcia_parse_events(struct pcmcia_socket
*s
, u_int events
)
731 dev_dbg(&s
->dev
, "parse_events: events %08x\n", events
);
733 spin_lock_irqsave(&s
->thread_lock
, flags
);
734 s
->thread_events
|= events
;
735 spin_unlock_irqrestore(&s
->thread_lock
, flags
);
737 wake_up_process(s
->thread
);
739 } /* pcmcia_parse_events */
740 EXPORT_SYMBOL(pcmcia_parse_events
);
743 * pcmcia_parse_uevents() - tell pccardd to issue manual commands
744 * @s: the PCMCIA socket we wan't to command
745 * @events: events to pass to pccardd
747 * userspace-issued insert, eject, suspend and resume commands must be
748 * handled by pccardd to avoid any sysfs-related deadlocks. Valid events
749 * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert),
750 * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend)
751 * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card).
753 void pcmcia_parse_uevents(struct pcmcia_socket
*s
, u_int events
)
756 dev_dbg(&s
->dev
, "parse_uevents: events %08x\n", events
);
758 spin_lock_irqsave(&s
->thread_lock
, flags
);
759 s
->sysfs_events
|= events
;
760 spin_unlock_irqrestore(&s
->thread_lock
, flags
);
762 wake_up_process(s
->thread
);
765 EXPORT_SYMBOL(pcmcia_parse_uevents
);
768 /* register pcmcia_callback */
769 int pccard_register_pcmcia(struct pcmcia_socket
*s
, struct pcmcia_callback
*c
)
773 /* s->skt_mutex also protects s->callback */
774 mutex_lock(&s
->skt_mutex
);
785 if ((s
->state
& (SOCKET_PRESENT
|SOCKET_CARDBUS
)) == SOCKET_PRESENT
)
786 send_event(s
, CS_EVENT_CARD_INSERTION
, CS_EVENT_PRI_LOW
);
790 mutex_unlock(&s
->skt_mutex
);
794 EXPORT_SYMBOL(pccard_register_pcmcia
);
797 /* I'm not sure which "reset" function this is supposed to use,
798 * but for now, it uses the low-level interface's reset, not the
802 int pcmcia_reset_card(struct pcmcia_socket
*skt
)
806 dev_dbg(&skt
->dev
, "resetting socket\n");
808 mutex_lock(&skt
->skt_mutex
);
810 if (!(skt
->state
& SOCKET_PRESENT
)) {
811 dev_dbg(&skt
->dev
, "can't reset, not present\n");
815 if (skt
->state
& SOCKET_SUSPEND
) {
816 dev_dbg(&skt
->dev
, "can't reset, suspended\n");
820 if (skt
->state
& SOCKET_CARDBUS
) {
821 dev_dbg(&skt
->dev
, "can't reset, is cardbus\n");
826 ret
= send_event(skt
, CS_EVENT_RESET_REQUEST
, CS_EVENT_PRI_LOW
);
828 send_event(skt
, CS_EVENT_RESET_PHYSICAL
, CS_EVENT_PRI_LOW
);
830 skt
->callback
->suspend(skt
);
831 mutex_lock(&skt
->ops_mutex
);
832 ret
= socket_reset(skt
);
833 mutex_unlock(&skt
->ops_mutex
);
835 send_event(skt
, CS_EVENT_CARD_RESET
, CS_EVENT_PRI_LOW
);
837 skt
->callback
->resume(skt
);
843 mutex_unlock(&skt
->skt_mutex
);
847 EXPORT_SYMBOL(pcmcia_reset_card
);
850 static int pcmcia_socket_uevent(struct device
*dev
,
851 struct kobj_uevent_env
*env
)
853 struct pcmcia_socket
*s
= container_of(dev
, struct pcmcia_socket
, dev
);
855 if (add_uevent_var(env
, "SOCKET_NO=%u", s
->sock
))
862 static struct completion pcmcia_unload
;
864 static void pcmcia_release_socket_class(struct class *data
)
866 complete(&pcmcia_unload
);
872 static int __pcmcia_pm_op(struct device
*dev
,
873 int (*callback
) (struct pcmcia_socket
*skt
))
875 struct pcmcia_socket
*s
= container_of(dev
, struct pcmcia_socket
, dev
);
878 mutex_lock(&s
->skt_mutex
);
880 mutex_unlock(&s
->skt_mutex
);
885 static int pcmcia_socket_dev_suspend_noirq(struct device
*dev
)
887 return __pcmcia_pm_op(dev
, socket_suspend
);
890 static int pcmcia_socket_dev_resume_noirq(struct device
*dev
)
892 return __pcmcia_pm_op(dev
, socket_early_resume
);
895 static int pcmcia_socket_dev_resume(struct device
*dev
)
897 return __pcmcia_pm_op(dev
, socket_late_resume
);
900 static const struct dev_pm_ops pcmcia_socket_pm_ops
= {
901 /* dev_resume may be called with IRQs enabled */
902 SET_SYSTEM_SLEEP_PM_OPS(NULL
,
903 pcmcia_socket_dev_resume
)
905 /* late suspend must be called with IRQs disabled */
906 .suspend_noirq
= pcmcia_socket_dev_suspend_noirq
,
907 .freeze_noirq
= pcmcia_socket_dev_suspend_noirq
,
908 .poweroff_noirq
= pcmcia_socket_dev_suspend_noirq
,
910 /* early resume must be called with IRQs disabled */
911 .resume_noirq
= pcmcia_socket_dev_resume_noirq
,
912 .thaw_noirq
= pcmcia_socket_dev_resume_noirq
,
913 .restore_noirq
= pcmcia_socket_dev_resume_noirq
,
916 #define PCMCIA_SOCKET_CLASS_PM_OPS (&pcmcia_socket_pm_ops)
918 #else /* CONFIG_PM */
920 #define PCMCIA_SOCKET_CLASS_PM_OPS NULL
922 #endif /* CONFIG_PM */
924 struct class pcmcia_socket_class
= {
925 .name
= "pcmcia_socket",
926 .dev_uevent
= pcmcia_socket_uevent
,
927 .dev_release
= pcmcia_release_socket
,
928 .class_release
= pcmcia_release_socket_class
,
929 .pm
= PCMCIA_SOCKET_CLASS_PM_OPS
,
931 EXPORT_SYMBOL(pcmcia_socket_class
);
934 static int __init
init_pcmcia_cs(void)
936 init_completion(&pcmcia_unload
);
937 return class_register(&pcmcia_socket_class
);
940 static void __exit
exit_pcmcia_cs(void)
942 class_unregister(&pcmcia_socket_class
);
943 wait_for_completion(&pcmcia_unload
);
946 subsys_initcall(init_pcmcia_cs
);
947 module_exit(exit_pcmcia_cs
);