Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: musb: musb_dsps: Wait for controller reset
@ 2026-10-14 17:47 Ettore Chimenti
  2026-10-14 17:59 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ettore Chimenti @ 2026-10-14 17:47 UTC (permalink / raw)
  To: Bin Liu, Greg Kroah-Hartman, Felipe Balbi, Ravi Babu,
	Ajay Kumar Gupta, andrew.goodbody, rouven.czerwinski
  Cc: linux-usb, linux-kernel, Ettore Chimenti

From: Andrew Goodbody <andrew.goodbody@linaro.org>

After soft resetting the USB controller wait for it to complete and then
set the mode of the controller. This ensures that the controller is in a
sane state. The timeout value used is just large as the board is likely
broken if it is ever reached so no need to optimise. It was tested with
a timeout of 500us which worked so gave it a 10x safety margin and used
5000us as the timeout value.

Fixes: 9ecb887522a0 ("usb: musb: Add support for ti81xx platform")
Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Signed-off-by: Ettore Chimenti <ettore.chimenti@linaro.org>
---
 drivers/usb/musb/musb_dsps.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index e3935f18dd56..d909c45c253d 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -15,6 +15,7 @@
  */
 
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/irq.h>
 #include <linux/err.h>
 #include <linux/platform_device.h>
@@ -35,6 +36,7 @@
 #include "musb_core.h"
 
 static const struct of_device_id musb_dsps_of_match[];
+static int dsps_musb_set_mode(struct musb *musb, u8 mode);
 
 /*
  * DSPS musb wrapper register offset.
@@ -466,7 +468,13 @@ static int dsps_musb_init(struct musb *musb)
 	timer_setup(&musb->dev_timer, otg_timer, 0);
 
 	/* Reset the musb */
-	musb_writel(reg_base, wrp->control, (1 << wrp->reset));
+	musb_writel(reg_base, wrp->control, BIT(wrp->reset));
+	read_poll_timeout(musb_readl, val, !(val & BIT(wrp->reset)), 2, 5000,
+			  false, reg_base, wrp->control);
+	if (val & BIT(wrp->reset))
+		return -ENODEV;
+
+	dsps_musb_set_mode(musb, musb->port_mode);
 
 	musb->isr = dsps_interrupt;
 

---
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
change-id: 20261014-patch-ektor5-dm8168-usb-d6ca2a5189f6

Best regards,
--  
Ettore Chimenti <ettore.chimenti@linaro.org>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: musb: musb_dsps: Wait for controller reset
  2026-10-14 17:47 [PATCH] usb: musb: musb_dsps: Wait for controller reset Ettore Chimenti
@ 2026-10-14 17:59 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-10-14 17:59 UTC (permalink / raw)
  To: Ettore Chimenti; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] usb: musb: dsps: PHY resource leak on reset timeout error path
--

commit dd6538e5ce8a20102c268b6b495d88356ce426bd
Author: Andrew Goodbody <andrew.goodbody@linaro.org>

usb: musb: musb_dsps: Wait for controller reset

This commit introduces a polling delay after soft resetting the USB controller
to ensure it completes before setting the controller mode. It uses a timeout of
5000us with read_poll_timeout to verify the controller reaches a sane state.

> diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
> index e3935f18dd56c..d909c45c253d4 100644
> --- a/drivers/usb/musb/musb_dsps.c
> +++ b/drivers/usb/musb/musb_dsps.c

[ ... ]

> @@ -466,7 +468,13 @@ static int dsps_musb_init(struct musb *musb)
>  	timer_setup(&musb->dev_timer, otg_timer, 0);
>  
>  	/* Reset the musb */
> -	musb_writel(reg_base, wrp->control, (1 << wrp->reset));
> +	musb_writel(reg_base, wrp->control, BIT(wrp->reset));
> +	read_poll_timeout(musb_readl, val, !(val & BIT(wrp->reset)), 2, 5000,
> +			  false, reg_base, wrp->control);
> +	if (val & BIT(wrp->reset))
> +		return -ENODEV;

[Severity: Medium]
If the controller reset times out here, does this leak the previously
initialized PHY?

Looking earlier in dsps_musb_init(), the PHY is initialized and powered on:

        ret = phy_init(musb->phy);
        if (ret < 0)
                return ret;
        ret = phy_power_on(musb->phy);
        if (ret) {
                phy_exit(musb->phy);
                return ret;
        }

If the hardware reset does not complete within 5000us, this new polling loop
times out and the function returns -ENODEV directly. This skips calling
phy_power_off() and phy_exit() to tear the PHY down.

Should we be adding cleanup for musb->phy on this error path?

> +
> +	dsps_musb_set_mode(musb, musb->port_mode);
>  
>  	musb->isr = dsps_interrupt;
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261014-patch-ektor5-dm8168-usb-v1-1-9670414271d6@linaro.org?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-14 17:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-14 17:47 [PATCH] usb: musb: musb_dsps: Wait for controller reset Ettore Chimenti
2026-10-14 17:59 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox