summaryrefslogtreecommitdiff
path: root/drivers/usb/core/sysfs.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2010-11-15 20:57:51 (GMT)
committerGreg Kroah-Hartman <gregkh@suse.de>2010-11-16 22:03:41 (GMT)
commitfcc4a01eb8661226e80632327673f67bf6a5840b (patch)
treedc05c200ccfac2daad6d1efe413ae6fa92f1638d /drivers/usb/core/sysfs.c
parent6ddf27cdbc218a412d7e993fdc08e30eec2042ce (diff)
downloadlinux-fsl-qoriq-fcc4a01eb8661226e80632327673f67bf6a5840b.tar.xz
USB: use the runtime-PM autosuspend implementation
This patch (as1428) converts USB over to the new runtime-PM core autosuspend framework. One slightly awkward aspect of the conversion is that USB devices will now have two suspend-delay attributes: the old power/autosuspend file and the new power/autosuspend_delay_ms file. One expresses the delay time in seconds and the other in milliseconds, but otherwise they do the same thing. The old attribute can be deprecated and then removed eventually. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core/sysfs.c')
-rw-r--r--drivers/usb/core/sysfs.c34
1 files changed, 5 insertions, 29 deletions
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 9561e08..6781c36 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -334,44 +334,20 @@ static DEVICE_ATTR(active_duration, S_IRUGO, show_active_duration, NULL);
static ssize_t
show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
{
- struct usb_device *udev = to_usb_device(dev);
-
- return sprintf(buf, "%d\n", udev->autosuspend_delay / HZ);
+ return sprintf(buf, "%d\n", dev->power.autosuspend_delay / 1000);
}
static ssize_t
set_autosuspend(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
- struct usb_device *udev = to_usb_device(dev);
- int value, old_delay;
- int rc;
+ int value;
- if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ ||
- value <= - INT_MAX/HZ)
+ if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/1000 ||
+ value <= -INT_MAX/1000)
return -EINVAL;
- value *= HZ;
-
- usb_lock_device(udev);
- old_delay = udev->autosuspend_delay;
- udev->autosuspend_delay = value;
-
- if (old_delay < 0) { /* Autosuspend wasn't allowed */
- if (value >= 0)
- usb_autosuspend_device(udev);
- } else { /* Autosuspend was allowed */
- if (value < 0) {
- rc = usb_autoresume_device(udev);
- if (rc < 0) {
- count = rc;
- udev->autosuspend_delay = old_delay;
- }
- } else {
- usb_try_autosuspend_device(udev);
- }
- }
- usb_unlock_device(udev);
+ pm_runtime_set_autosuspend_delay(dev, value * 1000);
return count;
}