USB: prepare for changover to Runtime PM framework
This patch (as1303) revises the USB Power Management infrastructure to make it compatible with the new driver-model Runtime PM framework: Drivers are no longer allowed to access intf->pm_usage_cnt directly; the PM framework manages its own usage counters. usb_autopm_set_interface() is eliminated, because it directly sets intf->pm_usage_cnt. usb_autopm_enable() and usb_autopm_disable() are eliminated, because they call usb_autopm_set_interface(). usb_autopm_get_interface_no_resume() and usb_autopm_put_interface_no_suspend() are added. They correspond to pm_runtime_get_noresume() and pm_runtime_put_noidle() in the PM framework. The power/level attribute no longer accepts "suspend", only "on" and "auto". The PM framework doesn't allow devices to be forced into a suspended mode. The hub driver contains the only code that violates the new guidelines. It is updated to use the new interface routines instead. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
9af23624ae
commit
8e4ceb38eb
@ -327,7 +327,6 @@ static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
|
||||
|
||||
static const char on_string[] = "on";
|
||||
static const char auto_string[] = "auto";
|
||||
static const char suspend_string[] = "suspend";
|
||||
|
||||
static ssize_t
|
||||
show_level(struct device *dev, struct device_attribute *attr, char *buf)
|
||||
@ -335,13 +334,8 @@ show_level(struct device *dev, struct device_attribute *attr, char *buf)
|
||||
struct usb_device *udev = to_usb_device(dev);
|
||||
const char *p = auto_string;
|
||||
|
||||
if (udev->state == USB_STATE_SUSPENDED) {
|
||||
if (udev->autoresume_disabled)
|
||||
p = suspend_string;
|
||||
} else {
|
||||
if (udev->autosuspend_disabled)
|
||||
p = on_string;
|
||||
}
|
||||
if (udev->state != USB_STATE_SUSPENDED && udev->autosuspend_disabled)
|
||||
p = on_string;
|
||||
return sprintf(buf, "%s\n", p);
|
||||
}
|
||||
|
||||
@ -353,7 +347,7 @@ set_level(struct device *dev, struct device_attribute *attr,
|
||||
int len = count;
|
||||
char *cp;
|
||||
int rc = 0;
|
||||
int old_autosuspend_disabled, old_autoresume_disabled;
|
||||
int old_autosuspend_disabled;
|
||||
|
||||
cp = memchr(buf, '\n', count);
|
||||
if (cp)
|
||||
@ -361,7 +355,6 @@ set_level(struct device *dev, struct device_attribute *attr,
|
||||
|
||||
usb_lock_device(udev);
|
||||
old_autosuspend_disabled = udev->autosuspend_disabled;
|
||||
old_autoresume_disabled = udev->autoresume_disabled;
|
||||
|
||||
/* Setting the flags without calling usb_pm_lock is a subject to
|
||||
* races, but who cares...
|
||||
@ -369,28 +362,18 @@ set_level(struct device *dev, struct device_attribute *attr,
|
||||
if (len == sizeof on_string - 1 &&
|
||||
strncmp(buf, on_string, len) == 0) {
|
||||
udev->autosuspend_disabled = 1;
|
||||
udev->autoresume_disabled = 0;
|
||||
rc = usb_external_resume_device(udev, PMSG_USER_RESUME);
|
||||
|
||||
} else if (len == sizeof auto_string - 1 &&
|
||||
strncmp(buf, auto_string, len) == 0) {
|
||||
udev->autosuspend_disabled = 0;
|
||||
udev->autoresume_disabled = 0;
|
||||
rc = usb_external_resume_device(udev, PMSG_USER_RESUME);
|
||||
|
||||
} else if (len == sizeof suspend_string - 1 &&
|
||||
strncmp(buf, suspend_string, len) == 0) {
|
||||
udev->autosuspend_disabled = 0;
|
||||
udev->autoresume_disabled = 1;
|
||||
rc = usb_external_suspend_device(udev, PMSG_USER_SUSPEND);
|
||||
|
||||
} else
|
||||
rc = -EINVAL;
|
||||
|
||||
if (rc) {
|
||||
if (rc)
|
||||
udev->autosuspend_disabled = old_autosuspend_disabled;
|
||||
udev->autoresume_disabled = old_autoresume_disabled;
|
||||
}
|
||||
usb_unlock_device(udev);
|
||||
return (rc < 0 ? rc : count);
|
||||
}
|
||||
|
Reference in New Issue
Block a user