diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2011-07-15 17:59:25 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2011-07-15 17:59:25 -0400 |
commit | 7ae033cc0dfce68d8e0c83aca60837cf2bf0d2e6 (patch) | |
tree | 91bb3b8ae2790c7fef06b1832a7df61ae496a77a /drivers | |
parent | ba1389d74f34c0c6e95cc135a332cd29c29d9c20 (diff) | |
parent | c8c9fda5069456eb9e0e403c19764b2e257802e1 (diff) |
Merge branch 'pm-runtime' into for-linus
* pm-runtime:
OMAP: PM: disable idle on suspend for GPIO and UART
OMAP: PM: omap_device: add API to disable idle on suspend
OMAP: PM: omap_device: add system PM methods for PM domain handling
OMAP: PM: omap_device: conditionally use PM domain runtime helpers
PM / Runtime: Add new helper function: pm_runtime_status_suspended()
PM / Runtime: Consistent utilization of deferred_resume
PM / Runtime: Prevent runtime_resume from racing with probe
PM / Runtime: Replace "run-time" with "runtime" in documentation
PM / Runtime: Improve documentation of enable, disable and barrier
PM: Limit race conditions between runtime PM and system sleep (v2)
PCI / PM: Detect early wakeup in pci_pm_prepare()
PM / Runtime: Return special error code if runtime PM is disabled
PM / Runtime: Update documentation of interactions with system sleep
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/power/main.c | 35 | ||||
-rw-r--r-- | drivers/base/power/runtime.c | 77 | ||||
-rw-r--r-- | drivers/base/power/sysfs.c | 6 | ||||
-rw-r--r-- | drivers/pci/pci-driver.c | 18 | ||||
-rw-r--r-- | drivers/scsi/scsi_pm.c | 8 |
5 files changed, 88 insertions, 56 deletions
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 85b591a5429a..a85459126bc6 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -505,6 +505,7 @@ static int legacy_resume(struct device *dev, int (*cb)(struct device *dev)) | |||
505 | static int device_resume(struct device *dev, pm_message_t state, bool async) | 505 | static int device_resume(struct device *dev, pm_message_t state, bool async) |
506 | { | 506 | { |
507 | int error = 0; | 507 | int error = 0; |
508 | bool put = false; | ||
508 | 509 | ||
509 | TRACE_DEVICE(dev); | 510 | TRACE_DEVICE(dev); |
510 | TRACE_RESUME(0); | 511 | TRACE_RESUME(0); |
@@ -521,6 +522,9 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
521 | if (!dev->power.is_suspended) | 522 | if (!dev->power.is_suspended) |
522 | goto Unlock; | 523 | goto Unlock; |
523 | 524 | ||
525 | pm_runtime_enable(dev); | ||
526 | put = true; | ||
527 | |||
524 | if (dev->pm_domain) { | 528 | if (dev->pm_domain) { |
525 | pm_dev_dbg(dev, state, "power domain "); | 529 | pm_dev_dbg(dev, state, "power domain "); |
526 | error = pm_op(dev, &dev->pm_domain->ops, state); | 530 | error = pm_op(dev, &dev->pm_domain->ops, state); |
@@ -563,6 +567,10 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
563 | complete_all(&dev->power.completion); | 567 | complete_all(&dev->power.completion); |
564 | 568 | ||
565 | TRACE_RESUME(error); | 569 | TRACE_RESUME(error); |
570 | |||
571 | if (put) | ||
572 | pm_runtime_put_sync(dev); | ||
573 | |||
566 | return error; | 574 | return error; |
567 | } | 575 | } |
568 | 576 | ||
@@ -843,16 +851,22 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
843 | int error = 0; | 851 | int error = 0; |
844 | 852 | ||
845 | dpm_wait_for_children(dev, async); | 853 | dpm_wait_for_children(dev, async); |
846 | device_lock(dev); | ||
847 | 854 | ||
848 | if (async_error) | 855 | if (async_error) |
849 | goto Unlock; | 856 | return 0; |
857 | |||
858 | pm_runtime_get_noresume(dev); | ||
859 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) | ||
860 | pm_wakeup_event(dev, 0); | ||
850 | 861 | ||
851 | if (pm_wakeup_pending()) { | 862 | if (pm_wakeup_pending()) { |
863 | pm_runtime_put_sync(dev); | ||
852 | async_error = -EBUSY; | 864 | async_error = -EBUSY; |
853 | goto Unlock; | 865 | return 0; |
854 | } | 866 | } |
855 | 867 | ||
868 | device_lock(dev); | ||
869 | |||
856 | if (dev->pm_domain) { | 870 | if (dev->pm_domain) { |
857 | pm_dev_dbg(dev, state, "power domain "); | 871 | pm_dev_dbg(dev, state, "power domain "); |
858 | error = pm_op(dev, &dev->pm_domain->ops, state); | 872 | error = pm_op(dev, &dev->pm_domain->ops, state); |
@@ -890,12 +904,15 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
890 | End: | 904 | End: |
891 | dev->power.is_suspended = !error; | 905 | dev->power.is_suspended = !error; |
892 | 906 | ||
893 | Unlock: | ||
894 | device_unlock(dev); | 907 | device_unlock(dev); |
895 | complete_all(&dev->power.completion); | 908 | complete_all(&dev->power.completion); |
896 | 909 | ||
897 | if (error) | 910 | if (error) { |
911 | pm_runtime_put_sync(dev); | ||
898 | async_error = error; | 912 | async_error = error; |
913 | } else if (dev->power.is_suspended) { | ||
914 | __pm_runtime_disable(dev, false); | ||
915 | } | ||
899 | 916 | ||
900 | return error; | 917 | return error; |
901 | } | 918 | } |
@@ -1035,13 +1052,7 @@ int dpm_prepare(pm_message_t state) | |||
1035 | get_device(dev); | 1052 | get_device(dev); |
1036 | mutex_unlock(&dpm_list_mtx); | 1053 | mutex_unlock(&dpm_list_mtx); |
1037 | 1054 | ||
1038 | pm_runtime_get_noresume(dev); | 1055 | error = device_prepare(dev, state); |
1039 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) | ||
1040 | pm_wakeup_event(dev, 0); | ||
1041 | |||
1042 | pm_runtime_put_sync(dev); | ||
1043 | error = pm_wakeup_pending() ? | ||
1044 | -EBUSY : device_prepare(dev, state); | ||
1045 | 1056 | ||
1046 | mutex_lock(&dpm_list_mtx); | 1057 | mutex_lock(&dpm_list_mtx); |
1047 | if (error) { | 1058 | if (error) { |
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 5f5c4236f006..8dc247c974af 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * drivers/base/power/runtime.c - Helper functions for device run-time PM | 2 | * drivers/base/power/runtime.c - Helper functions for device runtime PM |
3 | * | 3 | * |
4 | * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | 4 | * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. |
5 | * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu> | 5 | * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu> |
@@ -135,8 +135,9 @@ static int rpm_check_suspend_allowed(struct device *dev) | |||
135 | 135 | ||
136 | if (dev->power.runtime_error) | 136 | if (dev->power.runtime_error) |
137 | retval = -EINVAL; | 137 | retval = -EINVAL; |
138 | else if (atomic_read(&dev->power.usage_count) > 0 | 138 | else if (dev->power.disable_depth > 0) |
139 | || dev->power.disable_depth > 0) | 139 | retval = -EACCES; |
140 | else if (atomic_read(&dev->power.usage_count) > 0) | ||
140 | retval = -EAGAIN; | 141 | retval = -EAGAIN; |
141 | else if (!pm_children_suspended(dev)) | 142 | else if (!pm_children_suspended(dev)) |
142 | retval = -EBUSY; | 143 | retval = -EBUSY; |
@@ -158,7 +159,7 @@ static int rpm_check_suspend_allowed(struct device *dev) | |||
158 | * @dev: Device to notify the bus type about. | 159 | * @dev: Device to notify the bus type about. |
159 | * @rpmflags: Flag bits. | 160 | * @rpmflags: Flag bits. |
160 | * | 161 | * |
161 | * Check if the device's run-time PM status allows it to be suspended. If | 162 | * Check if the device's runtime PM status allows it to be suspended. If |
162 | * another idle notification has been started earlier, return immediately. If | 163 | * another idle notification has been started earlier, return immediately. If |
163 | * the RPM_ASYNC flag is set then queue an idle-notification request; otherwise | 164 | * the RPM_ASYNC flag is set then queue an idle-notification request; otherwise |
164 | * run the ->runtime_idle() callback directly. | 165 | * run the ->runtime_idle() callback directly. |
@@ -262,15 +263,15 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev) | |||
262 | spin_lock_irq(&dev->power.lock); | 263 | spin_lock_irq(&dev->power.lock); |
263 | } | 264 | } |
264 | dev->power.runtime_error = retval; | 265 | dev->power.runtime_error = retval; |
265 | return retval; | 266 | return retval != -EACCES ? retval : -EIO; |
266 | } | 267 | } |
267 | 268 | ||
268 | /** | 269 | /** |
269 | * rpm_suspend - Carry out run-time suspend of given device. | 270 | * rpm_suspend - Carry out runtime suspend of given device. |
270 | * @dev: Device to suspend. | 271 | * @dev: Device to suspend. |
271 | * @rpmflags: Flag bits. | 272 | * @rpmflags: Flag bits. |
272 | * | 273 | * |
273 | * Check if the device's run-time PM status allows it to be suspended. If | 274 | * Check if the device's runtime PM status allows it to be suspended. If |
274 | * another suspend has been started earlier, either return immediately or wait | 275 | * another suspend has been started earlier, either return immediately or wait |
275 | * for it to finish, depending on the RPM_NOWAIT and RPM_ASYNC flags. Cancel a | 276 | * for it to finish, depending on the RPM_NOWAIT and RPM_ASYNC flags. Cancel a |
276 | * pending idle notification. If the RPM_ASYNC flag is set then queue a | 277 | * pending idle notification. If the RPM_ASYNC flag is set then queue a |
@@ -388,7 +389,7 @@ static int rpm_suspend(struct device *dev, int rpmflags) | |||
388 | retval = rpm_callback(callback, dev); | 389 | retval = rpm_callback(callback, dev); |
389 | if (retval) { | 390 | if (retval) { |
390 | __update_runtime_status(dev, RPM_ACTIVE); | 391 | __update_runtime_status(dev, RPM_ACTIVE); |
391 | dev->power.deferred_resume = 0; | 392 | dev->power.deferred_resume = false; |
392 | if (retval == -EAGAIN || retval == -EBUSY) | 393 | if (retval == -EAGAIN || retval == -EBUSY) |
393 | dev->power.runtime_error = 0; | 394 | dev->power.runtime_error = 0; |
394 | else | 395 | else |
@@ -429,11 +430,11 @@ static int rpm_suspend(struct device *dev, int rpmflags) | |||
429 | } | 430 | } |
430 | 431 | ||
431 | /** | 432 | /** |
432 | * rpm_resume - Carry out run-time resume of given device. | 433 | * rpm_resume - Carry out runtime resume of given device. |
433 | * @dev: Device to resume. | 434 | * @dev: Device to resume. |
434 | * @rpmflags: Flag bits. | 435 | * @rpmflags: Flag bits. |
435 | * | 436 | * |
436 | * Check if the device's run-time PM status allows it to be resumed. Cancel | 437 | * Check if the device's runtime PM status allows it to be resumed. Cancel |
437 | * any scheduled or pending requests. If another resume has been started | 438 | * any scheduled or pending requests. If another resume has been started |
438 | * earlier, either return immediately or wait for it to finish, depending on the | 439 | * earlier, either return immediately or wait for it to finish, depending on the |
439 | * RPM_NOWAIT and RPM_ASYNC flags. Similarly, if there's a suspend running in | 440 | * RPM_NOWAIT and RPM_ASYNC flags. Similarly, if there's a suspend running in |
@@ -458,7 +459,7 @@ static int rpm_resume(struct device *dev, int rpmflags) | |||
458 | if (dev->power.runtime_error) | 459 | if (dev->power.runtime_error) |
459 | retval = -EINVAL; | 460 | retval = -EINVAL; |
460 | else if (dev->power.disable_depth > 0) | 461 | else if (dev->power.disable_depth > 0) |
461 | retval = -EAGAIN; | 462 | retval = -EACCES; |
462 | if (retval) | 463 | if (retval) |
463 | goto out; | 464 | goto out; |
464 | 465 | ||
@@ -550,7 +551,7 @@ static int rpm_resume(struct device *dev, int rpmflags) | |||
550 | 551 | ||
551 | spin_lock(&parent->power.lock); | 552 | spin_lock(&parent->power.lock); |
552 | /* | 553 | /* |
553 | * We can resume if the parent's run-time PM is disabled or it | 554 | * We can resume if the parent's runtime PM is disabled or it |
554 | * is set to ignore children. | 555 | * is set to ignore children. |
555 | */ | 556 | */ |
556 | if (!parent->power.disable_depth | 557 | if (!parent->power.disable_depth |
@@ -614,11 +615,11 @@ static int rpm_resume(struct device *dev, int rpmflags) | |||
614 | } | 615 | } |
615 | 616 | ||
616 | /** | 617 | /** |
617 | * pm_runtime_work - Universal run-time PM work function. | 618 | * pm_runtime_work - Universal runtime PM work function. |
618 | * @work: Work structure used for scheduling the execution of this function. | 619 | * @work: Work structure used for scheduling the execution of this function. |
619 | * | 620 | * |
620 | * Use @work to get the device object the work is to be done for, determine what | 621 | * Use @work to get the device object the work is to be done for, determine what |
621 | * is to be done and execute the appropriate run-time PM function. | 622 | * is to be done and execute the appropriate runtime PM function. |
622 | */ | 623 | */ |
623 | static void pm_runtime_work(struct work_struct *work) | 624 | static void pm_runtime_work(struct work_struct *work) |
624 | { | 625 | { |
@@ -717,7 +718,7 @@ int pm_schedule_suspend(struct device *dev, unsigned int delay) | |||
717 | EXPORT_SYMBOL_GPL(pm_schedule_suspend); | 718 | EXPORT_SYMBOL_GPL(pm_schedule_suspend); |
718 | 719 | ||
719 | /** | 720 | /** |
720 | * __pm_runtime_idle - Entry point for run-time idle operations. | 721 | * __pm_runtime_idle - Entry point for runtime idle operations. |
721 | * @dev: Device to send idle notification for. | 722 | * @dev: Device to send idle notification for. |
722 | * @rpmflags: Flag bits. | 723 | * @rpmflags: Flag bits. |
723 | * | 724 | * |
@@ -746,7 +747,7 @@ int __pm_runtime_idle(struct device *dev, int rpmflags) | |||
746 | EXPORT_SYMBOL_GPL(__pm_runtime_idle); | 747 | EXPORT_SYMBOL_GPL(__pm_runtime_idle); |
747 | 748 | ||
748 | /** | 749 | /** |
749 | * __pm_runtime_suspend - Entry point for run-time put/suspend operations. | 750 | * __pm_runtime_suspend - Entry point for runtime put/suspend operations. |
750 | * @dev: Device to suspend. | 751 | * @dev: Device to suspend. |
751 | * @rpmflags: Flag bits. | 752 | * @rpmflags: Flag bits. |
752 | * | 753 | * |
@@ -775,7 +776,7 @@ int __pm_runtime_suspend(struct device *dev, int rpmflags) | |||
775 | EXPORT_SYMBOL_GPL(__pm_runtime_suspend); | 776 | EXPORT_SYMBOL_GPL(__pm_runtime_suspend); |
776 | 777 | ||
777 | /** | 778 | /** |
778 | * __pm_runtime_resume - Entry point for run-time resume operations. | 779 | * __pm_runtime_resume - Entry point for runtime resume operations. |
779 | * @dev: Device to resume. | 780 | * @dev: Device to resume. |
780 | * @rpmflags: Flag bits. | 781 | * @rpmflags: Flag bits. |
781 | * | 782 | * |
@@ -801,11 +802,11 @@ int __pm_runtime_resume(struct device *dev, int rpmflags) | |||
801 | EXPORT_SYMBOL_GPL(__pm_runtime_resume); | 802 | EXPORT_SYMBOL_GPL(__pm_runtime_resume); |
802 | 803 | ||
803 | /** | 804 | /** |
804 | * __pm_runtime_set_status - Set run-time PM status of a device. | 805 | * __pm_runtime_set_status - Set runtime PM status of a device. |
805 | * @dev: Device to handle. | 806 | * @dev: Device to handle. |
806 | * @status: New run-time PM status of the device. | 807 | * @status: New runtime PM status of the device. |
807 | * | 808 | * |
808 | * If run-time PM of the device is disabled or its power.runtime_error field is | 809 | * If runtime PM of the device is disabled or its power.runtime_error field is |
809 | * different from zero, the status may be changed either to RPM_ACTIVE, or to | 810 | * different from zero, the status may be changed either to RPM_ACTIVE, or to |
810 | * RPM_SUSPENDED, as long as that reflects the actual state of the device. | 811 | * RPM_SUSPENDED, as long as that reflects the actual state of the device. |
811 | * However, if the device has a parent and the parent is not active, and the | 812 | * However, if the device has a parent and the parent is not active, and the |
@@ -851,7 +852,7 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status) | |||
851 | 852 | ||
852 | /* | 853 | /* |
853 | * It is invalid to put an active child under a parent that is | 854 | * It is invalid to put an active child under a parent that is |
854 | * not active, has run-time PM enabled and the | 855 | * not active, has runtime PM enabled and the |
855 | * 'power.ignore_children' flag unset. | 856 | * 'power.ignore_children' flag unset. |
856 | */ | 857 | */ |
857 | if (!parent->power.disable_depth | 858 | if (!parent->power.disable_depth |
@@ -885,7 +886,7 @@ EXPORT_SYMBOL_GPL(__pm_runtime_set_status); | |||
885 | * @dev: Device to handle. | 886 | * @dev: Device to handle. |
886 | * | 887 | * |
887 | * Flush all pending requests for the device from pm_wq and wait for all | 888 | * Flush all pending requests for the device from pm_wq and wait for all |
888 | * run-time PM operations involving the device in progress to complete. | 889 | * runtime PM operations involving the device in progress to complete. |
889 | * | 890 | * |
890 | * Should be called under dev->power.lock with interrupts disabled. | 891 | * Should be called under dev->power.lock with interrupts disabled. |
891 | */ | 892 | */ |
@@ -933,7 +934,7 @@ static void __pm_runtime_barrier(struct device *dev) | |||
933 | * Prevent the device from being suspended by incrementing its usage counter and | 934 | * Prevent the device from being suspended by incrementing its usage counter and |
934 | * if there's a pending resume request for the device, wake the device up. | 935 | * if there's a pending resume request for the device, wake the device up. |
935 | * Next, make sure that all pending requests for the device have been flushed | 936 | * Next, make sure that all pending requests for the device have been flushed |
936 | * from pm_wq and wait for all run-time PM operations involving the device in | 937 | * from pm_wq and wait for all runtime PM operations involving the device in |
937 | * progress to complete. | 938 | * progress to complete. |
938 | * | 939 | * |
939 | * Return value: | 940 | * Return value: |
@@ -963,18 +964,18 @@ int pm_runtime_barrier(struct device *dev) | |||
963 | EXPORT_SYMBOL_GPL(pm_runtime_barrier); | 964 | EXPORT_SYMBOL_GPL(pm_runtime_barrier); |
964 | 965 | ||
965 | /** | 966 | /** |
966 | * __pm_runtime_disable - Disable run-time PM of a device. | 967 | * __pm_runtime_disable - Disable runtime PM of a device. |
967 | * @dev: Device to handle. | 968 | * @dev: Device to handle. |
968 | * @check_resume: If set, check if there's a resume request for the device. | 969 | * @check_resume: If set, check if there's a resume request for the device. |
969 | * | 970 | * |
970 | * Increment power.disable_depth for the device and if was zero previously, | 971 | * Increment power.disable_depth for the device and if was zero previously, |
971 | * cancel all pending run-time PM requests for the device and wait for all | 972 | * cancel all pending runtime PM requests for the device and wait for all |
972 | * operations in progress to complete. The device can be either active or | 973 | * operations in progress to complete. The device can be either active or |
973 | * suspended after its run-time PM has been disabled. | 974 | * suspended after its runtime PM has been disabled. |
974 | * | 975 | * |
975 | * If @check_resume is set and there's a resume request pending when | 976 | * If @check_resume is set and there's a resume request pending when |
976 | * __pm_runtime_disable() is called and power.disable_depth is zero, the | 977 | * __pm_runtime_disable() is called and power.disable_depth is zero, the |
977 | * function will wake up the device before disabling its run-time PM. | 978 | * function will wake up the device before disabling its runtime PM. |
978 | */ | 979 | */ |
979 | void __pm_runtime_disable(struct device *dev, bool check_resume) | 980 | void __pm_runtime_disable(struct device *dev, bool check_resume) |
980 | { | 981 | { |
@@ -987,7 +988,7 @@ void __pm_runtime_disable(struct device *dev, bool check_resume) | |||
987 | 988 | ||
988 | /* | 989 | /* |
989 | * Wake up the device if there's a resume request pending, because that | 990 | * Wake up the device if there's a resume request pending, because that |
990 | * means there probably is some I/O to process and disabling run-time PM | 991 | * means there probably is some I/O to process and disabling runtime PM |
991 | * shouldn't prevent the device from processing the I/O. | 992 | * shouldn't prevent the device from processing the I/O. |
992 | */ | 993 | */ |
993 | if (check_resume && dev->power.request_pending | 994 | if (check_resume && dev->power.request_pending |
@@ -1012,7 +1013,7 @@ void __pm_runtime_disable(struct device *dev, bool check_resume) | |||
1012 | EXPORT_SYMBOL_GPL(__pm_runtime_disable); | 1013 | EXPORT_SYMBOL_GPL(__pm_runtime_disable); |
1013 | 1014 | ||
1014 | /** | 1015 | /** |
1015 | * pm_runtime_enable - Enable run-time PM of a device. | 1016 | * pm_runtime_enable - Enable runtime PM of a device. |
1016 | * @dev: Device to handle. | 1017 | * @dev: Device to handle. |
1017 | */ | 1018 | */ |
1018 | void pm_runtime_enable(struct device *dev) | 1019 | void pm_runtime_enable(struct device *dev) |
@@ -1031,7 +1032,7 @@ void pm_runtime_enable(struct device *dev) | |||
1031 | EXPORT_SYMBOL_GPL(pm_runtime_enable); | 1032 | EXPORT_SYMBOL_GPL(pm_runtime_enable); |
1032 | 1033 | ||
1033 | /** | 1034 | /** |
1034 | * pm_runtime_forbid - Block run-time PM of a device. | 1035 | * pm_runtime_forbid - Block runtime PM of a device. |
1035 | * @dev: Device to handle. | 1036 | * @dev: Device to handle. |
1036 | * | 1037 | * |
1037 | * Increase the device's usage count and clear its power.runtime_auto flag, | 1038 | * Increase the device's usage count and clear its power.runtime_auto flag, |
@@ -1054,7 +1055,7 @@ void pm_runtime_forbid(struct device *dev) | |||
1054 | EXPORT_SYMBOL_GPL(pm_runtime_forbid); | 1055 | EXPORT_SYMBOL_GPL(pm_runtime_forbid); |
1055 | 1056 | ||
1056 | /** | 1057 | /** |
1057 | * pm_runtime_allow - Unblock run-time PM of a device. | 1058 | * pm_runtime_allow - Unblock runtime PM of a device. |
1058 | * @dev: Device to handle. | 1059 | * @dev: Device to handle. |
1059 | * | 1060 | * |
1060 | * Decrease the device's usage count and set its power.runtime_auto flag. | 1061 | * Decrease the device's usage count and set its power.runtime_auto flag. |
@@ -1075,12 +1076,12 @@ void pm_runtime_allow(struct device *dev) | |||
1075 | EXPORT_SYMBOL_GPL(pm_runtime_allow); | 1076 | EXPORT_SYMBOL_GPL(pm_runtime_allow); |
1076 | 1077 | ||
1077 | /** | 1078 | /** |
1078 | * pm_runtime_no_callbacks - Ignore run-time PM callbacks for a device. | 1079 | * pm_runtime_no_callbacks - Ignore runtime PM callbacks for a device. |
1079 | * @dev: Device to handle. | 1080 | * @dev: Device to handle. |
1080 | * | 1081 | * |
1081 | * Set the power.no_callbacks flag, which tells the PM core that this | 1082 | * Set the power.no_callbacks flag, which tells the PM core that this |
1082 | * device is power-managed through its parent and has no run-time PM | 1083 | * device is power-managed through its parent and has no runtime PM |
1083 | * callbacks of its own. The run-time sysfs attributes will be removed. | 1084 | * callbacks of its own. The runtime sysfs attributes will be removed. |
1084 | */ | 1085 | */ |
1085 | void pm_runtime_no_callbacks(struct device *dev) | 1086 | void pm_runtime_no_callbacks(struct device *dev) |
1086 | { | 1087 | { |
@@ -1156,8 +1157,8 @@ static void update_autosuspend(struct device *dev, int old_delay, int old_use) | |||
1156 | * @delay: Value of the new delay in milliseconds. | 1157 | * @delay: Value of the new delay in milliseconds. |
1157 | * | 1158 | * |
1158 | * Set the device's power.autosuspend_delay value. If it changes to negative | 1159 | * Set the device's power.autosuspend_delay value. If it changes to negative |
1159 | * and the power.use_autosuspend flag is set, prevent run-time suspends. If it | 1160 | * and the power.use_autosuspend flag is set, prevent runtime suspends. If it |
1160 | * changes the other way, allow run-time suspends. | 1161 | * changes the other way, allow runtime suspends. |
1161 | */ | 1162 | */ |
1162 | void pm_runtime_set_autosuspend_delay(struct device *dev, int delay) | 1163 | void pm_runtime_set_autosuspend_delay(struct device *dev, int delay) |
1163 | { | 1164 | { |
@@ -1177,7 +1178,7 @@ EXPORT_SYMBOL_GPL(pm_runtime_set_autosuspend_delay); | |||
1177 | * @dev: Device to handle. | 1178 | * @dev: Device to handle. |
1178 | * @use: New value for use_autosuspend. | 1179 | * @use: New value for use_autosuspend. |
1179 | * | 1180 | * |
1180 | * Set the device's power.use_autosuspend flag, and allow or prevent run-time | 1181 | * Set the device's power.use_autosuspend flag, and allow or prevent runtime |
1181 | * suspends as needed. | 1182 | * suspends as needed. |
1182 | */ | 1183 | */ |
1183 | void __pm_runtime_use_autosuspend(struct device *dev, bool use) | 1184 | void __pm_runtime_use_autosuspend(struct device *dev, bool use) |
@@ -1194,7 +1195,7 @@ void __pm_runtime_use_autosuspend(struct device *dev, bool use) | |||
1194 | EXPORT_SYMBOL_GPL(__pm_runtime_use_autosuspend); | 1195 | EXPORT_SYMBOL_GPL(__pm_runtime_use_autosuspend); |
1195 | 1196 | ||
1196 | /** | 1197 | /** |
1197 | * pm_runtime_init - Initialize run-time PM fields in given device object. | 1198 | * pm_runtime_init - Initialize runtime PM fields in given device object. |
1198 | * @dev: Device object to initialize. | 1199 | * @dev: Device object to initialize. |
1199 | */ | 1200 | */ |
1200 | void pm_runtime_init(struct device *dev) | 1201 | void pm_runtime_init(struct device *dev) |
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index a9f5b8979611..942d6a7c9ae1 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -116,12 +116,14 @@ static ssize_t control_store(struct device * dev, struct device_attribute *attr, | |||
116 | cp = memchr(buf, '\n', n); | 116 | cp = memchr(buf, '\n', n); |
117 | if (cp) | 117 | if (cp) |
118 | len = cp - buf; | 118 | len = cp - buf; |
119 | device_lock(dev); | ||
119 | if (len == sizeof ctrl_auto - 1 && strncmp(buf, ctrl_auto, len) == 0) | 120 | if (len == sizeof ctrl_auto - 1 && strncmp(buf, ctrl_auto, len) == 0) |
120 | pm_runtime_allow(dev); | 121 | pm_runtime_allow(dev); |
121 | else if (len == sizeof ctrl_on - 1 && strncmp(buf, ctrl_on, len) == 0) | 122 | else if (len == sizeof ctrl_on - 1 && strncmp(buf, ctrl_on, len) == 0) |
122 | pm_runtime_forbid(dev); | 123 | pm_runtime_forbid(dev); |
123 | else | 124 | else |
124 | return -EINVAL; | 125 | n = -EINVAL; |
126 | device_unlock(dev); | ||
125 | return n; | 127 | return n; |
126 | } | 128 | } |
127 | 129 | ||
@@ -205,7 +207,9 @@ static ssize_t autosuspend_delay_ms_store(struct device *dev, | |||
205 | if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay) | 207 | if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay) |
206 | return -EINVAL; | 208 | return -EINVAL; |
207 | 209 | ||
210 | device_lock(dev); | ||
208 | pm_runtime_set_autosuspend_delay(dev, delay); | 211 | pm_runtime_set_autosuspend_delay(dev, delay); |
212 | device_unlock(dev); | ||
209 | return n; | 213 | return n; |
210 | } | 214 | } |
211 | 215 | ||
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 46767c53917a..12d1e81a8abe 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/sched.h> | 18 | #include <linux/sched.h> |
19 | #include <linux/cpu.h> | 19 | #include <linux/cpu.h> |
20 | #include <linux/pm_runtime.h> | 20 | #include <linux/pm_runtime.h> |
21 | #include <linux/suspend.h> | ||
21 | #include "pci.h" | 22 | #include "pci.h" |
22 | 23 | ||
23 | struct pci_dynid { | 24 | struct pci_dynid { |
@@ -616,6 +617,21 @@ static int pci_pm_prepare(struct device *dev) | |||
616 | int error = 0; | 617 | int error = 0; |
617 | 618 | ||
618 | /* | 619 | /* |
620 | * If a PCI device configured to wake up the system from sleep states | ||
621 | * has been suspended at run time and there's a resume request pending | ||
622 | * for it, this is equivalent to the device signaling wakeup, so the | ||
623 | * system suspend operation should be aborted. | ||
624 | */ | ||
625 | pm_runtime_get_noresume(dev); | ||
626 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) | ||
627 | pm_wakeup_event(dev, 0); | ||
628 | |||
629 | if (pm_wakeup_pending()) { | ||
630 | pm_runtime_put_sync(dev); | ||
631 | return -EBUSY; | ||
632 | } | ||
633 | |||
634 | /* | ||
619 | * PCI devices suspended at run time need to be resumed at this | 635 | * PCI devices suspended at run time need to be resumed at this |
620 | * point, because in general it is necessary to reconfigure them for | 636 | * point, because in general it is necessary to reconfigure them for |
621 | * system suspend. Namely, if the device is supposed to wake up the | 637 | * system suspend. Namely, if the device is supposed to wake up the |
@@ -624,7 +640,7 @@ static int pci_pm_prepare(struct device *dev) | |||
624 | * system from the sleep state, we'll have to prevent it from signaling | 640 | * system from the sleep state, we'll have to prevent it from signaling |
625 | * wake-up. | 641 | * wake-up. |
626 | */ | 642 | */ |
627 | pm_runtime_get_sync(dev); | 643 | pm_runtime_resume(dev); |
628 | 644 | ||
629 | if (drv && drv->pm && drv->pm->prepare) | 645 | if (drv && drv->pm && drv->pm->prepare) |
630 | error = drv->pm->prepare(dev); | 646 | error = drv->pm->prepare(dev); |
diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index d70e91ae60af..d82a023a9015 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c | |||
@@ -144,9 +144,9 @@ int scsi_autopm_get_device(struct scsi_device *sdev) | |||
144 | int err; | 144 | int err; |
145 | 145 | ||
146 | err = pm_runtime_get_sync(&sdev->sdev_gendev); | 146 | err = pm_runtime_get_sync(&sdev->sdev_gendev); |
147 | if (err < 0) | 147 | if (err < 0 && err !=-EACCES) |
148 | pm_runtime_put_sync(&sdev->sdev_gendev); | 148 | pm_runtime_put_sync(&sdev->sdev_gendev); |
149 | else if (err > 0) | 149 | else |
150 | err = 0; | 150 | err = 0; |
151 | return err; | 151 | return err; |
152 | } | 152 | } |
@@ -173,9 +173,9 @@ int scsi_autopm_get_host(struct Scsi_Host *shost) | |||
173 | int err; | 173 | int err; |
174 | 174 | ||
175 | err = pm_runtime_get_sync(&shost->shost_gendev); | 175 | err = pm_runtime_get_sync(&shost->shost_gendev); |
176 | if (err < 0) | 176 | if (err < 0 && err !=-EACCES) |
177 | pm_runtime_put_sync(&shost->shost_gendev); | 177 | pm_runtime_put_sync(&shost->shost_gendev); |
178 | else if (err > 0) | 178 | else |
179 | err = 0; | 179 | err = 0; |
180 | return err; | 180 | return err; |
181 | } | 181 | } |