aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/sleep.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-01 20:40:18 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-14 18:15:16 -0500
commit86b3832c64b6d01092216d84dc6a6b300875d0bb (patch)
tree3d990b5bee64a33159a3cfef7712949176832f6f /drivers/acpi/sleep.c
parentec2cd81ccfc055155ef4ca673f207168f516d287 (diff)
ACPI / PM: Move device power state selection routine to device_pm.c
The ACPI function for choosing device power state is now located in drivers/acpi/sleep.c, but drivers/acpi/device_pm.c is a more logical place for it, so move it there. However, instead of moving the function entirely, move its core only under a different name and with a different list of arguments, so that it is more flexible, and leave a wrapper around it in the original location. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/sleep.c')
-rw-r--r--drivers/acpi/sleep.c88
1 files changed, 3 insertions, 85 deletions
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 4defa0297ee4..fa20d0171887 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -19,7 +19,6 @@
19#include <linux/acpi.h> 19#include <linux/acpi.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pm_runtime.h> 21#include <linux/pm_runtime.h>
22#include <linux/pm_qos.h>
23 22
24#include <asm/io.h> 23#include <asm/io.h>
25 24
@@ -691,101 +690,20 @@ int acpi_suspend(u32 acpi_state)
691 * Return value: Preferred power state of the device on success, -ENODEV 690 * Return value: Preferred power state of the device on success, -ENODEV
692 * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure 691 * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure
693 * 692 *
694 * Find the lowest power (highest number) ACPI device power state that the
695 * device can be in while the system is in the sleep state represented
696 * by %acpi_target_sleep_state. If @d_min_p is set, the highest power (lowest
697 * number) device power state that @dev can be in for the given system sleep
698 * state is stored at the location pointed to by it.
699 *
700 * The caller must ensure that @dev is valid before using this function. 693 * The caller must ensure that @dev is valid before using this function.
701 */ 694 */
702int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in) 695int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
703{ 696{
704 acpi_handle handle = DEVICE_ACPI_HANDLE(dev); 697 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
705 struct acpi_device *adev; 698 struct acpi_device *adev;
706 char acpi_method[] = "_SxD";
707 unsigned long long d_min, d_max;
708 bool wakeup = false;
709 699
710 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3)
711 return -EINVAL;
712 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { 700 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
713 printk(KERN_DEBUG "ACPI handle has no context!\n"); 701 dev_dbg(dev, "ACPI handle without context in %s!\n", __func__);
714 return -ENODEV; 702 return -ENODEV;
715 } 703 }
716 if (d_max_in > ACPI_STATE_D3_HOT) {
717 enum pm_qos_flags_status stat;
718
719 stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF);
720 if (stat == PM_QOS_FLAGS_ALL)
721 d_max_in = ACPI_STATE_D3_HOT;
722 }
723
724 acpi_method[2] = '0' + acpi_target_sleep_state;
725 /*
726 * If the sleep state is S0, the lowest limit from ACPI is D3,
727 * but if the device has _S0W, we will use the value from _S0W
728 * as the lowest limit from ACPI. Finally, we will constrain
729 * the lowest limit with the specified one.
730 */
731 d_min = ACPI_STATE_D0;
732 d_max = ACPI_STATE_D3;
733
734 /*
735 * If present, _SxD methods return the minimum D-state (highest power
736 * state) we can use for the corresponding S-states. Otherwise, the
737 * minimum D-state is D0 (ACPI 3.x).
738 *
739 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
740 * provided -- that's our fault recovery, we ignore retval.
741 */
742 if (acpi_target_sleep_state > ACPI_STATE_S0) {
743 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
744 wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid
745 && adev->wakeup.sleep_state >= acpi_target_sleep_state;
746 } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) !=
747 PM_QOS_FLAGS_NONE) {
748 wakeup = adev->wakeup.flags.valid;
749 }
750
751 /*
752 * If _PRW says we can wake up the system from the target sleep state,
753 * the D-state returned by _SxD is sufficient for that (we assume a
754 * wakeup-aware driver if wake is set). Still, if _SxW exists
755 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
756 * can wake the system. _S0W may be valid, too.
757 */
758 if (wakeup) {
759 acpi_status status;
760
761 acpi_method[3] = 'W';
762 status = acpi_evaluate_integer(handle, acpi_method, NULL,
763 &d_max);
764 if (ACPI_FAILURE(status)) {
765 if (acpi_target_sleep_state != ACPI_STATE_S0 ||
766 status != AE_NOT_FOUND)
767 d_max = d_min;
768 } else if (d_max < d_min) {
769 /* Warn the user of the broken DSDT */
770 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
771 acpi_method);
772 /* Sanitize it */
773 d_min = d_max;
774 }
775 }
776 704
777 if (d_max_in < d_min) 705 return acpi_device_power_state(dev, adev, acpi_target_sleep_state,
778 return -EINVAL; 706 d_max_in, d_min_p);
779 if (d_min_p)
780 *d_min_p = d_min;
781 /* constrain d_max with specified lowest limit (max number) */
782 if (d_max > d_max_in) {
783 for (d_max = d_max_in; d_max > d_min; d_max--) {
784 if (adev->power.states[d_max].flags.valid)
785 break;
786 }
787 }
788 return d_max;
789} 707}
790EXPORT_SYMBOL(acpi_pm_device_sleep_state); 708EXPORT_SYMBOL(acpi_pm_device_sleep_state);
791#endif /* CONFIG_PM */ 709#endif /* CONFIG_PM */