Commit cad2b8ef authored by Patrick Mochel's avatar Patrick Mochel

[power] Begin to add sysfs files for controlling device power states.

- Moves sysfs controls to drivers/base/power/sysfs.c
- Creates dpm_sysfs_{add,remove} to add/remove sysfs attribute group.
- Creates 'state' file in 'pm' directory that properly controls device
  power state at runtime.
parent 92807f31
obj-y := shutdown.o obj-y := shutdown.o
obj-$(CONFIG_PM) += main.o suspend.o resume.o runtime.o obj-$(CONFIG_PM) += main.o suspend.o resume.o runtime.o sysfs.o
...@@ -31,15 +31,6 @@ LIST_HEAD(dpm_off_irq); ...@@ -31,15 +31,6 @@ LIST_HEAD(dpm_off_irq);
DECLARE_MUTEX(dpm_sem); DECLARE_MUTEX(dpm_sem);
static struct attribute power_attrs[] = {
{ .name = NULL },
};
static struct attribute_group pm_attr_group = {
.name = "pm",
.attrs = power_attrs,
};
/* /*
* PM Reference Counting. * PM Reference Counting.
*/ */
...@@ -88,7 +79,8 @@ int device_pm_add(struct device * dev) ...@@ -88,7 +79,8 @@ int device_pm_add(struct device * dev)
down(&dpm_sem); down(&dpm_sem);
list_add_tail(&dev->power.entry,&dpm_active); list_add_tail(&dev->power.entry,&dpm_active);
device_pm_set_parent(dev,dev->parent); device_pm_set_parent(dev,dev->parent);
error = sysfs_create_group(&dev->kobj,&pm_attr_group); if ((error = dpm_sysfs_add(dev)))
list_del(&dev->power.entry);
up(&dpm_sem); up(&dpm_sem);
return error; return error;
} }
...@@ -98,7 +90,7 @@ void device_pm_remove(struct device * dev) ...@@ -98,7 +90,7 @@ void device_pm_remove(struct device * dev)
pr_debug("PM: Removing info for %s:%s\n", pr_debug("PM: Removing info for %s:%s\n",
dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); dev->bus ? dev->bus->name : "No Bus", dev->kobj.name);
down(&dpm_sem); down(&dpm_sem);
sysfs_remove_group(&dev->kobj,&pm_attr_group); dpm_sysfs_remove(dev);
list_del(&dev->power.entry); list_del(&dev->power.entry);
up(&dpm_sem); up(&dpm_sem);
} }
......
/*
* drivers/base/power/sysfs.c - sysfs entries for device PM
*/
#include <linux/device.h>
#include "power.h"
static ssize_t state_show(struct device * dev, char * buf)
{
return sprintf(buf,"%u\n",dev->power.power_state);
}
static ssize_t state_store(struct device * dev, const char * buf, size_t n)
{
u32 state;
char * rest;
int error = 0;
state = simple_strtoul(buf,&rest,10);
if (rest)
return -EINVAL;
if (state)
error = dpm_runtime_suspend(dev,state);
else
dpm_runtime_resume(dev);
return error ? error : n;
}
DEVICE_ATTR(state,0644,state_show,state_store);
static struct attribute * power_attrs[] = {
&dev_attr_state.attr,
NULL,
};
static struct attribute_group pm_attr_group = {
.name = "pm",
.attrs = power_attrs,
};
int dpm_sysfs_add(struct device * dev)
{
return sysfs_create_group(&dev->kobj,&pm_attr_group);
}
void dpm_sysfs_remove(struct device * dev)
{
sysfs_remove_group(&dev->kobj,&pm_attr_group);
}
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