Kyle McMartin 641f5c9
From 141d0d01ab292d4ea3a6d5e96b4048e10e68c1d3 Mon Sep 17 00:00:00 2001
Kyle McMartin a56ba88
From: Kyle McMartin <kyle@mcmartin.ca>
Kyle McMartin a56ba88
Date: Mon, 24 Jan 2011 13:01:57 -0500
Kyle McMartin a56ba88
Subject: [PATCH] runtime_pm_fixups
Kyle McMartin a56ba88
Kyle McMartin a56ba88
---
Kyle McMartin a56ba88
 drivers/acpi/bus.c      |    3 ++-
Kyle McMartin 641f5c9
 drivers/acpi/pci_bind.c |    6 ++++++
Kyle McMartin a56ba88
 drivers/acpi/power.c    |    5 ++++-
Kyle McMartin a56ba88
 drivers/acpi/sleep.c    |    2 +-
Kyle McMartin a56ba88
 drivers/acpi/wakeup.c   |    2 +-
Kyle McMartin a56ba88
 drivers/pci/pci-acpi.c  |    2 +-
Kyle McMartin a56ba88
 include/acpi/acpi_bus.h |    2 +-
Kyle McMartin 641f5c9
 7 files changed, 16 insertions(+), 6 deletions(-)
Matthew Garrett 2df4496
Matthew Garrett 2df4496
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
Kyle McMartin a56ba88
index 7ced61f..e4e0114 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/bus.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/bus.c
Kyle McMartin a56ba88
@@ -256,7 +256,8 @@ static int __acpi_bus_set_power(struct acpi_device *device, int state)
Kyle McMartin a56ba88
 	 * a lower-powered state.
Kyle McMartin a56ba88
 	 */
Kyle McMartin a56ba88
 	if (state < device->power.state) {
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
Kyle McMartin 641f5c9
index 2ef0409..4b0bb68 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/pci_bind.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/pci_bind.c
Kyle McMartin a56ba88
@@ -32,6 +32,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
 
Kyle McMartin 641f5c9
@@ -65,6 +67,7 @@ static int acpi_pci_bind(struct acpi_device *device)
Kyle McMartin 641f5c9
 	acpi_handle handle;
Kyle McMartin 641f5c9
 	struct pci_bus *bus;
Kyle McMartin 641f5c9
 	struct pci_dev *dev;
Kyle McMartin 641f5c9
+	int state;
Kyle McMartin 641f5c9
 
Kyle McMartin 641f5c9
 	dev = acpi_get_pci_dev(device->handle);
Kyle McMartin 641f5c9
 	if (!dev)
Kyle McMartin 641f5c9
@@ -87,6 +90,9 @@ static int acpi_pci_bind(struct acpi_device *device)
Matthew Garrett 2df4496
 		device->ops.unbind = acpi_pci_unbind;
Matthew Garrett 2df4496
 	}
Matthew Garrett 2df4496
 
Kyle McMartin 641f5c9
+	acpi_power_get_inferred_state(device, &state);
Kyle McMartin 641f5c9
+	acpi_power_transition(device, state);
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
Kyle McMartin a56ba88
index 9ac2a9f..cd6a8df 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/power.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/power.c
Kyle McMartin a56ba88
@@ -412,7 +412,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
 
Kyle McMartin a56ba88
@@ -435,6 +435,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++) {
Kyle McMartin a56ba88
 		int ret = acpi_power_off(dev->wakeup.resources.handles[i]);
Matthew Garrett 2df4496
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
Kyle McMartin a56ba88
index d6a8cd1..5d68dc0 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/sleep.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/sleep.c
Kyle McMartin a56ba88
@@ -697,7 +697,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
Kyle McMartin a56ba88
index ed65014..a0cabc3 100644
Matthew Garrett 2df4496
--- a/drivers/acpi/wakeup.c
Matthew Garrett 2df4496
+++ b/drivers/acpi/wakeup.c
Kyle McMartin a56ba88
@@ -73,7 +73,7 @@ void acpi_disable_wakeup_devices(u8 sleep_state)
Matthew Garrett 2df4496
 				ACPI_GPE_DISABLE);
Matthew Garrett 2df4496
 
Kyle McMartin a56ba88
 		if (device_may_wakeup(&dev->dev))
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
Kyle McMartin a56ba88
index 6fe0772..819fa7a 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
Kyle McMartin a56ba88
index 78ca429..92d6e86 100644
Matthew Garrett 2df4496
--- a/include/acpi/acpi_bus.h
Matthew Garrett 2df4496
+++ b/include/acpi/acpi_bus.h
Kyle McMartin a56ba88
@@ -379,7 +379,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 *);
Kyle McMartin a56ba88
-- 
Kyle McMartin a56ba88
1.7.3.5
Kyle McMartin a56ba88