diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2010-11-15 15:57:51 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-11-16 17:03:41 -0500 |
commit | fcc4a01eb8661226e80632327673f67bf6a5840b (patch) | |
tree | dc05c200ccfac2daad6d1efe413ae6fa92f1638d /Documentation/usb | |
parent | 6ddf27cdbc218a412d7e993fdc08e30eec2042ce (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 'Documentation/usb')
-rw-r--r-- | Documentation/usb/power-management.txt | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/Documentation/usb/power-management.txt b/Documentation/usb/power-management.txt index b29d8e56cf28..c9ffa9ced7ee 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 |