All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: core: balance phy init and exit
@ 2021-09-08  2:28 Li Jun
  2021-09-09  2:08 ` John Stultz
  2021-09-09  5:12 ` Felipe Balbi
  0 siblings, 2 replies; 3+ messages in thread
From: Li Jun @ 2021-09-08  2:28 UTC (permalink / raw)
  To: balbi, gregkh
  Cc: Thinh.Nguyen, chenyu56, john.stultz, linux-usb, jun.li,
	faqiang.zhu, linux-imx

After we start to do core soft reset while usb role switch,
the phy init is invoked at every switch to device mode, but
its counter part de-init is missing, this causes the actual
phy init can not be done when we really want to re-init phy
like system resume, because the counter maintained by phy
core is not 0. considering phy init is actually redundant for
role switch, so move out the phy init from core soft reset to
dwc3 core init where is the only place required.

Fixes: f88359e1588b ("usb: dwc3: core: Do core softreset when switch mode")
Cc: <stable@vger.kernel.org>
Tested-by: faqiang.zhu <faqiang.zhu@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/usb/dwc3/core.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 4483275afb8a..a02229517d2f 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -264,19 +264,6 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
 {
 	u32		reg;
 	int		retries = 1000;
-	int		ret;
-
-	usb_phy_init(dwc->usb2_phy);
-	usb_phy_init(dwc->usb3_phy);
-	ret = phy_init(dwc->usb2_generic_phy);
-	if (ret < 0)
-		return ret;
-
-	ret = phy_init(dwc->usb3_generic_phy);
-	if (ret < 0) {
-		phy_exit(dwc->usb2_generic_phy);
-		return ret;
-	}
 
 	/*
 	 * We're resetting only the device side because, if we're in host mode,
@@ -310,9 +297,6 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
 			udelay(1);
 	} while (--retries);
 
-	phy_exit(dwc->usb3_generic_phy);
-	phy_exit(dwc->usb2_generic_phy);
-
 	return -ETIMEDOUT;
 
 done:
@@ -1010,9 +994,21 @@ static int dwc3_core_init(struct dwc3 *dwc)
 		dwc->phys_ready = true;
 	}
 
+	usb_phy_init(dwc->usb2_phy);
+	usb_phy_init(dwc->usb3_phy);
+	ret = phy_init(dwc->usb2_generic_phy);
+	if (ret < 0)
+		goto err0a;
+
+	ret = phy_init(dwc->usb3_generic_phy);
+	if (ret < 0) {
+		phy_exit(dwc->usb2_generic_phy);
+		goto err0a;
+	}
+
 	ret = dwc3_core_soft_reset(dwc);
 	if (ret)
-		goto err0a;
+		goto err1;
 
 	if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD &&
 	    !DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) {
-- 
2.25.1


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

* Re: [PATCH] usb: dwc3: core: balance phy init and exit
  2021-09-08  2:28 [PATCH] usb: dwc3: core: balance phy init and exit Li Jun
@ 2021-09-09  2:08 ` John Stultz
  2021-09-09  5:12 ` Felipe Balbi
  1 sibling, 0 replies; 3+ messages in thread
From: John Stultz @ 2021-09-09  2:08 UTC (permalink / raw)
  To: Li Jun
  Cc: Felipe Balbi, Greg Kroah-Hartman, Thinh Nguyen, Chen Yu,
	Linux USB List, faqiang.zhu, dl-linux-imx

On Tue, Sep 7, 2021 at 7:51 PM Li Jun <jun.li@nxp.com> wrote:
>
> After we start to do core soft reset while usb role switch,
> the phy init is invoked at every switch to device mode, but
> its counter part de-init is missing, this causes the actual
> phy init can not be done when we really want to re-init phy
> like system resume, because the counter maintained by phy
> core is not 0. considering phy init is actually redundant for
> role switch, so move out the phy init from core soft reset to
> dwc3 core init where is the only place required.
>
> Fixes: f88359e1588b ("usb: dwc3: core: Do core softreset when switch mode")
> Cc: <stable@vger.kernel.org>
> Tested-by: faqiang.zhu <faqiang.zhu@nxp.com>
> Signed-off-by: Li Jun <jun.li@nxp.com>

Tested-by: John Stultz <john.stultz@linaro.org> #HiKey960

thanks!
-john

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

* Re: [PATCH] usb: dwc3: core: balance phy init and exit
  2021-09-08  2:28 [PATCH] usb: dwc3: core: balance phy init and exit Li Jun
  2021-09-09  2:08 ` John Stultz
@ 2021-09-09  5:12 ` Felipe Balbi
  1 sibling, 0 replies; 3+ messages in thread
From: Felipe Balbi @ 2021-09-09  5:12 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh, Thinh.Nguyen, chenyu56, john.stultz, linux-usb,
	faqiang.zhu, linux-imx, kishon


Hi,

Li Jun <jun.li@nxp.com> writes:

> After we start to do core soft reset while usb role switch,
> the phy init is invoked at every switch to device mode, but
> its counter part de-init is missing, this causes the actual
> phy init can not be done when we really want to re-init phy
> like system resume, because the counter maintained by phy
> core is not 0. considering phy init is actually redundant for
> role switch, so move out the phy init from core soft reset to
> dwc3 core init where is the only place required.
>
> Fixes: f88359e1588b ("usb: dwc3: core: Do core softreset when switch mode")
> Cc: <stable@vger.kernel.org>
> Tested-by: faqiang.zhu <faqiang.zhu@nxp.com>
> Signed-off-by: Li Jun <jun.li@nxp.com>

we need a few more Tested-bys, but patch looks good:

Acked-by: Felipe Balbi <balbi@kernel.org>

-- 
balbi

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

end of thread, other threads:[~2021-09-09  5:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08  2:28 [PATCH] usb: dwc3: core: balance phy init and exit Li Jun
2021-09-09  2:08 ` John Stultz
2021-09-09  5:12 ` Felipe Balbi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.