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
);
80 * Low-level PCMCIA socket drivers need to register with the PCCard
81 * core using pcmcia_register_socket.
83 * socket drivers are expected to use the following callbacks in their
85 * - pcmcia_socket_dev_suspend
86 * - pcmcia_socket_dev_resume
87 * These functions check for the appropriate struct pcmcia_soket arrays,
88 * and pass them to the low-level functions pcmcia_{suspend,resume}_socket
90 static int socket_early_resume(struct pcmcia_socket
*skt
);
91 static int socket_late_resume(struct pcmcia_socket
*skt
);
92 static int socket_resume(struct pcmcia_socket
*skt
);
93 static int socket_suspend(struct pcmcia_socket
*skt
);
95 static void pcmcia_socket_dev_run(struct device
*dev
,
96 int (*cb
)(struct pcmcia_socket
*))
98 struct pcmcia_socket
*socket
;
100 down_read(&pcmcia_socket_list_rwsem
);
101 list_for_each_entry(socket
, &pcmcia_socket_list
, socket_list
) {
102 if (socket
->dev
.parent
!= dev
)
104 mutex_lock(&socket
->skt_mutex
);
106 mutex_unlock(&socket
->skt_mutex
);
108 up_read(&pcmcia_socket_list_rwsem
);
111 int pcmcia_socket_dev_suspend(struct device
*dev
)
113 pcmcia_socket_dev_run(dev
, socket_suspend
);
116 EXPORT_SYMBOL(pcmcia_socket_dev_suspend
);
118 void pcmcia_socket_dev_early_resume(struct device
*dev
)
120 pcmcia_socket_dev_run(dev
, socket_early_resume
);
122 EXPORT_SYMBOL(pcmcia_socket_dev_early_resume
);
124 void pcmcia_socket_dev_late_resume(struct device
*dev
)
126 pcmcia_socket_dev_run(dev
, socket_late_resume
);
128 EXPORT_SYMBOL(pcmcia_socket_dev_late_resume
);
130 int pcmcia_socket_dev_resume(struct device
*dev
)
132 pcmcia_socket_dev_run(dev
, socket_resume
);
135 EXPORT_SYMBOL(pcmcia_socket_dev_resume
);
138 struct pcmcia_socket
*pcmcia_get_socket(struct pcmcia_socket
*skt
)
140 struct device
*dev
= get_device(&skt
->dev
);
143 return dev_get_drvdata(dev
);
145 EXPORT_SYMBOL(pcmcia_get_socket
);
148 void pcmcia_put_socket(struct pcmcia_socket
*skt
)
150 put_device(&skt
->dev
);
152 EXPORT_SYMBOL(pcmcia_put_socket
);
155 static void pcmcia_release_socket(struct device
*dev
)
157 struct pcmcia_socket
*socket
= dev_get_drvdata(dev
);
159 complete(&socket
->socket_released
);
162 static int pccardd(void *__skt
);
165 * pcmcia_register_socket - add a new pcmcia socket device
166 * @socket: the &socket to register
168 int pcmcia_register_socket(struct pcmcia_socket
*socket
)
170 struct task_struct
*tsk
;
173 if (!socket
|| !socket
->ops
|| !socket
->dev
.parent
|| !socket
->resource_ops
)
176 dev_dbg(&socket
->dev
, "pcmcia_register_socket(0x%p)\n", socket
->ops
);
178 /* try to obtain a socket number [yes, it gets ugly if we
179 * register more than 2^sizeof(unsigned int) pcmcia
180 * sockets... but the socket number is deprecated
181 * anyways, so I don't care] */
182 down_write(&pcmcia_socket_list_rwsem
);
183 if (list_empty(&pcmcia_socket_list
))
186 unsigned int found
, i
= 1;
187 struct pcmcia_socket
*tmp
;
190 list_for_each_entry(tmp
, &pcmcia_socket_list
, socket_list
) {
196 socket
->sock
= i
- 1;
198 list_add_tail(&socket
->socket_list
, &pcmcia_socket_list
);
199 up_write(&pcmcia_socket_list_rwsem
);
201 #ifndef CONFIG_CARDBUS
203 * If we do not support Cardbus, ensure that
204 * the Cardbus socket capability is disabled.
206 socket
->features
&= ~SS_CAP_CARDBUS
;
209 /* set proper values in socket->dev */
210 dev_set_drvdata(&socket
->dev
, socket
);
211 socket
->dev
.class = &pcmcia_socket_class
;
212 dev_set_name(&socket
->dev
, "pcmcia_socket%u", socket
->sock
);
214 /* base address = 0, map = 0 */
215 socket
->cis_mem
.flags
= 0;
216 socket
->cis_mem
.speed
= cis_speed
;
218 INIT_LIST_HEAD(&socket
->cis_cache
);
220 init_completion(&socket
->socket_released
);
221 init_completion(&socket
->thread_done
);
222 mutex_init(&socket
->skt_mutex
);
223 mutex_init(&socket
->ops_mutex
);
224 spin_lock_init(&socket
->thread_lock
);
226 if (socket
->resource_ops
->init
) {
227 mutex_lock(&socket
->ops_mutex
);
228 ret
= socket
->resource_ops
->init(socket
);
229 mutex_unlock(&socket
->ops_mutex
);
234 tsk
= kthread_run(pccardd
, socket
, "pccardd");
240 wait_for_completion(&socket
->thread_done
);
241 if (!socket
->thread
) {
242 dev_printk(KERN_WARNING
, &socket
->dev
,
243 "PCMCIA: warning: socket thread did not start\n");
247 pcmcia_parse_events(socket
, SS_DETECT
);
250 * Let's try to get the PCMCIA module for 16-bit PCMCIA support.
251 * If it fails, it doesn't matter -- we still have 32-bit CardBus
252 * support to offer, so this is not a failure mode.
254 request_module_nowait("pcmcia");
259 down_write(&pcmcia_socket_list_rwsem
);
260 list_del(&socket
->socket_list
);
261 up_write(&pcmcia_socket_list_rwsem
);
263 } /* pcmcia_register_socket */
264 EXPORT_SYMBOL(pcmcia_register_socket
);
268 * pcmcia_unregister_socket - remove a pcmcia socket device
269 * @socket: the &socket to unregister
271 void pcmcia_unregister_socket(struct pcmcia_socket
*socket
)
276 dev_dbg(&socket
->dev
, "pcmcia_unregister_socket(0x%p)\n", socket
->ops
);
279 kthread_stop(socket
->thread
);
281 /* remove from our own list */
282 down_write(&pcmcia_socket_list_rwsem
);
283 list_del(&socket
->socket_list
);
284 up_write(&pcmcia_socket_list_rwsem
);
286 /* wait for sysfs to drop all references */
287 if (socket
->resource_ops
->exit
) {
288 mutex_lock(&socket
->ops_mutex
);
289 socket
->resource_ops
->exit(socket
);
290 mutex_unlock(&socket
->ops_mutex
);
292 wait_for_completion(&socket
->socket_released
);
293 } /* pcmcia_unregister_socket */
294 EXPORT_SYMBOL(pcmcia_unregister_socket
);
297 struct pcmcia_socket
*pcmcia_get_socket_by_nr(unsigned int nr
)
299 struct pcmcia_socket
*s
;
301 down_read(&pcmcia_socket_list_rwsem
);
302 list_for_each_entry(s
, &pcmcia_socket_list
, socket_list
)
304 up_read(&pcmcia_socket_list_rwsem
);
307 up_read(&pcmcia_socket_list_rwsem
);
312 EXPORT_SYMBOL(pcmcia_get_socket_by_nr
);
315 * The central event handler. Send_event() sends an event to the
316 * 16-bit subsystem, which then calls the relevant device drivers.
317 * Parse_events() interprets the event bits from
318 * a card status change report. Do_shutdown() handles the high
319 * priority stuff associated with a card removal.
322 /* NOTE: send_event needs to be called with skt->sem held. */
324 static int send_event(struct pcmcia_socket
*s
, event_t event
, int priority
)
328 if ((s
->state
& SOCKET_CARDBUS
) && (event
!= CS_EVENT_CARD_REMOVAL
))
331 dev_dbg(&s
->dev
, "send_event(event %d, pri %d, callback 0x%p)\n",
332 event
, priority
, s
->callback
);
336 if (!try_module_get(s
->callback
->owner
))
339 ret
= s
->callback
->event(s
, event
, priority
);
341 module_put(s
->callback
->owner
);
346 static int socket_reset(struct pcmcia_socket
*skt
)
350 dev_dbg(&skt
->dev
, "reset\n");
352 skt
->socket
.flags
|= SS_OUTPUT_ENA
| SS_RESET
;
353 skt
->ops
->set_socket(skt
, &skt
->socket
);
354 udelay((long)reset_time
);
356 skt
->socket
.flags
&= ~SS_RESET
;
357 skt
->ops
->set_socket(skt
, &skt
->socket
);
359 msleep(unreset_delay
* 10);
360 for (i
= 0; i
< unreset_limit
; i
++) {
361 skt
->ops
->get_status(skt
, &status
);
363 if (!(status
& SS_DETECT
))
366 if (status
& SS_READY
)
369 msleep(unreset_check
* 10);
372 dev_printk(KERN_ERR
, &skt
->dev
, "time out after reset.\n");
377 * socket_setup() and socket_shutdown() are called by the main event handler
378 * when card insertion and removal events are received.
379 * socket_setup() turns on socket power and resets the socket, in two stages.
380 * socket_shutdown() unconfigures a socket and turns off socket power.
382 static void socket_shutdown(struct pcmcia_socket
*s
)
386 dev_dbg(&s
->dev
, "shutdown\n");
388 send_event(s
, CS_EVENT_CARD_REMOVAL
, CS_EVENT_PRI_HIGH
);
390 mutex_lock(&s
->ops_mutex
);
391 s
->state
&= SOCKET_INUSE
| SOCKET_PRESENT
;
392 msleep(shutdown_delay
* 10);
393 s
->state
&= SOCKET_INUSE
;
395 /* Blank out the socket state */
396 s
->socket
= dead_socket
;
398 s
->ops
->set_socket(s
, &s
->socket
);
399 s
->irq
.AssignedIRQ
= s
->irq
.Config
= 0;
403 #ifdef CONFIG_CARDBUS
408 /* give socket some time to power down */
411 s
->ops
->get_status(s
, &status
);
412 if (status
& SS_POWERON
) {
413 dev_printk(KERN_ERR
, &s
->dev
,
414 "*** DANGER *** unable to remove socket power\n");
417 s
->state
&= ~SOCKET_INUSE
;
418 mutex_unlock(&s
->ops_mutex
);
421 static int socket_setup(struct pcmcia_socket
*skt
, int initial_delay
)
425 dev_dbg(&skt
->dev
, "setup\n");
427 skt
->ops
->get_status(skt
, &status
);
428 if (!(status
& SS_DETECT
))
431 msleep(initial_delay
* 10);
433 for (i
= 0; i
< 100; i
++) {
434 skt
->ops
->get_status(skt
, &status
);
435 if (!(status
& SS_DETECT
))
438 if (!(status
& SS_PENDING
))
444 if (status
& SS_PENDING
) {
445 dev_printk(KERN_ERR
, &skt
->dev
,
446 "voltage interrogation timed out.\n");
450 if (status
& SS_CARDBUS
) {
451 if (!(skt
->features
& SS_CAP_CARDBUS
)) {
452 dev_printk(KERN_ERR
, &skt
->dev
,
453 "cardbus cards are not supported.\n");
456 skt
->state
|= SOCKET_CARDBUS
;
458 skt
->state
&= ~SOCKET_CARDBUS
;
461 * Decode the card voltage requirements, and apply power to the card.
463 if (status
& SS_3VCARD
)
464 skt
->socket
.Vcc
= skt
->socket
.Vpp
= 33;
465 else if (!(status
& SS_XVCARD
))
466 skt
->socket
.Vcc
= skt
->socket
.Vpp
= 50;
468 dev_printk(KERN_ERR
, &skt
->dev
, "unsupported voltage key.\n");
473 skt
->power_hook(skt
, HOOK_POWER_PRE
);
475 skt
->socket
.flags
= 0;
476 skt
->ops
->set_socket(skt
, &skt
->socket
);
479 * Wait "vcc_settle" for the supply to stabilise.
481 msleep(vcc_settle
* 10);
483 skt
->ops
->get_status(skt
, &status
);
484 if (!(status
& SS_POWERON
)) {
485 dev_printk(KERN_ERR
, &skt
->dev
, "unable to apply power.\n");
489 status
= socket_reset(skt
);
492 skt
->power_hook(skt
, HOOK_POWER_POST
);
498 * Handle card insertion. Setup the socket, reset the card,
499 * and then tell the rest of PCMCIA that a card is present.
501 static int socket_insert(struct pcmcia_socket
*skt
)
505 dev_dbg(&skt
->dev
, "insert\n");
507 mutex_lock(&skt
->ops_mutex
);
508 WARN_ON(skt
->state
& SOCKET_INUSE
);
509 skt
->state
|= SOCKET_INUSE
;
511 ret
= socket_setup(skt
, setup_delay
);
513 skt
->state
|= SOCKET_PRESENT
;
515 dev_printk(KERN_NOTICE
, &skt
->dev
,
516 "pccard: %s card inserted into slot %d\n",
517 (skt
->state
& SOCKET_CARDBUS
) ? "CardBus" : "PCMCIA",
520 #ifdef CONFIG_CARDBUS
521 if (skt
->state
& SOCKET_CARDBUS
) {
523 skt
->state
|= SOCKET_CARDBUS_CONFIG
;
526 dev_dbg(&skt
->dev
, "insert done\n");
527 mutex_unlock(&skt
->ops_mutex
);
529 send_event(skt
, CS_EVENT_CARD_INSERTION
, CS_EVENT_PRI_LOW
);
531 mutex_unlock(&skt
->ops_mutex
);
532 socket_shutdown(skt
);
538 static int socket_suspend(struct pcmcia_socket
*skt
)
540 if (skt
->state
& SOCKET_SUSPEND
)
543 mutex_lock(&skt
->ops_mutex
);
544 skt
->suspended_state
= skt
->state
;
546 send_event(skt
, CS_EVENT_PM_SUSPEND
, CS_EVENT_PRI_LOW
);
547 skt
->socket
= dead_socket
;
548 skt
->ops
->set_socket(skt
, &skt
->socket
);
549 if (skt
->ops
->suspend
)
550 skt
->ops
->suspend(skt
);
551 skt
->state
|= SOCKET_SUSPEND
;
552 mutex_unlock(&skt
->ops_mutex
);
556 static int socket_early_resume(struct pcmcia_socket
*skt
)
558 mutex_lock(&skt
->ops_mutex
);
559 skt
->socket
= dead_socket
;
561 skt
->ops
->set_socket(skt
, &skt
->socket
);
562 if (skt
->state
& SOCKET_PRESENT
)
563 skt
->resume_status
= socket_setup(skt
, resume_delay
);
564 mutex_unlock(&skt
->ops_mutex
);
568 static int socket_late_resume(struct pcmcia_socket
*skt
)
570 mutex_lock(&skt
->ops_mutex
);
571 skt
->state
&= ~SOCKET_SUSPEND
;
572 mutex_unlock(&skt
->ops_mutex
);
574 if (!(skt
->state
& SOCKET_PRESENT
))
575 return socket_insert(skt
);
577 if (skt
->resume_status
) {
578 socket_shutdown(skt
);
582 if (skt
->suspended_state
!= skt
->state
) {
584 "suspend state 0x%x != resume state 0x%x\n",
585 skt
->suspended_state
, skt
->state
);
587 socket_shutdown(skt
);
588 return socket_insert(skt
);
591 #ifdef CONFIG_CARDBUS
592 if (skt
->state
& SOCKET_CARDBUS
) {
593 /* We can't be sure the CardBus card is the same
594 * as the one previously inserted. Therefore, remove
602 send_event(skt
, CS_EVENT_PM_RESUME
, CS_EVENT_PRI_LOW
);
607 * Resume a socket. If a card is present, verify its CIS against
608 * our cached copy. If they are different, the card has been
609 * replaced, and we need to tell the drivers.
611 static int socket_resume(struct pcmcia_socket
*skt
)
613 if (!(skt
->state
& SOCKET_SUSPEND
))
616 socket_early_resume(skt
);
617 return socket_late_resume(skt
);
620 static void socket_remove(struct pcmcia_socket
*skt
)
622 dev_printk(KERN_NOTICE
, &skt
->dev
,
623 "pccard: card ejected from slot %d\n", skt
->sock
);
624 socket_shutdown(skt
);
628 * Process a socket card detect status change.
630 * If we don't have a card already present, delay the detect event for
631 * about 20ms (to be on the safe side) before reading the socket status.
633 * Some i82365-based systems send multiple SS_DETECT events during card
634 * insertion, and the "card present" status bit seems to bounce. This
635 * will probably be true with GPIO-based card detection systems after
636 * the product has aged.
638 static void socket_detect_change(struct pcmcia_socket
*skt
)
640 if (!(skt
->state
& SOCKET_SUSPEND
)) {
643 if (!(skt
->state
& SOCKET_PRESENT
))
646 skt
->ops
->get_status(skt
, &status
);
647 if ((skt
->state
& SOCKET_PRESENT
) &&
648 !(status
& SS_DETECT
))
650 if (!(skt
->state
& SOCKET_PRESENT
) &&
651 (status
& SS_DETECT
))
656 static int pccardd(void *__skt
)
658 struct pcmcia_socket
*skt
= __skt
;
661 skt
->thread
= current
;
662 skt
->socket
= dead_socket
;
664 skt
->ops
->set_socket(skt
, &skt
->socket
);
666 /* register with the device core */
667 ret
= device_register(&skt
->dev
);
669 dev_printk(KERN_WARNING
, &skt
->dev
,
670 "PCMCIA: unable to register socket\n");
672 complete(&skt
->thread_done
);
675 ret
= pccard_sysfs_add_socket(&skt
->dev
);
677 dev_warn(&skt
->dev
, "err %d adding socket attributes\n", ret
);
679 complete(&skt
->thread_done
);
686 set_current_state(TASK_INTERRUPTIBLE
);
688 spin_lock_irqsave(&skt
->thread_lock
, flags
);
689 events
= skt
->thread_events
;
690 skt
->thread_events
= 0;
691 spin_unlock_irqrestore(&skt
->thread_lock
, flags
);
694 mutex_lock(&skt
->skt_mutex
);
695 if (events
& SS_DETECT
)
696 socket_detect_change(skt
);
697 if (events
& SS_BATDEAD
)
698 send_event(skt
, CS_EVENT_BATTERY_DEAD
, CS_EVENT_PRI_LOW
);
699 if (events
& SS_BATWARN
)
700 send_event(skt
, CS_EVENT_BATTERY_LOW
, CS_EVENT_PRI_LOW
);
701 if (events
& SS_READY
)
702 send_event(skt
, CS_EVENT_READY_CHANGE
, CS_EVENT_PRI_LOW
);
703 mutex_unlock(&skt
->skt_mutex
);
707 if (kthread_should_stop())
713 /* make sure we are running before we exit */
714 set_current_state(TASK_RUNNING
);
716 /* shut down socket, if a device is still present */
717 if (skt
->state
& SOCKET_PRESENT
) {
718 mutex_lock(&skt
->skt_mutex
);
720 mutex_unlock(&skt
->skt_mutex
);
723 /* remove from the device core */
724 pccard_sysfs_remove_socket(&skt
->dev
);
725 device_unregister(&skt
->dev
);
731 * Yenta (at least) probes interrupts before registering the socket and
732 * starting the handler thread.
734 void pcmcia_parse_events(struct pcmcia_socket
*s
, u_int events
)
737 dev_dbg(&s
->dev
, "parse_events: events %08x\n", events
);
739 spin_lock_irqsave(&s
->thread_lock
, flags
);
740 s
->thread_events
|= events
;
741 spin_unlock_irqrestore(&s
->thread_lock
, flags
);
743 wake_up_process(s
->thread
);
745 } /* pcmcia_parse_events */
746 EXPORT_SYMBOL(pcmcia_parse_events
);
749 /* register pcmcia_callback */
750 int pccard_register_pcmcia(struct pcmcia_socket
*s
, struct pcmcia_callback
*c
)
754 /* s->skt_mutex also protects s->callback */
755 mutex_lock(&s
->skt_mutex
);
766 if ((s
->state
& (SOCKET_PRESENT
|SOCKET_CARDBUS
)) == SOCKET_PRESENT
)
767 send_event(s
, CS_EVENT_CARD_INSERTION
, CS_EVENT_PRI_LOW
);
771 mutex_unlock(&s
->skt_mutex
);
775 EXPORT_SYMBOL(pccard_register_pcmcia
);
778 /* I'm not sure which "reset" function this is supposed to use,
779 * but for now, it uses the low-level interface's reset, not the
783 int pcmcia_reset_card(struct pcmcia_socket
*skt
)
787 dev_dbg(&skt
->dev
, "resetting socket\n");
789 mutex_lock(&skt
->skt_mutex
);
791 if (!(skt
->state
& SOCKET_PRESENT
)) {
792 dev_dbg(&skt
->dev
, "can't reset, not present\n");
796 if (skt
->state
& SOCKET_SUSPEND
) {
797 dev_dbg(&skt
->dev
, "can't reset, suspended\n");
801 if (skt
->state
& SOCKET_CARDBUS
) {
802 dev_dbg(&skt
->dev
, "can't reset, is cardbus\n");
807 ret
= send_event(skt
, CS_EVENT_RESET_REQUEST
, CS_EVENT_PRI_LOW
);
809 send_event(skt
, CS_EVENT_RESET_PHYSICAL
, CS_EVENT_PRI_LOW
);
811 skt
->callback
->suspend(skt
);
812 mutex_lock(&skt
->ops_mutex
);
813 ret
= socket_reset(skt
);
814 mutex_unlock(&skt
->ops_mutex
);
816 send_event(skt
, CS_EVENT_CARD_RESET
, CS_EVENT_PRI_LOW
);
818 skt
->callback
->resume(skt
);
824 mutex_unlock(&skt
->skt_mutex
);
828 EXPORT_SYMBOL(pcmcia_reset_card
);
831 /* These shut down or wake up a socket. They are sort of user
832 * initiated versions of the APM suspend and resume actions.
834 int pcmcia_suspend_card(struct pcmcia_socket
*skt
)
838 dev_dbg(&skt
->dev
, "suspending socket\n");
840 mutex_lock(&skt
->skt_mutex
);
842 if (!(skt
->state
& SOCKET_PRESENT
)) {
846 if (skt
->state
& SOCKET_CARDBUS
) {
851 ret
= skt
->callback
->suspend(skt
);
855 ret
= socket_suspend(skt
);
857 mutex_unlock(&skt
->skt_mutex
);
861 EXPORT_SYMBOL(pcmcia_suspend_card
);
864 int pcmcia_resume_card(struct pcmcia_socket
*skt
)
868 dev_dbg(&skt
->dev
, "waking up socket\n");
870 mutex_lock(&skt
->skt_mutex
);
872 if (!(skt
->state
& SOCKET_PRESENT
)) {
876 if (skt
->state
& SOCKET_CARDBUS
) {
880 ret
= socket_resume(skt
);
881 if (!ret
&& skt
->callback
)
882 skt
->callback
->resume(skt
);
884 mutex_unlock(&skt
->skt_mutex
);
888 EXPORT_SYMBOL(pcmcia_resume_card
);
891 /* These handle user requests to eject or insert a card. */
892 int pcmcia_eject_card(struct pcmcia_socket
*skt
)
896 dev_dbg(&skt
->dev
, "user eject request\n");
898 mutex_lock(&skt
->skt_mutex
);
900 if (!(skt
->state
& SOCKET_PRESENT
)) {
905 ret
= send_event(skt
, CS_EVENT_EJECTION_REQUEST
, CS_EVENT_PRI_LOW
);
914 mutex_unlock(&skt
->skt_mutex
);
918 EXPORT_SYMBOL(pcmcia_eject_card
);
921 int pcmcia_insert_card(struct pcmcia_socket
*skt
)
925 dev_dbg(&skt
->dev
, "user insert request\n");
927 mutex_lock(&skt
->skt_mutex
);
929 if (skt
->state
& SOCKET_PRESENT
) {
933 if (socket_insert(skt
) == -ENODEV
) {
939 mutex_unlock(&skt
->skt_mutex
);
943 EXPORT_SYMBOL(pcmcia_insert_card
);
946 static int pcmcia_socket_uevent(struct device
*dev
,
947 struct kobj_uevent_env
*env
)
949 struct pcmcia_socket
*s
= container_of(dev
, struct pcmcia_socket
, dev
);
951 if (add_uevent_var(env
, "SOCKET_NO=%u", s
->sock
))
958 static struct completion pcmcia_unload
;
960 static void pcmcia_release_socket_class(struct class *data
)
962 complete(&pcmcia_unload
);
966 struct class pcmcia_socket_class
= {
967 .name
= "pcmcia_socket",
968 .dev_uevent
= pcmcia_socket_uevent
,
969 .dev_release
= pcmcia_release_socket
,
970 .class_release
= pcmcia_release_socket_class
,
972 EXPORT_SYMBOL(pcmcia_socket_class
);
975 static int __init
init_pcmcia_cs(void)
977 init_completion(&pcmcia_unload
);
978 return class_register(&pcmcia_socket_class
);
981 static void __exit
exit_pcmcia_cs(void)
983 class_unregister(&pcmcia_socket_class
);
984 wait_for_completion(&pcmcia_unload
);
987 subsys_initcall(init_pcmcia_cs
);
988 module_exit(exit_pcmcia_cs
);