Linux USB
 help / color / mirror / Atom feed
* [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init
@ 2026-11-23  6:54 Bobek Brzeczyszczykiewicz via B4 Relay
  2026-11-23  6:54 ` [PATCH v2 1/3] usb: musb: " Bobek Brzeczyszczykiewicz via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Bobek Brzeczyszczykiewicz via B4 Relay @ 2026-11-23  6:54 UTC (permalink / raw)
  To: Bin Liu, Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Philipp Zabel, Vinod Koul, Neil Armstrong,
	Manivannan Sadhasivam, Hans de Goede, Felipe Balbi,
	Kishon Vijay Abraham I, Maxime Ripard, Andre Przywara
  Cc: linux-usb, linux-arm-kernel, linux-sunxi, linux-kernel, linux-phy,
	Bobek Brzeczyszczykiewicz

When a bootloader such as U-Boot (for example with
CONFIG_USB_MUSB_HOST=y) initializes USB host mode and boots Linux
without stopping USB first, both the MUSB controller and USB PHY
reset lines are already deasserted when Linux probes them.

Because reset_control_deassert() alone is a no-op on an already
deasserted reset line, stale hardware 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.

This series ensures both the MUSB controller and USB PHYs are reset
cleanly regardless of prior bootloader state, and fixes a related
PHY2 clock reference imbalance spotted during review:

- Patch 1 uses devm_reset_control_get_exclusive() and briefly asserts
  glue->rst in sunxi_musb_init().
- Patch 2 uses devm_reset_control_get_exclusive() and asserts all PHY
  resets in sun4i_usb_phy_probe() before registering the PHY provider,
  avoiding disrupting shared PHY2 on SoCs with needs_phy2_siddq.
- Patch 3 fixes a pre-existing phy2->clk2 reference imbalance in
  sun4i_usb_phy_init() on SoCs with needs_phy2_siddq.

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

Signed-off-by: Bobek Brzeczyszczykiewicz <admin@roadbobek.com>
---
Changes in v2:
- Use devm_reset_control_get_exclusive() in both sunxi_musb_probe() and
  sun4i_usb_phy_probe() (Philipp Zabel).
- Move the USB PHY reset assertion from sun4i_usb_phy_init() to
  sun4i_usb_phy_probe() so initializing PHY2 on SoCs with
  needs_phy2_siddq does not reset an already active shared PHY2.
- Add Fixes tags to both reset patches.
- Add Patch 3 fixing the pre-existing phy2->clk2 clock reference
  imbalance in sun4i_usb_phy_init().
- Link to v1: https://patch.msgid.link/20261117-usb-sunxi-reset-fix-v1-0-c2b76e0e84e1@roadbobek.com

To: Bin Liu <b-liu@ti.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Chen-Yu Tsai <wens@kernel.org>
To: Jernej Skrabec <jernej.skrabec@gmail.com>
To: Samuel Holland <samuel@sholland.org>
To: Philipp Zabel <p.zabel@pengutronix.de>
To: Hans de Goede <hansg@kernel.org>
To: Felipe Balbi <balbi@ti.com>
To: Vinod Koul <vkoul@kernel.org>
To: Neil Armstrong <neil.armstrong@linaro.org>
To: Manivannan Sadhasivam <mani@kernel.org>
To: Kishon Vijay Abraham I <kishon@kernel.org>
To: Maxime Ripard <mripard@kernel.org>
To: Andre Przywara <andre.przywara@arm.com>
Cc: linux-usb@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-sunxi@lists.linux.dev
Cc: linux-kernel@vger.kernel.org
Cc: linux-phy@lists.infradead.org

---
Bobek Brzeczyszczykiewicz (3):
      usb: musb: sunxi: Assert reset before deasserting on init
      phy: sun4i-usb: Assert PHY resets in sun4i_usb_phy_probe()
      phy: sun4i-usb: Fix phy2->clk2 reference imbalance in sun4i_usb_phy_init()

 drivers/phy/allwinner/phy-sun4i-usb.c | 23 +++++++++++++++++++++--
 drivers/usb/musb/sunxi.c              |  5 ++++-
 2 files changed, 25 insertions(+), 3 deletions(-)
---
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
change-id: 20261117-usb-sunxi-reset-fix-d1a0001440a9

Best regards,
--  
Bobek Brzeczyszczykiewicz <admin@roadbobek.com>



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

* [PATCH v2 1/3] usb: musb: sunxi: Assert reset before deasserting on init
  2026-11-23  6:54 [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init Bobek Brzeczyszczykiewicz via B4 Relay
@ 2026-11-23  6:54 ` Bobek Brzeczyszczykiewicz via B4 Relay
  2026-11-23  7:00   ` sashiko-bot
  2026-11-23  6:54 ` [PATCH v2 2/3] phy: sun4i-usb: Assert PHY resets in sun4i_usb_phy_probe() Bobek Brzeczyszczykiewicz via B4 Relay
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Bobek Brzeczyszczykiewicz via B4 Relay @ 2026-11-23  6:54 UTC (permalink / raw)
  To: Bin Liu, Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Philipp Zabel, Vinod Koul, Neil Armstrong,
	Manivannan Sadhasivam, Hans de Goede, Felipe Balbi,
	Kishon Vijay Abraham I, Maxime Ripard, Andre Przywara
  Cc: linux-usb, linux-arm-kernel, linux-sunxi, linux-kernel, linux-phy,
	Bobek Brzeczyszczykiewicz

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(-)

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");

-- 
2.53.0



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

* [PATCH v2 2/3] phy: sun4i-usb: Assert PHY resets in sun4i_usb_phy_probe()
  2026-11-23  6:54 [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init Bobek Brzeczyszczykiewicz via B4 Relay
  2026-11-23  6:54 ` [PATCH v2 1/3] usb: musb: " Bobek Brzeczyszczykiewicz via B4 Relay
@ 2026-11-23  6:54 ` Bobek Brzeczyszczykiewicz via B4 Relay
  2026-11-23  6:54 ` [PATCH v2 3/3] phy: sun4i-usb: Fix phy2->clk2 reference imbalance in sun4i_usb_phy_init() Bobek Brzeczyszczykiewicz via B4 Relay
  2026-11-23  7:00 ` [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: Bobek Brzeczyszczykiewicz via B4 Relay @ 2026-11-23  6:54 UTC (permalink / raw)
  To: Bin Liu, Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Philipp Zabel, Vinod Koul, Neil Armstrong,
	Manivannan Sadhasivam, Hans de Goede, Felipe Balbi,
	Kishon Vijay Abraham I, Maxime Ripard, Andre Przywara
  Cc: linux-usb, linux-arm-kernel, linux-sunxi, linux-kernel, linux-phy,
	Bobek Brzeczyszczykiewicz

From: Bobek Brzeczyszczykiewicz <admin@roadbobek.com>

When a bootloader initializes USB before booting Linux without first
tearing down the controller, phy->reset may already be deasserted when
Linux probes the USB PHY driver.

Because reset_control_deassert() alone is a no-op on an already
deasserted reset line, stale USB PHY state can persist across the
bootloader-to-kernel handoff. Asserting phy->reset inside
sun4i_usb_phy_init(), however, could disrupt active PHYs on SoCs with
needs_phy2_siddq (such as the Allwinner H616), where PHY0, PHY1, and
PHY3 depend on PHY2 remaining out of reset once enabled.

Request exclusive reset controls via devm_reset_control_get_exclusive()
and assert all PHY resets in sun4i_usb_phy_probe() before registering
the PHY provider so every PHY starts from a clean reset state before
any consumer calls sun4i_usb_phy_init().

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

Fixes: ba4bdc9e1dc0 ("PHY: sunxi: Add driver for sunxi usb phy")
Signed-off-by: Bobek Brzeczyszczykiewicz <admin@roadbobek.com>
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index f26eed0db17e..a62558124d2d 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -787,7 +787,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
 			continue;
 
 		snprintf(name, sizeof(name), "usb%d_reset", i);
-		phy->reset = devm_reset_control_get(dev, name);
+		phy->reset = devm_reset_control_get_exclusive(dev, name);
 		if (IS_ERR(phy->reset)) {
 			if (PTR_ERR(phy->reset) == -ENOENT)
 				break;
@@ -855,6 +855,25 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
 	}
 	data->num_phys = i;
 
+	/*
+	 * Assert reset on each PHY before they get deasserted in
+	 * sun4i_usb_phy_init(), in case the bootloader left them active.
+	 */
+	for (i = 0; i < data->num_phys; i++) {
+		struct sun4i_usb_phy *phy = data->phys + i;
+
+		if (data->cfg->missing_phys & BIT(i))
+			continue;
+
+		ret = reset_control_assert(phy->reset);
+		if (ret) {
+			dev_err(dev, "Err asserting reset on PHY: %d\n", ret);
+			return ret;
+		}
+	}
+
+	usleep_range(10, 20); /* hold PHY in reset briefly */
+
 	data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
 	if (data->id_det_irq > 0) {
 		ret = devm_request_irq(dev, data->id_det_irq,

-- 
2.53.0



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

* [PATCH v2 3/3] phy: sun4i-usb: Fix phy2->clk2 reference imbalance in sun4i_usb_phy_init()
  2026-11-23  6:54 [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init Bobek Brzeczyszczykiewicz via B4 Relay
  2026-11-23  6:54 ` [PATCH v2 1/3] usb: musb: " Bobek Brzeczyszczykiewicz via B4 Relay
  2026-11-23  6:54 ` [PATCH v2 2/3] phy: sun4i-usb: Assert PHY resets in sun4i_usb_phy_probe() Bobek Brzeczyszczykiewicz via B4 Relay
@ 2026-11-23  6:54 ` Bobek Brzeczyszczykiewicz via B4 Relay
  2026-11-23  7:00 ` [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: Bobek Brzeczyszczykiewicz via B4 Relay @ 2026-11-23  6:54 UTC (permalink / raw)
  To: Bin Liu, Greg Kroah-Hartman, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Philipp Zabel, Vinod Koul, Neil Armstrong,
	Manivannan Sadhasivam, Hans de Goede, Felipe Balbi,
	Kishon Vijay Abraham I, Maxime Ripard, Andre Przywara
  Cc: linux-usb, linux-arm-kernel, linux-sunxi, linux-kernel, linux-phy,
	Bobek Brzeczyszczykiewicz

From: Bobek Brzeczyszczykiewicz <admin@roadbobek.com>

In sun4i_usb_phy_init(), the needs_phy2_siddq path enables phy2->clk2
to access the REG_HCI_PHY_CTL PMU register for PHY2, but then disables
phy->clk2 instead of phy2->clk2.

This leaks a prepare/enable reference on phy2->clk2 while prematurely
disabling phy->clk2, causing a clock disable/unprepare underflow when
sun4i_usb_phy_exit() later runs.

Disable and unprepare phy2->clk2 instead of phy->clk2.

Fixes: b45c6d80325b ("phy: sun4i-usb: Introduce port2 SIDDQ quirk")
Signed-off-by: Bobek Brzeczyszczykiewicz <admin@roadbobek.com>
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index a62558124d2d..6e35eb77c879 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -318,7 +318,7 @@ static int sun4i_usb_phy_init(struct phy *_phy)
 			writel(val, phy2->pmu + REG_HCI_PHY_CTL);
 		}
 
-		clk_disable_unprepare(phy->clk2);
+		clk_disable_unprepare(phy2->clk2);
 	}
 
 	if (phy->pmu && data->cfg->hci_phy_ctl_clear) {

-- 
2.53.0



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

* Re: [PATCH v2 1/3] usb: musb: sunxi: Assert reset before deasserting on init
  2026-11-23  6:54 ` [PATCH v2 1/3] usb: musb: " Bobek Brzeczyszczykiewicz via B4 Relay
@ 2026-11-23  7:00   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-23  7:00 UTC (permalink / raw)
  To: Bobek Brzeczyszczykiewicz
  Cc: linux-usb, linux-sunxi, linux-phy, vkoul, neil.armstrong, olteanv

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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-usb-sunxi-reset-fix-v2-0-4e51d3a64964@roadbobek.com?part=1

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

* Re: [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init
  2026-11-23  6:54 [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init Bobek Brzeczyszczykiewicz via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-23  6:54 ` [PATCH v2 3/3] phy: sun4i-usb: Fix phy2->clk2 reference imbalance in sun4i_usb_phy_init() Bobek Brzeczyszczykiewicz via B4 Relay
@ 2026-11-23  7:00 ` sashiko-bot
  3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-23  7:00 UTC (permalink / raw)
  To: Bobek Brzeczyszczykiewicz; +Cc: linux-usb

Sashiko has finished reviewing this 3-patch series:

- Patches 2 and 3: no issues found.
- Patch 1 ("usb: musb: sunxi: Assert reset before deasserting on..."): 1
  potential issue (1 Low)

A detailed review has been sent as a separate reply to patch 1.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-usb-sunxi-reset-fix-v2-0-4e51d3a64964@roadbobek.com

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

end of thread, other threads:[~2026-11-23  7:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  6:54 [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init Bobek Brzeczyszczykiewicz via B4 Relay
2026-11-23  6:54 ` [PATCH v2 1/3] usb: musb: " Bobek Brzeczyszczykiewicz via B4 Relay
2026-11-23  7:00   ` sashiko-bot
2026-11-23  6:54 ` [PATCH v2 2/3] phy: sun4i-usb: Assert PHY resets in sun4i_usb_phy_probe() Bobek Brzeczyszczykiewicz via B4 Relay
2026-11-23  6:54 ` [PATCH v2 3/3] phy: sun4i-usb: Fix phy2->clk2 reference imbalance in sun4i_usb_phy_init() Bobek Brzeczyszczykiewicz via B4 Relay
2026-11-23  7:00 ` [PATCH v2 0/3] usb/phy: sunxi: Assert reset before deasserting on init sashiko-bot

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