diff mbox series

[RESEND,2/3] common/usb.c: Work around keyboard reporting "USB device not accepting new address"

Message ID 20200818143419.117637-3-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
When resetting the rpi3 board sometimes it will display:
     USB device not accepting new address (error=0)

After the message appears, the usb keyboard will not work.  It seems
that the configuration actually did succeed however.  Checking the
device status for a return code of zero and continuing allows the usb
keyboard and other usb devices to work function.

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

Comments

Marek Vasut Aug. 18, 2020, 3:08 p.m. UTC | #1
On 8/18/20 4:34 PM, Jason Wessel wrote:
> When resetting the rpi3 board sometimes it will display:
>      USB device not accepting new address (error=0)
> 
> After the message appears, the usb keyboard will not work.  It seems
> that the configuration actually did succeed however.  Checking the
> device status for a return code of zero and continuing allows the usb
> keyboard and other usb devices to work function.
> 
> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
> ---
>  common/usb.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/common/usb.c b/common/usb.c
> index aad13fd9c5..0eb5d40a2d 100644
> --- a/common/usb.c
> +++ b/common/usb.c
> @@ -1054,11 +1054,12 @@ static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
>  	dev->devnum = addr;
>  
>  	err = usb_set_address(dev); /* set address */
> -
> -	if (err < 0) {
> +	if (err < 0)
> +		debug("\n       usb_set_address return < 0\n");

Please print the return code here.

Is dev->status always set by usb_set_address() when err < 0 ?

> +	if (err < 0 && dev->status != 0) {
>  		printf("\n      USB device not accepting new address " \
>  			"(error=%lX)\n", dev->status);
> -		return err;
> +			return err;
>  	}
>  
>  	mdelay(10);	/* Let the SET_ADDRESS settle */
>
Jason Wessel Aug. 18, 2020, 6:16 p.m. UTC | #2
On 8/18/20 10:08 AM, Marek Vasut wrote:
> On 8/18/20 4:34 PM, Jason Wessel wrote:
>> When resetting the rpi3 board sometimes it will display:
>>      USB device not accepting new address (error=0)
>>
>> After the message appears, the usb keyboard will not work.  It seems
>> that the configuration actually did succeed however.  Checking the
>> device status for a return code of zero and continuing allows the usb
>> keyboard and other usb devices to work function.
>>
>> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
>> ---
>>  common/usb.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/common/usb.c b/common/usb.c
>> index aad13fd9c5..0eb5d40a2d 100644
>> --- a/common/usb.c
>> +++ b/common/usb.c
>> @@ -1054,11 +1054,12 @@ static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
>>  	dev->devnum = addr;
>>  
>>  	err = usb_set_address(dev); /* set address */
>> -
>> -	if (err < 0) {
>> +	if (err < 0)
>> +		debug("\n       usb_set_address return < 0\n");
> 
> Please print the return code here.

Good idea.

> 
> Is dev->status always set by usb_set_address() when err < 0 ?

Yes.  The status is filled in as far as I can tell.  I had
received other values when exceeding timing thresholds with
too many printfs() to the serial port while debugging.

The usb hardware hardware devices seem to like their initialization
to be completed in a timely manner.

Jason.

> 
>> +	if (err < 0 && dev->status != 0) {
>>  		printf("\n      USB device not accepting new address " \
>>  			"(error=%lX)\n", dev->status);
>> -		return err;
>> +			return err;
>>  	}
>>  
>>  	mdelay(10);	/* Let the SET_ADDRESS settle */
>>
Marek Vasut Aug. 18, 2020, 9:05 p.m. UTC | #3
On 8/18/20 8:16 PM, Jason Wessel wrote:
> 
> 
> On 8/18/20 10:08 AM, Marek Vasut wrote:
>> On 8/18/20 4:34 PM, Jason Wessel wrote:
>>> When resetting the rpi3 board sometimes it will display:
>>>      USB device not accepting new address (error=0)
>>>
>>> After the message appears, the usb keyboard will not work.  It seems
>>> that the configuration actually did succeed however.  Checking the
>>> device status for a return code of zero and continuing allows the usb
>>> keyboard and other usb devices to work function.
>>>
>>> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
>>> ---
>>>  common/usb.c | 7 ++++---
>>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/common/usb.c b/common/usb.c
>>> index aad13fd9c5..0eb5d40a2d 100644
>>> --- a/common/usb.c
>>> +++ b/common/usb.c
>>> @@ -1054,11 +1054,12 @@ static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
>>>  	dev->devnum = addr;
>>>  
>>>  	err = usb_set_address(dev); /* set address */
>>> -
>>> -	if (err < 0) {
>>> +	if (err < 0)
>>> +		debug("\n       usb_set_address return < 0\n");
>>
>> Please print the return code here.
> 
> Good idea.
> 
>>
>> Is dev->status always set by usb_set_address() when err < 0 ?
> 
> Yes.  The status is filled in as far as I can tell.  I had
> received other values when exceeding timing thresholds with
> too many printfs() to the serial port while debugging.
> 
> The usb hardware hardware devices seem to like their initialization
> to be completed in a timely manner.

I'd say, init the variable before usb_set_address with 0. All USB_ST_*
are non-zero, so no matter what usb_set_address() does,
usb_control_msg() will set dev->status to != 0, so the check is always
true then.
diff mbox series

Patch

diff --git a/common/usb.c b/common/usb.c
index aad13fd9c5..0eb5d40a2d 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -1054,11 +1054,12 @@  static int usb_prepare_device(struct usb_device *dev, int addr, bool do_read,
 	dev->devnum = addr;
 
 	err = usb_set_address(dev); /* set address */
-
-	if (err < 0) {
+	if (err < 0)
+		debug("\n       usb_set_address return < 0\n");
+	if (err < 0 && dev->status != 0) {
 		printf("\n      USB device not accepting new address " \
 			"(error=%lX)\n", dev->status);
-		return err;
+			return err;
 	}
 
 	mdelay(10);	/* Let the SET_ADDRESS settle */