[v2,1/3] usb: musb: sunxi: Assert reset before deasserting on init

Message ID 20261123-usb-sunxi-reset-fix-v2-1-4e51d3a64964@roadbobek.com (mailing list archive)
State New
Headers
Series usb/phy: sunxi: Assert reset before deasserting on init |

Commit Message

Bobek Brzeczyszczykiewicz via B4 Relay Nov. 23, 2026, 6:54 a.m. UTC
From: Bobek Brzeczyszczykiewicz <admin@roadbobek.com>

When a bootloader such as U-Boot (for example with
CONFIG_USB_MUSB_HOST=y) initializes MUSB and boots Linux without
stopping USB first, the controller reset line is already deasserted at
probe time.

In that case reset_control_deassert() in sunxi_musb_init() is a no-op
and stale MUSB register state persists across boot. On Allwinner A33,
MUSB stays wedged in a_wait_bcon with DevCtl=0x99, Power=0xf0, and a
frozen Frame counter even across hot-unplug and replug.

Request exclusive reset control via devm_reset_control_get_exclusive()
and assert glue->rst briefly before deasserting it when
SUNXI_MUSB_FL_HAS_RESET is set so MUSB starts cleanly.

Tested on an Allwinner A33 Q8 tablet (Laser MID-786).

Fixes: 132e23775779 ("usb: musb: sunxi: Add support for musb controller in A31 SoC")
Signed-off-by: Bobek Brzeczyszczykiewicz <admin@roadbobek.com>
---
 drivers/usb/musb/sunxi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

sashiko-bot@kernel.org Nov. 23, 2026, 7 a.m. UTC | #1
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: musb: sunxi: unchecked reset_control_assert() in
  sunxi_musb_init()
--

commit 979d5486eac0aa36960d582b6b645fa08e41d62e
Author: Bobek Brzeczyszczykiewicz <admin@roadbobek.com>

usb: musb: sunxi: Assert reset before deasserting on init

This commit requests an exclusive reset control in sunxi_musb_probe() and
briefly asserts glue->rst before deasserting it in sunxi_musb_init() so
that MUSB starts from a clean state when a bootloader left the reset line
deasserted.

> diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
> index a17b1c150626b..5f63d519237b4 100644
> --- a/drivers/usb/musb/sunxi.c
> +++ b/drivers/usb/musb/sunxi.c
[ ... ]
> @@ -239,6 +240,8 @@ static int sunxi_musb_init(struct musb *musb)
>  		goto error_sram_release;
>  
>  	if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) {
> +		reset_control_assert(glue->rst);
> +		usleep_range(10, 20);
>  		ret = reset_control_deassert(glue->rst);
>  		if (ret)
>  			goto error_clk_disable;

[Severity: Low]
As reported by Philipp Zabel on v1 [1], should the return value of
reset_control_assert(glue->rst) be checked and jump to error_clk_disable
on failure, matching reset_control_deassert() right below?

[1] https://lore.kernel.org/r/974d629b23d38d46a033513db9b4e783b9c11cda.camel@pengutronix.de
  

Patch

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index a17b1c150626..5f63d519237b 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -9,6 +9,7 @@ 
  */
 
 #include <linux/clk.h>
+#include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/extcon.h>
 #include <linux/io.h>
@@ -239,6 +240,8 @@  static int sunxi_musb_init(struct musb *musb)
 		goto error_sram_release;
 
 	if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) {
+		reset_control_assert(glue->rst);
+		usleep_range(10, 20);
 		ret = reset_control_deassert(glue->rst);
 		if (ret)
 			goto error_clk_disable;
@@ -745,7 +748,7 @@  static int sunxi_musb_probe(struct platform_device *pdev)
 	}
 
 	if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) {
-		glue->rst = devm_reset_control_get(&pdev->dev, NULL);
+		glue->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
 		if (IS_ERR(glue->rst))
 			return dev_err_probe(&pdev->dev, PTR_ERR(glue->rst),
 					     "Error getting reset\n");