ACPI: PM: Fix sharing of wakeup power resources
[linux-2.6-microblaze.git] / drivers / acpi / power.c
index 1b7431f..ba6aaf7 100644 (file)
@@ -52,7 +52,6 @@ struct acpi_power_resource {
        u32 order;
        unsigned int ref_count;
        u8 state;
-       bool wakeup_enabled;
        struct mutex resource_lock;
        struct list_head dependents;
 };
@@ -710,7 +709,6 @@ int acpi_device_sleep_wake(struct acpi_device *dev,
  */
 int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
 {
-       struct acpi_power_resource_entry *entry;
        int err = 0;
 
        if (!dev || !dev->wakeup.flags.valid)
@@ -721,26 +719,13 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
        if (dev->wakeup.prepare_count++)
                goto out;
 
-       list_for_each_entry(entry, &dev->wakeup.resources, node) {
-               struct acpi_power_resource *resource = entry->resource;
-
-               mutex_lock(&resource->resource_lock);
-
-               if (!resource->wakeup_enabled) {
-                       err = acpi_power_on_unlocked(resource);
-                       if (!err)
-                               resource->wakeup_enabled = true;
-               }
-
-               mutex_unlock(&resource->resource_lock);
-
-               if (err) {
-                       dev_err(&dev->dev,
-                               "Cannot turn wakeup power resources on\n");
-                       dev->wakeup.flags.valid = 0;
-                       goto out;
-               }
+       err = acpi_power_on_list(&dev->wakeup.resources);
+       if (err) {
+               dev_err(&dev->dev, "Cannot turn on wakeup power resources\n");
+               dev->wakeup.flags.valid = 0;
+               goto out;
        }
+
        /*
         * Passing 3 as the third argument below means the device may be
         * put into arbitrary power state afterward.
@@ -770,39 +755,33 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev)
 
        mutex_lock(&acpi_device_lock);
 
-       if (--dev->wakeup.prepare_count > 0)
+       if (dev->wakeup.prepare_count > 1) {
+               dev->wakeup.prepare_count--;
                goto out;
+       }
 
-       /*
-        * Executing the code below even if prepare_count is already zero when
-        * the function is called may be useful, for example for initialisation.
-        */
-       if (dev->wakeup.prepare_count < 0)
-               dev->wakeup.prepare_count = 0;
+       /* Do nothing if wakeup power has not been enabled for this device. */
+       if (!dev->wakeup.prepare_count)
+               goto out;
 
        err = acpi_device_sleep_wake(dev, 0, 0, 0);
        if (err)
                goto out;
 
+       /*
+        * All of the power resources in the list need to be turned off even if
+        * there are errors.
+        */
        list_for_each_entry(entry, &dev->wakeup.resources, node) {
-               struct acpi_power_resource *resource = entry->resource;
-
-               mutex_lock(&resource->resource_lock);
-
-               if (resource->wakeup_enabled) {
-                       err = acpi_power_off_unlocked(resource);
-                       if (!err)
-                               resource->wakeup_enabled = false;
-               }
-
-               mutex_unlock(&resource->resource_lock);
+               int ret;
 
-               if (err) {
-                       dev_err(&dev->dev,
-                               "Cannot turn wakeup power resources off\n");
-                       dev->wakeup.flags.valid = 0;
-                       break;
-               }
+               ret = acpi_power_off(entry->resource);
+               if (ret && !err)
+                       err = ret;
+       }
+       if (err) {
+               dev_err(&dev->dev, "Cannot turn off wakeup power resources\n");
+               dev->wakeup.flags.valid = 0;
        }
 
  out: