Linux USB
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Roger Quadros <rogerq@kernel.org>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Siddharth Vadapalli <s-vadapalli@ti.com>,
	"srk@ti.com" <srk@ti.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] usb: dwc3: dwc3-am62: Re-initialize controller if lost power in PM suspend
Date: Mon, 25 Nov 2024 18:23:42 +0000	[thread overview]
Message-ID: <20241125182343.bfnecsub2oxohrns@synopsys.com> (raw)
In-Reply-To: <20241122-am62-dwc3-io-ddr-v1-1-cc4956449420@kernel.org>

On Fri, Nov 22, 2024, Roger Quadros wrote:
> If controller looses power during PM suspend then re-initialize
> it. We use the DEBUG_CFG register to track if controller lost power
> or was reset in PM suspend.
> 
> Move all initialization code into dwc3_ti_init() so it can be re-used.
> 
> Signed-off-by: Roger Quadros <rogerq@kernel.org>
> ---
>  drivers/usb/dwc3/dwc3-am62.c | 82 +++++++++++++++++++++++++++++---------------
>  1 file changed, 55 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-am62.c b/drivers/usb/dwc3/dwc3-am62.c
> index fad151e78fd6..2192222faf4f 100644
> --- a/drivers/usb/dwc3/dwc3-am62.c
> +++ b/drivers/usb/dwc3/dwc3-am62.c
> @@ -108,6 +108,9 @@
>  
>  #define DWC3_AM62_AUTOSUSPEND_DELAY	100
>  
> +#define USBSS_DEBUG_CFG_OFF		0x7
> +#define USBSS_DEBUG_CFG_DISABLED	0x7

Do we need 2 different macros with the same value of the same register
for this?

Regardless,

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

Thanks,
Thinh

> +
>  struct dwc3_am62 {
>  	struct device *dev;
>  	void __iomem *usbss;
> @@ -117,6 +120,7 @@ struct dwc3_am62 {
>  	unsigned int offset;
>  	unsigned int vbus_divider;
>  	u32 wakeup_stat;
> +	void __iomem *phy;
>  };
>  
>  static const int dwc3_ti_rate_table[] = {	/* in KHZ */
> @@ -184,15 +188,47 @@ static int phy_syscon_pll_refclk(struct dwc3_am62 *am62)
>  	return 0;
>  }
>  
> +static int dwc3_ti_init(struct dwc3_am62 *am62)
> +{
> +	int ret;
> +	u32 reg;
> +
> +	/* Read the syscon property and set the rate code */
> +	ret = phy_syscon_pll_refclk(am62);
> +	if (ret)
> +		return ret;
> +
> +	/* Workaround Errata i2409 */
> +	if (am62->phy) {
> +		reg = readl(am62->phy + USB_PHY_PLL_REG12);
> +		reg |= USB_PHY_PLL_LDO_REF_EN | USB_PHY_PLL_LDO_REF_EN_EN;
> +		writel(reg, am62->phy + USB_PHY_PLL_REG12);
> +	}
> +
> +	/* VBUS divider select */
> +	reg = dwc3_ti_readl(am62, USBSS_PHY_CONFIG);
> +	if (am62->vbus_divider)
> +		reg |= 1 << USBSS_PHY_VBUS_SEL_SHIFT;
> +
> +	dwc3_ti_writel(am62, USBSS_PHY_CONFIG, reg);
> +
> +	clk_prepare_enable(am62->usb2_refclk);
> +
> +	/* Set mode valid bit to indicate role is valid */
> +	reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL);
> +	reg |= USBSS_MODE_VALID;
> +	dwc3_ti_writel(am62, USBSS_MODE_CONTROL, reg);
> +
> +	return 0;
> +}
> +
>  static int dwc3_ti_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
>  	struct device_node *node = pdev->dev.of_node;
>  	struct dwc3_am62 *am62;
>  	unsigned long rate;
> -	void __iomem *phy;
>  	int i, ret;
> -	u32 reg;
>  
>  	am62 = devm_kzalloc(dev, sizeof(*am62), GFP_KERNEL);
>  	if (!am62)
> @@ -228,29 +264,17 @@ static int dwc3_ti_probe(struct platform_device *pdev)
>  
>  	am62->rate_code = i;
>  
> -	/* Read the syscon property and set the rate code */
> -	ret = phy_syscon_pll_refclk(am62);
> -	if (ret)
> -		return ret;
> -
> -	/* Workaround Errata i2409 */
> -	phy = devm_platform_ioremap_resource(pdev, 1);
> -	if (IS_ERR(phy)) {
> +	am62->phy = devm_platform_ioremap_resource(pdev, 1);
> +	if (IS_ERR(am62->phy)) {
>  		dev_err(dev, "can't map PHY IOMEM resource. Won't apply i2409 fix.\n");
> -		phy = NULL;
> -	} else {
> -		reg = readl(phy + USB_PHY_PLL_REG12);
> -		reg |= USB_PHY_PLL_LDO_REF_EN | USB_PHY_PLL_LDO_REF_EN_EN;
> -		writel(reg, phy + USB_PHY_PLL_REG12);
> +		am62->phy = NULL;
>  	}
>  
> -	/* VBUS divider select */
>  	am62->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider");
> -	reg = dwc3_ti_readl(am62, USBSS_PHY_CONFIG);
> -	if (am62->vbus_divider)
> -		reg |= 1 << USBSS_PHY_VBUS_SEL_SHIFT;
>  
> -	dwc3_ti_writel(am62, USBSS_PHY_CONFIG, reg);
> +	ret = dwc3_ti_init(am62);
> +	if (ret)
> +		return ret;
>  
>  	pm_runtime_set_active(dev);
>  	pm_runtime_enable(dev);
> @@ -258,7 +282,6 @@ static int dwc3_ti_probe(struct platform_device *pdev)
>  	 * Don't ignore its dependencies with its children
>  	 */
>  	pm_suspend_ignore_children(dev, false);
> -	clk_prepare_enable(am62->usb2_refclk);
>  	pm_runtime_get_noresume(dev);
>  
>  	ret = of_platform_populate(node, NULL, NULL, dev);
> @@ -267,11 +290,6 @@ static int dwc3_ti_probe(struct platform_device *pdev)
>  		goto err_pm_disable;
>  	}
>  
> -	/* Set mode valid bit to indicate role is valid */
> -	reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL);
> -	reg |= USBSS_MODE_VALID;
> -	dwc3_ti_writel(am62, USBSS_MODE_CONTROL, reg);
> -
>  	/* Device has capability to wakeup system from sleep */
>  	device_set_wakeup_capable(dev, true);
>  	ret = device_wakeup_enable(dev);
> @@ -338,6 +356,9 @@ static int dwc3_ti_suspend_common(struct device *dev)
>  		dwc3_ti_writel(am62, USBSS_WAKEUP_STAT, USBSS_WAKEUP_STAT_CLR);
>  	}
>  
> +	/* just to track if module resets on suspend */
> +	dwc3_ti_writel(am62, USBSS_DEBUG_CFG, USBSS_DEBUG_CFG_DISABLED);
> +
>  	clk_disable_unprepare(am62->usb2_refclk);
>  
>  	return 0;
> @@ -348,7 +369,14 @@ static int dwc3_ti_resume_common(struct device *dev)
>  	struct dwc3_am62 *am62 = dev_get_drvdata(dev);
>  	u32 reg;
>  
> -	clk_prepare_enable(am62->usb2_refclk);
> +	reg = dwc3_ti_readl(am62, USBSS_DEBUG_CFG);
> +	if (reg != USBSS_DEBUG_CFG_DISABLED) {
> +		/* lost power/context */
> +		dwc3_ti_init(am62);
> +	} else {
> +		dwc3_ti_writel(am62, USBSS_DEBUG_CFG, USBSS_DEBUG_CFG_OFF);
> +		clk_prepare_enable(am62->usb2_refclk);
> +	}
>  
>  	if (device_may_wakeup(dev)) {
>  		/* Clear wakeup config enable bits */
> 
> ---
> base-commit: adc218676eef25575469234709c2d87185ca223a
> change-id: 20241122-am62-dwc3-io-ddr-3bcb683a91a0
> 
> Best regards,
> -- 
> Roger Quadros <rogerq@kernel.org>
> 

  reply	other threads:[~2024-11-25 18:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-22 13:57 [PATCH] usb: dwc3: dwc3-am62: Re-initialize controller if lost power in PM suspend Roger Quadros
2024-11-25 18:23 ` Thinh Nguyen [this message]
2024-11-25 19:01   ` Roger Quadros
2024-11-26 22:15     ` Thinh Nguyen
2024-11-27 14:35       ` Roger Quadros
2024-12-03  0:50         ` Thinh Nguyen

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=20241125182343.bfnecsub2oxohrns@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rogerq@kernel.org \
    --cc=s-vadapalli@ti.com \
    --cc=srk@ti.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