linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V1] mmc: tegra: add sdhci tegra suspend and resume
@ 2019-04-02  5:27 Sowjanya Komatineni
  2019-04-02 14:59 ` Thierry Reding
  0 siblings, 1 reply; 4+ messages in thread
From: Sowjanya Komatineni @ 2019-04-02  5:27 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson
  Cc: skomatineni, thierry.reding, jonathanh, anrao, talho, bbiswas,
	linux-tegra, linux-kernel, linux-mmc

This patch adds suspend and resume PM ops for tegra SDHCI.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
---
 drivers/mmc/host/sdhci-tegra.c | 45 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
index eafaaefab4a6..68263ea4a93e 100644
--- a/drivers/mmc/host/sdhci-tegra.c
+++ b/drivers/mmc/host/sdhci-tegra.c
@@ -1611,11 +1611,54 @@ static int sdhci_tegra_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int sdhci_tegra_suspend(struct device *dev)
+{
+	struct sdhci_host *host = dev_get_drvdata(dev);
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	int ret;
+
+	if (host->mmc->caps2 & MMC_CAP2_CQE) {
+		ret = cqhci_suspend(host->mmc);
+		if (ret)
+			return ret;
+	}
+
+	ret = sdhci_suspend_host(host);
+	if (ret)
+		return ret;
+
+	clk_disable_unprepare(pltfm_host->clk);
+	return 0;
+}
+
+static int sdhci_tegra_resume(struct device *dev)
+{
+	struct sdhci_host *host = dev_get_drvdata(dev);
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	int ret;
+
+	clk_prepare_enable(pltfm_host->clk);
+
+	ret = sdhci_resume_host(host);
+	if (ret)
+		return ret;
+
+	if (host->mmc->caps2 & MMC_CAP2_CQE)
+		return cqhci_resume(host->mmc);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(sdhci_tegra_dev_pm_ops, sdhci_tegra_suspend,
+			 sdhci_tegra_resume);
+
 static struct platform_driver sdhci_tegra_driver = {
 	.driver		= {
 		.name	= "sdhci-tegra",
 		.of_match_table = sdhci_tegra_dt_match,
-		.pm	= &sdhci_pltfm_pmops,
+		.pm	= &sdhci_tegra_dev_pm_ops,
 	},
 	.probe		= sdhci_tegra_probe,
 	.remove		= sdhci_tegra_remove,
-- 
2.7.4


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

* Re: [PATCH V1] mmc: tegra: add sdhci tegra suspend and resume
  2019-04-02  5:27 [PATCH V1] mmc: tegra: add sdhci tegra suspend and resume Sowjanya Komatineni
@ 2019-04-02 14:59 ` Thierry Reding
  2019-04-02 16:41   ` Sowjanya Komatineni
  0 siblings, 1 reply; 4+ messages in thread
From: Thierry Reding @ 2019-04-02 14:59 UTC (permalink / raw)
  To: Sowjanya Komatineni
  Cc: adrian.hunter, ulf.hansson, jonathanh, anrao, talho, bbiswas,
	linux-tegra, linux-kernel, linux-mmc

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

On Mon, Apr 01, 2019 at 10:27:33PM -0700, Sowjanya Komatineni wrote:
> This patch adds suspend and resume PM ops for tegra SDHCI.
> 
> Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
> ---
>  drivers/mmc/host/sdhci-tegra.c | 45 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 44 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
> index eafaaefab4a6..68263ea4a93e 100644
> --- a/drivers/mmc/host/sdhci-tegra.c
> +++ b/drivers/mmc/host/sdhci-tegra.c
> @@ -1611,11 +1611,54 @@ static int sdhci_tegra_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#ifdef CONFIG_PM_SLEEP
> +static int sdhci_tegra_suspend(struct device *dev)
> +{
> +	struct sdhci_host *host = dev_get_drvdata(dev);
> +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> +	int ret;
> +
> +	if (host->mmc->caps2 & MMC_CAP2_CQE) {
> +		ret = cqhci_suspend(host->mmc);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	ret = sdhci_suspend_host(host);
> +	if (ret)
> +		return ret;
> +
> +	clk_disable_unprepare(pltfm_host->clk);
> +	return 0;
> +}
> +
> +static int sdhci_tegra_resume(struct device *dev)
> +{
> +	struct sdhci_host *host = dev_get_drvdata(dev);
> +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> +	int ret;
> +
> +	clk_prepare_enable(pltfm_host->clk);

You need to check this for errors here.

> +
> +	ret = sdhci_resume_host(host);
> +	if (ret)
> +		return ret;

And clk_disable_unprepare() in case of failure.

> +
> +	if (host->mmc->caps2 & MMC_CAP2_CQE)
> +		return cqhci_resume(host->mmc);

Same here. Also make sure to sdhci_suspend_host() if cqhci_resume()
fails. It's probably best to have a standard error cleanup path for
this.

Thierry

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

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

* RE: [PATCH V1] mmc: tegra: add sdhci tegra suspend and resume
  2019-04-02 14:59 ` Thierry Reding
@ 2019-04-02 16:41   ` Sowjanya Komatineni
  2019-04-02 16:48     ` Thierry Reding
  0 siblings, 1 reply; 4+ messages in thread
From: Sowjanya Komatineni @ 2019-04-02 16:41 UTC (permalink / raw)
  To: Thierry Reding
  Cc: adrian.hunter, ulf.hansson, Jonathan Hunter, Aniruddha Tvs Rao,
	Timo Alho, Bitan Biswas, linux-tegra, linux-kernel, linux-mmc

> On Mon, Apr 01, 2019 at 10:27:33PM -0700, Sowjanya Komatineni wrote:
> > This patch adds suspend and resume PM ops for tegra SDHCI.
> > 
> > Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
> > ---
> >  drivers/mmc/host/sdhci-tegra.c | 45 
> > +++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 44 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mmc/host/sdhci-tegra.c 
> > b/drivers/mmc/host/sdhci-tegra.c index eafaaefab4a6..68263ea4a93e 
> > 100644
> > --- a/drivers/mmc/host/sdhci-tegra.c
> > +++ b/drivers/mmc/host/sdhci-tegra.c
> > @@ -1611,11 +1611,54 @@ static int sdhci_tegra_remove(struct platform_device *pdev)
> >  	return 0;
> >  }
> >  
> > +#ifdef CONFIG_PM_SLEEP
> > +static int sdhci_tegra_suspend(struct device *dev) {
> > +	struct sdhci_host *host = dev_get_drvdata(dev);
> > +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> > +	int ret;
> > +
> > +	if (host->mmc->caps2 & MMC_CAP2_CQE) {
> > +		ret = cqhci_suspend(host->mmc);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> > +	ret = sdhci_suspend_host(host);
> > +	if (ret)
> > +		return ret;
> > +
> > +	clk_disable_unprepare(pltfm_host->clk);
> > +	return 0;
> > +}
> > +
> > +static int sdhci_tegra_resume(struct device *dev) {
> > +	struct sdhci_host *host = dev_get_drvdata(dev);
> > +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> > +	int ret;
> > +
> > +	clk_prepare_enable(pltfm_host->clk);
>
> You need to check this for errors here.
>
> > +
> > +	ret = sdhci_resume_host(host);
> > +	if (ret)
> > +		return ret;
>
> And clk_disable_unprepare() in case of failure.
>
> > +
> > +	if (host->mmc->caps2 & MMC_CAP2_CQE)
> > +		return cqhci_resume(host->mmc);
>
> Same here. Also make sure to sdhci_suspend_host() if cqhci_resume() fails. It's probably best to have a standard error cleanup path for this.
>
> Thierry

Thanks Thierry. Will add error check and cleanup for clock and sdhci_resume_host.
Regarding, cqhci_resume always returns 0. Infact, it does nothing as resume happens on first cqhci_request.
Since helper functions exists in cqhci driver, was using it for explicit resume call.

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

* Re: [PATCH V1] mmc: tegra: add sdhci tegra suspend and resume
  2019-04-02 16:41   ` Sowjanya Komatineni
@ 2019-04-02 16:48     ` Thierry Reding
  0 siblings, 0 replies; 4+ messages in thread
From: Thierry Reding @ 2019-04-02 16:48 UTC (permalink / raw)
  To: Sowjanya Komatineni
  Cc: adrian.hunter, ulf.hansson, Jonathan Hunter, Aniruddha Tvs Rao,
	Timo Alho, Bitan Biswas, linux-tegra, linux-kernel, linux-mmc

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

On Tue, Apr 02, 2019 at 04:41:18PM +0000, Sowjanya Komatineni wrote:
> > On Mon, Apr 01, 2019 at 10:27:33PM -0700, Sowjanya Komatineni wrote:
> > > This patch adds suspend and resume PM ops for tegra SDHCI.
> > > 
> > > Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
> > > ---
> > >  drivers/mmc/host/sdhci-tegra.c | 45 
> > > +++++++++++++++++++++++++++++++++++++++++-
> > >  1 file changed, 44 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/mmc/host/sdhci-tegra.c 
> > > b/drivers/mmc/host/sdhci-tegra.c index eafaaefab4a6..68263ea4a93e 
> > > 100644
> > > --- a/drivers/mmc/host/sdhci-tegra.c
> > > +++ b/drivers/mmc/host/sdhci-tegra.c
> > > @@ -1611,11 +1611,54 @@ static int sdhci_tegra_remove(struct platform_device *pdev)
> > >  	return 0;
> > >  }
> > >  
> > > +#ifdef CONFIG_PM_SLEEP
> > > +static int sdhci_tegra_suspend(struct device *dev) {
> > > +	struct sdhci_host *host = dev_get_drvdata(dev);
> > > +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> > > +	int ret;
> > > +
> > > +	if (host->mmc->caps2 & MMC_CAP2_CQE) {
> > > +		ret = cqhci_suspend(host->mmc);
> > > +		if (ret)
> > > +			return ret;
> > > +	}
> > > +
> > > +	ret = sdhci_suspend_host(host);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	clk_disable_unprepare(pltfm_host->clk);
> > > +	return 0;
> > > +}
> > > +
> > > +static int sdhci_tegra_resume(struct device *dev) {
> > > +	struct sdhci_host *host = dev_get_drvdata(dev);
> > > +	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
> > > +	int ret;
> > > +
> > > +	clk_prepare_enable(pltfm_host->clk);
> >
> > You need to check this for errors here.
> >
> > > +
> > > +	ret = sdhci_resume_host(host);
> > > +	if (ret)
> > > +		return ret;
> >
> > And clk_disable_unprepare() in case of failure.
> >
> > > +
> > > +	if (host->mmc->caps2 & MMC_CAP2_CQE)
> > > +		return cqhci_resume(host->mmc);
> >
> > Same here. Also make sure to sdhci_suspend_host() if cqhci_resume() fails. It's probably best to have a standard error cleanup path for this.
> >
> > Thierry
> 
> Thanks Thierry. Will add error check and cleanup for clock and sdhci_resume_host.
> Regarding, cqhci_resume always returns 0. Infact, it does nothing as resume happens on first cqhci_request.
> Since helper functions exists in cqhci driver, was using it for explicit resume call.

Yeah, I think it's good to use it. And I think it's also the safest
option to handle errors from it properly because somebody may eventually
add code to it that can fail. If we properly handle errors we'll be
prepared for when that happens.

Thierry

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

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

end of thread, other threads:[~2019-04-02 16:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-02  5:27 [PATCH V1] mmc: tegra: add sdhci tegra suspend and resume Sowjanya Komatineni
2019-04-02 14:59 ` Thierry Reding
2019-04-02 16:41   ` Sowjanya Komatineni
2019-04-02 16:48     ` Thierry Reding

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).