linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regmap: mmio: prepare/unprepare clk only when read/write
@ 2020-04-23  5:46 peng.fan
  2020-04-23 10:39 ` Aisheng Dong
  2020-04-23 10:40 ` Mark Brown
  0 siblings, 2 replies; 14+ messages in thread
From: peng.fan @ 2020-04-23  5:46 UTC (permalink / raw)
  To: broonie; +Cc: rafael, linux-kernel, linux-imx, shengjiu.wang, Peng Fan

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


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

end of thread, other threads:[~2022-02-05 18:25 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23  5:46 [PATCH] regmap: mmio: prepare/unprepare clk only when read/write peng.fan
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

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