|
@@ -202,37 +202,44 @@ static const char *state_string(int state)
|
|
|
|
|
|
static int __acpi_bus_get_power(struct acpi_device *device, int *state)
|
|
static int __acpi_bus_get_power(struct acpi_device *device, int *state)
|
|
{
|
|
{
|
|
- int result = 0;
|
|
|
|
- acpi_status status = 0;
|
|
|
|
- unsigned long long psc = 0;
|
|
|
|
|
|
+ int result = ACPI_STATE_UNKNOWN;
|
|
|
|
|
|
if (!device || !state)
|
|
if (!device || !state)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- *state = ACPI_STATE_UNKNOWN;
|
|
|
|
-
|
|
|
|
- if (device->flags.power_manageable) {
|
|
|
|
- /*
|
|
|
|
- * Get the device's power state either directly (via _PSC) or
|
|
|
|
- * indirectly (via power resources).
|
|
|
|
- */
|
|
|
|
- if (device->power.flags.power_resources) {
|
|
|
|
- result = acpi_power_get_inferred_state(device, state);
|
|
|
|
- if (result)
|
|
|
|
- return result;
|
|
|
|
- } else if (device->power.flags.explicit_get) {
|
|
|
|
- status = acpi_evaluate_integer(device->handle, "_PSC",
|
|
|
|
- NULL, &psc);
|
|
|
|
- if (ACPI_FAILURE(status))
|
|
|
|
- return -ENODEV;
|
|
|
|
- *state = (int)psc;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
|
|
+ if (!device->flags.power_manageable) {
|
|
/* TBD: Non-recursive algorithm for walking up hierarchy. */
|
|
/* TBD: Non-recursive algorithm for walking up hierarchy. */
|
|
*state = device->parent ?
|
|
*state = device->parent ?
|
|
device->parent->power.state : ACPI_STATE_D0;
|
|
device->parent->power.state : ACPI_STATE_D0;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Get the device's power state either directly (via _PSC) or
|
|
|
|
+ * indirectly (via power resources).
|
|
|
|
+ */
|
|
|
|
+ if (device->power.flags.explicit_get) {
|
|
|
|
+ unsigned long long psc;
|
|
|
|
+ acpi_status status = acpi_evaluate_integer(device->handle,
|
|
|
|
+ "_PSC", NULL, &psc);
|
|
|
|
+ if (ACPI_FAILURE(status))
|
|
|
|
+ return -ENODEV;
|
|
|
|
+
|
|
|
|
+ result = psc;
|
|
|
|
+ }
|
|
|
|
+ /* The test below covers ACPI_STATE_UNKNOWN too. */
|
|
|
|
+ if (result <= ACPI_STATE_D2) {
|
|
|
|
+ ; /* Do nothing. */
|
|
|
|
+ } else if (device->power.flags.power_resources) {
|
|
|
|
+ int error = acpi_power_get_inferred_state(device, &result);
|
|
|
|
+ if (error)
|
|
|
|
+ return error;
|
|
|
|
+ } else if (result == ACPI_STATE_D3_HOT) {
|
|
|
|
+ result = ACPI_STATE_D3;
|
|
}
|
|
}
|
|
|
|
+ *state = result;
|
|
|
|
|
|
|
|
+ out:
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n",
|
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n",
|
|
device->pnp.bus_id, state_string(*state)));
|
|
device->pnp.bus_id, state_string(*state)));
|
|
|
|
|