aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/sysfs.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2010-11-15 15:57:51 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-11-16 17:03:41 -0500
commitfcc4a01eb8661226e80632327673f67bf6a5840b (patch)
treedc05c200ccfac2daad6d1efe413ae6fa92f1638d /drivers/usb/core/sysfs.c
parent6ddf27cdbc218a412d7e993fdc08e30eec2042ce (diff)
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 9561e087907d..6781c369ce2d 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);
334static ssize_t 334static ssize_t
335show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) 335show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf)
336{ 336{
337 struct usb_device *udev = to_usb_device(dev); 337 return sprintf(buf, "%d\n", dev->power.autosuspend_delay / 1000);
338
339 return sprintf(buf, "%d\n", udev->autosuspend_delay / HZ);
340} 338}
341 339
342static ssize_t 340static ssize_t
343set_autosuspend(struct device *dev, struct device_attribute *attr, 341set_autosuspend(struct device *dev, struct device_attribute *attr,
344 const char *buf, size_t count) 342 const char *buf, size_t count)
345{ 343{
346 struct usb_device *udev = to_usb_device(dev); 344 int value;
347 int value, old_delay;
348 int rc;
349 345
350 if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ || 346 if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/1000 ||
351 value <= - INT_MAX/HZ) 347 value <= -INT_MAX/1000)
352 return -EINVAL; 348 return -EINVAL;
353 value *= HZ;
354
355 usb_lock_device(udev);
356 old_delay = udev->autosuspend_delay;
357 udev->autosuspend_delay = value;
358
359 if (old_delay < 0) { /* Autosuspend wasn't allowed */
360 if (value >= 0)
361 usb_autosuspend_device(udev);
362 } else { /* Autosuspend was allowed */
363 if (value < 0) {
364 rc = usb_autoresume_device(udev);
365 if (rc < 0) {
366 count = rc;
367 udev->autosuspend_delay = old_delay;
368 }
369 } else {
370 usb_try_autosuspend_device(udev);
371 }
372 }
373 349
374 usb_unlock_device(udev); 350 pm_runtime_set_autosuspend_delay(dev, value * 1000);
375 return count; 351 return count;
376} 352}
377 353