aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Ripard <maxime.ripard@free-electrons.com>2018-02-21 04:20:25 -0500
committerMark Brown <broonie@kernel.org>2018-02-26 06:05:44 -0500
commit31895662f9ba81e8ea9ef05abf8edcb29d4b9c18 (patch)
tree977da55be387cc63f74a29393193261cb082780c
parent7928b2cbe55b2a410a0f5c1f154610059c57b1b2 (diff)
regmap: mmio: Add function to attach a clock
regmap_init_mmio_clk allows to specify a clock that needs to be enabled while accessing the registers. However, that clock is retrieved through its clock ID, which means it will lookup that clock based on the current device that registers the regmap, and, in the DT case, will only look in that device OF node. This might be problematic if the clock to enable is stored in another node. Let's add a function that allows to attach a clock that has already been retrieved to a regmap in order to fix this. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/base/regmap/regmap-mmio.c24
-rw-r--r--include/linux/regmap.h3
2 files changed, 27 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index 5189fd6182f6..5cadfd3394d8 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -28,6 +28,8 @@
28struct regmap_mmio_context { 28struct regmap_mmio_context {
29 void __iomem *regs; 29 void __iomem *regs;
30 unsigned val_bytes; 30 unsigned val_bytes;
31
32 bool attached_clk;
31 struct clk *clk; 33 struct clk *clk;
32 34
33 void (*reg_write)(struct regmap_mmio_context *ctx, 35 void (*reg_write)(struct regmap_mmio_context *ctx,
@@ -363,4 +365,26 @@ struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
363} 365}
364EXPORT_SYMBOL_GPL(__devm_regmap_init_mmio_clk); 366EXPORT_SYMBOL_GPL(__devm_regmap_init_mmio_clk);
365 367
368int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk)
369{
370 struct regmap_mmio_context *ctx = map->bus_context;
371
372 ctx->clk = clk;
373 ctx->attached_clk = true;
374
375 return clk_prepare(ctx->clk);
376}
377EXPORT_SYMBOL_GPL(regmap_mmio_attach_clk);
378
379void regmap_mmio_detach_clk(struct regmap *map)
380{
381 struct regmap_mmio_context *ctx = map->bus_context;
382
383 clk_unprepare(ctx->clk);
384
385 ctx->attached_clk = false;
386 ctx->clk = NULL;
387}
388EXPORT_SYMBOL_GPL(regmap_mmio_detach_clk);
389
366MODULE_LICENSE("GPL v2"); 390MODULE_LICENSE("GPL v2");
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 6a3aeba40e9e..5f7ad0552c03 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -21,6 +21,7 @@
21#include <linux/lockdep.h> 21#include <linux/lockdep.h>
22 22
23struct module; 23struct module;
24struct clk;
24struct device; 25struct device;
25struct i2c_client; 26struct i2c_client;
26struct irq_domain; 27struct irq_domain;
@@ -905,6 +906,8 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
905 __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \ 906 __regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config, \
906 sdw, config) 907 sdw, config)
907 908
909int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk);
910void regmap_mmio_detach_clk(struct regmap *map);
908void regmap_exit(struct regmap *map); 911void regmap_exit(struct regmap *map);
909int regmap_reinit_cache(struct regmap *map, 912int regmap_reinit_cache(struct regmap *map,
910 const struct regmap_config *config); 913 const struct regmap_config *config);