[ACPI] pci_set_power_state() now calls
authorDavid Shaohua Li <shaohua.li@intel.com>
Sat, 19 Mar 2005 05:16:18 +0000 (00:16 -0500)
committerLen Brown <len.brown@intel.com>
Tue, 12 Jul 2005 03:47:06 +0000 (23:47 -0400)
platform_pci_set_power_state()
and ACPI can answer

http://bugzilla.kernel.org/show_bug.cgi?id=4277

Signed-off-by: David Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
drivers/acpi/bus.c
drivers/pci/pci-acpi.c
drivers/pci/pci.c
drivers/pci/pci.h

index 4edff17385791ce10070529414625267aed2d59b..d77c2307883c65efbf57d34b4dec54799d0a2337 100644 (file)
@@ -212,6 +212,12 @@ acpi_bus_set_power (
                ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Device is not power manageable\n"));
                return_VALUE(-ENODEV);
        }
+       /*
+        * Get device's current power state if it's unknown
+        * This means device power state isn't initialized or previous setting failed
+        */
+       if (device->power.state == ACPI_STATE_UNKNOWN)
+               acpi_bus_get_power(device->handle, &device->power.state);
        if (state == device->power.state) {
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", state));
                return_VALUE(0);
@@ -231,7 +237,7 @@ acpi_bus_set_power (
         * On transitions to a high-powered state we first apply power (via
         * power resources) then evalute _PSx.  Conversly for transitions to
         * a lower-powered state.
-        */ 
+        */
        if (state < device->power.state) {
                if (device->power.flags.power_resources) {
                        result = acpi_power_transition(device, state);
index 8eb599708de8b9053bddeb88419da294eec8f9b8..a0d43ea872df6706df9c0faa19b156a33d82d796 100644 (file)
@@ -253,6 +253,24 @@ static int acpi_pci_choose_state(struct pci_dev *pdev, pm_message_t state)
        return -ENODEV;
 }
 
+static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
+{
+       acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       static int state_conv[] = {
+               [0] = 0,
+               [1] = 1,
+               [2] = 2,
+               [3] = 3,
+               [4] = 3
+       };
+       int acpi_state = state_conv[(int __force) state];
+
+       if (!handle)
+               return -ENODEV;
+       return acpi_bus_set_power(handle, acpi_state);
+}
+
+
 /* ACPI bus type */
 static int pci_acpi_find_device(struct device *dev, acpi_handle *handle)
 {
@@ -300,6 +318,7 @@ static int __init pci_acpi_init(void)
        if (ret)
                return 0;
        platform_pci_choose_state = acpi_pci_choose_state;
+       platform_pci_set_power_state = acpi_pci_set_power_state;
        return 0;
 }
 arch_initcall(pci_acpi_init);
index 5af9418077850d8356e02c5d1abd19af92c204c2..a1c66e8ea5f2ced74345db9a1c173f290326eb82 100644 (file)
@@ -235,7 +235,7 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
  * -EIO if device does not support PCI PM.
  * 0 if we can successfully change the power state.
  */
-
+int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t) = NULL;
 int
 pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 {
@@ -299,8 +299,15 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
                msleep(10);
        else if (state == PCI_D2 || dev->current_state == PCI_D2)
                udelay(200);
-       dev->current_state = state;
 
+       /*
+        * Give firmware a chance to be called, such as ACPI _PRx, _PSx
+        * Firmware method after natice method ?
+        */
+       if (platform_pci_set_power_state)
+               platform_pci_set_power_state(dev, state);
+
+       dev->current_state = state;
        return 0;
 }
 
index 25c44922f7dbc893044a0a3679eb167164851fa7..d94d7af4f7a0ce850134688a4407dc95c686f44e 100644 (file)
@@ -13,6 +13,7 @@ extern int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
                                  void *alignf_data);
 /* Firmware callbacks */
 extern int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
+extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state);
 
 /* PCI /proc functions */
 #ifdef CONFIG_PROC_FS