Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 298063
b: refs/heads/master
c: 0090def
h: refs/heads/master
i:
  298061: e064262
  298059: 2502075
  298055: d8ef406
  298047: 1093d32
v: v3
  • Loading branch information
Lin Ming authored and Len Brown committed Mar 30, 2012
1 parent 0ac5225 commit d36b6bb
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3ebc81b8937d2bc1d0d0064bed29434dfce490aa
refs/heads/master: 0090def6c37c8ea29508a435e581f2ef26fea10f
162 changes: 162 additions & 0 deletions trunk/drivers/acpi/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
#include <linux/init.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/pm_runtime.h>
#include <acpi/acpi_bus.h>
#include <acpi/acpi_drivers.h>
#include "sleep.h"
#include "internal.h"

#define PREFIX "ACPI: "

Expand Down Expand Up @@ -77,13 +79,30 @@ static struct acpi_driver acpi_power_driver = {
},
};

/*
* A power managed device
* A device may rely on multiple power resources.
* */
struct acpi_power_managed_device {
struct device *dev; /* The physical device */
acpi_handle *handle;
};

struct acpi_power_resource_device {
struct acpi_power_managed_device *device;
struct acpi_power_resource_device *next;
};

struct acpi_power_resource {
struct acpi_device * device;
acpi_bus_id name;
u32 system_level;
u32 order;
unsigned int ref_count;
struct mutex resource_lock;

/* List of devices relying on this power resource */
struct acpi_power_resource_device *devices;
};

static struct list_head acpi_power_resource_list;
Expand Down Expand Up @@ -183,8 +202,26 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
return 0;
}

/* Resume the device when all power resources in _PR0 are on */
static void acpi_power_on_device(struct acpi_power_managed_device *device)
{
struct acpi_device *acpi_dev;
acpi_handle handle = device->handle;
int state;

if (acpi_bus_get_device(handle, &acpi_dev))
return;

if(acpi_power_get_inferred_state(acpi_dev, &state))
return;

if (state == ACPI_STATE_D0 && pm_runtime_suspended(device->dev))
pm_request_resume(device->dev);
}

static int __acpi_power_on(struct acpi_power_resource *resource)
{
struct acpi_power_resource_device *device_list = resource->devices;
acpi_status status = AE_OK;

status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
Expand All @@ -197,6 +234,12 @@ static int __acpi_power_on(struct acpi_power_resource *resource)
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Power resource [%s] turned on\n",
resource->name));

while (device_list) {
acpi_power_on_device(device_list->device);

device_list = device_list->next;
}

return 0;
}

Expand Down Expand Up @@ -299,6 +342,125 @@ static int acpi_power_on_list(struct acpi_handle_list *list)
return result;
}

static void __acpi_power_resource_unregister_device(struct device *dev,
acpi_handle res_handle)
{
struct acpi_power_resource *resource = NULL;
struct acpi_power_resource_device *prev, *curr;

if (acpi_power_get_context(res_handle, &resource))
return;

mutex_lock(&resource->resource_lock);
prev = NULL;
curr = resource->devices;
while (curr) {
if (curr->device->dev == dev) {
if (!prev)
resource->devices = curr->next;
else
prev->next = curr->next;

kfree(curr);
break;
}

prev = curr;
curr = curr->next;
}
mutex_unlock(&resource->resource_lock);
}

/* Unlink dev from all power resources in _PR0 */
void acpi_power_resource_unregister_device(struct device *dev, acpi_handle handle)
{
struct acpi_device *acpi_dev;
struct acpi_handle_list *list;
int i;

if (!dev || !handle)
return;

if (acpi_bus_get_device(handle, &acpi_dev))
return;

list = &acpi_dev->power.states[ACPI_STATE_D0].resources;

for (i = 0; i < list->count; i++)
__acpi_power_resource_unregister_device(dev,
list->handles[i]);
}

static int __acpi_power_resource_register_device(
struct acpi_power_managed_device *powered_device, acpi_handle handle)
{
struct acpi_power_resource *resource = NULL;
struct acpi_power_resource_device *power_resource_device;
int result;

result = acpi_power_get_context(handle, &resource);
if (result)
return result;

power_resource_device = kzalloc(
sizeof(*power_resource_device), GFP_KERNEL);
if (!power_resource_device)
return -ENOMEM;

power_resource_device->device = powered_device;

mutex_lock(&resource->resource_lock);
power_resource_device->next = resource->devices;
resource->devices = power_resource_device;
mutex_unlock(&resource->resource_lock);

return 0;
}

/* Link dev to all power resources in _PR0 */
int acpi_power_resource_register_device(struct device *dev, acpi_handle handle)
{
struct acpi_device *acpi_dev;
struct acpi_handle_list *list;
struct acpi_power_managed_device *powered_device;
int i, ret;

if (!dev || !handle)
return -ENODEV;

ret = acpi_bus_get_device(handle, &acpi_dev);
if (ret)
goto no_power_resource;

if (!acpi_dev->power.flags.power_resources)
goto no_power_resource;

powered_device = kzalloc(sizeof(*powered_device), GFP_KERNEL);
if (!powered_device)
return -ENOMEM;

powered_device->dev = dev;
powered_device->handle = handle;

list = &acpi_dev->power.states[ACPI_STATE_D0].resources;

for (i = 0; i < list->count; i++) {
ret = __acpi_power_resource_register_device(powered_device,
list->handles[i]);

if (ret) {
acpi_power_resource_unregister_device(dev, handle);
break;
}
}

return ret;

no_power_resource:
printk(KERN_WARNING PREFIX "Invalid Power Resource to register!");
return -ENODEV;
}

/**
* acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in
* ACPI 3.0) _PSW (Power State Wake)
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/acpi/acpi_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ int acpi_bus_set_power(acpi_handle handle, int state);
int acpi_bus_update_power(acpi_handle handle, int *state_p);
bool acpi_bus_power_manageable(acpi_handle handle);
bool acpi_bus_can_wakeup(acpi_handle handle);
int acpi_power_resource_register_device(struct device *dev, acpi_handle handle);
void acpi_power_resource_unregister_device(struct device *dev, acpi_handle handle);
#ifdef CONFIG_ACPI_PROC_EVENT
int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data);
int acpi_bus_generate_proc_event4(const char *class, const char *bid, u8 type, int data);
Expand Down

0 comments on commit d36b6bb

Please sign in to comment.