From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Han Xu <han.xu@nxp.com>
Cc: vigneshr@ti.com, richard@nod.at, esben@geanix.com,
sean@geanix.com, boris.brezillon@collabora.com,
linux-mtd@lists.infradead.org, martin@geanix.com,
s.hauer@pengutronix.de
Subject: Re: [PATCH] mtd: rawnand: gpmi: fix the suspend/resume issue
Date: Thu, 9 Jan 2020 20:01:27 +0100 [thread overview]
Message-ID: <20200109200127.0ace18cb@xps13> (raw)
In-Reply-To: <1578589556-683-1-git-send-email-han.xu@nxp.com>
Hi Esben, Han,
Han Xu <han.xu@nxp.com> wrote on Fri, 10 Jan 2020 01:05:56 +0800:
> fix several issues when system suspend/resume,
>
> - leverage the runtime pm for system suspend/resume
> - enable the clock before register access
> - re-apply timing settings
> - set the proper pinctrl state
Esben are you fine with this patch?
Or maybe Han you could take over Eben's patch and extend it?
>
> Signed-off-by: Han Xu <han.xu@nxp.com>
> ---
> drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 59 ++++++++++++++++------
> 1 file changed, 44 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> index 334fe3130285..37437d47ab9a 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> @@ -15,6 +15,7 @@
> #include <linux/of.h>
> #include <linux/of_device.h>
> #include <linux/pm_runtime.h>
> +#include <linux/pinctrl/consumer.h>
> #include <linux/dma/mxs-dma.h>
> #include "gpmi-nand.h"
> #include "gpmi-regs.h"
> @@ -146,7 +147,11 @@ static int __gpmi_enable_clk(struct gpmi_nand_data *this, bool v)
> static int gpmi_init(struct gpmi_nand_data *this)
> {
> struct resources *r = &this->resources;
> - int ret;
> + int ret = 0;
> +
> + ret = pm_runtime_get_sync(this->dev);
> + if (ret < 0)
> + return ret;
>
> ret = gpmi_reset_block(r->gpmi_regs, false);
> if (ret)
> @@ -179,8 +184,10 @@ static int gpmi_init(struct gpmi_nand_data *this)
> */
> writel(BM_GPMI_CTRL1_DECOUPLE_CS, r->gpmi_regs + HW_GPMI_CTRL1_SET);
>
> - return 0;
> err_out:
> + pm_runtime_mark_last_busy(this->dev);
> + pm_runtime_put_autosuspend(this->dev);
> +
> return ret;
> }
>
> @@ -528,7 +535,7 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this)
> static int bch_set_geometry(struct gpmi_nand_data *this)
> {
> struct resources *r = &this->resources;
> - int ret;
> + int ret = 0;
>
> ret = common_nfc_set_geometry(this);
> if (ret)
> @@ -550,7 +557,6 @@ static int bch_set_geometry(struct gpmi_nand_data *this)
> /* Set *all* chip selects to use layout 0. */
> writel(0, r->bch_regs + HW_BCH_LAYOUTSELECT);
>
> - ret = 0;
> err_out:
> pm_runtime_mark_last_busy(this->dev);
> pm_runtime_put_autosuspend(this->dev);
> @@ -2676,7 +2682,7 @@ static int gpmi_nand_probe(struct platform_device *pdev)
> return 0;
>
> exit_nfc_init:
> - pm_runtime_put(&pdev->dev);
> + pm_runtime_dont_use_autosuspend(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
> release_resources(this);
> exit_acquire_resources:
> @@ -2688,7 +2694,6 @@ static int gpmi_nand_remove(struct platform_device *pdev)
> {
> struct gpmi_nand_data *this = platform_get_drvdata(pdev);
>
> - pm_runtime_put_sync(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
>
> nand_release(&this->nand);
> @@ -2700,10 +2705,12 @@ static int gpmi_nand_remove(struct platform_device *pdev)
> #ifdef CONFIG_PM_SLEEP
> static int gpmi_pm_suspend(struct device *dev)
> {
> - struct gpmi_nand_data *this = dev_get_drvdata(dev);
> + int ret;
>
> - release_dma_channels(this);
> - return 0;
> + pinctrl_pm_select_sleep_state(dev);
> + ret = pm_runtime_force_suspend(dev);
> +
> + return ret;
> }
>
> static int gpmi_pm_resume(struct device *dev)
> @@ -2711,9 +2718,13 @@ static int gpmi_pm_resume(struct device *dev)
> struct gpmi_nand_data *this = dev_get_drvdata(dev);
> int ret;
>
> - ret = acquire_dma_channels(this);
> - if (ret < 0)
> + ret = pm_runtime_force_resume(dev);
> + if (ret) {
> + dev_err(this->dev, "Error in resume %d\n", ret);
> return ret;
> + }
> +
> + pinctrl_pm_select_default_state(dev);
>
> /* re-init the GPMI registers */
> ret = gpmi_init(this);
> @@ -2729,22 +2740,40 @@ static int gpmi_pm_resume(struct device *dev)
> return ret;
> }
>
> + /* re-apply the timing setting */
> + this->hw.must_apply_timings = true;
> +
> return 0;
> }
> #endif /* CONFIG_PM_SLEEP */
>
> -static int __maybe_unused gpmi_runtime_suspend(struct device *dev)
> +#define gpmi_enable_clk(x) __gpmi_enable_clk(x, true)
> +#define gpmi_disable_clk(x) __gpmi_enable_clk(x, false)
> +
> +static int gpmi_runtime_suspend(struct device *dev)
> {
> struct gpmi_nand_data *this = dev_get_drvdata(dev);
>
> - return __gpmi_enable_clk(this, false);
> + gpmi_disable_clk(this);
> + release_dma_channels(this);
> +
> + return 0;
> }
>
> -static int __maybe_unused gpmi_runtime_resume(struct device *dev)
> +static int gpmi_runtime_resume(struct device *dev)
> {
> struct gpmi_nand_data *this = dev_get_drvdata(dev);
> + int ret;
>
> - return __gpmi_enable_clk(this, true);
> + ret = gpmi_enable_clk(this);
> + if (ret)
> + return ret;
> +
> + ret = acquire_dma_channels(this);
> + if (ret < 0)
> + return ret;
> +
> + return 0;
> }
>
> static const struct dev_pm_ops gpmi_pm_ops = {
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2020-01-09 19:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-09 17:05 [PATCH] mtd: rawnand: gpmi: fix the suspend/resume issue Han Xu
2020-01-09 19:01 ` Miquel Raynal [this message]
2020-01-09 20:06 ` Esben Haabendal
2020-01-09 20:09 ` Han Xu
2020-01-13 17:30 ` Miquel Raynal
2020-01-09 20:45 ` Esben Haabendal
2020-01-14 21:53 ` Han Xu
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=20200109200127.0ace18cb@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=boris.brezillon@collabora.com \
--cc=esben@geanix.com \
--cc=han.xu@nxp.com \
--cc=linux-mtd@lists.infradead.org \
--cc=martin@geanix.com \
--cc=richard@nod.at \
--cc=s.hauer@pengutronix.de \
--cc=sean@geanix.com \
--cc=vigneshr@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.