diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2010-09-25 17:35:21 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2010-10-16 19:57:48 -0400 |
commit | 15bcb91d7e607d8a2e060f01f7784a7454668da4 (patch) | |
tree | 6d59964cb78ab4b7c93a3c4d06f0dad256b99140 /drivers/base/power/sysfs.c | |
parent | 7490e44239e60293bca0c2663229050c36c660c2 (diff) |
PM / Runtime: Implement autosuspend support
This patch (as1427) implements the "autosuspend" facility for runtime
PM. A few new fields are added to the dev_pm_info structure and
several new PM helper functions are defined, for telling the PM core
whether or not a device uses autosuspend, for setting the autosuspend
delay, and for marking periods of device activity.
Drivers that do not want to use autosuspend can continue using the
same helper functions as before; their behavior will not change. In
addition, drivers supporting autosuspend can also call the old helper
functions to get the old behavior.
The details are all explained in Documentation/power/runtime_pm.txt
and Documentation/ABI/testing/sysfs-devices-power.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'drivers/base/power/sysfs.c')
-rw-r--r-- | drivers/base/power/sysfs.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index b5708c47ce2d..0b1e46bf3e56 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -75,6 +75,18 @@ | |||
75 | * attribute is set to "enabled" by bus type code or device drivers and in | 75 | * attribute is set to "enabled" by bus type code or device drivers and in |
76 | * that cases it should be safe to leave the default value. | 76 | * that cases it should be safe to leave the default value. |
77 | * | 77 | * |
78 | * autosuspend_delay_ms - Report/change a device's autosuspend_delay value | ||
79 | * | ||
80 | * Some drivers don't want to carry out a runtime suspend as soon as a | ||
81 | * device becomes idle; they want it always to remain idle for some period | ||
82 | * of time before suspending it. This period is the autosuspend_delay | ||
83 | * value (expressed in milliseconds) and it can be controlled by the user. | ||
84 | * If the value is negative then the device will never be runtime | ||
85 | * suspended. | ||
86 | * | ||
87 | * NOTE: The autosuspend_delay_ms attribute and the autosuspend_delay | ||
88 | * value are used only if the driver calls pm_runtime_use_autosuspend(). | ||
89 | * | ||
78 | * wakeup_count - Report the number of wakeup events related to the device | 90 | * wakeup_count - Report the number of wakeup events related to the device |
79 | */ | 91 | */ |
80 | 92 | ||
@@ -173,6 +185,33 @@ static ssize_t rtpm_status_show(struct device *dev, | |||
173 | } | 185 | } |
174 | 186 | ||
175 | static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL); | 187 | static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL); |
188 | |||
189 | static ssize_t autosuspend_delay_ms_show(struct device *dev, | ||
190 | struct device_attribute *attr, char *buf) | ||
191 | { | ||
192 | if (!dev->power.use_autosuspend) | ||
193 | return -EIO; | ||
194 | return sprintf(buf, "%d\n", dev->power.autosuspend_delay); | ||
195 | } | ||
196 | |||
197 | static ssize_t autosuspend_delay_ms_store(struct device *dev, | ||
198 | struct device_attribute *attr, const char *buf, size_t n) | ||
199 | { | ||
200 | long delay; | ||
201 | |||
202 | if (!dev->power.use_autosuspend) | ||
203 | return -EIO; | ||
204 | |||
205 | if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay) | ||
206 | return -EINVAL; | ||
207 | |||
208 | pm_runtime_set_autosuspend_delay(dev, delay); | ||
209 | return n; | ||
210 | } | ||
211 | |||
212 | static DEVICE_ATTR(autosuspend_delay_ms, 0644, autosuspend_delay_ms_show, | ||
213 | autosuspend_delay_ms_store); | ||
214 | |||
176 | #endif | 215 | #endif |
177 | 216 | ||
178 | static ssize_t | 217 | static ssize_t |
@@ -428,6 +467,7 @@ static struct attribute *runtime_attrs[] = { | |||
428 | &dev_attr_control.attr, | 467 | &dev_attr_control.attr, |
429 | &dev_attr_runtime_suspended_time.attr, | 468 | &dev_attr_runtime_suspended_time.attr, |
430 | &dev_attr_runtime_active_time.attr, | 469 | &dev_attr_runtime_active_time.attr, |
470 | &dev_attr_autosuspend_delay_ms.attr, | ||
431 | NULL, | 471 | NULL, |
432 | }; | 472 | }; |
433 | static struct attribute_group pm_runtime_attr_group = { | 473 | static struct attribute_group pm_runtime_attr_group = { |