mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: peng.fan@nxp.com
To: broonie@kernel.org
Cc: rafael@kernel.org, linux-kernel@vger.kernel.org,
	linux-imx@nxp.com, shengjiu.wang@nxp.com,
	Peng Fan <peng.fan@nxp.com>
Subject: [PATCH] regmap: mmio: prepare/unprepare clk only when read/write
Date: Thu, 23 Apr 2020 13:46:31 +0800	[thread overview]
Message-ID: <1587620791-5279-1-git-send-email-peng.fan@nxp.com> (raw)

From: Peng Fan <peng.fan@nxp.com>

use clk_prepare at the very beginning will invoke pm runtime resume,
if the clk is binded with a power domain. This will cause runtime
power high. Let's use clk_prepare_enable and clk_disable_unprepare
when read/write to avoid the runtime power issue.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/base/regmap/regmap-mmio.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index af967d8f975e..a1ad7419c4a3 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -118,7 +118,7 @@ static int regmap_mmio_write(void *context, unsigned int reg, unsigned int val)
 	int ret;
 
 	if (!IS_ERR(ctx->clk)) {
-		ret = clk_enable(ctx->clk);
+		ret = clk_prepare_enable(ctx->clk);
 		if (ret < 0)
 			return ret;
 	}
@@ -126,7 +126,7 @@ static int regmap_mmio_write(void *context, unsigned int reg, unsigned int val)
 	ctx->reg_write(ctx, reg, val);
 
 	if (!IS_ERR(ctx->clk))
-		clk_disable(ctx->clk);
+		clk_disable_unprepare(ctx->clk);
 
 	return 0;
 }
@@ -175,7 +175,7 @@ static int regmap_mmio_read(void *context, unsigned int reg, unsigned int *val)
 	int ret;
 
 	if (!IS_ERR(ctx->clk)) {
-		ret = clk_enable(ctx->clk);
+		ret = clk_prepare_enable(ctx->clk);
 		if (ret < 0)
 			return ret;
 	}
@@ -183,7 +183,7 @@ static int regmap_mmio_read(void *context, unsigned int reg, unsigned int *val)
 	*val = ctx->reg_read(ctx, reg);
 
 	if (!IS_ERR(ctx->clk))
-		clk_disable(ctx->clk);
+		clk_disable_unprepare(ctx->clk);
 
 	return 0;
 }
@@ -193,7 +193,6 @@ static void regmap_mmio_free_context(void *context)
 	struct regmap_mmio_context *ctx = context;
 
 	if (!IS_ERR(ctx->clk)) {
-		clk_unprepare(ctx->clk);
 		if (!ctx->attached_clk)
 			clk_put(ctx->clk);
 	}
@@ -305,12 +304,6 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev,
 		goto err_free;
 	}
 
-	ret = clk_prepare(ctx->clk);
-	if (ret < 0) {
-		clk_put(ctx->clk);
-		goto err_free;
-	}
-
 	return ctx;
 
 err_free:
@@ -361,7 +354,7 @@ int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk)
 	ctx->clk = clk;
 	ctx->attached_clk = true;
 
-	return clk_prepare(ctx->clk);
+	return 0;
 }
 EXPORT_SYMBOL_GPL(regmap_mmio_attach_clk);
 
@@ -369,8 +362,6 @@ void regmap_mmio_detach_clk(struct regmap *map)
 {
 	struct regmap_mmio_context *ctx = map->bus_context;
 
-	clk_unprepare(ctx->clk);
-
 	ctx->attached_clk = false;
 	ctx->clk = NULL;
 }
-- 
2.16.4


             reply	other threads:[~2020-04-23  5:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23  5:46 peng.fan [this message]
2020-04-23 10:39 ` Aisheng Dong
2020-04-23 10:40 ` Mark Brown
2020-04-23 10:51   ` Peng Fan
2020-04-23 11:22     ` Mark Brown
2020-04-24  1:27       ` Peng Fan
2020-04-24 10:30         ` Mark Brown
2022-01-24 23:50           ` regmap: mmio: lack of runtime_pm support for debugfs Brian Norris
2022-02-04 19:02             ` Mark Brown
2022-02-04 19:21               ` Brian Norris
2022-02-04 19:41                 ` Mark Brown
2022-02-04 19:53                   ` Brian Norris
2022-02-05 18:25                     ` Mark Brown
2022-02-04 20:05                 ` Brian Norris

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=1587620791-5279-1-git-send-email-peng.fan@nxp.com \
    --to=peng.fan@nxp.com \
    --cc=broonie@kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=shengjiu.wang@nxp.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

all inboxes | Powered by JetHome®