diff mbox series

[RESEND,3/3] usb.c: Add a retry in the usb_prepare_device()

Message ID 20200818143419.117637-4-jason.wessel@windriver.com
State Changes Requested
Delegated to: Marek Vasut
Headers show
Series Raspberry pi improvements usb core | expand

Commit Message

Jason Wessel Aug. 18, 2020, 2:34 p.m. UTC
I have found through testing some USB 2 composite mouse/keyboard
devices do not response to the usb_set_address call immediately
following the port reset.  It can take anywhere from 2ms to 20ms.

This patch adds a retry and delay for usb_prepare_device() and allows
all the USB keyboards I tried to function properly.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
 common/usb.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Marek Vasut Aug. 18, 2020, 3:08 p.m. UTC | #1
On 8/18/20 4:34 PM, Jason Wessel wrote:
> I have found through testing some USB 2 composite mouse/keyboard
> devices do not response to the usb_set_address call immediately
> following the port reset.  It can take anywhere from 2ms to 20ms.

Does it work if you do

=> setenv usb_pgood_delay 2000

before your test ?
Jason Wessel Aug. 18, 2020, 6:01 p.m. UTC | #2
From the Raspberry Pi3 - With the patch removed:

U-Boot> setenv usb_pgood_delay 2000
U-Boot> usb reset
resetting USB...
Bus usb@7e980000: USB DWC2
scanning bus usb@7e980000 for devices... unable to get device descriptor (error=-22)
6 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found


The only way I found to make it work reliably was to have it retry in the usb_prepare_device().

Jason.


On 8/18/20 10:08 AM, Marek Vasut wrote:
> On 8/18/20 4:34 PM, Jason Wessel wrote:
>> I have found through testing some USB 2 composite mouse/keyboard
>> devices do not response to the usb_set_address call immediately
>> following the port reset.  It can take anywhere from 2ms to 20ms.
> 
> Does it work if you do
> 
> => setenv usb_pgood_delay 2000
> 
> before your test ?
>
Marek Vasut Aug. 18, 2020, 9:06 p.m. UTC | #3
On 8/18/20 8:01 PM, Jason Wessel wrote:
>>From the Raspberry Pi3 - With the patch removed:
> 
> U-Boot> setenv usb_pgood_delay 2000
> U-Boot> usb reset
> resetting USB...
> Bus usb@7e980000: USB DWC2
> scanning bus usb@7e980000 for devices... unable to get device descriptor (error=-22)
> 6 USB Device(s) found
>        scanning usb for storage devices... 1 Storage Device(s) found
> 
> 
> The only way I found to make it work reliably was to have it retry in the usb_prepare_device().
> 
> Jason.
> 
> 
> On 8/18/20 10:08 AM, Marek Vasut wrote:
>> On 8/18/20 4:34 PM, Jason Wessel wrote:
>>> I have found through testing some USB 2 composite mouse/keyboard
>>> devices do not response to the usb_set_address call immediately
>>> following the port reset.  It can take anywhere from 2ms to 20ms.
>>
>> Does it work if you do
>>
>> => setenv usb_pgood_delay 2000
>>
>> before your test ?

Please stop top-posting.

Can you check whether the pgood_delay isn't EHCI-only ? It does sure
look similar to the problems which pgood_delay was supposed to help with.
diff mbox series

Patch

diff --git a/common/usb.c b/common/usb.c
index 0eb5d40a2d..39bae86a11 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -1032,6 +1032,7 @@  static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
 			      struct usb_device *parent)
 {
 	int err;
+	int retry_msec = 0;
 
 	/*
 	 * Allocate usb 3.0 device context.
@@ -1054,6 +1055,14 @@  static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
 	dev->devnum = addr;
 
 	err = usb_set_address(dev); /* set address */
+	/* Retry for old composite keyboard/mouse usb2 hardware */
+	while (err < 0 && retry_msec <= 40) {
+		retry_msec += 20;
+		mdelay(20);
+		err = usb_set_address(dev); /* set address */
+	}
+	if (retry_msec > 0)
+		debug("usb_set_address delay: %i\n", retry_msec);
 	if (err < 0)
 		debug("\n       usb_set_address return < 0\n");
 	if (err < 0 && dev->status != 0) {