[PATCH 1/2] usb: hub: introduce HUB_DEBOUNCE_TIMEOUT

Introduce define for connection timeout, named HUB_DEBOUNCE_TIMEOUT as in linux kernel drivers/usb/core/hub.c
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
common/usb_hub.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/common/usb_hub.c b/common/usb_hub.c index ba11a188ca6..d73638950b9 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -47,6 +47,8 @@ #define HUB_SHORT_RESET_TIME 20 #define HUB_LONG_RESET_TIME 200
+#define HUB_DEBOUNCE_TIMEOUT 1000 + #define PORT_OVERCURRENT_MAX_SCAN_COUNT 3
struct usb_device_scan { @@ -208,10 +210,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub) * will be done based on this value in the USB port loop in * usb_hub_configure() later. */ - hub->connect_timeout = hub->query_delay + 1000; + hub->connect_timeout = hub->query_delay + HUB_DEBOUNCE_TIMEOUT; debug("devnum=%d poweron: query_delay=%d connect_timeout=%d\n", dev->devnum, max(100, (int)pgood_delay), - max(100, (int)pgood_delay) + 1000); + max(100, (int)pgood_delay) + HUB_DEBOUNCE_TIMEOUT); }
#if !CONFIG_IS_ENABLED(DM_USB)

Increase HUB_DEBOUNCE_TIMEOUT to 2000 because some usb device needs around 1.5s or more to make the hub port status to be connected steadily after being powered off and powered on.
These value is aligned with Linux driver and avoids to configure "usb_pgood_delay" as a workaround for connection timeout on some USB device; normally the env variable "usb_pgood_delay" is used to delay the first query after power ON and thus the device answer, but this variable not to increase the connection timeout delay.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com --- Hi,
I think this patch solves a general issue because a 1s timeout for USB connection is too short on problematic USB keys / USB HUB. The issue was introduced by the commit c998da0d6709 ("usb: Change power-on / scanning timeout handling")
Patching usb_hub allows to avoid to patch in each board/driver.
For example, commit 0417169054cb ("imx: ventana: add usb_pgood_delay 2sec default") => use pgood_delay = 2s !?
or ("ARM: stm32: Increase USB power-good delay on DHSOM") https://patchwork.ozlabs.org/project/uboot/patch/20211113022444.231801-1-mar...
or commit 2bf352f0c1b7 ("usb: dwc2: Add delay to fix the USB detection problem on SoCFPGA") => patch in USB DWC2 driver to add a timeout in driver
The commit 319418c01c95 ("usb: hub: allow pgood_delay to be specified via env") introduces an env variable for warm-up times managed by hub->query_delay.
But it is not linked to the connect timeout after power on managed by hub->connect_timeout.
This patch can increase the boot time for some board when USB device is not available; if it is a problem I can introduce a new config: CONFIG_USB_HUB_DEBOUNCE_TIMEOUT to define this value with default = 1s to keep the current behavior.
This issue appears with DWC2 and USB HUB used in STM32MP135F-DK board; pgood_delay=2 is not enough to solved all the USB key detection issues.
Patrick
common/usb_hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/usb_hub.c b/common/usb_hub.c index d73638950b9..e681f1b3073 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -47,7 +47,7 @@ #define HUB_SHORT_RESET_TIME 20 #define HUB_LONG_RESET_TIME 200
-#define HUB_DEBOUNCE_TIMEOUT 1000 +#define HUB_DEBOUNCE_TIMEOUT 2000
#define PORT_OVERCURRENT_MAX_SCAN_COUNT 3

On 7/4/22 12:45, Patrick Delaunay wrote:
Increase HUB_DEBOUNCE_TIMEOUT to 2000 because some usb device needs around 1.5s or more to make the hub port status to be connected steadily after being powered off and powered on.
These value is aligned with Linux driver and avoids to configure "usb_pgood_delay" as a workaround for connection timeout on some USB device; normally the env variable "usb_pgood_delay" is used to delay the first query after power ON and thus the device answer, but this variable not to increase the connection timeout delay.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
Hi,
I think this patch solves a general issue because a 1s timeout for USB connection is too short on problematic USB keys / USB HUB. The issue was introduced by the commit c998da0d6709 ("usb: Change power-on / scanning timeout handling")
Patching usb_hub allows to avoid to patch in each board/driver.
For example, commit 0417169054cb ("imx: ventana: add usb_pgood_delay 2sec default") => use pgood_delay = 2s !?
or ("ARM: stm32: Increase USB power-good delay on DHSOM") https://patchwork.ozlabs.org/project/uboot/patch/20211113022444.231801-1-mar...
or commit 2bf352f0c1b7 ("usb: dwc2: Add delay to fix the USB detection problem on SoCFPGA") => patch in USB DWC2 driver to add a timeout in driver
The commit 319418c01c95 ("usb: hub: allow pgood_delay to be specified via env") introduces an env variable for warm-up times managed by hub->query_delay.
But it is not linked to the connect timeout after power on managed by hub->connect_timeout.
This patch can increase the boot time for some board when USB device is not available; if it is a problem I can introduce a new config: CONFIG_USB_HUB_DEBOUNCE_TIMEOUT to define this value with default = 1s to keep the current behavior.
This issue appears with DWC2 and USB HUB used in STM32MP135F-DK board; pgood_delay=2 is not enough to solved all the USB key detection issues.
Patrick
common/usb_hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/usb_hub.c b/common/usb_hub.c index d73638950b9..e681f1b3073 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -47,7 +47,7 @@ #define HUB_SHORT_RESET_TIME 20 #define HUB_LONG_RESET_TIME 200
-#define HUB_DEBOUNCE_TIMEOUT 1000 +#define HUB_DEBOUNCE_TIMEOUT 2000
Do you think it is possible to make this somehow dynamic , so not all devices would wait so long ?

Hi Marek,
On 7/8/22 17:34, Marek Vasut wrote:
On 7/4/22 12:45, Patrick Delaunay wrote:
Increase HUB_DEBOUNCE_TIMEOUT to 2000 because some usb device needs around 1.5s or more to make the hub port status to be connected steadily after being powered off and powered on.
These value is aligned with Linux driver and avoids to configure "usb_pgood_delay" as a workaround for connection timeout on some USB device; normally the env variable "usb_pgood_delay" is used to delay the first query after power ON and thus the device answer, but this variable not to increase the connection timeout delay.
Signed-off-by: Patrick Delaunay patrick.delaunay@foss.st.com
Hi,
I think this patch solves a general issue because a 1s timeout for USB connection is too short on problematic USB keys / USB HUB. The issue was introduced by the commit c998da0d6709 ("usb: Change power-on / scanning timeout handling")
Patching usb_hub allows to avoid to patch in each board/driver.
For example, commit 0417169054cb ("imx: ventana: add usb_pgood_delay 2sec default") => use pgood_delay = 2s !?
or ("ARM: stm32: Increase USB power-good delay on DHSOM") https://patchwork.ozlabs.org/project/uboot/patch/20211113022444.231801-1-mar...
or commit 2bf352f0c1b7 ("usb: dwc2: Add delay to fix the USB detection problem on SoCFPGA") => patch in USB DWC2 driver to add a timeout in driver
The commit 319418c01c95 ("usb: hub: allow pgood_delay to be specified via env") introduces an env variable for warm-up times managed by hub->query_delay.
But it is not linked to the connect timeout after power on managed by hub->connect_timeout.
This patch can increase the boot time for some board when USB device is not available; if it is a problem I can introduce a new config: CONFIG_USB_HUB_DEBOUNCE_TIMEOUT to define this value with default = 1s to keep the current behavior.
This issue appears with DWC2 and USB HUB used in STM32MP135F-DK board; pgood_delay=2 is not enough to solved all the USB key detection issues.
Patrick
common/usb_hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/usb_hub.c b/common/usb_hub.c index d73638950b9..e681f1b3073 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -47,7 +47,7 @@ #define HUB_SHORT_RESET_TIME 20 #define HUB_LONG_RESET_TIME 200 -#define HUB_DEBOUNCE_TIMEOUT 1000 +#define HUB_DEBOUNCE_TIMEOUT 2000
Do you think it is possible to make this somehow dynamic , so not all devices would wait so long ?
Yes I do it in V2.
Patrick

On 9/8/22 13:20, Patrick DELAUNAY wrote:
[...]
diff --git a/common/usb_hub.c b/common/usb_hub.c index d73638950b9..e681f1b3073 100644 --- a/common/usb_hub.c +++ b/common/usb_hub.c @@ -47,7 +47,7 @@ #define HUB_SHORT_RESET_TIME 20 #define HUB_LONG_RESET_TIME 200 -#define HUB_DEBOUNCE_TIMEOUT 1000 +#define HUB_DEBOUNCE_TIMEOUT 2000
Do you think it is possible to make this somehow dynamic , so not all devices would wait so long ?
Yes I do it in V2.
Thank you
Maybe this should be a DT property of some regulator or some such.
participants (3)
-
Marek Vasut
-
Patrick DELAUNAY
-
Patrick Delaunay