Commit c2ebf788 authored by Ulf Hansson's avatar Ulf Hansson Committed by Rafael J. Wysocki

ACPI / PM: Split code validating need for runtime resume in ->prepare()

Move the code dealing with validation of whether runtime resuming the
device is needed during system suspend.

In this way it becomes more clear for what circumstances ACPI is prevented
from trying the direct_complete path.
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent e4da817d
...@@ -966,6 +966,27 @@ int acpi_dev_suspend_late(struct device *dev) ...@@ -966,6 +966,27 @@ int acpi_dev_suspend_late(struct device *dev)
} }
EXPORT_SYMBOL_GPL(acpi_dev_suspend_late); EXPORT_SYMBOL_GPL(acpi_dev_suspend_late);
static bool acpi_dev_needs_resume(struct device *dev, struct acpi_device *adev)
{
u32 sys_target = acpi_target_system_state();
int ret, state;
if (device_may_wakeup(dev) != !!adev->wakeup.prepare_count)
return true;
if (sys_target == ACPI_STATE_S0)
return false;
if (adev->power.flags.dsw_present)
return true;
ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state);
if (ret)
return true;
return state != adev->power.state;
}
/** /**
* acpi_subsys_prepare - Prepare device for system transition to a sleep state. * acpi_subsys_prepare - Prepare device for system transition to a sleep state.
* @dev: Device to prepare. * @dev: Device to prepare.
...@@ -973,26 +994,16 @@ EXPORT_SYMBOL_GPL(acpi_dev_suspend_late); ...@@ -973,26 +994,16 @@ EXPORT_SYMBOL_GPL(acpi_dev_suspend_late);
int acpi_subsys_prepare(struct device *dev) int acpi_subsys_prepare(struct device *dev)
{ {
struct acpi_device *adev = ACPI_COMPANION(dev); struct acpi_device *adev = ACPI_COMPANION(dev);
u32 sys_target; int ret;
int ret, state;
ret = pm_generic_prepare(dev); ret = pm_generic_prepare(dev);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (!adev || !pm_runtime_suspended(dev) if (!adev || !pm_runtime_suspended(dev))
|| device_may_wakeup(dev) != !!adev->wakeup.prepare_count)
return 0;
sys_target = acpi_target_system_state();
if (sys_target == ACPI_STATE_S0)
return 1;
if (adev->power.flags.dsw_present)
return 0; return 0;
ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state); return !acpi_dev_needs_resume(dev, adev);
return !ret && state == adev->power.state;
} }
EXPORT_SYMBOL_GPL(acpi_subsys_prepare); EXPORT_SYMBOL_GPL(acpi_subsys_prepare);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment