linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@kernel.org>
To: Peter Chen <peter.chen@nxp.com>
Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com,
	rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com,
	Peter Chen <peter.chen@nxp.com>
Subject: Re: [PATCH v7 3/3] usb: cdns3: imx: add glue layer runtime pm implementation
Date: Thu, 27 Aug 2020 16:20:15 +0300	[thread overview]
Message-ID: <87eensi5tc.fsf@kernel.org> (raw)
In-Reply-To: <20200825021120.4926-4-peter.chen@nxp.com>

[-- Attachment #1: Type: text/plain, Size: 7653 bytes --]

Peter Chen <peter.chen@nxp.com> writes:

> Add imx glue layer runtime pm implementation, and the runtime
> pm is default off.
>
> Reviewed-by: Pawel Laszczak <pawell@cadence.com>
> Signed-off-by: Peter Chen <peter.chen@nxp.com>
> ---
>  drivers/usb/cdns3/cdns3-imx.c | 203 ++++++++++++++++++++++++++++++++--
>  1 file changed, 192 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c
> index aba988e71958..a413df26e948 100644
> --- a/drivers/usb/cdns3/cdns3-imx.c
> +++ b/drivers/usb/cdns3/cdns3-imx.c
> @@ -15,6 +15,8 @@
>  #include <linux/io.h>
>  #include <linux/of_platform.h>
>  #include <linux/iopoll.h>
> +#include <linux/pm_runtime.h>
> +#include "core.h"
>  
>  #define USB3_CORE_CTRL1    0x00
>  #define USB3_CORE_CTRL2    0x04
> @@ -32,7 +34,7 @@
>  /* Register bits definition */
>  
>  /* USB3_CORE_CTRL1 */
> -#define SW_RESET_MASK	(0x3f << 26)
> +#define SW_RESET_MASK	GENMASK(31, 26)

why is this part of adding imx runtime pm?

> @@ -44,17 +46,17 @@
>  #define OC_DISABLE	BIT(9)
>  #define MDCTRL_CLK_SEL	BIT(7)
>  #define MODE_STRAP_MASK	(0x7)
> -#define DEV_MODE	(1 << 2)
> -#define HOST_MODE	(1 << 1)
> -#define OTG_MODE	(1 << 0)
> +#define DEV_MODE	BIT(2)
> +#define HOST_MODE	BIT(1)
> +#define OTG_MODE	BIT(0)

and these?

>  
>  /* USB3_INT_REG */
>  #define CLK_125_REQ	BIT(29)
>  #define LPM_CLK_REQ	BIT(28)
>  #define DEVU3_WAEKUP_EN	BIT(14)
>  #define OTG_WAKEUP_EN	BIT(12)
> -#define DEV_INT_EN (3 << 8) /* DEV INT b9:8 */
> -#define HOST_INT1_EN (1 << 0) /* HOST INT b7:0 */
> +#define DEV_INT_EN	GENMASK(9, 8) /* DEV INT b9:8 */
> +#define HOST_INT1_EN	BIT(0) /* HOST INT b7:0 */

what about these?

> @@ -62,15 +64,34 @@
>  #define HOST_POWER_ON_READY	BIT(12)
>  
>  /* USB3_SSPHY_STATUS */
> -#define CLK_VALID_MASK		(0x3f << 26)
> -#define CLK_VALID_COMPARE_BITS	(0xf << 28)
> -#define PHY_REFCLK_REQ		(1 << 0)
> +#define CLK_VALID_MASK		GENMASK(31, 26)
> +#define CLK_VALID_COMPARE_BITS	GENMASK(31, 28)
> +#define PHY_REFCLK_REQ		BIT(0)

these?

> +/* OTG registers definition */
> +#define OTGSTS		0x4
> +/* OTGSTS */
> +#define OTG_NRDY	BIT(11)
> +
> +/* xHCI registers definition  */
> +#define XECP_PM_PMCSR		0x8018
> +#define XECP_AUX_CTRL_REG1	0x8120
> +
> +/* Register bits definition */
> +/* XECP_AUX_CTRL_REG1 */
> +#define CFG_RXDET_P3_EN		BIT(15)
> +
> +/* XECP_PM_PMCSR */
> +#define PS_MASK			GENMASK(1, 0)
> +#define PS_D0			0
> +#define PS_D1			1

I think only these are part of $subject

>  struct cdns_imx {
>  	struct device *dev;
>  	void __iomem *noncore;
>  	struct clk_bulk_data *clks;
>  	int num_clks;
> +	struct platform_device *cdns3_pdev;
>  };
>  
>  static inline u32 cdns_imx_readl(struct cdns_imx *data, u32 offset)
> @@ -126,6 +147,20 @@ static int cdns_imx_noncore_init(struct cdns_imx *data)
>  	return ret;
>  }
>  
> +static int cdns_imx_platform_suspend(struct device *dev,
> +	bool suspend, bool wakeup);
> +static struct cdns3_platform_data cdns_imx_pdata = {

make it const?

> +	.platform_suspend = cdns_imx_platform_suspend,
> +};
> +
> +static struct of_dev_auxdata cdns_imx_auxdata[] = {

const?

> +	{
> +	.compatible = "cdns,usb3",
> +	.platform_data = &cdns_imx_pdata,
> +	},

bad indentation

> @@ -194,6 +233,147 @@ static int cdns_imx_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#ifdef CONFIG_PM
> +static void cdns3_set_wakeup(struct cdns_imx *data, bool enable)
> +{
> +	u32 value;
> +
> +	value = cdns_imx_readl(data, USB3_INT_REG);
> +	if (enable)
> +		value |= OTG_WAKEUP_EN | DEVU3_WAEKUP_EN;
> +	else
> +		value &= ~(OTG_WAKEUP_EN | DEVU3_WAEKUP_EN);
> +
> +	cdns_imx_writel(data, USB3_INT_REG, value);
> +}
> +
> +static int cdns_imx_platform_suspend(struct device *dev,
> +		bool suspend, bool wakeup)
> +{
> +	struct cdns3 *cdns = dev_get_drvdata(dev);
> +	struct device *parent = dev->parent;
> +	struct cdns_imx *data = dev_get_drvdata(parent);
> +	void __iomem *otg_regs = (void __iomem *)(cdns->otg_regs);

why the cast?

> +	void __iomem *xhci_regs = cdns->xhci_regs;
> +	u32 value;
> +	int ret = 0;
> +
> +	if (cdns->role != USB_ROLE_HOST)
> +		return 0;
> +
> +	if (suspend) {
> +		/* SW request low power when all usb ports allow to it ??? */
> +		value = readl(xhci_regs + XECP_PM_PMCSR);
> +		value &= ~PS_MASK;
> +		value |= PS_D1;
> +		writel(value, xhci_regs + XECP_PM_PMCSR);
> +
> +		/* mdctrl_clk_sel */
> +		value = cdns_imx_readl(data, USB3_CORE_CTRL1);
> +		value |= MDCTRL_CLK_SEL;
> +		cdns_imx_writel(data, USB3_CORE_CTRL1, value);
> +
> +		/* wait for mdctrl_clk_status */
> +		value = cdns_imx_readl(data, USB3_CORE_STATUS);
> +		ret = readl_poll_timeout(data->noncore + USB3_CORE_STATUS, value,
> +			(value & MDCTRL_CLK_STATUS) == MDCTRL_CLK_STATUS,
> +			10, 100000);
> +		if (ret)
> +			dev_warn(parent, "wait mdctrl_clk_status timeout\n");
> +
> +		/* wait lpm_clk_req to be 0 */
> +		value = cdns_imx_readl(data, USB3_INT_REG);
> +		ret = readl_poll_timeout(data->noncore + USB3_INT_REG, value,
> +			(value & LPM_CLK_REQ) != LPM_CLK_REQ,
> +			10, 100000);
> +		if (ret)
> +			dev_warn(parent, "wait lpm_clk_req timeout\n");
> +
> +		/* wait phy_refclk_req to be 0 */
> +		value = cdns_imx_readl(data, USB3_SSPHY_STATUS);
> +		ret = readl_poll_timeout(data->noncore + USB3_SSPHY_STATUS, value,
> +			(value & PHY_REFCLK_REQ) != PHY_REFCLK_REQ,
> +			10, 100000);
> +		if (ret)
> +			dev_warn(parent, "wait phy_refclk_req timeout\n");
> +
> +		cdns3_set_wakeup(data, wakeup);
> +	} else {
> +		cdns3_set_wakeup(data, false);
> +
> +		/* SW request D0 */
> +		value = readl(xhci_regs + XECP_PM_PMCSR);
> +		value &= ~PS_MASK;
> +		value |= PS_D0;
> +		writel(value, xhci_regs + XECP_PM_PMCSR);
> +
> +		/* clr CFG_RXDET_P3_EN */
> +		value = readl(xhci_regs + XECP_AUX_CTRL_REG1);
> +		value &= ~CFG_RXDET_P3_EN;
> +		writel(value, xhci_regs + XECP_AUX_CTRL_REG1);
> +
> +		/* clear mdctrl_clk_sel */
> +		value = cdns_imx_readl(data, USB3_CORE_CTRL1);
> +		value &= ~MDCTRL_CLK_SEL;
> +		cdns_imx_writel(data, USB3_CORE_CTRL1, value);
> +
> +		/* wait CLK_125_REQ to be 1 */
> +		value = cdns_imx_readl(data, USB3_INT_REG);
> +		ret = readl_poll_timeout(data->noncore + USB3_INT_REG, value,
> +			(value & CLK_125_REQ) == CLK_125_REQ,
> +			10, 100000);
> +		if (ret)
> +			dev_warn(parent, "wait CLK_125_REQ timeout\n");
> +
> +		/* wait for mdctrl_clk_status is cleared */
> +		value = cdns_imx_readl(data, USB3_CORE_STATUS);
> +		ret = readl_poll_timeout(data->noncore + USB3_CORE_STATUS, value,
> +			(value & MDCTRL_CLK_STATUS) != MDCTRL_CLK_STATUS,
> +			10, 100000);
> +		if (ret)
> +			dev_warn(parent, "wait mdctrl_clk_status cleared timeout\n");
> +
> +		/* Wait until OTG_NRDY is 0 */
> +		value = readl(otg_regs + OTGSTS);
> +		ret = readl_poll_timeout(otg_regs + OTGSTS, value,
> +			(value & OTG_NRDY) != OTG_NRDY,
> +			10, 100000);
> +		if (ret)
> +			dev_warn(parent, "wait OTG ready timeout\n");
> +	}
> +
> +	return ret;
> +
> +}
> +
> +static int cdns_imx_resume(struct device *dev)
> +{
> +	struct cdns_imx *data = dev_get_drvdata(dev);
> +
> +	return clk_bulk_prepare_enable(data->num_clks, data->clks);

do you need to prepare and unprepare for every suspend/resume? Isn't
enable/disable enough?

> +static const struct dev_pm_ops cdns_imx_pm_ops = {
> +	SET_RUNTIME_PM_OPS(cdns_imx_suspend, cdns_imx_resume, NULL)

could the same be used for system sleep?

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 857 bytes --]

  reply	other threads:[~2020-08-27 13:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-25  2:11 [PATCH v7 0/3] usb: cdns3: add runtime pm support Peter Chen
2020-08-25  2:11 ` [PATCH v7 1/3] usb: cdns3: introduce set_phy_power_on{off} APIs Peter Chen
2020-08-27 13:09   ` Felipe Balbi
2020-08-28  0:33     ` Peter Chen
2020-08-25  2:11 ` [PATCH v7 2/3] usb: cdns3: add runtime PM support Peter Chen
2020-08-27 13:16   ` Felipe Balbi
2020-08-28  1:01     ` Peter Chen
2020-08-25  2:11 ` [PATCH v7 3/3] usb: cdns3: imx: add glue layer runtime pm implementation Peter Chen
2020-08-27 13:20   ` Felipe Balbi [this message]
2020-08-28  1:17     ` Peter Chen
2020-09-02  9:49       ` Peter Chen

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=87eensi5tc.fsf@kernel.org \
    --to=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jun.li@nxp.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=pawell@cadence.com \
    --cc=peter.chen@nxp.com \
    --cc=rogerq@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;
as well as URLs for NNTP newsgroup(s).