Skip to content

Commit a903098

Browse files
AlanSterngregkh
authored andcommitted
USB: deprecate the power/level sysfs attribute
This patch (as1367) deprecates USB's power/level sysfs attribute in favor of the power/control attribute provided by the runtime PM core. The two attributes do the same thing. It would be nice to replace power/level with a symlink to power/control, but at the moment sysfs doesn't offer any way to do so. Signed-off-by: Alan Stern <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9e18c82 commit a903098

File tree

4 files changed

+54
-36
lines changed

4 files changed

+54
-36
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
What: /sys/bus/usb/devices/.../power/level
2+
Date: March 2007
3+
KernelVersion: 2.6.21
4+
Contact: Alan Stern <[email protected]>
5+
Description:
6+
Each USB device directory will contain a file named
7+
power/level. This file holds a power-level setting for
8+
the device, either "on" or "auto".
9+
10+
"on" means that the device is not allowed to autosuspend,
11+
although normal suspends for system sleep will still
12+
be honored. "auto" means the device will autosuspend
13+
and autoresume in the usual manner, according to the
14+
capabilities of its driver.
15+
16+
During normal use, devices should be left in the "auto"
17+
level. The "on" level is meant for administrative uses.
18+
If you want to suspend a device immediately but leave it
19+
free to wake up in response to I/O requests, you should
20+
write "0" to power/autosuspend.
21+
22+
Device not capable of proper suspend and resume should be
23+
left in the "on" level. Although the USB spec requires
24+
devices to support suspend/resume, many of them do not.
25+
In fact so many don't that by default, the USB core
26+
initializes all non-hub devices in the "on" level. Some
27+
drivers may change this setting when they are bound.
28+
29+
This file is deprecated and will be removed after 2010.
30+
Use the power/control file instead; it does exactly the
31+
same thing.

Documentation/ABI/testing/sysfs-bus-usb

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,6 @@ Description:
1414
The autosuspend delay for newly-created devices is set to
1515
the value of the usbcore.autosuspend module parameter.
1616

17-
What: /sys/bus/usb/devices/.../power/level
18-
Date: March 2007
19-
KernelVersion: 2.6.21
20-
Contact: Alan Stern <[email protected]>
21-
Description:
22-
Each USB device directory will contain a file named
23-
power/level. This file holds a power-level setting for
24-
the device, either "on" or "auto".
25-
26-
"on" means that the device is not allowed to autosuspend,
27-
although normal suspends for system sleep will still
28-
be honored. "auto" means the device will autosuspend
29-
and autoresume in the usual manner, according to the
30-
capabilities of its driver.
31-
32-
During normal use, devices should be left in the "auto"
33-
level. The "on" level is meant for administrative uses.
34-
If you want to suspend a device immediately but leave it
35-
free to wake up in response to I/O requests, you should
36-
write "0" to power/autosuspend.
37-
38-
Device not capable of proper suspend and resume should be
39-
left in the "on" level. Although the USB spec requires
40-
devices to support suspend/resume, many of them do not.
41-
In fact so many don't that by default, the USB core
42-
initializes all non-hub devices in the "on" level. Some
43-
drivers may change this setting when they are bound.
44-
4517
What: /sys/bus/usb/devices/.../power/persist
4618
Date: May 2007
4719
KernelVersion: 2.6.23

Documentation/usb/power-management.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ allowed to issue dynamic suspends.
107107
The user interface for controlling dynamic PM is located in the power/
108108
subdirectory of each USB device's sysfs directory, that is, in
109109
/sys/bus/usb/devices/.../power/ where "..." is the device's ID. The
110-
relevant attribute files are: wakeup, level, and autosuspend.
110+
relevant attribute files are: wakeup, control, and autosuspend.
111+
(There may also be a file named "level"; this file was deprecated
112+
as of the 2.6.35 kernel and replaced by the "control" file.)
111113

112114
power/wakeup
113115

@@ -120,7 +122,7 @@ relevant attribute files are: wakeup, level, and autosuspend.
120122
while the device is suspended, the change won't take
121123
effect until the following suspend.)
122124

123-
power/level
125+
power/control
124126

125127
This file contains one of two words: "on" or "auto".
126128
You can write those words to the file to change the
@@ -148,14 +150,15 @@ relevant attribute files are: wakeup, level, and autosuspend.
148150
never to autosuspend. You can write a number to the
149151
file to change the autosuspend idle-delay time.
150152

151-
Writing "-1" to power/autosuspend and writing "on" to power/level do
153+
Writing "-1" to power/autosuspend and writing "on" to power/control do
152154
essentially the same thing -- they both prevent the device from being
153155
autosuspended. Yes, this is a redundancy in the API.
154156

155157
(In 2.6.21 writing "0" to power/autosuspend would prevent the device
156158
from being autosuspended; the behavior was changed in 2.6.22. The
157159
power/autosuspend attribute did not exist prior to 2.6.21, and the
158-
power/level attribute did not exist prior to 2.6.22.)
160+
power/level attribute did not exist prior to 2.6.22. power/control
161+
was added in 2.6.34.)
159162

160163

161164
Changing the default idle-delay time
@@ -212,7 +215,7 @@ among printers and scanners, but plenty of other types of device have
212215
the same deficiency.
213216

214217
For this reason, by default the kernel disables autosuspend (the
215-
power/level attribute is initialized to "on") for all devices other
218+
power/control attribute is initialized to "on") for all devices other
216219
than hubs. Hubs, at least, appear to be reasonably well-behaved in
217220
this regard.
218221

@@ -373,7 +376,7 @@ usb_autopm_put_interface() in its close or release routine. But other
373376
patterns are possible.
374377

375378
The autosuspend attempts mentioned above will often fail for one
376-
reason or another. For example, the power/level attribute might be
379+
reason or another. For example, the power/control attribute might be
377380
set to "on", or another interface in the same device might not be
378381
idle. This is perfectly normal. If the reason for failure was that
379382
the device hasn't been idle for long enough, a timer is scheduled to
@@ -394,12 +397,12 @@ Drivers can enable autosuspend for their devices by calling
394397

395398
in their probe() routine, if they know that the device is capable of
396399
suspending and resuming correctly. This is exactly equivalent to
397-
writing "auto" to the device's power/level attribute. Likewise,
400+
writing "auto" to the device's power/control attribute. Likewise,
398401
drivers can disable autosuspend by calling
399402

400403
usb_disable_autosuspend(struct usb_device *udev);
401404

402-
This is exactly the same as writing "on" to the power/level attribute.
405+
This is exactly the same as writing "on" to the power/control attribute.
403406

404407
Sometimes a driver needs to make sure that remote wakeup is enabled
405408
during autosuspend. For example, there's not much point

drivers/usb/core/sysfs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,23 @@ static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
383383
static const char on_string[] = "on";
384384
static const char auto_string[] = "auto";
385385

386+
static void warn_level(void) {
387+
static int level_warned;
388+
389+
if (!level_warned) {
390+
level_warned = 1;
391+
printk(KERN_WARNING "WARNING! power/level is deprecated; "
392+
"use power/control instead\n");
393+
}
394+
}
395+
386396
static ssize_t
387397
show_level(struct device *dev, struct device_attribute *attr, char *buf)
388398
{
389399
struct usb_device *udev = to_usb_device(dev);
390400
const char *p = auto_string;
391401

402+
warn_level();
392403
if (udev->state != USB_STATE_SUSPENDED && !udev->dev.power.runtime_auto)
393404
p = on_string;
394405
return sprintf(buf, "%s\n", p);
@@ -403,6 +414,7 @@ set_level(struct device *dev, struct device_attribute *attr,
403414
char *cp;
404415
int rc = count;
405416

417+
warn_level();
406418
cp = memchr(buf, '\n', count);
407419
if (cp)
408420
len = cp - buf;

0 commit comments

Comments
 (0)