This source file includes following definitions.
- pcmcia_get_socket
- pcmcia_put_socket
- pcmcia_release_socket
- pcmcia_register_socket
- pcmcia_unregister_socket
- pcmcia_get_socket_by_nr
- socket_reset
- socket_shutdown
- socket_setup
- socket_insert
- socket_suspend
- socket_early_resume
- socket_late_resume
- socket_complete_resume
- socket_resume
- socket_remove
- socket_detect_change
- pccardd
- pcmcia_parse_events
- pcmcia_parse_uevents
- pccard_register_pcmcia
- pcmcia_reset_card
- pcmcia_socket_uevent
- pcmcia_release_socket_class
- __pcmcia_pm_op
- pcmcia_socket_dev_suspend_noirq
- pcmcia_socket_dev_resume_noirq
- pcmcia_socket_dev_resume
- pcmcia_socket_dev_complete
- init_pcmcia_cs
- exit_pcmcia_cs
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/major.h>
18 #include <linux/errno.h>
19 #include <linux/slab.h>
20 #include <linux/mm.h>
21 #include <linux/interrupt.h>
22 #include <linux/timer.h>
23 #include <linux/ioport.h>
24 #include <linux/delay.h>
25 #include <linux/pm.h>
26 #include <linux/device.h>
27 #include <linux/kthread.h>
28 #include <linux/freezer.h>
29 #include <asm/irq.h>
30
31 #include <pcmcia/ss.h>
32 #include <pcmcia/cistpl.h>
33 #include <pcmcia/cisreg.h>
34 #include <pcmcia/ds.h>
35 #include "cs_internal.h"
36
37
38
39
40 MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
41 MODULE_DESCRIPTION("Linux Kernel Card Services");
42 MODULE_LICENSE("GPL");
43
44 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
45
46 INT_MODULE_PARM(setup_delay, 10);
47 INT_MODULE_PARM(resume_delay, 20);
48 INT_MODULE_PARM(shutdown_delay, 3);
49 INT_MODULE_PARM(vcc_settle, 40);
50 INT_MODULE_PARM(reset_time, 10);
51 INT_MODULE_PARM(unreset_delay, 10);
52 INT_MODULE_PARM(unreset_check, 10);
53 INT_MODULE_PARM(unreset_limit, 30);
54
55
56 INT_MODULE_PARM(cis_speed, 300);
57
58
59 socket_state_t dead_socket = {
60 .csc_mask = SS_DETECT,
61 };
62 EXPORT_SYMBOL(dead_socket);
63
64
65
66 LIST_HEAD(pcmcia_socket_list);
67 EXPORT_SYMBOL(pcmcia_socket_list);
68
69 DECLARE_RWSEM(pcmcia_socket_list_rwsem);
70 EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
71
72
73 struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt)
74 {
75 struct device *dev = get_device(&skt->dev);
76 if (!dev)
77 return NULL;
78 return dev_get_drvdata(dev);
79 }
80 EXPORT_SYMBOL(pcmcia_get_socket);
81
82
83 void pcmcia_put_socket(struct pcmcia_socket *skt)
84 {
85 put_device(&skt->dev);
86 }
87 EXPORT_SYMBOL(pcmcia_put_socket);
88
89
90 static void pcmcia_release_socket(struct device *dev)
91 {
92 struct pcmcia_socket *socket = dev_get_drvdata(dev);
93
94 complete(&socket->socket_released);
95 }
96
97 static int pccardd(void *__skt);
98
99
100
101
102
103 int pcmcia_register_socket(struct pcmcia_socket *socket)
104 {
105 struct task_struct *tsk;
106 int ret;
107
108 if (!socket || !socket->ops || !socket->dev.parent || !socket->resource_ops)
109 return -EINVAL;
110
111 dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops);
112
113
114
115
116
117 down_write(&pcmcia_socket_list_rwsem);
118 if (list_empty(&pcmcia_socket_list))
119 socket->sock = 0;
120 else {
121 unsigned int found, i = 1;
122 struct pcmcia_socket *tmp;
123 do {
124 found = 1;
125 list_for_each_entry(tmp, &pcmcia_socket_list, socket_list) {
126 if (tmp->sock == i)
127 found = 0;
128 }
129 i++;
130 } while (!found);
131 socket->sock = i - 1;
132 }
133 list_add_tail(&socket->socket_list, &pcmcia_socket_list);
134 up_write(&pcmcia_socket_list_rwsem);
135
136 #ifndef CONFIG_CARDBUS
137
138
139
140
141 socket->features &= ~SS_CAP_CARDBUS;
142 #endif
143
144
145 dev_set_drvdata(&socket->dev, socket);
146 socket->dev.class = &pcmcia_socket_class;
147 dev_set_name(&socket->dev, "pcmcia_socket%u", socket->sock);
148
149
150 socket->cis_mem.flags = 0;
151 socket->cis_mem.speed = cis_speed;
152
153 INIT_LIST_HEAD(&socket->cis_cache);
154
155 init_completion(&socket->socket_released);
156 init_completion(&socket->thread_done);
157 mutex_init(&socket->skt_mutex);
158 mutex_init(&socket->ops_mutex);
159 spin_lock_init(&socket->thread_lock);
160
161 if (socket->resource_ops->init) {
162 mutex_lock(&socket->ops_mutex);
163 ret = socket->resource_ops->init(socket);
164 mutex_unlock(&socket->ops_mutex);
165 if (ret)
166 goto err;
167 }
168
169 tsk = kthread_run(pccardd, socket, "pccardd");
170 if (IS_ERR(tsk)) {
171 ret = PTR_ERR(tsk);
172 goto err;
173 }
174
175 wait_for_completion(&socket->thread_done);
176 if (!socket->thread) {
177 dev_warn(&socket->dev,
178 "PCMCIA: warning: socket thread did not start\n");
179 return -EIO;
180 }
181
182 pcmcia_parse_events(socket, SS_DETECT);
183
184
185
186
187
188
189 request_module_nowait("pcmcia");
190
191 return 0;
192
193 err:
194 down_write(&pcmcia_socket_list_rwsem);
195 list_del(&socket->socket_list);
196 up_write(&pcmcia_socket_list_rwsem);
197 return ret;
198 }
199 EXPORT_SYMBOL(pcmcia_register_socket);
200
201
202
203
204
205
206 void pcmcia_unregister_socket(struct pcmcia_socket *socket)
207 {
208 if (!socket)
209 return;
210
211 dev_dbg(&socket->dev, "pcmcia_unregister_socket(0x%p)\n", socket->ops);
212
213 if (socket->thread)
214 kthread_stop(socket->thread);
215
216
217 down_write(&pcmcia_socket_list_rwsem);
218 list_del(&socket->socket_list);
219 up_write(&pcmcia_socket_list_rwsem);
220
221
222 if (socket->resource_ops->exit) {
223 mutex_lock(&socket->ops_mutex);
224 socket->resource_ops->exit(socket);
225 mutex_unlock(&socket->ops_mutex);
226 }
227 wait_for_completion(&socket->socket_released);
228 }
229 EXPORT_SYMBOL(pcmcia_unregister_socket);
230
231
232 struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr)
233 {
234 struct pcmcia_socket *s;
235
236 down_read(&pcmcia_socket_list_rwsem);
237 list_for_each_entry(s, &pcmcia_socket_list, socket_list)
238 if (s->sock == nr) {
239 up_read(&pcmcia_socket_list_rwsem);
240 return s;
241 }
242 up_read(&pcmcia_socket_list_rwsem);
243
244 return NULL;
245
246 }
247 EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
248
249 static int socket_reset(struct pcmcia_socket *skt)
250 {
251 int status, i;
252
253 dev_dbg(&skt->dev, "reset\n");
254
255 skt->socket.flags |= SS_OUTPUT_ENA | SS_RESET;
256 skt->ops->set_socket(skt, &skt->socket);
257 udelay((long)reset_time);
258
259 skt->socket.flags &= ~SS_RESET;
260 skt->ops->set_socket(skt, &skt->socket);
261
262 msleep(unreset_delay * 10);
263 for (i = 0; i < unreset_limit; i++) {
264 skt->ops->get_status(skt, &status);
265
266 if (!(status & SS_DETECT))
267 return -ENODEV;
268
269 if (status & SS_READY)
270 return 0;
271
272 msleep(unreset_check * 10);
273 }
274
275 dev_err(&skt->dev, "time out after reset\n");
276 return -ETIMEDOUT;
277 }
278
279
280
281
282
283
284
285 static void socket_shutdown(struct pcmcia_socket *s)
286 {
287 int status;
288
289 dev_dbg(&s->dev, "shutdown\n");
290
291 if (s->callback)
292 s->callback->remove(s);
293
294 mutex_lock(&s->ops_mutex);
295 s->state &= SOCKET_INUSE | SOCKET_PRESENT;
296 msleep(shutdown_delay * 10);
297 s->state &= SOCKET_INUSE;
298
299
300 s->socket = dead_socket;
301 s->ops->init(s);
302 s->ops->set_socket(s, &s->socket);
303 s->lock_count = 0;
304 kfree(s->fake_cis);
305 s->fake_cis = NULL;
306 s->functions = 0;
307
308
309
310
311
312
313
314 mutex_unlock(&s->ops_mutex);
315
316 #ifdef CONFIG_CARDBUS
317 cb_free(s);
318 #endif
319
320
321 msleep(100);
322
323 s->ops->get_status(s, &status);
324 if (status & SS_POWERON) {
325 dev_err(&s->dev,
326 "*** DANGER *** unable to remove socket power\n");
327 }
328
329 s->state &= ~SOCKET_INUSE;
330 }
331
332 static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
333 {
334 int status, i;
335
336 dev_dbg(&skt->dev, "setup\n");
337
338 skt->ops->get_status(skt, &status);
339 if (!(status & SS_DETECT))
340 return -ENODEV;
341
342 msleep(initial_delay * 10);
343
344 for (i = 0; i < 100; i++) {
345 skt->ops->get_status(skt, &status);
346 if (!(status & SS_DETECT))
347 return -ENODEV;
348
349 if (!(status & SS_PENDING))
350 break;
351
352 msleep(100);
353 }
354
355 if (status & SS_PENDING) {
356 dev_err(&skt->dev, "voltage interrogation timed out\n");
357 return -ETIMEDOUT;
358 }
359
360 if (status & SS_CARDBUS) {
361 if (!(skt->features & SS_CAP_CARDBUS)) {
362 dev_err(&skt->dev, "cardbus cards are not supported\n");
363 return -EINVAL;
364 }
365 skt->state |= SOCKET_CARDBUS;
366 } else
367 skt->state &= ~SOCKET_CARDBUS;
368
369
370
371
372 if (status & SS_3VCARD)
373 skt->socket.Vcc = skt->socket.Vpp = 33;
374 else if (!(status & SS_XVCARD))
375 skt->socket.Vcc = skt->socket.Vpp = 50;
376 else {
377 dev_err(&skt->dev, "unsupported voltage key\n");
378 return -EIO;
379 }
380
381 if (skt->power_hook)
382 skt->power_hook(skt, HOOK_POWER_PRE);
383
384 skt->socket.flags = 0;
385 skt->ops->set_socket(skt, &skt->socket);
386
387
388
389
390 msleep(vcc_settle * 10);
391
392 skt->ops->get_status(skt, &status);
393 if (!(status & SS_POWERON)) {
394 dev_err(&skt->dev, "unable to apply power\n");
395 return -EIO;
396 }
397
398 status = socket_reset(skt);
399
400 if (skt->power_hook)
401 skt->power_hook(skt, HOOK_POWER_POST);
402
403 return status;
404 }
405
406
407
408
409
410 static int socket_insert(struct pcmcia_socket *skt)
411 {
412 int ret;
413
414 dev_dbg(&skt->dev, "insert\n");
415
416 mutex_lock(&skt->ops_mutex);
417 if (skt->state & SOCKET_INUSE) {
418 mutex_unlock(&skt->ops_mutex);
419 return -EINVAL;
420 }
421 skt->state |= SOCKET_INUSE;
422
423 ret = socket_setup(skt, setup_delay);
424 if (ret == 0) {
425 skt->state |= SOCKET_PRESENT;
426
427 dev_notice(&skt->dev, "pccard: %s card inserted into slot %d\n",
428 (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA",
429 skt->sock);
430
431 #ifdef CONFIG_CARDBUS
432 if (skt->state & SOCKET_CARDBUS) {
433 cb_alloc(skt);
434 skt->state |= SOCKET_CARDBUS_CONFIG;
435 }
436 #endif
437 dev_dbg(&skt->dev, "insert done\n");
438 mutex_unlock(&skt->ops_mutex);
439
440 if (!(skt->state & SOCKET_CARDBUS) && (skt->callback))
441 skt->callback->add(skt);
442 } else {
443 mutex_unlock(&skt->ops_mutex);
444 socket_shutdown(skt);
445 }
446
447 return ret;
448 }
449
450 static int socket_suspend(struct pcmcia_socket *skt)
451 {
452 if ((skt->state & SOCKET_SUSPEND) && !(skt->state & SOCKET_IN_RESUME))
453 return -EBUSY;
454
455 mutex_lock(&skt->ops_mutex);
456
457 if (!(skt->state & SOCKET_IN_RESUME))
458 skt->suspended_state = skt->state;
459
460 skt->socket = dead_socket;
461 skt->ops->set_socket(skt, &skt->socket);
462 if (skt->ops->suspend)
463 skt->ops->suspend(skt);
464 skt->state |= SOCKET_SUSPEND;
465 skt->state &= ~SOCKET_IN_RESUME;
466 mutex_unlock(&skt->ops_mutex);
467 return 0;
468 }
469
470 static int socket_early_resume(struct pcmcia_socket *skt)
471 {
472 mutex_lock(&skt->ops_mutex);
473 skt->socket = dead_socket;
474 skt->ops->init(skt);
475 skt->ops->set_socket(skt, &skt->socket);
476 if (skt->state & SOCKET_PRESENT)
477 skt->resume_status = socket_setup(skt, resume_delay);
478 skt->state |= SOCKET_IN_RESUME;
479 mutex_unlock(&skt->ops_mutex);
480 return 0;
481 }
482
483 static int socket_late_resume(struct pcmcia_socket *skt)
484 {
485 int ret = 0;
486
487 mutex_lock(&skt->ops_mutex);
488 skt->state &= ~(SOCKET_SUSPEND | SOCKET_IN_RESUME);
489 mutex_unlock(&skt->ops_mutex);
490
491 if (!(skt->state & SOCKET_PRESENT)) {
492 ret = socket_insert(skt);
493 if (ret == -ENODEV)
494 ret = 0;
495 return ret;
496 }
497
498 if (skt->resume_status) {
499 socket_shutdown(skt);
500 return 0;
501 }
502
503 if (skt->suspended_state != skt->state) {
504 dev_dbg(&skt->dev,
505 "suspend state 0x%x != resume state 0x%x\n",
506 skt->suspended_state, skt->state);
507
508 socket_shutdown(skt);
509 return socket_insert(skt);
510 }
511
512 if (!(skt->state & SOCKET_CARDBUS) && (skt->callback))
513 ret = skt->callback->early_resume(skt);
514 return ret;
515 }
516
517
518
519
520
521
522 static int socket_complete_resume(struct pcmcia_socket *skt)
523 {
524 int ret = 0;
525 #ifdef CONFIG_CARDBUS
526 if (skt->state & SOCKET_CARDBUS) {
527
528
529
530 cb_free(skt);
531 ret = cb_alloc(skt);
532 if (ret)
533 cb_free(skt);
534 }
535 #endif
536 return ret;
537 }
538
539
540
541
542
543
544 static int socket_resume(struct pcmcia_socket *skt)
545 {
546 int err;
547 if (!(skt->state & SOCKET_SUSPEND))
548 return -EBUSY;
549
550 socket_early_resume(skt);
551 err = socket_late_resume(skt);
552 if (!err)
553 err = socket_complete_resume(skt);
554 return err;
555 }
556
557 static void socket_remove(struct pcmcia_socket *skt)
558 {
559 dev_notice(&skt->dev, "pccard: card ejected from slot %d\n", skt->sock);
560 socket_shutdown(skt);
561 }
562
563
564
565
566
567
568
569
570
571
572
573
574 static void socket_detect_change(struct pcmcia_socket *skt)
575 {
576 if (!(skt->state & SOCKET_SUSPEND)) {
577 int status;
578
579 if (!(skt->state & SOCKET_PRESENT))
580 msleep(20);
581
582 skt->ops->get_status(skt, &status);
583 if ((skt->state & SOCKET_PRESENT) &&
584 !(status & SS_DETECT))
585 socket_remove(skt);
586 if (!(skt->state & SOCKET_PRESENT) &&
587 (status & SS_DETECT))
588 socket_insert(skt);
589 }
590 }
591
592 static int pccardd(void *__skt)
593 {
594 struct pcmcia_socket *skt = __skt;
595 int ret;
596
597 skt->thread = current;
598 skt->socket = dead_socket;
599 skt->ops->init(skt);
600 skt->ops->set_socket(skt, &skt->socket);
601
602
603 ret = device_register(&skt->dev);
604 if (ret) {
605 dev_warn(&skt->dev, "PCMCIA: unable to register socket\n");
606 skt->thread = NULL;
607 complete(&skt->thread_done);
608 return 0;
609 }
610 ret = pccard_sysfs_add_socket(&skt->dev);
611 if (ret)
612 dev_warn(&skt->dev, "err %d adding socket attributes\n", ret);
613
614 complete(&skt->thread_done);
615
616
617 msleep(250);
618
619 set_freezable();
620 for (;;) {
621 unsigned long flags;
622 unsigned int events;
623 unsigned int sysfs_events;
624
625 spin_lock_irqsave(&skt->thread_lock, flags);
626 events = skt->thread_events;
627 skt->thread_events = 0;
628 sysfs_events = skt->sysfs_events;
629 skt->sysfs_events = 0;
630 spin_unlock_irqrestore(&skt->thread_lock, flags);
631
632 mutex_lock(&skt->skt_mutex);
633 if (events & SS_DETECT)
634 socket_detect_change(skt);
635
636 if (sysfs_events) {
637 if (sysfs_events & PCMCIA_UEVENT_EJECT)
638 socket_remove(skt);
639 if (sysfs_events & PCMCIA_UEVENT_INSERT)
640 socket_insert(skt);
641 if ((sysfs_events & PCMCIA_UEVENT_SUSPEND) &&
642 !(skt->state & SOCKET_CARDBUS)) {
643 if (skt->callback)
644 ret = skt->callback->suspend(skt);
645 else
646 ret = 0;
647 if (!ret) {
648 socket_suspend(skt);
649 msleep(100);
650 }
651 }
652 if ((sysfs_events & PCMCIA_UEVENT_RESUME) &&
653 !(skt->state & SOCKET_CARDBUS)) {
654 ret = socket_resume(skt);
655 if (!ret && skt->callback)
656 skt->callback->resume(skt);
657 }
658 if ((sysfs_events & PCMCIA_UEVENT_REQUERY) &&
659 !(skt->state & SOCKET_CARDBUS)) {
660 if (!ret && skt->callback)
661 skt->callback->requery(skt);
662 }
663 }
664 mutex_unlock(&skt->skt_mutex);
665
666 if (events || sysfs_events)
667 continue;
668
669 if (kthread_should_stop())
670 break;
671
672 set_current_state(TASK_INTERRUPTIBLE);
673
674 schedule();
675
676
677 __set_current_state(TASK_RUNNING);
678
679 try_to_freeze();
680 }
681
682
683 if (skt->state & SOCKET_PRESENT) {
684 mutex_lock(&skt->skt_mutex);
685 socket_remove(skt);
686 mutex_unlock(&skt->skt_mutex);
687 }
688
689
690 pccard_sysfs_remove_socket(&skt->dev);
691 device_unregister(&skt->dev);
692
693 return 0;
694 }
695
696
697
698
699
700 void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
701 {
702 unsigned long flags;
703 dev_dbg(&s->dev, "parse_events: events %08x\n", events);
704 if (s->thread) {
705 spin_lock_irqsave(&s->thread_lock, flags);
706 s->thread_events |= events;
707 spin_unlock_irqrestore(&s->thread_lock, flags);
708
709 wake_up_process(s->thread);
710 }
711 }
712 EXPORT_SYMBOL(pcmcia_parse_events);
713
714
715
716
717
718
719
720
721
722
723
724
725 void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events)
726 {
727 unsigned long flags;
728 dev_dbg(&s->dev, "parse_uevents: events %08x\n", events);
729 if (s->thread) {
730 spin_lock_irqsave(&s->thread_lock, flags);
731 s->sysfs_events |= events;
732 spin_unlock_irqrestore(&s->thread_lock, flags);
733
734 wake_up_process(s->thread);
735 }
736 }
737 EXPORT_SYMBOL(pcmcia_parse_uevents);
738
739
740
741 int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
742 {
743 int ret = 0;
744
745
746 mutex_lock(&s->skt_mutex);
747
748 if (c) {
749
750 if (s->callback) {
751 ret = -EBUSY;
752 goto err;
753 }
754
755 s->callback = c;
756
757 if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT)
758 s->callback->add(s);
759 } else
760 s->callback = NULL;
761 err:
762 mutex_unlock(&s->skt_mutex);
763
764 return ret;
765 }
766 EXPORT_SYMBOL(pccard_register_pcmcia);
767
768
769
770
771
772
773
774 int pcmcia_reset_card(struct pcmcia_socket *skt)
775 {
776 int ret;
777
778 dev_dbg(&skt->dev, "resetting socket\n");
779
780 mutex_lock(&skt->skt_mutex);
781 do {
782 if (!(skt->state & SOCKET_PRESENT)) {
783 dev_dbg(&skt->dev, "can't reset, not present\n");
784 ret = -ENODEV;
785 break;
786 }
787 if (skt->state & SOCKET_SUSPEND) {
788 dev_dbg(&skt->dev, "can't reset, suspended\n");
789 ret = -EBUSY;
790 break;
791 }
792 if (skt->state & SOCKET_CARDBUS) {
793 dev_dbg(&skt->dev, "can't reset, is cardbus\n");
794 ret = -EPERM;
795 break;
796 }
797
798 if (skt->callback)
799 skt->callback->suspend(skt);
800 mutex_lock(&skt->ops_mutex);
801 ret = socket_reset(skt);
802 mutex_unlock(&skt->ops_mutex);
803 if ((ret == 0) && (skt->callback))
804 skt->callback->resume(skt);
805
806 ret = 0;
807 } while (0);
808 mutex_unlock(&skt->skt_mutex);
809
810 return ret;
811 }
812 EXPORT_SYMBOL(pcmcia_reset_card);
813
814
815 static int pcmcia_socket_uevent(struct device *dev,
816 struct kobj_uevent_env *env)
817 {
818 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
819
820 if (add_uevent_var(env, "SOCKET_NO=%u", s->sock))
821 return -ENOMEM;
822
823 return 0;
824 }
825
826
827 static struct completion pcmcia_unload;
828
829 static void pcmcia_release_socket_class(struct class *data)
830 {
831 complete(&pcmcia_unload);
832 }
833
834
835 #ifdef CONFIG_PM
836
837 static int __pcmcia_pm_op(struct device *dev,
838 int (*callback) (struct pcmcia_socket *skt))
839 {
840 struct pcmcia_socket *s = container_of(dev, struct pcmcia_socket, dev);
841 int ret;
842
843 mutex_lock(&s->skt_mutex);
844 ret = callback(s);
845 mutex_unlock(&s->skt_mutex);
846
847 return ret;
848 }
849
850 static int pcmcia_socket_dev_suspend_noirq(struct device *dev)
851 {
852 return __pcmcia_pm_op(dev, socket_suspend);
853 }
854
855 static int pcmcia_socket_dev_resume_noirq(struct device *dev)
856 {
857 return __pcmcia_pm_op(dev, socket_early_resume);
858 }
859
860 static int __used pcmcia_socket_dev_resume(struct device *dev)
861 {
862 return __pcmcia_pm_op(dev, socket_late_resume);
863 }
864
865 static void __used pcmcia_socket_dev_complete(struct device *dev)
866 {
867 WARN(__pcmcia_pm_op(dev, socket_complete_resume),
868 "failed to complete resume");
869 }
870
871 static const struct dev_pm_ops pcmcia_socket_pm_ops = {
872
873 SET_SYSTEM_SLEEP_PM_OPS(NULL,
874 pcmcia_socket_dev_resume)
875
876
877 .suspend_noirq = pcmcia_socket_dev_suspend_noirq,
878 .freeze_noirq = pcmcia_socket_dev_suspend_noirq,
879 .poweroff_noirq = pcmcia_socket_dev_suspend_noirq,
880
881
882 .resume_noirq = pcmcia_socket_dev_resume_noirq,
883 .thaw_noirq = pcmcia_socket_dev_resume_noirq,
884 .restore_noirq = pcmcia_socket_dev_resume_noirq,
885 .complete = pcmcia_socket_dev_complete,
886 };
887
888 #define PCMCIA_SOCKET_CLASS_PM_OPS (&pcmcia_socket_pm_ops)
889
890 #else
891
892 #define PCMCIA_SOCKET_CLASS_PM_OPS NULL
893
894 #endif
895
896 struct class pcmcia_socket_class = {
897 .name = "pcmcia_socket",
898 .dev_uevent = pcmcia_socket_uevent,
899 .dev_release = pcmcia_release_socket,
900 .class_release = pcmcia_release_socket_class,
901 .pm = PCMCIA_SOCKET_CLASS_PM_OPS,
902 };
903 EXPORT_SYMBOL(pcmcia_socket_class);
904
905
906 static int __init init_pcmcia_cs(void)
907 {
908 init_completion(&pcmcia_unload);
909 return class_register(&pcmcia_socket_class);
910 }
911
912 static void __exit exit_pcmcia_cs(void)
913 {
914 class_unregister(&pcmcia_socket_class);
915 wait_for_completion(&pcmcia_unload);
916 }
917
918 subsys_initcall(init_pcmcia_cs);
919 module_exit(exit_pcmcia_cs);
920