diff mbox series

[v1,2/2] usb: cdns3: imx: add power lost support for system resume

Message ID 20210218225109.265730-2-Frank.Li@nxp.com
State New
Headers show
Series None | expand

Commit Message

Frank Li Feb. 18, 2021, 10:51 p.m. UTC
From: Frank Li <Frank.li@nxp.com>

imx need special handle when controller lost power

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
split imx part 

 drivers/usb/cdns3/cdns3-imx.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

Peter Chen March 6, 2021, 3:13 a.m. UTC | #1
On 21-02-18 16:51:09, Frank Li wrote:
> From: Frank Li <Frank.li@nxp.com>

> 

> imx need special handle when controller lost power

> 

> Signed-off-by: Peter Chen <peter.chen@nxp.com>

> Signed-off-by: Frank Li <Frank.Li@nxp.com>


Applied both, thanks.

Peter

> ---

> split imx part 

> 

>  drivers/usb/cdns3/cdns3-imx.c | 34 ++++++++++++++++++++++++++++++++++

>  1 file changed, 34 insertions(+)

> 

> diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c

> index 8f88eec0b0ea..708b51cc5844 100644

> --- a/drivers/usb/cdns3/cdns3-imx.c

> +++ b/drivers/usb/cdns3/cdns3-imx.c

> @@ -361,6 +361,39 @@ static int cdns_imx_suspend(struct device *dev)

>  

>  	return 0;

>  }

> +

> +

> +/* Indicate if the controller was power lost before */

> +static inline bool cdns_imx_is_power_lost(struct cdns_imx *data)

> +{

> +	u32 value;

> +

> +	value = cdns_imx_readl(data, USB3_CORE_CTRL1);

> +	if ((value & SW_RESET_MASK) == ALL_SW_RESET)

> +		return true;

> +	else

> +		return false;

> +}

> +

> +static int cdns_imx_system_resume(struct device *dev)

> +{

> +	struct cdns_imx *data = dev_get_drvdata(dev);

> +	int ret;

> +

> +	ret = cdns_imx_resume(dev);

> +	if (ret)

> +		return ret;

> +

> +	if (cdns_imx_is_power_lost(data)) {

> +		dev_dbg(dev, "resume from power lost\n");

> +		ret = cdns_imx_noncore_init(data);

> +		if (ret)

> +			cdns_imx_suspend(dev);

> +	}

> +

> +	return ret;

> +}

> +

>  #else

>  static int cdns_imx_platform_suspend(struct device *dev,

>  	bool suspend, bool wakeup)

> @@ -372,6 +405,7 @@ static int cdns_imx_platform_suspend(struct device *dev,

>  

>  static const struct dev_pm_ops cdns_imx_pm_ops = {

>  	SET_RUNTIME_PM_OPS(cdns_imx_suspend, cdns_imx_resume, NULL)

> +	SET_SYSTEM_SLEEP_PM_OPS(cdns_imx_suspend, cdns_imx_system_resume)

>  };

>  

>  static const struct of_device_id cdns_imx_of_match[] = {

> -- 

> 2.25.1

> 


-- 

Thanks,
Peter Chen
diff mbox series

Patch

diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c
index 8f88eec0b0ea..708b51cc5844 100644
--- a/drivers/usb/cdns3/cdns3-imx.c
+++ b/drivers/usb/cdns3/cdns3-imx.c
@@ -361,6 +361,39 @@  static int cdns_imx_suspend(struct device *dev)
 
 	return 0;
 }
+
+
+/* Indicate if the controller was power lost before */
+static inline bool cdns_imx_is_power_lost(struct cdns_imx *data)
+{
+	u32 value;
+
+	value = cdns_imx_readl(data, USB3_CORE_CTRL1);
+	if ((value & SW_RESET_MASK) == ALL_SW_RESET)
+		return true;
+	else
+		return false;
+}
+
+static int cdns_imx_system_resume(struct device *dev)
+{
+	struct cdns_imx *data = dev_get_drvdata(dev);
+	int ret;
+
+	ret = cdns_imx_resume(dev);
+	if (ret)
+		return ret;
+
+	if (cdns_imx_is_power_lost(data)) {
+		dev_dbg(dev, "resume from power lost\n");
+		ret = cdns_imx_noncore_init(data);
+		if (ret)
+			cdns_imx_suspend(dev);
+	}
+
+	return ret;
+}
+
 #else
 static int cdns_imx_platform_suspend(struct device *dev,
 	bool suspend, bool wakeup)
@@ -372,6 +405,7 @@  static int cdns_imx_platform_suspend(struct device *dev,
 
 static const struct dev_pm_ops cdns_imx_pm_ops = {
 	SET_RUNTIME_PM_OPS(cdns_imx_suspend, cdns_imx_resume, NULL)
+	SET_SYSTEM_SLEEP_PM_OPS(cdns_imx_suspend, cdns_imx_system_resume)
 };
 
 static const struct of_device_id cdns_imx_of_match[] = {