mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@nxp.com>
To: Laurentiu Palcu <laurentiu.palcu@oss.nxp.com>
Cc: imx@lists.linux.dev, Abel Vesa <abelvesa@kernel.org>,
	Peng Fan <peng.fan@nxp.com>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>, Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	dri-devel@lists.freedesktop.org, Abel Vesa <abel.vesa@linaro.org>,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/8] clk: imx95-blk-ctl: Cache registers when RPM routines are called
Date: Fri, 11 Jul 2025 00:03:22 -0400	[thread overview]
Message-ID: <aHCNCokZxIRNPgT6@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20250709122332.2874632-2-laurentiu.palcu@oss.nxp.com>

Subject:
save and store registers at suspend()/resume() function

On Wed, Jul 09, 2025 at 03:23:20PM +0300, Laurentiu Palcu wrote:
> If runtime PM is used for the clock providers and they're part of a
> power domain, then the power domain supply will be cut off when runtime
> suspended. That means all BLK CTL registers belonging to that power
> domain will be reset. Hence, the clock settings will revert to default
> values messing up the consumer clock settings.

Needn't "hence ..."

Save/restore register value at suspend/resume functions to fix this problem.

>
> Also, fix the suspend/resume routines as well, as the clock was left ON
> when going to suspend.

Do you means fix the problem clock left ON after suspend?

Pomain cut off, why clock can left on?

>
> Fixes: 5224b189462f ("clk: imx: add i.MX95 BLK CTL clk driver")
> Signed-off-by: Laurentiu Palcu <laurentiu.palcu@oss.nxp.com>
> ---
>  drivers/clk/imx/clk-imx95-blk-ctl.c | 55 ++++++++++++++++++-----------
>  1 file changed, 34 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/clk/imx/clk-imx95-blk-ctl.c b/drivers/clk/imx/clk-imx95-blk-ctl.c
> index 7e88877a62451..7f9bbca517284 100644
> --- a/drivers/clk/imx/clk-imx95-blk-ctl.c
> +++ b/drivers/clk/imx/clk-imx95-blk-ctl.c
> @@ -448,12 +448,36 @@ static int imx95_bc_probe(struct platform_device *pdev)
>  	return ret;
>  }
>
> +static void __maybe_unused imx95_bc_save_reg(struct imx95_blk_ctl *bc)
> +{
> +	const struct imx95_blk_ctl_dev_data *bc_data;
> +
> +	bc_data = of_device_get_match_data(bc->dev);
> +	if (!bc_data)
> +		return;
> +
> +	bc->clk_reg_restore = readl(bc->base + bc_data->clk_reg_offset);
> +}
> +
> +static void __maybe_unused imx95_bc_restore_reg(struct imx95_blk_ctl *bc)
> +{
> +	const struct imx95_blk_ctl_dev_data *bc_data;
> +
> +	bc_data = of_device_get_match_data(bc->dev);

Generally, bc_data should in imx95_blk_ctl_dev_data and set once at probe.

So imx95_bc_save_reg() and imx95_bc_restore_reg() will be simpfied.

> +	if (!bc_data)
> +		return;
> +
> +	writel(bc->clk_reg_restore, bc->base + bc_data->clk_reg_offset);
> +}
> +
>  #ifdef CONFIG_PM
>  static int imx95_bc_runtime_suspend(struct device *dev)
>  {
>  	struct imx95_blk_ctl *bc = dev_get_drvdata(dev);
>
> +	imx95_bc_save_reg(bc);

this help function just one line. direct use

writel(bc->clk_reg_restore, bc->base + bc->bc_data->clk_reg_offset);

>  	clk_disable_unprepare(bc->clk_apb);
> +
>  	return 0;
>  }
>
> @@ -461,7 +485,10 @@ static int imx95_bc_runtime_resume(struct device *dev)
>  {
>  	struct imx95_blk_ctl *bc = dev_get_drvdata(dev);
>
> -	return clk_prepare_enable(bc->clk_apb);
> +	clk_prepare_enable(bc->clk_apb);

Need check ret value;

> +	imx95_bc_restore_reg(bc);
> +
> +	return 0;
>  }
>  #endif
>
> @@ -469,22 +496,12 @@ static int imx95_bc_runtime_resume(struct device *dev)
>  static int imx95_bc_suspend(struct device *dev)
>  {
>  	struct imx95_blk_ctl *bc = dev_get_drvdata(dev);
> -	const struct imx95_blk_ctl_dev_data *bc_data;
> -	int ret;
>
> -	bc_data = of_device_get_match_data(dev);
> -	if (!bc_data)
> +	if (pm_runtime_suspended(dev))
>  		return 0;
>
> -	if (bc_data->rpm_enabled) {
> -		ret = pm_runtime_get_sync(bc->dev);
> -		if (ret < 0) {
> -			pm_runtime_put_noidle(bc->dev);
> -			return ret;
> -		}
> -	}
> -
> -	bc->clk_reg_restore = readl(bc->base + bc_data->clk_reg_offset);
> +	imx95_bc_save_reg(bc);
> +	clk_disable_unprepare(bc->clk_apb);
>
>  	return 0;
>  }
> @@ -492,16 +509,12 @@ static int imx95_bc_suspend(struct device *dev)
>  static int imx95_bc_resume(struct device *dev)
>  {
>  	struct imx95_blk_ctl *bc = dev_get_drvdata(dev);
> -	const struct imx95_blk_ctl_dev_data *bc_data;
>
> -	bc_data = of_device_get_match_data(dev);
> -	if (!bc_data)
> +	if (pm_runtime_suspended(dev))
>  		return 0;
>
> -	writel(bc->clk_reg_restore, bc->base + bc_data->clk_reg_offset);
> -
> -	if (bc_data->rpm_enabled)
> -		pm_runtime_put(bc->dev);
> +	clk_prepare_enable(bc->clk_apb);
> +	imx95_bc_restore_reg(bc);
>
>  	return 0;
>  }

look like imx95_bc_suspend(resume) is simple enough

Can you use DEFINE_RUNTIME_DEV_PM_OPS?

Frank

> --
> 2.46.1
>

  reply	other threads:[~2025-07-11  4:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 12:23 [PATCH 0/8] Add support for i.MX94 DCIF Laurentiu Palcu
2025-07-09 12:23 ` [PATCH 1/8] clk: imx95-blk-ctl: Cache registers when RPM routines are called Laurentiu Palcu
2025-07-11  4:03   ` Frank Li [this message]
2025-07-15 12:03     ` Laurentiu Palcu
2025-07-09 12:23 ` [PATCH 2/8] dt-bindings: display: fsl,ldb: Add binding for i.MX94 Laurentiu Palcu
2025-07-10 22:15   ` Rob Herring
2025-07-09 12:23 ` [PATCH 3/8] drm/bridge: fsl-ldb: Get the next non-panel bridge Laurentiu Palcu
2025-07-11  4:19   ` Frank Li
2025-07-11  5:31     ` Liu Ying
2025-07-09 12:23 ` [PATCH 4/8] drm/bridge: fsl-ldb: Add support for i.MX94 Laurentiu Palcu
2025-07-11  4:26   ` Frank Li
2025-07-09 12:23 ` [PATCH 5/8] dt-bindings: display: imx: Add bindings for i.MX94 DCIF Laurentiu Palcu
2025-07-10 22:18   ` Rob Herring
2025-07-09 12:23 ` [PATCH 6/8] drm/imx: Add support " Laurentiu Palcu
2025-07-11  5:01   ` Frank Li
2025-07-15 12:04     ` Laurentiu Palcu
2025-07-09 12:23 ` [PATCH 7/8] arm64: dts: imx943-evk: Add support for DCIF and LVDS Laurentiu Palcu
2025-07-11  5:07   ` Frank Li
2025-07-15 12:05     ` Laurentiu Palcu
2025-07-09 12:23 ` [PATCH 8/8] MAINTAINERS: Add entry for i.MX94 DCIF driver Laurentiu Palcu
2025-07-09 12:53   ` Daniel Baluta

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=aHCNCokZxIRNPgT6@lizhi-Precision-Tower-5810 \
    --to=frank.li@nxp.com \
    --cc=abel.vesa@linaro.org \
    --cc=abelvesa@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=laurentiu.palcu@oss.nxp.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=peng.fan@nxp.com \
    --cc=s.hauer@pengutronix.de \
    --cc=sboyd@kernel.org \
    --cc=shawnguo@kernel.org \
    /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

all inboxes | Powered by JetHome®