diff options
-rw-r--r-- | drivers/acpi/bus.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index a9fe8e6bc40e..9657abc4a7fb 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
@@ -196,34 +196,24 @@ EXPORT_SYMBOL(acpi_bus_get_private_data); | |||
196 | Power Management | 196 | Power Management |
197 | -------------------------------------------------------------------------- */ | 197 | -------------------------------------------------------------------------- */ |
198 | 198 | ||
199 | int acpi_bus_get_power(acpi_handle handle, int *state) | 199 | static int __acpi_bus_get_power(struct acpi_device *device, int *state) |
200 | { | 200 | { |
201 | int result = 0; | 201 | int result = 0; |
202 | acpi_status status = 0; | 202 | acpi_status status = 0; |
203 | struct acpi_device *device = NULL; | ||
204 | unsigned long long psc = 0; | 203 | unsigned long long psc = 0; |
205 | 204 | ||
206 | 205 | if (!device || !state) | |
207 | result = acpi_bus_get_device(handle, &device); | 206 | return -EINVAL; |
208 | if (result) | ||
209 | return result; | ||
210 | 207 | ||
211 | *state = ACPI_STATE_UNKNOWN; | 208 | *state = ACPI_STATE_UNKNOWN; |
212 | 209 | ||
213 | if (!device->flags.power_manageable) { | 210 | if (device->flags.power_manageable) { |
214 | /* TBD: Non-recursive algorithm for walking up hierarchy */ | ||
215 | if (device->parent) | ||
216 | *state = device->parent->power.state; | ||
217 | else | ||
218 | *state = ACPI_STATE_D0; | ||
219 | } else { | ||
220 | /* | 211 | /* |
221 | * Get the device's power state either directly (via _PSC) or | 212 | * Get the device's power state either directly (via _PSC) or |
222 | * indirectly (via power resources). | 213 | * indirectly (via power resources). |
223 | */ | 214 | */ |
224 | if (device->power.flags.power_resources) { | 215 | if (device->power.flags.power_resources) { |
225 | result = acpi_power_get_inferred_state(device, | 216 | result = acpi_power_get_inferred_state(device, state); |
226 | &device->power.state); | ||
227 | if (result) | 217 | if (result) |
228 | return result; | 218 | return result; |
229 | } else if (device->power.flags.explicit_get) { | 219 | } else if (device->power.flags.explicit_get) { |
@@ -231,20 +221,40 @@ int acpi_bus_get_power(acpi_handle handle, int *state) | |||
231 | NULL, &psc); | 221 | NULL, &psc); |
232 | if (ACPI_FAILURE(status)) | 222 | if (ACPI_FAILURE(status)) |
233 | return -ENODEV; | 223 | return -ENODEV; |
234 | device->power.state = (int)psc; | 224 | *state = (int)psc; |
235 | } | 225 | } |
236 | 226 | } else { | |
237 | *state = device->power.state; | 227 | /* TBD: Non-recursive algorithm for walking up hierarchy. */ |
228 | *state = device->parent ? | ||
229 | device->parent->power.state : ACPI_STATE_D0; | ||
238 | } | 230 | } |
239 | 231 | ||
240 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", | 232 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n", |
241 | device->pnp.bus_id, device->power.state)); | 233 | device->pnp.bus_id, *state)); |
242 | 234 | ||
243 | return 0; | 235 | return 0; |
244 | } | 236 | } |
245 | 237 | ||
238 | |||
239 | int acpi_bus_get_power(acpi_handle handle, int *state) | ||
240 | { | ||
241 | struct acpi_device *device; | ||
242 | int result; | ||
243 | |||
244 | result = acpi_bus_get_device(handle, &device); | ||
245 | if (result) | ||
246 | return result; | ||
247 | |||
248 | result = __acpi_bus_get_power(device, state); | ||
249 | if (result) | ||
250 | return result; | ||
251 | |||
252 | device->power.state = *state; | ||
253 | return 0; | ||
254 | } | ||
246 | EXPORT_SYMBOL(acpi_bus_get_power); | 255 | EXPORT_SYMBOL(acpi_bus_get_power); |
247 | 256 | ||
257 | |||
248 | int acpi_bus_set_power(acpi_handle handle, int state) | 258 | int acpi_bus_set_power(acpi_handle handle, int state) |
249 | { | 259 | { |
250 | int result = 0; | 260 | int result = 0; |