Re: [PATCH v4 2/2] usb: overridable hub bInterval by device node
From: Johan Hovold
Date: Tue Dec 03 2019 - 11:52:59 EST
On Tue, Dec 03, 2019 at 06:15:52PM +0800, Ikjoon Jang wrote:
> This patch enables hub device to override its own endpoint descriptor's
> bInterval when the hub has a device node with "hub,interval" property.
>
> When we know reducing autosuspend delay for built-in HIDs is better for
> power saving, we can reduce it to the optimal value. But if a parent hub
> has a long bInterval, mouse lags a lot from more frequent autosuspend.
> So this enables overriding bInterval for a hard wired hub device only
> when we know that reduces the power consumption.
I think I saw you argue about why this shouldn't simply be configured at
runtime. Please include that here too, I can't seem to remember why...
> Signed-off-by: Ikjoon Jang <ikjn@xxxxxxxxxxxx>
> Acked-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
> ---
> drivers/usb/core/config.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index 5f40117e68e7..95ec5af42a1c 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -6,6 +6,7 @@
> #include <linux/usb.h>
> #include <linux/usb/ch9.h>
> #include <linux/usb/hcd.h>
> +#include <linux/usb/of.h>
> #include <linux/usb/quirks.h>
> #include <linux/module.h>
> #include <linux/slab.h>
> @@ -257,6 +258,14 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
> memcpy(&endpoint->desc, d, n);
> INIT_LIST_HEAD(&endpoint->urb_list);
>
> + /* device node property overrides bInterval */
> + if (usb_of_has_combined_node(to_usb_device(ddev))) {
Not only hubs have combined nodes so you probably need to check
bDeviceClass here instead.
> + u32 interval = 0;
> + if (!of_property_read_u32(ddev->of_node, "hub,interval",
> + &interval))
> + d->bInterval = min_t(u8, interval, 255);
You want min_t(u32, ...) here to avoid surprises when someone specifies
a value > 255.
> + }
> +
> /*
> * Fix up bInterval values outside the legal range.
> * Use 10 or 8 ms if no proper value can be guessed.
Johan