ACPI / PM: Add function for device power state initialization
authorRafael J. Wysocki <rjw@sisk.pl>
Wed, 24 Nov 2010 23:08:36 +0000 (00:08 +0100)
committerLen Brown <len.brown@intel.com>
Wed, 12 Jan 2011 09:48:44 +0000 (04:48 -0500)
Add function acpi_bus_init_power() for getting the initial power
state of an ACPI device and reference counting its power resources
as appropriate.

Make acpi_bus_get_power_flags() use the new function instead of
acpi_bus_get_power() that updates device->power.state without
reference counting the device's power resources.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Len Brown <len.brown@intel.com>
drivers/acpi/bus.c
drivers/acpi/internal.h
drivers/acpi/scan.c

index 9657abc4a7fb534f50c120020c039fcd43577620..4534510905028996beaf78e4c08f26b0a3038c22 100644 (file)
@@ -364,6 +364,31 @@ int acpi_bus_set_power(acpi_handle handle, int state)
 
 EXPORT_SYMBOL(acpi_bus_set_power);
 
+
+int acpi_bus_init_power(struct acpi_device *device)
+{
+       int state;
+       int result;
+
+       if (!device)
+               return -EINVAL;
+
+       device->power.state = ACPI_STATE_UNKNOWN;
+
+       result = __acpi_bus_get_power(device, &state);
+       if (result)
+               return result;
+
+       if (device->power.flags.power_resources)
+               result = acpi_power_on_resources(device, state);
+
+       if (!result)
+               device->power.state = state;
+
+       return result;
+}
+
+
 bool acpi_bus_power_manageable(acpi_handle handle)
 {
        struct acpi_device *device;
index 433a8ee8ac2c37b9a84470e844883bea8e464de8..7493e6c7a003ef984d0a3f5445d016cc847c77e7 100644 (file)
@@ -44,6 +44,7 @@ int acpi_device_sleep_wake(struct acpi_device *dev,
 int acpi_power_get_inferred_state(struct acpi_device *device, int *state);
 int acpi_power_on_resources(struct acpi_device *device, int state);
 int acpi_power_transition(struct acpi_device *device, int state);
+int acpi_bus_init_power(struct acpi_device *device);
 extern int acpi_power_nocheck;
 
 int acpi_wakeup_device_init(void);
index 29ef505c487b92efe1b12e79c2231aa85c0298ce..ef8e659771e107eacf9068563f060957bf6b4614 100644 (file)
@@ -901,10 +901,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
        device->power.states[ACPI_STATE_D3].flags.valid = 1;
        device->power.states[ACPI_STATE_D3].power = 0;
 
-       /* TBD: System wake support and resource requirements. */
-
-       device->power.state = ACPI_STATE_UNKNOWN;
-       acpi_bus_get_power(device->handle, &(device->power.state));
+       acpi_bus_init_power(device);
 
        return 0;
 }