Commit a51e145f authored by Zhao Yakui's avatar Zhao Yakui Committed by Len Brown

ACPI: Get the device power state in the course of scanning device

Get the device power state in the course of scanning device if the device
power flag is power_managable. i.e. The device has the _PSx/_PRx object.

At the same time before the drivers/acpi/power module is loaded, there is no
relation between acpi_power_resource and acpi device. So the first parameter
of acpi_power_get_state is changed to acpi_handle.

http://bugzilla.kernel.org/show_bug.cgi?id=8049
http://bugzilla.kernel.org/show_bug.cgi?id=11000Signed-off-by: default avatarZhao Yakui <yakui.zhao@intel.com>
Signed-off-by: default avatarLi Shaohua <shaohua.li@intel.com>
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 08237974
...@@ -128,16 +128,16 @@ acpi_power_get_context(acpi_handle handle, ...@@ -128,16 +128,16 @@ acpi_power_get_context(acpi_handle handle,
return 0; return 0;
} }
static int acpi_power_get_state(struct acpi_power_resource *resource, int *state) static int acpi_power_get_state(acpi_handle handle, int *state)
{ {
acpi_status status = AE_OK; acpi_status status = AE_OK;
unsigned long sta = 0; unsigned long sta = 0;
if (!resource || !state) if (!handle || !state)
return -EINVAL; return -EINVAL;
status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta); status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENODEV; return -ENODEV;
...@@ -145,7 +145,7 @@ static int acpi_power_get_state(struct acpi_power_resource *resource, int *state ...@@ -145,7 +145,7 @@ static int acpi_power_get_state(struct acpi_power_resource *resource, int *state
ACPI_POWER_RESOURCE_STATE_OFF; ACPI_POWER_RESOURCE_STATE_OFF;
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n", ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n",
resource->name, state ? "on" : "off")); acpi_ut_get_node_name(handle), state ? "on" : "off"));
return 0; return 0;
} }
...@@ -153,7 +153,6 @@ static int acpi_power_get_state(struct acpi_power_resource *resource, int *state ...@@ -153,7 +153,6 @@ static int acpi_power_get_state(struct acpi_power_resource *resource, int *state
static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
{ {
int result = 0, state1; int result = 0, state1;
struct acpi_power_resource *resource = NULL;
u32 i = 0; u32 i = 0;
...@@ -161,12 +160,15 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) ...@@ -161,12 +160,15 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
return -EINVAL; return -EINVAL;
/* The state of the list is 'on' IFF all resources are 'on'. */ /* The state of the list is 'on' IFF all resources are 'on'. */
/* */
for (i = 0; i < list->count; i++) { for (i = 0; i < list->count; i++) {
result = acpi_power_get_context(list->handles[i], &resource); /*
if (result) * The state of the power resource can be obtained by
return result; * using the ACPI handle. In such case it is unnecessary to
result = acpi_power_get_state(resource, &state1); * get the Power resource first and then get its state again.
*/
result = acpi_power_get_state(list->handles[i], &state1);
if (result) if (result)
return result; return result;
...@@ -226,7 +228,7 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev) ...@@ -226,7 +228,7 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENODEV; return -ENODEV;
result = acpi_power_get_state(resource, &state); result = acpi_power_get_state(resource->device->handle, &state);
if (result) if (result)
return result; return result;
if (state != ACPI_POWER_RESOURCE_STATE_ON) if (state != ACPI_POWER_RESOURCE_STATE_ON)
...@@ -277,7 +279,7 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev) ...@@ -277,7 +279,7 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
return -ENODEV; return -ENODEV;
result = acpi_power_get_state(resource, &state); result = acpi_power_get_state(handle, &state);
if (result) if (result)
return result; return result;
if (state != ACPI_POWER_RESOURCE_STATE_OFF) if (state != ACPI_POWER_RESOURCE_STATE_OFF)
...@@ -555,7 +557,7 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset) ...@@ -555,7 +557,7 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
if (!resource) if (!resource)
goto end; goto end;
result = acpi_power_get_state(resource, &state); result = acpi_power_get_state(resource->device->handle, &state);
if (result) if (result)
goto end; goto end;
...@@ -668,7 +670,7 @@ static int acpi_power_add(struct acpi_device *device) ...@@ -668,7 +670,7 @@ static int acpi_power_add(struct acpi_device *device)
resource->system_level = acpi_object.power_resource.system_level; resource->system_level = acpi_object.power_resource.system_level;
resource->order = acpi_object.power_resource.resource_order; resource->order = acpi_object.power_resource.resource_order;
result = acpi_power_get_state(resource, &state); result = acpi_power_get_state(device->handle, &state);
if (result) if (result)
goto end; goto end;
...@@ -735,7 +737,7 @@ static int acpi_power_resume(struct acpi_device *device) ...@@ -735,7 +737,7 @@ static int acpi_power_resume(struct acpi_device *device)
resource = (struct acpi_power_resource *)acpi_driver_data(device); resource = (struct acpi_power_resource *)acpi_driver_data(device);
result = acpi_power_get_state(resource, &state); result = acpi_power_get_state(device->handle, &state);
if (result) if (result)
return result; return result;
......
...@@ -807,6 +807,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device) ...@@ -807,6 +807,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
/* TBD: System wake support and resource requirements. */ /* TBD: System wake support and resource requirements. */
device->power.state = ACPI_STATE_UNKNOWN; device->power.state = ACPI_STATE_UNKNOWN;
acpi_bus_get_power(device->handle, &(device->power.state));
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment