diff options
Diffstat (limited to 'drivers/pcmcia/cs.c')
-rw-r--r-- | drivers/pcmcia/cs.c | 312 |
1 files changed, 142 insertions, 170 deletions
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 6d6f82b38a68..e679e708db63 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c | |||
@@ -140,19 +140,13 @@ struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt) | |||
140 | struct device *dev = get_device(&skt->dev); | 140 | struct device *dev = get_device(&skt->dev); |
141 | if (!dev) | 141 | if (!dev) |
142 | return NULL; | 142 | return NULL; |
143 | skt = dev_get_drvdata(dev); | 143 | return dev_get_drvdata(dev); |
144 | if (!try_module_get(skt->owner)) { | ||
145 | put_device(&skt->dev); | ||
146 | return NULL; | ||
147 | } | ||
148 | return skt; | ||
149 | } | 144 | } |
150 | EXPORT_SYMBOL(pcmcia_get_socket); | 145 | EXPORT_SYMBOL(pcmcia_get_socket); |
151 | 146 | ||
152 | 147 | ||
153 | void pcmcia_put_socket(struct pcmcia_socket *skt) | 148 | void pcmcia_put_socket(struct pcmcia_socket *skt) |
154 | { | 149 | { |
155 | module_put(skt->owner); | ||
156 | put_device(&skt->dev); | 150 | put_device(&skt->dev); |
157 | } | 151 | } |
158 | EXPORT_SYMBOL(pcmcia_put_socket); | 152 | EXPORT_SYMBOL(pcmcia_put_socket); |
@@ -181,8 +175,6 @@ int pcmcia_register_socket(struct pcmcia_socket *socket) | |||
181 | 175 | ||
182 | dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops); | 176 | dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops); |
183 | 177 | ||
184 | spin_lock_init(&socket->lock); | ||
185 | |||
186 | /* try to obtain a socket number [yes, it gets ugly if we | 178 | /* try to obtain a socket number [yes, it gets ugly if we |
187 | * register more than 2^sizeof(unsigned int) pcmcia | 179 | * register more than 2^sizeof(unsigned int) pcmcia |
188 | * sockets... but the socket number is deprecated | 180 | * sockets... but the socket number is deprecated |
@@ -228,10 +220,13 @@ int pcmcia_register_socket(struct pcmcia_socket *socket) | |||
228 | init_completion(&socket->socket_released); | 220 | init_completion(&socket->socket_released); |
229 | init_completion(&socket->thread_done); | 221 | init_completion(&socket->thread_done); |
230 | mutex_init(&socket->skt_mutex); | 222 | mutex_init(&socket->skt_mutex); |
223 | mutex_init(&socket->ops_mutex); | ||
231 | spin_lock_init(&socket->thread_lock); | 224 | spin_lock_init(&socket->thread_lock); |
232 | 225 | ||
233 | if (socket->resource_ops->init) { | 226 | if (socket->resource_ops->init) { |
227 | mutex_lock(&socket->ops_mutex); | ||
234 | ret = socket->resource_ops->init(socket); | 228 | ret = socket->resource_ops->init(socket); |
229 | mutex_unlock(&socket->ops_mutex); | ||
235 | if (ret) | 230 | if (ret) |
236 | goto err; | 231 | goto err; |
237 | } | 232 | } |
@@ -283,15 +278,17 @@ void pcmcia_unregister_socket(struct pcmcia_socket *socket) | |||
283 | if (socket->thread) | 278 | if (socket->thread) |
284 | kthread_stop(socket->thread); | 279 | kthread_stop(socket->thread); |
285 | 280 | ||
286 | release_cis_mem(socket); | ||
287 | |||
288 | /* remove from our own list */ | 281 | /* remove from our own list */ |
289 | down_write(&pcmcia_socket_list_rwsem); | 282 | down_write(&pcmcia_socket_list_rwsem); |
290 | list_del(&socket->socket_list); | 283 | list_del(&socket->socket_list); |
291 | up_write(&pcmcia_socket_list_rwsem); | 284 | up_write(&pcmcia_socket_list_rwsem); |
292 | 285 | ||
293 | /* wait for sysfs to drop all references */ | 286 | /* wait for sysfs to drop all references */ |
294 | release_resource_db(socket); | 287 | if (socket->resource_ops->exit) { |
288 | mutex_lock(&socket->ops_mutex); | ||
289 | socket->resource_ops->exit(socket); | ||
290 | mutex_unlock(&socket->ops_mutex); | ||
291 | } | ||
295 | wait_for_completion(&socket->socket_released); | 292 | wait_for_completion(&socket->socket_released); |
296 | } /* pcmcia_unregister_socket */ | 293 | } /* pcmcia_unregister_socket */ |
297 | EXPORT_SYMBOL(pcmcia_unregister_socket); | 294 | EXPORT_SYMBOL(pcmcia_unregister_socket); |
@@ -328,7 +325,7 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) | |||
328 | { | 325 | { |
329 | int ret; | 326 | int ret; |
330 | 327 | ||
331 | if (s->state & SOCKET_CARDBUS) | 328 | if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL)) |
332 | return 0; | 329 | return 0; |
333 | 330 | ||
334 | dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n", | 331 | dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n", |
@@ -346,13 +343,6 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) | |||
346 | return ret; | 343 | return ret; |
347 | } | 344 | } |
348 | 345 | ||
349 | static void socket_remove_drivers(struct pcmcia_socket *skt) | ||
350 | { | ||
351 | dev_dbg(&skt->dev, "remove_drivers\n"); | ||
352 | |||
353 | send_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); | ||
354 | } | ||
355 | |||
356 | static int socket_reset(struct pcmcia_socket *skt) | 346 | static int socket_reset(struct pcmcia_socket *skt) |
357 | { | 347 | { |
358 | int status, i; | 348 | int status, i; |
@@ -395,7 +385,9 @@ static void socket_shutdown(struct pcmcia_socket *s) | |||
395 | 385 | ||
396 | dev_dbg(&s->dev, "shutdown\n"); | 386 | dev_dbg(&s->dev, "shutdown\n"); |
397 | 387 | ||
398 | socket_remove_drivers(s); | 388 | send_event(s, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); |
389 | |||
390 | mutex_lock(&s->ops_mutex); | ||
399 | s->state &= SOCKET_INUSE | SOCKET_PRESENT; | 391 | s->state &= SOCKET_INUSE | SOCKET_PRESENT; |
400 | msleep(shutdown_delay * 10); | 392 | msleep(shutdown_delay * 10); |
401 | s->state &= SOCKET_INUSE; | 393 | s->state &= SOCKET_INUSE; |
@@ -406,11 +398,21 @@ static void socket_shutdown(struct pcmcia_socket *s) | |||
406 | s->ops->set_socket(s, &s->socket); | 398 | s->ops->set_socket(s, &s->socket); |
407 | s->irq.AssignedIRQ = s->irq.Config = 0; | 399 | s->irq.AssignedIRQ = s->irq.Config = 0; |
408 | s->lock_count = 0; | 400 | s->lock_count = 0; |
409 | destroy_cis_cache(s); | 401 | kfree(s->fake_cis); |
402 | s->fake_cis = NULL; | ||
403 | s->functions = 0; | ||
404 | |||
405 | /* From here on we can be sure that only we (that is, the | ||
406 | * pccardd thread) accesses this socket, and all (16-bit) | ||
407 | * PCMCIA interactions are gone. Therefore, release | ||
408 | * ops_mutex so that we don't get a sysfs-related lockdep | ||
409 | * warning. | ||
410 | */ | ||
411 | mutex_unlock(&s->ops_mutex); | ||
412 | |||
410 | #ifdef CONFIG_CARDBUS | 413 | #ifdef CONFIG_CARDBUS |
411 | cb_free(s); | 414 | cb_free(s); |
412 | #endif | 415 | #endif |
413 | s->functions = 0; | ||
414 | 416 | ||
415 | /* give socket some time to power down */ | 417 | /* give socket some time to power down */ |
416 | msleep(100); | 418 | msleep(100); |
@@ -421,7 +423,7 @@ static void socket_shutdown(struct pcmcia_socket *s) | |||
421 | "*** DANGER *** unable to remove socket power\n"); | 423 | "*** DANGER *** unable to remove socket power\n"); |
422 | } | 424 | } |
423 | 425 | ||
424 | cs_socket_put(s); | 426 | s->state &= ~SOCKET_INUSE; |
425 | } | 427 | } |
426 | 428 | ||
427 | static int socket_setup(struct pcmcia_socket *skt, int initial_delay) | 429 | static int socket_setup(struct pcmcia_socket *skt, int initial_delay) |
@@ -460,7 +462,8 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay) | |||
460 | return -EINVAL; | 462 | return -EINVAL; |
461 | } | 463 | } |
462 | skt->state |= SOCKET_CARDBUS; | 464 | skt->state |= SOCKET_CARDBUS; |
463 | } | 465 | } else |
466 | skt->state &= ~SOCKET_CARDBUS; | ||
464 | 467 | ||
465 | /* | 468 | /* |
466 | * Decode the card voltage requirements, and apply power to the card. | 469 | * Decode the card voltage requirements, and apply power to the card. |
@@ -509,8 +512,12 @@ static int socket_insert(struct pcmcia_socket *skt) | |||
509 | 512 | ||
510 | dev_dbg(&skt->dev, "insert\n"); | 513 | dev_dbg(&skt->dev, "insert\n"); |
511 | 514 | ||
512 | if (!cs_socket_get(skt)) | 515 | mutex_lock(&skt->ops_mutex); |
513 | return -ENODEV; | 516 | if (skt->state & SOCKET_INUSE) { |
517 | mutex_unlock(&skt->ops_mutex); | ||
518 | return -EINVAL; | ||
519 | } | ||
520 | skt->state |= SOCKET_INUSE; | ||
514 | 521 | ||
515 | ret = socket_setup(skt, setup_delay); | 522 | ret = socket_setup(skt, setup_delay); |
516 | if (ret == 0) { | 523 | if (ret == 0) { |
@@ -528,9 +535,11 @@ static int socket_insert(struct pcmcia_socket *skt) | |||
528 | } | 535 | } |
529 | #endif | 536 | #endif |
530 | dev_dbg(&skt->dev, "insert done\n"); | 537 | dev_dbg(&skt->dev, "insert done\n"); |
538 | mutex_unlock(&skt->ops_mutex); | ||
531 | 539 | ||
532 | send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); | 540 | send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); |
533 | } else { | 541 | } else { |
542 | mutex_unlock(&skt->ops_mutex); | ||
534 | socket_shutdown(skt); | 543 | socket_shutdown(skt); |
535 | } | 544 | } |
536 | 545 | ||
@@ -542,58 +551,66 @@ static int socket_suspend(struct pcmcia_socket *skt) | |||
542 | if (skt->state & SOCKET_SUSPEND) | 551 | if (skt->state & SOCKET_SUSPEND) |
543 | return -EBUSY; | 552 | return -EBUSY; |
544 | 553 | ||
554 | mutex_lock(&skt->ops_mutex); | ||
555 | skt->suspended_state = skt->state; | ||
556 | |||
545 | send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); | 557 | send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); |
546 | skt->socket = dead_socket; | 558 | skt->socket = dead_socket; |
547 | skt->ops->set_socket(skt, &skt->socket); | 559 | skt->ops->set_socket(skt, &skt->socket); |
548 | if (skt->ops->suspend) | 560 | if (skt->ops->suspend) |
549 | skt->ops->suspend(skt); | 561 | skt->ops->suspend(skt); |
550 | skt->state |= SOCKET_SUSPEND; | 562 | skt->state |= SOCKET_SUSPEND; |
551 | 563 | mutex_unlock(&skt->ops_mutex); | |
552 | return 0; | 564 | return 0; |
553 | } | 565 | } |
554 | 566 | ||
555 | static int socket_early_resume(struct pcmcia_socket *skt) | 567 | static int socket_early_resume(struct pcmcia_socket *skt) |
556 | { | 568 | { |
569 | mutex_lock(&skt->ops_mutex); | ||
557 | skt->socket = dead_socket; | 570 | skt->socket = dead_socket; |
558 | skt->ops->init(skt); | 571 | skt->ops->init(skt); |
559 | skt->ops->set_socket(skt, &skt->socket); | 572 | skt->ops->set_socket(skt, &skt->socket); |
560 | if (skt->state & SOCKET_PRESENT) | 573 | if (skt->state & SOCKET_PRESENT) |
561 | skt->resume_status = socket_setup(skt, resume_delay); | 574 | skt->resume_status = socket_setup(skt, resume_delay); |
575 | mutex_unlock(&skt->ops_mutex); | ||
562 | return 0; | 576 | return 0; |
563 | } | 577 | } |
564 | 578 | ||
565 | static int socket_late_resume(struct pcmcia_socket *skt) | 579 | static int socket_late_resume(struct pcmcia_socket *skt) |
566 | { | 580 | { |
567 | if (!(skt->state & SOCKET_PRESENT)) { | 581 | mutex_lock(&skt->ops_mutex); |
568 | skt->state &= ~SOCKET_SUSPEND; | 582 | skt->state &= ~SOCKET_SUSPEND; |
583 | mutex_unlock(&skt->ops_mutex); | ||
584 | |||
585 | if (!(skt->state & SOCKET_PRESENT)) | ||
569 | return socket_insert(skt); | 586 | return socket_insert(skt); |
587 | |||
588 | if (skt->resume_status) { | ||
589 | socket_shutdown(skt); | ||
590 | return 0; | ||
570 | } | 591 | } |
571 | 592 | ||
572 | if (skt->resume_status == 0) { | 593 | if (skt->suspended_state != skt->state) { |
573 | /* | 594 | dev_dbg(&skt->dev, |
574 | * FIXME: need a better check here for cardbus cards. | 595 | "suspend state 0x%x != resume state 0x%x\n", |
575 | */ | 596 | skt->suspended_state, skt->state); |
576 | if (verify_cis_cache(skt) != 0) { | 597 | |
577 | dev_dbg(&skt->dev, "cis mismatch - different card\n"); | ||
578 | socket_remove_drivers(skt); | ||
579 | destroy_cis_cache(skt); | ||
580 | /* | ||
581 | * Workaround: give DS time to schedule removal. | ||
582 | * Remove me once the 100ms delay is eliminated | ||
583 | * in ds.c | ||
584 | */ | ||
585 | msleep(200); | ||
586 | send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); | ||
587 | } else { | ||
588 | dev_dbg(&skt->dev, "cis matches cache\n"); | ||
589 | send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW); | ||
590 | } | ||
591 | } else { | ||
592 | socket_shutdown(skt); | 598 | socket_shutdown(skt); |
599 | return socket_insert(skt); | ||
593 | } | 600 | } |
594 | 601 | ||
595 | skt->state &= ~SOCKET_SUSPEND; | 602 | #ifdef CONFIG_CARDBUS |
603 | if (skt->state & SOCKET_CARDBUS) { | ||
604 | /* We can't be sure the CardBus card is the same | ||
605 | * as the one previously inserted. Therefore, remove | ||
606 | * and re-add... */ | ||
607 | cb_free(skt); | ||
608 | cb_alloc(skt); | ||
609 | return 0; | ||
610 | } | ||
611 | #endif | ||
596 | 612 | ||
613 | send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW); | ||
597 | return 0; | 614 | return 0; |
598 | } | 615 | } |
599 | 616 | ||
@@ -672,20 +689,26 @@ static int pccardd(void *__skt) | |||
672 | 689 | ||
673 | complete(&skt->thread_done); | 690 | complete(&skt->thread_done); |
674 | 691 | ||
692 | /* wait for userspace to catch up */ | ||
693 | msleep(250); | ||
694 | |||
675 | set_freezable(); | 695 | set_freezable(); |
676 | for (;;) { | 696 | for (;;) { |
677 | unsigned long flags; | 697 | unsigned long flags; |
678 | unsigned int events; | 698 | unsigned int events; |
699 | unsigned int sysfs_events; | ||
679 | 700 | ||
680 | set_current_state(TASK_INTERRUPTIBLE); | 701 | set_current_state(TASK_INTERRUPTIBLE); |
681 | 702 | ||
682 | spin_lock_irqsave(&skt->thread_lock, flags); | 703 | spin_lock_irqsave(&skt->thread_lock, flags); |
683 | events = skt->thread_events; | 704 | events = skt->thread_events; |
684 | skt->thread_events = 0; | 705 | skt->thread_events = 0; |
706 | sysfs_events = skt->sysfs_events; | ||
707 | skt->sysfs_events = 0; | ||
685 | spin_unlock_irqrestore(&skt->thread_lock, flags); | 708 | spin_unlock_irqrestore(&skt->thread_lock, flags); |
686 | 709 | ||
710 | mutex_lock(&skt->skt_mutex); | ||
687 | if (events) { | 711 | if (events) { |
688 | mutex_lock(&skt->skt_mutex); | ||
689 | if (events & SS_DETECT) | 712 | if (events & SS_DETECT) |
690 | socket_detect_change(skt); | 713 | socket_detect_change(skt); |
691 | if (events & SS_BATDEAD) | 714 | if (events & SS_BATDEAD) |
@@ -694,10 +717,39 @@ static int pccardd(void *__skt) | |||
694 | send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); | 717 | send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); |
695 | if (events & SS_READY) | 718 | if (events & SS_READY) |
696 | send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); | 719 | send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); |
697 | mutex_unlock(&skt->skt_mutex); | ||
698 | continue; | ||
699 | } | 720 | } |
700 | 721 | ||
722 | if (sysfs_events) { | ||
723 | if (sysfs_events & PCMCIA_UEVENT_EJECT) | ||
724 | socket_remove(skt); | ||
725 | if (sysfs_events & PCMCIA_UEVENT_INSERT) | ||
726 | socket_insert(skt); | ||
727 | if ((sysfs_events & PCMCIA_UEVENT_RESUME) && | ||
728 | !(skt->state & SOCKET_CARDBUS)) { | ||
729 | ret = socket_resume(skt); | ||
730 | if (!ret && skt->callback) | ||
731 | skt->callback->resume(skt); | ||
732 | } | ||
733 | if ((sysfs_events & PCMCIA_UEVENT_SUSPEND) && | ||
734 | !(skt->state & SOCKET_CARDBUS)) { | ||
735 | if (skt->callback) | ||
736 | ret = skt->callback->suspend(skt); | ||
737 | else | ||
738 | ret = 0; | ||
739 | if (!ret) | ||
740 | socket_suspend(skt); | ||
741 | } | ||
742 | if ((sysfs_events & PCMCIA_UEVENT_REQUERY) && | ||
743 | !(skt->state & SOCKET_CARDBUS)) { | ||
744 | if (!ret && skt->callback) | ||
745 | skt->callback->requery(skt); | ||
746 | } | ||
747 | } | ||
748 | mutex_unlock(&skt->skt_mutex); | ||
749 | |||
750 | if (events || sysfs_events) | ||
751 | continue; | ||
752 | |||
701 | if (kthread_should_stop()) | 753 | if (kthread_should_stop()) |
702 | break; | 754 | break; |
703 | 755 | ||
@@ -707,6 +759,13 @@ static int pccardd(void *__skt) | |||
707 | /* make sure we are running before we exit */ | 759 | /* make sure we are running before we exit */ |
708 | set_current_state(TASK_RUNNING); | 760 | set_current_state(TASK_RUNNING); |
709 | 761 | ||
762 | /* shut down socket, if a device is still present */ | ||
763 | if (skt->state & SOCKET_PRESENT) { | ||
764 | mutex_lock(&skt->skt_mutex); | ||
765 | socket_remove(skt); | ||
766 | mutex_unlock(&skt->skt_mutex); | ||
767 | } | ||
768 | |||
710 | /* remove from the device core */ | 769 | /* remove from the device core */ |
711 | pccard_sysfs_remove_socket(&skt->dev); | 770 | pccard_sysfs_remove_socket(&skt->dev); |
712 | device_unregister(&skt->dev); | 771 | device_unregister(&skt->dev); |
@@ -732,6 +791,31 @@ void pcmcia_parse_events(struct pcmcia_socket *s, u_int events) | |||
732 | } /* pcmcia_parse_events */ | 791 | } /* pcmcia_parse_events */ |
733 | EXPORT_SYMBOL(pcmcia_parse_events); | 792 | EXPORT_SYMBOL(pcmcia_parse_events); |
734 | 793 | ||
794 | /** | ||
795 | * pcmcia_parse_uevents() - tell pccardd to issue manual commands | ||
796 | * @s: the PCMCIA socket we wan't to command | ||
797 | * @events: events to pass to pccardd | ||
798 | * | ||
799 | * userspace-issued insert, eject, suspend and resume commands must be | ||
800 | * handled by pccardd to avoid any sysfs-related deadlocks. Valid events | ||
801 | * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert), | ||
802 | * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend) | ||
803 | * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card). | ||
804 | */ | ||
805 | void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events) | ||
806 | { | ||
807 | unsigned long flags; | ||
808 | dev_dbg(&s->dev, "parse_uevents: events %08x\n", events); | ||
809 | if (s->thread) { | ||
810 | spin_lock_irqsave(&s->thread_lock, flags); | ||
811 | s->sysfs_events |= events; | ||
812 | spin_unlock_irqrestore(&s->thread_lock, flags); | ||
813 | |||
814 | wake_up_process(s->thread); | ||
815 | } | ||
816 | } | ||
817 | EXPORT_SYMBOL(pcmcia_parse_uevents); | ||
818 | |||
735 | 819 | ||
736 | /* register pcmcia_callback */ | 820 | /* register pcmcia_callback */ |
737 | int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) | 821 | int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) |
@@ -796,7 +880,10 @@ int pcmcia_reset_card(struct pcmcia_socket *skt) | |||
796 | send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); | 880 | send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); |
797 | if (skt->callback) | 881 | if (skt->callback) |
798 | skt->callback->suspend(skt); | 882 | skt->callback->suspend(skt); |
799 | if (socket_reset(skt) == 0) { | 883 | mutex_lock(&skt->ops_mutex); |
884 | ret = socket_reset(skt); | ||
885 | mutex_unlock(&skt->ops_mutex); | ||
886 | if (ret == 0) { | ||
800 | send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); | 887 | send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); |
801 | if (skt->callback) | 888 | if (skt->callback) |
802 | skt->callback->resume(skt); | 889 | skt->callback->resume(skt); |
@@ -812,121 +899,6 @@ int pcmcia_reset_card(struct pcmcia_socket *skt) | |||
812 | EXPORT_SYMBOL(pcmcia_reset_card); | 899 | EXPORT_SYMBOL(pcmcia_reset_card); |
813 | 900 | ||
814 | 901 | ||
815 | /* These shut down or wake up a socket. They are sort of user | ||
816 | * initiated versions of the APM suspend and resume actions. | ||
817 | */ | ||
818 | int pcmcia_suspend_card(struct pcmcia_socket *skt) | ||
819 | { | ||
820 | int ret; | ||
821 | |||
822 | dev_dbg(&skt->dev, "suspending socket\n"); | ||
823 | |||
824 | mutex_lock(&skt->skt_mutex); | ||
825 | do { | ||
826 | if (!(skt->state & SOCKET_PRESENT)) { | ||
827 | ret = -ENODEV; | ||
828 | break; | ||
829 | } | ||
830 | if (skt->state & SOCKET_CARDBUS) { | ||
831 | ret = -EPERM; | ||
832 | break; | ||
833 | } | ||
834 | if (skt->callback) { | ||
835 | ret = skt->callback->suspend(skt); | ||
836 | if (ret) | ||
837 | break; | ||
838 | } | ||
839 | ret = socket_suspend(skt); | ||
840 | } while (0); | ||
841 | mutex_unlock(&skt->skt_mutex); | ||
842 | |||
843 | return ret; | ||
844 | } /* suspend_card */ | ||
845 | EXPORT_SYMBOL(pcmcia_suspend_card); | ||
846 | |||
847 | |||
848 | int pcmcia_resume_card(struct pcmcia_socket *skt) | ||
849 | { | ||
850 | int ret; | ||
851 | |||
852 | dev_dbg(&skt->dev, "waking up socket\n"); | ||
853 | |||
854 | mutex_lock(&skt->skt_mutex); | ||
855 | do { | ||
856 | if (!(skt->state & SOCKET_PRESENT)) { | ||
857 | ret = -ENODEV; | ||
858 | break; | ||
859 | } | ||
860 | if (skt->state & SOCKET_CARDBUS) { | ||
861 | ret = -EPERM; | ||
862 | break; | ||
863 | } | ||
864 | ret = socket_resume(skt); | ||
865 | if (!ret && skt->callback) | ||
866 | skt->callback->resume(skt); | ||
867 | } while (0); | ||
868 | mutex_unlock(&skt->skt_mutex); | ||
869 | |||
870 | return ret; | ||
871 | } /* resume_card */ | ||
872 | EXPORT_SYMBOL(pcmcia_resume_card); | ||
873 | |||
874 | |||
875 | /* These handle user requests to eject or insert a card. */ | ||
876 | int pcmcia_eject_card(struct pcmcia_socket *skt) | ||
877 | { | ||
878 | int ret; | ||
879 | |||
880 | dev_dbg(&skt->dev, "user eject request\n"); | ||
881 | |||
882 | mutex_lock(&skt->skt_mutex); | ||
883 | do { | ||
884 | if (!(skt->state & SOCKET_PRESENT)) { | ||
885 | ret = -ENODEV; | ||
886 | break; | ||
887 | } | ||
888 | |||
889 | ret = send_event(skt, CS_EVENT_EJECTION_REQUEST, CS_EVENT_PRI_LOW); | ||
890 | if (ret != 0) { | ||
891 | ret = -EINVAL; | ||
892 | break; | ||
893 | } | ||
894 | |||
895 | socket_remove(skt); | ||
896 | ret = 0; | ||
897 | } while (0); | ||
898 | mutex_unlock(&skt->skt_mutex); | ||
899 | |||
900 | return ret; | ||
901 | } /* eject_card */ | ||
902 | EXPORT_SYMBOL(pcmcia_eject_card); | ||
903 | |||
904 | |||
905 | int pcmcia_insert_card(struct pcmcia_socket *skt) | ||
906 | { | ||
907 | int ret; | ||
908 | |||
909 | dev_dbg(&skt->dev, "user insert request\n"); | ||
910 | |||
911 | mutex_lock(&skt->skt_mutex); | ||
912 | do { | ||
913 | if (skt->state & SOCKET_PRESENT) { | ||
914 | ret = -EBUSY; | ||
915 | break; | ||
916 | } | ||
917 | if (socket_insert(skt) == -ENODEV) { | ||
918 | ret = -ENODEV; | ||
919 | break; | ||
920 | } | ||
921 | ret = 0; | ||
922 | } while (0); | ||
923 | mutex_unlock(&skt->skt_mutex); | ||
924 | |||
925 | return ret; | ||
926 | } /* insert_card */ | ||
927 | EXPORT_SYMBOL(pcmcia_insert_card); | ||
928 | |||
929 | |||
930 | static int pcmcia_socket_uevent(struct device *dev, | 902 | static int pcmcia_socket_uevent(struct device *dev, |
931 | struct kobj_uevent_env *env) | 903 | struct kobj_uevent_env *env) |
932 | { | 904 | { |