diff options
-rw-r--r-- | Documentation/usb/power-management.txt | 113 | ||||
-rw-r--r-- | drivers/usb/core/driver.c | 77 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 1 | ||||
-rw-r--r-- | drivers/usb/core/quirks.c | 6 | ||||
-rw-r--r-- | drivers/usb/core/sysfs.c | 34 | ||||
-rw-r--r-- | drivers/usb/core/usb.c | 3 | ||||
-rw-r--r-- | drivers/usb/core/usb.h | 2 | ||||
-rw-r--r-- | include/linux/usb.h | 2 |
8 files changed, 71 insertions, 167 deletions
diff --git a/Documentation/usb/power-management.txt b/Documentation/usb/power-management.txt index b29d8e56cf2..c9ffa9ced7e 100644 --- a/Documentation/usb/power-management.txt +++ b/Documentation/usb/power-management.txt | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | Alan Stern <stern@rowland.harvard.edu> | 3 | Alan Stern <stern@rowland.harvard.edu> |
4 | 4 | ||
5 | December 11, 2009 | 5 | October 28, 2010 |
6 | 6 | ||
7 | 7 | ||
8 | 8 | ||
@@ -107,9 +107,14 @@ allowed to issue dynamic suspends. | |||
107 | The user interface for controlling dynamic PM is located in the power/ | 107 | The user interface for controlling dynamic PM is located in the power/ |
108 | subdirectory of each USB device's sysfs directory, that is, in | 108 | subdirectory of each USB device's sysfs directory, that is, in |
109 | /sys/bus/usb/devices/.../power/ where "..." is the device's ID. The | 109 | /sys/bus/usb/devices/.../power/ where "..." is the device's ID. The |
110 | relevant attribute files are: wakeup, control, and autosuspend. | 110 | relevant attribute files are: wakeup, control, and |
111 | (There may also be a file named "level"; this file was deprecated | 111 | autosuspend_delay_ms. (There may also be a file named "level"; this |
112 | as of the 2.6.35 kernel and replaced by the "control" file.) | 112 | file was deprecated as of the 2.6.35 kernel and replaced by the |
113 | "control" file. In 2.6.38 the "autosuspend" file will be deprecated | ||
114 | and replaced by the "autosuspend_delay_ms" file. The only difference | ||
115 | is that the newer file expresses the delay in milliseconds whereas the | ||
116 | older file uses seconds. Confusingly, both files are present in 2.6.37 | ||
117 | but only "autosuspend" works.) | ||
113 | 118 | ||
114 | power/wakeup | 119 | power/wakeup |
115 | 120 | ||
@@ -140,33 +145,36 @@ as of the 2.6.35 kernel and replaced by the "control" file.) | |||
140 | suspended and autoresume was not allowed. This | 145 | suspended and autoresume was not allowed. This |
141 | setting is no longer supported.) | 146 | setting is no longer supported.) |
142 | 147 | ||
143 | power/autosuspend | 148 | power/autosuspend_delay_ms |
144 | 149 | ||
145 | This file contains an integer value, which is the | 150 | This file contains an integer value, which is the |
146 | number of seconds the device should remain idle before | 151 | number of milliseconds the device should remain idle |
147 | the kernel will autosuspend it (the idle-delay time). | 152 | before the kernel will autosuspend it (the idle-delay |
148 | The default is 2. 0 means to autosuspend as soon as | 153 | time). The default is 2000. 0 means to autosuspend |
149 | the device becomes idle, and negative values mean | 154 | as soon as the device becomes idle, and negative |
150 | never to autosuspend. You can write a number to the | 155 | values mean never to autosuspend. You can write a |
151 | file to change the autosuspend idle-delay time. | 156 | number to the file to change the autosuspend |
152 | 157 | idle-delay time. | |
153 | Writing "-1" to power/autosuspend and writing "on" to power/control do | 158 | |
154 | essentially the same thing -- they both prevent the device from being | 159 | Writing "-1" to power/autosuspend_delay_ms and writing "on" to |
155 | autosuspended. Yes, this is a redundancy in the API. | 160 | power/control do essentially the same thing -- they both prevent the |
161 | device from being autosuspended. Yes, this is a redundancy in the | ||
162 | API. | ||
156 | 163 | ||
157 | (In 2.6.21 writing "0" to power/autosuspend would prevent the device | 164 | (In 2.6.21 writing "0" to power/autosuspend would prevent the device |
158 | from being autosuspended; the behavior was changed in 2.6.22. The | 165 | from being autosuspended; the behavior was changed in 2.6.22. The |
159 | power/autosuspend attribute did not exist prior to 2.6.21, and the | 166 | power/autosuspend attribute did not exist prior to 2.6.21, and the |
160 | power/level attribute did not exist prior to 2.6.22. power/control | 167 | power/level attribute did not exist prior to 2.6.22. power/control |
161 | was added in 2.6.34.) | 168 | was added in 2.6.34, and power/autosuspend_delay_ms was added in |
169 | 2.6.37 but did not become functional until 2.6.38.) | ||
162 | 170 | ||
163 | 171 | ||
164 | Changing the default idle-delay time | 172 | Changing the default idle-delay time |
165 | ------------------------------------ | 173 | ------------------------------------ |
166 | 174 | ||
167 | The default autosuspend idle-delay time is controlled by a module | 175 | The default autosuspend idle-delay time (in seconds) is controlled by |
168 | parameter in usbcore. You can specify the value when usbcore is | 176 | a module parameter in usbcore. You can specify the value when usbcore |
169 | loaded. For example, to set it to 5 seconds instead of 2 you would | 177 | is loaded. For example, to set it to 5 seconds instead of 2 you would |
170 | do: | 178 | do: |
171 | 179 | ||
172 | modprobe usbcore autosuspend=5 | 180 | modprobe usbcore autosuspend=5 |
@@ -234,25 +242,23 @@ every device. | |||
234 | 242 | ||
235 | If a driver knows that its device has proper suspend/resume support, | 243 | If a driver knows that its device has proper suspend/resume support, |
236 | it can enable autosuspend all by itself. For example, the video | 244 | it can enable autosuspend all by itself. For example, the video |
237 | driver for a laptop's webcam might do this, since these devices are | 245 | driver for a laptop's webcam might do this (in recent kernels they |
238 | rarely used and so should normally be autosuspended. | 246 | do), since these devices are rarely used and so should normally be |
247 | autosuspended. | ||
239 | 248 | ||
240 | Sometimes it turns out that even when a device does work okay with | 249 | Sometimes it turns out that even when a device does work okay with |
241 | autosuspend there are still problems. For example, there are | 250 | autosuspend there are still problems. For example, the usbhid driver, |
242 | experimental patches adding autosuspend support to the usbhid driver, | 251 | which manages keyboards and mice, has autosuspend support. Tests with |
243 | which manages keyboards and mice, among other things. Tests with a | 252 | a number of keyboards show that typing on a suspended keyboard, while |
244 | number of keyboards showed that typing on a suspended keyboard, while | 253 | causing the keyboard to do a remote wakeup all right, will nonetheless |
245 | causing the keyboard to do a remote wakeup all right, would | 254 | frequently result in lost keystrokes. Tests with mice show that some |
246 | nonetheless frequently result in lost keystrokes. Tests with mice | 255 | of them will issue a remote-wakeup request in response to button |
247 | showed that some of them would issue a remote-wakeup request in | 256 | presses but not to motion, and some in response to neither. |
248 | response to button presses but not to motion, and some in response to | ||
249 | neither. | ||
250 | 257 | ||
251 | The kernel will not prevent you from enabling autosuspend on devices | 258 | The kernel will not prevent you from enabling autosuspend on devices |
252 | that can't handle it. It is even possible in theory to damage a | 259 | that can't handle it. It is even possible in theory to damage a |
253 | device by suspending it at the wrong time -- for example, suspending a | 260 | device by suspending it at the wrong time. (Highly unlikely, but |
254 | USB hard disk might cause it to spin down without parking the heads. | 261 | possible.) Take care. |
255 | (Highly unlikely, but possible.) Take care. | ||
256 | 262 | ||
257 | 263 | ||
258 | The driver interface for Power Management | 264 | The driver interface for Power Management |
@@ -336,10 +342,6 @@ autosuspend the interface's device. When the usage counter is = 0 | |||
336 | then the interface is considered to be idle, and the kernel may | 342 | then the interface is considered to be idle, and the kernel may |
337 | autosuspend the device. | 343 | autosuspend the device. |
338 | 344 | ||
339 | (There is a similar usage counter field in struct usb_device, | ||
340 | associated with the device itself rather than any of its interfaces. | ||
341 | This counter is used only by the USB core.) | ||
342 | |||
343 | Drivers need not be concerned about balancing changes to the usage | 345 | Drivers need not be concerned about balancing changes to the usage |
344 | counter; the USB core will undo any remaining "get"s when a driver | 346 | counter; the USB core will undo any remaining "get"s when a driver |
345 | is unbound from its interface. As a corollary, drivers must not call | 347 | is unbound from its interface. As a corollary, drivers must not call |
@@ -409,11 +411,11 @@ during autosuspend. For example, there's not much point | |||
409 | autosuspending a keyboard if the user can't cause the keyboard to do a | 411 | autosuspending a keyboard if the user can't cause the keyboard to do a |
410 | remote wakeup by typing on it. If the driver sets | 412 | remote wakeup by typing on it. If the driver sets |
411 | intf->needs_remote_wakeup to 1, the kernel won't autosuspend the | 413 | intf->needs_remote_wakeup to 1, the kernel won't autosuspend the |
412 | device if remote wakeup isn't available or has been disabled through | 414 | device if remote wakeup isn't available. (If the device is already |
413 | the power/wakeup attribute. (If the device is already autosuspended, | 415 | autosuspended, though, setting this flag won't cause the kernel to |
414 | though, setting this flag won't cause the kernel to autoresume it. | 416 | autoresume it. Normally a driver would set this flag in its probe |
415 | Normally a driver would set this flag in its probe method, at which | 417 | method, at which time the device is guaranteed not to be |
416 | time the device is guaranteed not to be autosuspended.) | 418 | autosuspended.) |
417 | 419 | ||
418 | If a driver does its I/O asynchronously in interrupt context, it | 420 | If a driver does its I/O asynchronously in interrupt context, it |
419 | should call usb_autopm_get_interface_async() before starting output and | 421 | should call usb_autopm_get_interface_async() before starting output and |
@@ -422,20 +424,19 @@ it receives an input event, it should call | |||
422 | 424 | ||
423 | usb_mark_last_busy(struct usb_device *udev); | 425 | usb_mark_last_busy(struct usb_device *udev); |
424 | 426 | ||
425 | in the event handler. This sets udev->last_busy to the current time. | 427 | in the event handler. This tells the PM core that the device was just |
426 | udev->last_busy is the field used for idle-delay calculations; | 428 | busy and therefore the next autosuspend idle-delay expiration should |
427 | updating it will cause any pending autosuspend to be moved back. Most | 429 | be pushed back. Many of the usb_autopm_* routines also make this call, |
428 | of the usb_autopm_* routines will also set the last_busy field to the | 430 | so drivers need to worry only when interrupt-driven input arrives. |
429 | current time. | ||
430 | 431 | ||
431 | Asynchronous operation is always subject to races. For example, a | 432 | Asynchronous operation is always subject to races. For example, a |
432 | driver may call one of the usb_autopm_*_interface_async() routines at | 433 | driver may call the usb_autopm_get_interface_async() routine at a time |
433 | a time when the core has just finished deciding the device has been | 434 | when the core has just finished deciding the device has been idle for |
434 | idle for long enough but not yet gotten around to calling the driver's | 435 | long enough but not yet gotten around to calling the driver's suspend |
435 | suspend method. The suspend method must be responsible for | 436 | method. The suspend method must be responsible for synchronizing with |
436 | synchronizing with the output request routine and the URB completion | 437 | the I/O request routine and the URB completion handler; it should |
437 | handler; it should cause autosuspends to fail with -EBUSY if the | 438 | cause autosuspends to fail with -EBUSY if the driver needs to use the |
438 | driver needs to use the device. | 439 | device. |
439 | 440 | ||
440 | External suspend calls should never be allowed to fail in this way, | 441 | External suspend calls should never be allowed to fail in this way, |
441 | only autosuspend calls. The driver can tell them apart by checking | 442 | only autosuspend calls. The driver can tell them apart by checking |
@@ -472,7 +473,9 @@ Firstly, a device may already be autosuspended when a system suspend | |||
472 | occurs. Since system suspends are supposed to be as transparent as | 473 | occurs. Since system suspends are supposed to be as transparent as |
473 | possible, the device should remain suspended following the system | 474 | possible, the device should remain suspended following the system |
474 | resume. But this theory may not work out well in practice; over time | 475 | resume. But this theory may not work out well in practice; over time |
475 | the kernel's behavior in this regard has changed. | 476 | the kernel's behavior in this regard has changed. As of 2.6.37 the |
477 | policy is to resume all devices during a system resume and let them | ||
478 | handle their own runtime suspends afterward. | ||
476 | 479 | ||
477 | Secondly, a dynamic power-management event may occur as a system | 480 | Secondly, a dynamic power-management event may occur as a system |
478 | suspend is underway. The window for this is short, since system | 481 | suspend is underway. The window for this is short, since system |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 0a63e968c68..43c25c29ac1 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -1397,32 +1397,7 @@ void usb_autosuspend_device(struct usb_device *udev) | |||
1397 | int status; | 1397 | int status; |
1398 | 1398 | ||
1399 | usb_mark_last_busy(udev); | 1399 | usb_mark_last_busy(udev); |
1400 | status = pm_runtime_put_sync(&udev->dev); | 1400 | status = pm_runtime_put_sync_autosuspend(&udev->dev); |
1401 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", | ||
1402 | __func__, atomic_read(&udev->dev.power.usage_count), | ||
1403 | status); | ||
1404 | } | ||
1405 | |||
1406 | /** | ||
1407 | * usb_try_autosuspend_device - attempt an autosuspend of a USB device and its interfaces | ||
1408 | * @udev: the usb_device to autosuspend | ||
1409 | * | ||
1410 | * This routine should be called when a core subsystem thinks @udev may | ||
1411 | * be ready to autosuspend. | ||
1412 | * | ||
1413 | * @udev's usage counter left unchanged. If it is 0 and all the interfaces | ||
1414 | * are inactive then an autosuspend will be attempted. The attempt may | ||
1415 | * fail or be delayed. | ||
1416 | * | ||
1417 | * The caller must hold @udev's device lock. | ||
1418 | * | ||
1419 | * This routine can run only in process context. | ||
1420 | */ | ||
1421 | void usb_try_autosuspend_device(struct usb_device *udev) | ||
1422 | { | ||
1423 | int status; | ||
1424 | |||
1425 | status = pm_runtime_idle(&udev->dev); | ||
1426 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", | 1401 | dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n", |
1427 | __func__, atomic_read(&udev->dev.power.usage_count), | 1402 | __func__, atomic_read(&udev->dev.power.usage_count), |
1428 | status); | 1403 | status); |
@@ -1508,32 +1483,11 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface); | |||
1508 | void usb_autopm_put_interface_async(struct usb_interface *intf) | 1483 | void usb_autopm_put_interface_async(struct usb_interface *intf) |
1509 | { | 1484 | { |
1510 | struct usb_device *udev = interface_to_usbdev(intf); | 1485 | struct usb_device *udev = interface_to_usbdev(intf); |
1511 | unsigned long last_busy; | 1486 | int status; |
1512 | int status = 0; | ||
1513 | 1487 | ||
1514 | last_busy = udev->dev.power.last_busy; | ||
1515 | usb_mark_last_busy(udev); | 1488 | usb_mark_last_busy(udev); |
1516 | atomic_dec(&intf->pm_usage_cnt); | 1489 | atomic_dec(&intf->pm_usage_cnt); |
1517 | pm_runtime_put_noidle(&intf->dev); | 1490 | status = pm_runtime_put(&intf->dev); |
1518 | |||
1519 | if (udev->dev.power.runtime_auto) { | ||
1520 | /* Optimization: Don't schedule a delayed autosuspend if | ||
1521 | * the timer is already running and the expiration time | ||
1522 | * wouldn't change. | ||
1523 | * | ||
1524 | * We have to use the interface's timer. Attempts to | ||
1525 | * schedule a suspend for the device would fail because | ||
1526 | * the interface is still active. | ||
1527 | */ | ||
1528 | if (intf->dev.power.timer_expires == 0 || | ||
1529 | round_jiffies_up(last_busy) != | ||
1530 | round_jiffies_up(jiffies)) { | ||
1531 | status = pm_schedule_suspend(&intf->dev, | ||
1532 | jiffies_to_msecs( | ||
1533 | round_jiffies_up_relative( | ||
1534 | udev->autosuspend_delay))); | ||
1535 | } | ||
1536 | } | ||
1537 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", | 1491 | dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n", |
1538 | __func__, atomic_read(&intf->dev.power.usage_count), | 1492 | __func__, atomic_read(&intf->dev.power.usage_count), |
1539 | status); | 1493 | status); |
@@ -1651,7 +1605,6 @@ static int autosuspend_check(struct usb_device *udev) | |||
1651 | { | 1605 | { |
1652 | int w, i; | 1606 | int w, i; |
1653 | struct usb_interface *intf; | 1607 | struct usb_interface *intf; |
1654 | unsigned long suspend_time, j; | ||
1655 | 1608 | ||
1656 | /* Fail if autosuspend is disabled, or any interfaces are in use, or | 1609 | /* Fail if autosuspend is disabled, or any interfaces are in use, or |
1657 | * any interface drivers require remote wakeup but it isn't available. | 1610 | * any interface drivers require remote wakeup but it isn't available. |
@@ -1691,17 +1644,6 @@ static int autosuspend_check(struct usb_device *udev) | |||
1691 | return -EOPNOTSUPP; | 1644 | return -EOPNOTSUPP; |
1692 | } | 1645 | } |
1693 | udev->do_remote_wakeup = w; | 1646 | udev->do_remote_wakeup = w; |
1694 | |||
1695 | /* If everything is okay but the device hasn't been idle for long | ||
1696 | * enough, queue a delayed autosuspend request. | ||
1697 | */ | ||
1698 | j = ACCESS_ONCE(jiffies); | ||
1699 | suspend_time = udev->dev.power.last_busy + udev->autosuspend_delay; | ||
1700 | if (time_before(j, suspend_time)) { | ||
1701 | pm_schedule_suspend(&udev->dev, jiffies_to_msecs( | ||
1702 | round_jiffies_up_relative(suspend_time - j))); | ||
1703 | return -EAGAIN; | ||
1704 | } | ||
1705 | return 0; | 1647 | return 0; |
1706 | } | 1648 | } |
1707 | 1649 | ||
@@ -1719,17 +1661,8 @@ static int usb_runtime_suspend(struct device *dev) | |||
1719 | 1661 | ||
1720 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); | 1662 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
1721 | 1663 | ||
1722 | /* If an interface fails the suspend, adjust the last_busy | ||
1723 | * time so that we don't get another suspend attempt right | ||
1724 | * away. | ||
1725 | */ | ||
1726 | if (status) { | ||
1727 | udev->dev.power.last_busy = jiffies + | ||
1728 | (udev->autosuspend_delay == 0 ? HZ/2 : 0); | ||
1729 | } | ||
1730 | |||
1731 | /* Prevent the parent from suspending immediately after */ | 1664 | /* Prevent the parent from suspending immediately after */ |
1732 | else if (udev->parent) | 1665 | if (status == 0 && udev->parent) |
1733 | usb_mark_last_busy(udev->parent); | 1666 | usb_mark_last_busy(udev->parent); |
1734 | 1667 | ||
1735 | return status; | 1668 | return status; |
@@ -1756,7 +1689,7 @@ static int usb_runtime_idle(struct device *dev) | |||
1756 | * autosuspend checks. | 1689 | * autosuspend checks. |
1757 | */ | 1690 | */ |
1758 | if (autosuspend_check(udev) == 0) | 1691 | if (autosuspend_check(udev) == 0) |
1759 | pm_runtime_suspend(dev); | 1692 | pm_runtime_autosuspend(dev); |
1760 | return 0; | 1693 | return 0; |
1761 | } | 1694 | } |
1762 | 1695 | ||
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 7c2405eccc4..fdb62ca10d8 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -1803,6 +1803,7 @@ int usb_new_device(struct usb_device *udev) | |||
1803 | 1803 | ||
1804 | /* Tell the runtime-PM framework the device is active */ | 1804 | /* Tell the runtime-PM framework the device is active */ |
1805 | pm_runtime_set_active(&udev->dev); | 1805 | pm_runtime_set_active(&udev->dev); |
1806 | pm_runtime_use_autosuspend(&udev->dev); | ||
1806 | pm_runtime_enable(&udev->dev); | 1807 | pm_runtime_enable(&udev->dev); |
1807 | 1808 | ||
1808 | err = usb_enumerate_device(udev); /* Read descriptors */ | 1809 | err = usb_enumerate_device(udev); /* Read descriptors */ |
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index 25719da45e3..e3531da1613 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c | |||
@@ -124,12 +124,6 @@ void usb_detect_quirks(struct usb_device *udev) | |||
124 | */ | 124 | */ |
125 | usb_disable_autosuspend(udev); | 125 | usb_disable_autosuspend(udev); |
126 | 126 | ||
127 | /* Autosuspend can also be disabled if the initial autosuspend_delay | ||
128 | * is negative. | ||
129 | */ | ||
130 | if (udev->autosuspend_delay < 0) | ||
131 | usb_autoresume_device(udev); | ||
132 | |||
133 | #endif | 127 | #endif |
134 | 128 | ||
135 | /* For the present, all devices default to USB-PERSIST enabled */ | 129 | /* For the present, all devices default to USB-PERSIST enabled */ |
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 9561e087907..6781c369ce2 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); | |||
334 | static ssize_t | 334 | static ssize_t |
335 | show_autosuspend(struct device *dev, struct device_attribute *attr, char *buf) | 335 | show_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 | ||
342 | static ssize_t | 340 | static ssize_t |
343 | set_autosuspend(struct device *dev, struct device_attribute *attr, | 341 | set_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 | ||
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index fdd4130fbb7..079cb57bab4 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c | |||
@@ -445,7 +445,8 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, | |||
445 | INIT_LIST_HEAD(&dev->filelist); | 445 | INIT_LIST_HEAD(&dev->filelist); |
446 | 446 | ||
447 | #ifdef CONFIG_PM | 447 | #ifdef CONFIG_PM |
448 | dev->autosuspend_delay = usb_autosuspend_delay * HZ; | 448 | pm_runtime_set_autosuspend_delay(&dev->dev, |
449 | usb_autosuspend_delay * 1000); | ||
449 | dev->connect_time = jiffies; | 450 | dev->connect_time = jiffies; |
450 | dev->active_duration = -jiffies; | 451 | dev->active_duration = -jiffies; |
451 | #endif | 452 | #endif |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index cd882203ad3..b975450f403 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -75,14 +75,12 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
75 | #ifdef CONFIG_USB_SUSPEND | 75 | #ifdef CONFIG_USB_SUSPEND |
76 | 76 | ||
77 | extern void usb_autosuspend_device(struct usb_device *udev); | 77 | extern void usb_autosuspend_device(struct usb_device *udev); |
78 | extern void usb_try_autosuspend_device(struct usb_device *udev); | ||
79 | extern int usb_autoresume_device(struct usb_device *udev); | 78 | extern int usb_autoresume_device(struct usb_device *udev); |
80 | extern int usb_remote_wakeup(struct usb_device *dev); | 79 | extern int usb_remote_wakeup(struct usb_device *dev); |
81 | 80 | ||
82 | #else | 81 | #else |
83 | 82 | ||
84 | #define usb_autosuspend_device(udev) do {} while (0) | 83 | #define usb_autosuspend_device(udev) do {} while (0) |
85 | #define usb_try_autosuspend_device(udev) do {} while (0) | ||
86 | static inline int usb_autoresume_device(struct usb_device *udev) | 84 | static inline int usb_autoresume_device(struct usb_device *udev) |
87 | { | 85 | { |
88 | return 0; | 86 | return 0; |
diff --git a/include/linux/usb.h b/include/linux/usb.h index 7d22b3340a7..5ee2223af08 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h | |||
@@ -408,7 +408,6 @@ struct usb_tt; | |||
408 | * @quirks: quirks of the whole device | 408 | * @quirks: quirks of the whole device |
409 | * @urbnum: number of URBs submitted for the whole device | 409 | * @urbnum: number of URBs submitted for the whole device |
410 | * @active_duration: total time device is not suspended | 410 | * @active_duration: total time device is not suspended |
411 | * @autosuspend_delay: in jiffies | ||
412 | * @connect_time: time device was first connected | 411 | * @connect_time: time device was first connected |
413 | * @do_remote_wakeup: remote wakeup should be enabled | 412 | * @do_remote_wakeup: remote wakeup should be enabled |
414 | * @reset_resume: needs reset instead of resume | 413 | * @reset_resume: needs reset instead of resume |
@@ -481,7 +480,6 @@ struct usb_device { | |||
481 | unsigned long active_duration; | 480 | unsigned long active_duration; |
482 | 481 | ||
483 | #ifdef CONFIG_PM | 482 | #ifdef CONFIG_PM |
484 | int autosuspend_delay; | ||
485 | unsigned long connect_time; | 483 | unsigned long connect_time; |
486 | 484 | ||
487 | unsigned do_remote_wakeup:1; | 485 | unsigned do_remote_wakeup:1; |