Matthew Garrett 2df4496
Experimental fixes for the interactions between runtime PM and ACPI power
Matthew Garrett 2df4496
resources. Needs some work with upstream.
Matthew Garrett 2df4496
Matthew Garrett 2df4496
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
Matthew Garrett 2df4496
index 310e3b9..371debe 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/bus.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/bus.c
Matthew Garrett 2df4496
@@ -329,7 +329,8 @@ int acpi_bus_set_power(acpi_handle handle, int state)
Matthew Garrett 2df4496
 				goto end;
Matthew Garrett 2df4496
 			}
Matthew Garrett 2df4496
 		}
Matthew Garrett 2df4496
-		if (device->power.flags.power_resources) {
Matthew Garrett 2df4496
+		if (device->power.flags.power_resources &&
Matthew Garrett 2df4496
+		    !device->wakeup.run_wake_count) {
Matthew Garrett 2df4496
 			result = acpi_power_transition(device, state);
Matthew Garrett 2df4496
 			if (result)
Matthew Garrett 2df4496
 				goto end;
Matthew Garrett 2df4496
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
Matthew Garrett 2df4496
index 8b3cc6a..b013174 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/pci_bind.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/pci_bind.c
Matthew Garrett 2df4496
@@ -33,6 +33,8 @@
Matthew Garrett 2df4496
 #include <acpi/acpi_bus.h>
Matthew Garrett 2df4496
 #include <acpi/acpi_drivers.h>
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
+#include "internal.h"
Matthew Garrett 2df4496
+
Matthew Garrett 2df4496
 #define _COMPONENT		ACPI_PCI_COMPONENT
Matthew Garrett 2df4496
 ACPI_MODULE_NAME("pci_bind");
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
@@ -173,6 +175,8 @@ static int acpi_pci_bind(struct acpi_device *device)
Matthew Garrett 2df4496
 		device->ops.unbind = acpi_pci_unbind;
Matthew Garrett 2df4496
 	}
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
+	acpi_power_transition(device, acpi_power_get_inferred_state(device));
Matthew Garrett 2df4496
+
Matthew Garrett 2df4496
 	/*
Matthew Garrett 2df4496
 	 * Evaluate and parse _PRT, if exists.  This code allows parsing of
Matthew Garrett 2df4496
 	 * _PRT objects within the scope of non-bridge devices.  Note that
Matthew Garrett 2df4496
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
Matthew Garrett 2df4496
index 844c155..8a42ddf 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/power.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/power.c
Matthew Garrett 2df4496
@@ -394,7 +394,7 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
Matthew Garrett 2df4496
  *    State Wake) for the device, if present
Matthew Garrett 2df4496
  * 2. Shutdown down the power resources
Matthew Garrett 2df4496
  */
Matthew Garrett 2df4496
-int acpi_disable_wakeup_device_power(struct acpi_device *dev)
Matthew Garrett 2df4496
+int acpi_disable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
Matthew Garrett 2df4496
 {
Matthew Garrett 2df4496
 	int i, err = 0;
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
@@ -417,6 +417,9 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev)
Matthew Garrett 2df4496
 	if (err)
Matthew Garrett 2df4496
 		goto out;
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
+	if (sleep_state == ACPI_STATE_S0)
Matthew Garrett 2df4496
+		goto out;
Matthew Garrett 2df4496
+
Matthew Garrett 2df4496
 	/* Close power resource */
Matthew Garrett 2df4496
 	for (i = 0; i < dev->wakeup.resources.count; i++) {
Matthew Garrett 2df4496
 		int ret = acpi_power_off_device(
Matthew Garrett 2df4496
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
Matthew Garrett 2df4496
index 2c5cd02..6bf016b 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/sleep.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/sleep.c
Matthew Garrett 2df4496
@@ -670,7 +670,7 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
 	error = enable ?
Matthew Garrett 2df4496
 		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
Matthew Garrett 2df4496
-		acpi_disable_wakeup_device_power(adev);
Matthew Garrett 2df4496
+		acpi_disable_wakeup_device_power(adev, acpi_target_sleep_state);
Matthew Garrett 2df4496
 	if (!error)
Matthew Garrett 2df4496
 		dev_info(dev, "wake-up capability %s by ACPI\n",
Matthew Garrett 2df4496
 				enable ? "enabled" : "disabled");
Matthew Garrett 2df4496
diff --git a/drivers/acpi/wakeup.c b/drivers/acpi/wakeup.c
Matthew Garrett 2df4496
index f62a50c..ff48a54 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/wakeup.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/wakeup.c
Matthew Garrett 2df4496
@@ -71,7 +71,7 @@ void acpi_disable_wakeup_devices(u8 sleep_state)
Matthew Garrett 2df4496
 				ACPI_GPE_DISABLE);
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
 		if (dev->wakeup.state.enabled)
Matthew Garrett 2df4496
-			acpi_disable_wakeup_device_power(dev);
Matthew Garrett 2df4496
+			acpi_disable_wakeup_device_power(dev, sleep_state);
Matthew Garrett 2df4496
 	}
Matthew Garrett 2df4496
 }
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
Matthew Garrett 2df4496
index 24e19c5..cd99494 100644
Matthew Garrett 2df4496
--- a/drivers/pci/pci-acpi.c
Matthew Garrett 2df4496
+++ b/drivers/pci/pci-acpi.c
Matthew Garrett 2df4496
@@ -302,7 +302,7 @@ static int acpi_dev_run_wake(struct device *phys_dev, bool enable)
Matthew Garrett 2df4496
 		if (!--dev->wakeup.run_wake_count) {
Matthew Garrett 2df4496
 			acpi_disable_gpe(dev->wakeup.gpe_device,
Matthew Garrett 2df4496
 					 dev->wakeup.gpe_number);
Matthew Garrett 2df4496
-			acpi_disable_wakeup_device_power(dev);
Matthew Garrett 2df4496
+			acpi_disable_wakeup_device_power(dev, ACPI_STATE_S0);
Matthew Garrett 2df4496
 		}
Matthew Garrett 2df4496
 	} else {
Matthew Garrett 2df4496
 		error = -EALREADY;
Matthew Garrett 2df4496
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
Matthew Garrett 2df4496
index 4de84ce..284f43c 100644
Matthew Garrett 2df4496
--- a/include/acpi/acpi_bus.h
Matthew Garrett 2df4496
+++ b/include/acpi/acpi_bus.h
Matthew Garrett 2df4496
@@ -387,7 +387,7 @@ struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
Matthew Garrett 2df4496
 #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
Matthew Garrett 2df4496
 
Matthew Garrett 2df4496
 int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
Matthew Garrett 2df4496
-int acpi_disable_wakeup_device_power(struct acpi_device *dev);
Matthew Garrett 2df4496
+int acpi_disable_wakeup_device_power(struct acpi_device *dev, int state);
Matthew Garrett 2df4496
 
Kyle McMartin 7b2f649
 #ifdef CONFIG_PM_OPS
Matthew Garrett 2df4496
 int acpi_pm_device_sleep_state(struct device *, int *);