mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Selvarasu Ganesan <selvarasu.g@samsung.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"balbi@ti.com" <balbi@ti.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"jh0801.jung@samsung.com" <jh0801.jung@samsung.com>,
	"dh10.jung@samsung.com" <dh10.jung@samsung.com>,
	"naushad@samsung.com" <naushad@samsung.com>,
	"akash.m5@samsung.com" <akash.m5@samsung.com>,
	"h10.kim@samsung.com" <h10.kim@samsung.com>,
	"eomji.oh@samsung.com" <eomji.oh@samsung.com>,
	"alim.akhtar@samsung.com" <alim.akhtar@samsung.com>,
	"thiagu.r@samsung.com" <thiagu.r@samsung.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v2] usb: dwc3: Fix timeout issue during controller enter/exit from halt state
Date: Mon, 3 Feb 2025 23:46:28 +0000	[thread overview]
Message-ID: <20250203234616.k5nl32tdb26jhtgf@synopsys.com> (raw)
In-Reply-To: <20250201163903.459-1-selvarasu.g@samsung.com>

On Sat, Feb 01, 2025, Selvarasu Ganesan wrote:
> There is a frequent timeout during controller enter/exit from halt state
> after toggling the run_stop bit by SW. This timeout occurs when
> performing frequent role switches between host and device, causing
> device enumeration issues due to the timeout. This issue was not present
> when USB2 suspend PHY was disabled by passing the SNPS quirks
> (snps,dis_u2_susphy_quirk and snps,dis_enblslpm_quirk) from the DTS.
> However, there is a requirement to enable USB2 suspend PHY by setting of
> GUSB2PHYCFG.ENBLSLPM and GUSB2PHYCFG.SUSPHY bits when controller starts
> in gadget or host mode results in the timeout issue.
> 
> This commit addresses this timeout issue by ensuring that the bits
> GUSB2PHYCFG.ENBLSLPM and GUSB2PHYCFG.SUSPHY are cleared before starting
> the dwc3_gadget_run_stop sequence and restoring them after the
> dwc3_gadget_run_stop sequence is completed.
> 
> Fixes: 72246da40f37 ("usb: Introduce DesignWare USB3 DRD Driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Selvarasu Ganesan <selvarasu.g@samsung.com>
> ---
> 
> Changes in v2:
>  - Added some comments before the changes.
>  - And removed "unlikely" in the condition check.
>  - Link to v1: https://urldefense.com/v3/__https://lore.kernel.org/linux-usb/20250131110832.438-1-selvarasu.g@samsung.com/__;!!A4F2R9G_pg!aIY9c56j1jjbSvIIW4zaudkdAGozvtMu-PwjhrMy0_v0FxGBaYhMXS8fTrVTzEOevr8QitekXvuOPKPfDxiHGa93hjI$ 
> ---
>  drivers/usb/dwc3/gadget.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index d27af65eb08a..ddd6b2ce5710 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2629,10 +2629,38 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
>  {
>  	u32			reg;
>  	u32			timeout = 2000;
> +	u32			saved_config = 0;
>  
>  	if (pm_runtime_suspended(dwc->dev))
>  		return 0;
>  
> +	/*
> +	 * When operating in USB 2.0 speeds (HS/FS), ensure that
> +	 * GUSB2PHYCFG.ENBLSLPM and GUSB2PHYCFG.SUSPHY are cleared before starting
> +	 * or stopping the controller. This resolves timeout issues that occur
> +	 * during frequent role switches between host and device modes.
> +	 *
> +	 * Save and clear these settings, then restore them after completing the
> +	 * controller start or stop sequence.
> +	 *
> +	 * This solution was discovered through experimentation as it is not
> +	 * mentioned in the dwc3 programming guide. It has been tested on an
> +	 * Exynos platforms.
> +	 */
> +	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
> +	if (reg & DWC3_GUSB2PHYCFG_SUSPHY) {
> +		saved_config |= DWC3_GUSB2PHYCFG_SUSPHY;
> +		reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
> +	}
> +
> +	if (reg & DWC3_GUSB2PHYCFG_ENBLSLPM) {
> +		saved_config |= DWC3_GUSB2PHYCFG_ENBLSLPM;
> +		reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
> +	}
> +
> +	if (saved_config)
> +		dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
> +
>  	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
>  	if (is_on) {
>  		if (DWC3_VER_IS_WITHIN(DWC3, ANY, 187A)) {
> @@ -2660,6 +2688,12 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
>  		reg &= DWC3_DSTS_DEVCTRLHLT;
>  	} while (--timeout && !(!is_on ^ !reg));
>  
> +	if (saved_config) {
> +		reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
> +		reg |= saved_config;
> +		dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
> +	}
> +
>  	if (!timeout)
>  		return -ETIMEDOUT;
>  
> -- 
> 2.17.1
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thanks,
Thinh

      reply	other threads:[~2025-02-03 23:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20250201163953epcas5p10cb7ed0c0090558d4f52c5bef63fb2dc@epcas5p1.samsung.com>
2025-02-01 16:39 ` Selvarasu Ganesan
2025-02-03 23:46   ` Thinh Nguyen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250203234616.k5nl32tdb26jhtgf@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=akash.m5@samsung.com \
    --cc=alim.akhtar@samsung.com \
    --cc=balbi@ti.com \
    --cc=dh10.jung@samsung.com \
    --cc=eomji.oh@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=h10.kim@samsung.com \
    --cc=jh0801.jung@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=naushad@samsung.com \
    --cc=selvarasu.g@samsung.com \
    --cc=stable@vger.kernel.org \
    --cc=thiagu.r@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®