aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/power.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/power.c')
-rw-r--r--drivers/acpi/power.c104
1 files changed, 4 insertions, 100 deletions
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 0dbe5cdf3396..c2ad391d8041 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -59,16 +59,9 @@ ACPI_MODULE_NAME("power");
59#define ACPI_POWER_RESOURCE_STATE_ON 0x01 59#define ACPI_POWER_RESOURCE_STATE_ON 0x01
60#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF 60#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
61 61
62struct acpi_power_dependent_device {
63 struct list_head node;
64 struct acpi_device *adev;
65 struct work_struct work;
66};
67
68struct acpi_power_resource { 62struct acpi_power_resource {
69 struct acpi_device device; 63 struct acpi_device device;
70 struct list_head list_node; 64 struct list_head list_node;
71 struct list_head dependent;
72 char *name; 65 char *name;
73 u32 system_level; 66 u32 system_level;
74 u32 order; 67 u32 order;
@@ -233,32 +226,6 @@ static int acpi_power_get_list_state(struct list_head *list, int *state)
233 return 0; 226 return 0;
234} 227}
235 228
236static void acpi_power_resume_dependent(struct work_struct *work)
237{
238 struct acpi_power_dependent_device *dep;
239 struct acpi_device_physical_node *pn;
240 struct acpi_device *adev;
241 int state;
242
243 dep = container_of(work, struct acpi_power_dependent_device, work);
244 adev = dep->adev;
245 if (acpi_power_get_inferred_state(adev, &state))
246 return;
247
248 if (state > ACPI_STATE_D0)
249 return;
250
251 mutex_lock(&adev->physical_node_lock);
252
253 list_for_each_entry(pn, &adev->physical_node_list, node)
254 pm_request_resume(pn->dev);
255
256 list_for_each_entry(pn, &adev->power_dependent, node)
257 pm_request_resume(pn->dev);
258
259 mutex_unlock(&adev->physical_node_lock);
260}
261
262static int __acpi_power_on(struct acpi_power_resource *resource) 229static int __acpi_power_on(struct acpi_power_resource *resource)
263{ 230{
264 acpi_status status = AE_OK; 231 acpi_status status = AE_OK;
@@ -283,14 +250,8 @@ static int acpi_power_on_unlocked(struct acpi_power_resource *resource)
283 resource->name)); 250 resource->name));
284 } else { 251 } else {
285 result = __acpi_power_on(resource); 252 result = __acpi_power_on(resource);
286 if (result) { 253 if (result)
287 resource->ref_count--; 254 resource->ref_count--;
288 } else {
289 struct acpi_power_dependent_device *dep;
290
291 list_for_each_entry(dep, &resource->dependent, node)
292 schedule_work(&dep->work);
293 }
294 } 255 }
295 return result; 256 return result;
296} 257}
@@ -390,52 +351,6 @@ static int acpi_power_on_list(struct list_head *list)
390 return result; 351 return result;
391} 352}
392 353
393static void acpi_power_add_dependent(struct acpi_power_resource *resource,
394 struct acpi_device *adev)
395{
396 struct acpi_power_dependent_device *dep;
397
398 mutex_lock(&resource->resource_lock);
399
400 list_for_each_entry(dep, &resource->dependent, node)
401 if (dep->adev == adev)
402 goto out;
403
404 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
405 if (!dep)
406 goto out;
407
408 dep->adev = adev;
409 INIT_WORK(&dep->work, acpi_power_resume_dependent);
410 list_add_tail(&dep->node, &resource->dependent);
411
412 out:
413 mutex_unlock(&resource->resource_lock);
414}
415
416static void acpi_power_remove_dependent(struct acpi_power_resource *resource,
417 struct acpi_device *adev)
418{
419 struct acpi_power_dependent_device *dep;
420 struct work_struct *work = NULL;
421
422 mutex_lock(&resource->resource_lock);
423
424 list_for_each_entry(dep, &resource->dependent, node)
425 if (dep->adev == adev) {
426 list_del(&dep->node);
427 work = &dep->work;
428 break;
429 }
430
431 mutex_unlock(&resource->resource_lock);
432
433 if (work) {
434 cancel_work_sync(work);
435 kfree(dep);
436 }
437}
438
439static struct attribute *attrs[] = { 354static struct attribute *attrs[] = {
440 NULL, 355 NULL,
441}; 356};
@@ -524,8 +439,6 @@ static void acpi_power_expose_hide(struct acpi_device *adev,
524 439
525void acpi_power_add_remove_device(struct acpi_device *adev, bool add) 440void acpi_power_add_remove_device(struct acpi_device *adev, bool add)
526{ 441{
527 struct acpi_device_power_state *ps;
528 struct acpi_power_resource_entry *entry;
529 int state; 442 int state;
530 443
531 if (adev->wakeup.flags.valid) 444 if (adev->wakeup.flags.valid)
@@ -535,16 +448,6 @@ void acpi_power_add_remove_device(struct acpi_device *adev, bool add)
535 if (!adev->power.flags.power_resources) 448 if (!adev->power.flags.power_resources)
536 return; 449 return;
537 450
538 ps = &adev->power.states[ACPI_STATE_D0];
539 list_for_each_entry(entry, &ps->resources, node) {
540 struct acpi_power_resource *resource = entry->resource;
541
542 if (add)
543 acpi_power_add_dependent(resource, adev);
544 else
545 acpi_power_remove_dependent(resource, adev);
546 }
547
548 for (state = ACPI_STATE_D0; state <= ACPI_STATE_D3_HOT; state++) 451 for (state = ACPI_STATE_D0; state <= ACPI_STATE_D3_HOT; state++)
549 acpi_power_expose_hide(adev, 452 acpi_power_expose_hide(adev,
550 &adev->power.states[state].resources, 453 &adev->power.states[state].resources,
@@ -882,7 +785,6 @@ int acpi_add_power_resource(acpi_handle handle)
882 acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER, 785 acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER,
883 ACPI_STA_DEFAULT); 786 ACPI_STA_DEFAULT);
884 mutex_init(&resource->resource_lock); 787 mutex_init(&resource->resource_lock);
885 INIT_LIST_HEAD(&resource->dependent);
886 INIT_LIST_HEAD(&resource->list_node); 788 INIT_LIST_HEAD(&resource->list_node);
887 resource->name = device->pnp.bus_id; 789 resource->name = device->pnp.bus_id;
888 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 790 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
@@ -936,8 +838,10 @@ void acpi_resume_power_resources(void)
936 mutex_lock(&resource->resource_lock); 838 mutex_lock(&resource->resource_lock);
937 839
938 result = acpi_power_get_state(resource->device.handle, &state); 840 result = acpi_power_get_state(resource->device.handle, &state);
939 if (result) 841 if (result) {
842 mutex_unlock(&resource->resource_lock);
940 continue; 843 continue;
844 }
941 845
942 if (state == ACPI_POWER_RESOURCE_STATE_OFF 846 if (state == ACPI_POWER_RESOURCE_STATE_OFF
943 && resource->ref_count) { 847 && resource->ref_count) {