diff mbox

[U-Boot] MUSB timeout broken

Message ID 4E11D02E.7030803@flatfrog.com
State Changes Requested
Headers show

Commit Message

Orjan Friberg July 4, 2011, 2:37 p.m. UTC
The following construct (musb_hcd.c, usb_lowlevel_init)

    timeout = musb_cfg.timeout;
         while (timeout--)
                 if (readb(&musbr->devctl) & MUSB_DEVCTL_HM)
                         break;

will leave timeout == -1 when the timeout is reached, hence the timeout 
detecting code that follows will not trigger:

         /* if musb core is not in host mode, then return */
         if (!timeout)
                 return -1;


Without the patch below, doing a 'usb reset' without a device connected 
makes it impossible to discover connected devices later.  I have not 
investigated why this happens since the timeout logic was broken (and 
correcting that fixed the issue at hand).

Changed to pre-decrement since I assume the timeout value is not *that* 
exact.

Thanks,
Orjan

Comments

Wolfgang Denk July 4, 2011, 3:07 p.m. UTC | #1
Dear Orjan Friberg,

In message <4E11D02E.7030803@flatfrog.com> you wrote:
> The following construct (musb_hcd.c, usb_lowlevel_init)
> 
>     timeout = musb_cfg.timeout;
>          while (timeout--)
>                  if (readb(&musbr->devctl) & MUSB_DEVCTL_HM)
>                          break;
> 
> will leave timeout == -1 when the timeout is reached, hence the timeout 
> detecting code that follows will not trigger:
> 
>          /* if musb core is not in host mode, then return */
>          if (!timeout)
>                  return -1;
> 
> 
> Without the patch below, doing a 'usb reset' without a device connected 
> makes it impossible to discover connected devices later.  I have not 
> investigated why this happens since the timeout logic was broken (and 
> correcting that fixed the issue at hand).
> 
> Changed to pre-decrement since I assume the timeout value is not *that* 
> exact.

Thanks for spotting and reporting.

> Thanks,
> Orjan
> 
> diff --git a/drivers/usb/musb/musb_hcd.c b/drivers/usb/musb/musb_hcd.c
> index 974bb31..adcf7f7 100644
> --- a/drivers/usb/musb/musb_hcd.c
> +++ b/drivers/usb/musb/musb_hcd.c
> @@ -1114,7 +1114,7 @@ int usb_lowlevel_init(void)
>           * should be a usb device connected.
>           */
>          timeout = musb_cfg.timeout;
> -       while (timeout--)
> +       while (--timeout)
>                  if (readb(&musbr->devctl) & MUSB_DEVCTL_HM)
>                          break;

Unfortunately, your patch is white space corrupted, and missing a
proper Signed-off-by: line.

Please fix and repost.  Thanks.

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/drivers/usb/musb/musb_hcd.c b/drivers/usb/musb/musb_hcd.c
index 974bb31..adcf7f7 100644
--- a/drivers/usb/musb/musb_hcd.c
+++ b/drivers/usb/musb/musb_hcd.c
@@ -1114,7 +1114,7 @@  int usb_lowlevel_init(void)
          * should be a usb device connected.
          */
         timeout = musb_cfg.timeout;
-       while (timeout--)
+       while (--timeout)
                 if (readb(&musbr->devctl) & MUSB_DEVCTL_HM)
                         break;