ACPI / PM: Avoid resuming devices in ACPI PM domain during system suspend
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 16 May 2014 22:18:13 +0000 (00:18 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 20 May 2014 11:22:48 +0000 (13:22 +0200)
Rework the ACPI PM domain's PM callbacks to avoid resuming devices
during system suspend (in order to modify their wakeup settings etc.)
if that isn't necessary.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/device_pm.c
drivers/acpi/scan.c
include/acpi/acpi_bus.h

index d047739f3380f2d0e53304002499205abe08abd1..9e5fd9c440b7525e7bf65119c8d9783c9803ac45 100644 (file)
@@ -900,17 +900,45 @@ EXPORT_SYMBOL_GPL(acpi_dev_resume_early);
  */
 int acpi_subsys_prepare(struct device *dev)
 {
-       /*
-        * Devices having power.ignore_children set may still be necessary for
-        * suspending their children in the next phase of device suspend.
-        */
-       if (dev->power.ignore_children)
-               pm_runtime_resume(dev);
+       struct acpi_device *adev = ACPI_COMPANION(dev);
+       u32 sys_target;
+       int ret, state;
+
+       ret = pm_generic_prepare(dev);
+       if (ret < 0)
+               return ret;
+
+       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;
 
-       return pm_generic_prepare(dev);
+       if (adev->power.flags.dsw_present)
+               return 0;
+
+       ret = acpi_dev_pm_get_state(dev, adev, sys_target, NULL, &state);
+       return !ret && state == adev->power.state;
 }
 EXPORT_SYMBOL_GPL(acpi_subsys_prepare);
 
+/**
+ * acpi_subsys_complete - Finalize device's resume during system resume.
+ * @dev: Device to handle.
+ */
+static void acpi_subsys_complete(struct device *dev)
+{
+       /*
+        * If the device had been runtime-suspended before the system went into
+        * the sleep state it is going out of and it has never been resumed till
+        * now, resume it in case the firmware powered it up.
+        */
+       if (dev->power.direct_complete)
+               pm_request_resume(dev);
+}
+
 /**
  * acpi_subsys_suspend - Run the device driver's suspend callback.
  * @dev: Device to handle.
@@ -979,6 +1007,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
 #endif
 #ifdef CONFIG_PM_SLEEP
                .prepare = acpi_subsys_prepare,
+               .complete = acpi_subsys_complete,
                .suspend = acpi_subsys_suspend,
                .suspend_late = acpi_subsys_suspend_late,
                .resume_early = acpi_subsys_resume_early,
index 7efe546a8c42704137f3cbae8a3159485f3473b9..df6e4c924b353a24db62d5b222572135f0240816 100644 (file)
@@ -1551,9 +1551,13 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)
         */
        if (acpi_has_method(device->handle, "_PSC"))
                device->power.flags.explicit_get = 1;
+
        if (acpi_has_method(device->handle, "_IRC"))
                device->power.flags.inrush_current = 1;
 
+       if (acpi_has_method(device->handle, "_DSW"))
+               device->power.flags.dsw_present = 1;
+
        /*
         * Enumerate supported power management states
         */
index 84a2e29a231409701de1a9d579a1a139cccbd40c..7417a16c8d86a94ea1d64101e020dba006a681c1 100644 (file)
@@ -261,7 +261,8 @@ struct acpi_device_power_flags {
        u32 inrush_current:1;   /* Serialize Dx->D0 */
        u32 power_removed:1;    /* Optimize Dx->D0 */
        u32 ignore_parent:1;    /* Power is independent of parent power state */
-       u32 reserved:27;
+       u32 dsw_present:1;      /* _DSW present? */
+       u32 reserved:26;
 };
 
 struct acpi_device_power_state {