Skip to content

Commit

Permalink
usb: core: enable remote wakeup function for usb controller
Browse files Browse the repository at this point in the history
The remote wake up function is a regular function on usb device and
I think keeping it enabled by default will make the usb application
more convenient and usb device remote wake up function keep enabled
that ask usb controller remote wake up was enabled at first.

This patch only enable wake up on usb root hub device, among which,
usb3.0 root hub doesn't be set wakeup node property but use command
USB_INTRF_FUNC_SUSPEND to enable remote wake up function.

Signed-off-by: Yinbo Zhu <zhuyinbo@loongson.cn>
  • Loading branch information
YinboZhu authored and intel-lab-lkp committed Dec 8, 2021
1 parent f772987 commit e900e8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 18 additions & 2 deletions drivers/usb/core/hub.c
Expand Up @@ -2509,6 +2509,8 @@ static void set_usb_port_removable(struct usb_device *udev)
*/
int usb_new_device(struct usb_device *udev)
{
struct usb_host_config *config;
int ncfg;
int err;

if (udev->parent) {
Expand Down Expand Up @@ -2540,6 +2542,18 @@ int usb_new_device(struct usb_device *udev)
udev->dev.devt = MKDEV(USB_DEVICE_MAJOR,
(((udev->bus->busnum-1) * 128) + (udev->devnum-1)));

for (ncfg = 0; ncfg < udev->descriptor.bNumConfigurations; ncfg++) {
config = &udev->config[ncfg];
if ((config->desc.bmAttributes & (1 << 5)) == 0)
break;
if (ncfg + 1 == udev->descriptor.bNumConfigurations) {
err = usb_enable_remote_wakeup(udev);
if (err)
dev_dbg(&udev->dev,
"won't remote wakeup, err %d\n", err);
}
}

/* Tell the world! */
announce_device(udev);

Expand Down Expand Up @@ -3234,7 +3248,7 @@ EXPORT_SYMBOL_GPL(usb_enable_ltm);
* enable remote wake for the first interface. FIXME if the interface
* association descriptor shows there's more than one function.
*/
static int usb_enable_remote_wakeup(struct usb_device *udev)
int usb_enable_remote_wakeup(struct usb_device *udev)
{
if (udev->speed < USB_SPEED_SUPER)
return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
Expand All @@ -3249,6 +3263,7 @@ static int usb_enable_remote_wakeup(struct usb_device *udev)
USB_INTRF_FUNC_SUSPEND_LP,
NULL, 0, USB_CTRL_SET_TIMEOUT);
}
EXPORT_SYMBOL_GPL(usb_enable_remote_wakeup);

/*
* usb_disable_remote_wakeup - disable remote wakeup for a device
Expand All @@ -3260,7 +3275,7 @@ static int usb_enable_remote_wakeup(struct usb_device *udev)
* disable remote wake for the first interface. FIXME if the interface
* association descriptor shows there's more than one function.
*/
static int usb_disable_remote_wakeup(struct usb_device *udev)
int usb_disable_remote_wakeup(struct usb_device *udev)
{
if (udev->speed < USB_SPEED_SUPER)
return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
Expand All @@ -3273,6 +3288,7 @@ static int usb_disable_remote_wakeup(struct usb_device *udev)
USB_INTRF_FUNC_SUSPEND, 0, NULL, 0,
USB_CTRL_SET_TIMEOUT);
}
EXPORT_SYMBOL_GPL(usb_disable_remote_wakeup);

/* Count of wakeup-enabled devices at or below udev */
unsigned usb_wakeup_enabled_descendants(struct usb_device *udev)
Expand Down
4 changes: 3 additions & 1 deletion include/linux/usb.h
Expand Up @@ -754,8 +754,10 @@ static inline bool usb_acpi_power_manageable(struct usb_device *hdev, int index)
{ return true; }
#endif

/* USB autosuspend and autoresume */
#ifdef CONFIG_PM
extern int usb_enable_remote_wakeup(struct usb_device *udev);
extern int usb_disable_remote_wakeup(struct usb_device *udev);

extern void usb_enable_autosuspend(struct usb_device *udev);
extern void usb_disable_autosuspend(struct usb_device *udev);

Expand Down

0 comments on commit e900e8c

Please sign in to comment.