Skip to content

Commit 9e18c82

Browse files
AlanSterngregkh
authored andcommitted
USB: use PM core routines to enable/disable autosuspend
This patch (as1366) replaces the private routines usb_enable_autosuspend() and usb_disable_autosuspend() with calls to the standard pm_runtime_allow() and pm_runtime_forbid() functions in the runtime PM framework. They do the same thing. Signed-off-by: Alan Stern <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7aba8d0 commit 9e18c82

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

drivers/usb/core/driver.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,13 +1356,9 @@ int usb_resume(struct device *dev, pm_message_t msg)
13561356
*
13571357
* The caller must hold @udev's device lock.
13581358
*/
1359-
int usb_enable_autosuspend(struct usb_device *udev)
1359+
void usb_enable_autosuspend(struct usb_device *udev)
13601360
{
1361-
if (udev->autosuspend_disabled) {
1362-
udev->autosuspend_disabled = 0;
1363-
usb_autosuspend_device(udev);
1364-
}
1365-
return 0;
1361+
pm_runtime_allow(&udev->dev);
13661362
}
13671363
EXPORT_SYMBOL_GPL(usb_enable_autosuspend);
13681364

@@ -1375,16 +1371,9 @@ EXPORT_SYMBOL_GPL(usb_enable_autosuspend);
13751371
*
13761372
* The caller must hold @udev's device lock.
13771373
*/
1378-
int usb_disable_autosuspend(struct usb_device *udev)
1374+
void usb_disable_autosuspend(struct usb_device *udev)
13791375
{
1380-
int rc = 0;
1381-
1382-
if (!udev->autosuspend_disabled) {
1383-
rc = usb_autoresume_device(udev);
1384-
if (rc == 0)
1385-
udev->autosuspend_disabled = 1;
1386-
}
1387-
return rc;
1376+
pm_runtime_forbid(&udev->dev);
13881377
}
13891378
EXPORT_SYMBOL_GPL(usb_disable_autosuspend);
13901379

@@ -1528,7 +1517,7 @@ void usb_autopm_put_interface_async(struct usb_interface *intf)
15281517
atomic_dec(&intf->pm_usage_cnt);
15291518
pm_runtime_put_noidle(&intf->dev);
15301519

1531-
if (!udev->autosuspend_disabled) {
1520+
if (udev->dev.power.runtime_auto) {
15321521
/* Optimization: Don't schedule a delayed autosuspend if
15331522
* the timer is already running and the expiration time
15341523
* wouldn't change.

drivers/usb/core/sysfs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ show_level(struct device *dev, struct device_attribute *attr, char *buf)
389389
struct usb_device *udev = to_usb_device(dev);
390390
const char *p = auto_string;
391391

392-
if (udev->state != USB_STATE_SUSPENDED && udev->autosuspend_disabled)
392+
if (udev->state != USB_STATE_SUSPENDED && !udev->dev.power.runtime_auto)
393393
p = on_string;
394394
return sprintf(buf, "%s\n", p);
395395
}
@@ -401,7 +401,7 @@ set_level(struct device *dev, struct device_attribute *attr,
401401
struct usb_device *udev = to_usb_device(dev);
402402
int len = count;
403403
char *cp;
404-
int rc;
404+
int rc = count;
405405

406406
cp = memchr(buf, '\n', count);
407407
if (cp)
@@ -411,17 +411,17 @@ set_level(struct device *dev, struct device_attribute *attr,
411411

412412
if (len == sizeof on_string - 1 &&
413413
strncmp(buf, on_string, len) == 0)
414-
rc = usb_disable_autosuspend(udev);
414+
usb_disable_autosuspend(udev);
415415

416416
else if (len == sizeof auto_string - 1 &&
417417
strncmp(buf, auto_string, len) == 0)
418-
rc = usb_enable_autosuspend(udev);
418+
usb_enable_autosuspend(udev);
419419

420420
else
421421
rc = -EINVAL;
422422

423423
usb_unlock_device(udev);
424-
return (rc < 0 ? rc : count);
424+
return rc;
425425
}
426426

427427
static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level);

include/linux/usb.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ struct usb_tt;
425425
* @connect_time: time device was first connected
426426
* @do_remote_wakeup: remote wakeup should be enabled
427427
* @reset_resume: needs reset instead of resume
428-
* @autosuspend_disabled: autosuspend disabled by the user
429428
* @wusb_dev: if this is a Wireless USB device, link to the WUSB
430429
* specific data for the device.
431430
* @slot_id: Slot ID assigned by xHCI
@@ -501,7 +500,6 @@ struct usb_device {
501500

502501
unsigned do_remote_wakeup:1;
503502
unsigned reset_resume:1;
504-
unsigned autosuspend_disabled:1;
505503
#endif
506504
struct wusb_dev *wusb_dev;
507505
int slot_id;
@@ -526,8 +524,8 @@ extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id);
526524

527525
/* USB autosuspend and autoresume */
528526
#ifdef CONFIG_USB_SUSPEND
529-
extern int usb_enable_autosuspend(struct usb_device *udev);
530-
extern int usb_disable_autosuspend(struct usb_device *udev);
527+
extern void usb_enable_autosuspend(struct usb_device *udev);
528+
extern void usb_disable_autosuspend(struct usb_device *udev);
531529

532530
extern int usb_autopm_get_interface(struct usb_interface *intf);
533531
extern void usb_autopm_put_interface(struct usb_interface *intf);

0 commit comments

Comments
 (0)