]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
regmap: Let users check if a register is cached
authorMark Brown <broonie@kernel.org>
Mon, 17 Jul 2023 20:33:03 +0000 (21:33 +0100)
committerMark Brown <broonie@kernel.org>
Tue, 18 Jul 2023 14:05:10 +0000 (15:05 +0100)
The HDA driver has a use case for checking if a register is cached which
it bodges in awkwardly and unclearly. Provide an API which allows it to
directly do what it's trying to do.

Reviewed-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20230717-regmap-cache-check-v1-1-73ef688afae3@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/regmap/regcache.c
include/linux/regmap.h

index 156490ab7f34da65fb0cccf5e79ac7ca00def25b..8accf6292fe1258af0a0d8514bdc5fa6dc382aa7 100644 (file)
@@ -561,6 +561,29 @@ void regcache_cache_bypass(struct regmap *map, bool enable)
 }
 EXPORT_SYMBOL_GPL(regcache_cache_bypass);
 
+/**
+ * regcache_reg_cached - Check if a register is cached
+ *
+ * @map: map to check
+ * @reg: register to check
+ *
+ * Reports if a register is cached.
+ */
+bool regcache_reg_cached(struct regmap *map, unsigned int reg)
+{
+       unsigned int val;
+       int ret;
+
+       map->lock(map->lock_arg);
+
+       ret = regcache_read(map, reg, &val);
+
+       map->unlock(map->lock_arg);
+
+       return ret == 0;
+}
+EXPORT_SYMBOL_GPL(regcache_reg_cached);
+
 void regcache_set_val(struct regmap *map, void *base, unsigned int idx,
                      unsigned int val)
 {
index 8fc0b3ebce44639537591f9c5843346f018e47f6..c9182a47736ef883517ad571fb359f4f90d93d6d 100644 (file)
@@ -1287,6 +1287,7 @@ int regcache_drop_region(struct regmap *map, unsigned int min,
 void regcache_cache_only(struct regmap *map, bool enable);
 void regcache_cache_bypass(struct regmap *map, bool enable);
 void regcache_mark_dirty(struct regmap *map);
+bool regcache_reg_cached(struct regmap *map, unsigned int reg);
 
 bool regmap_check_range_table(struct regmap *map, unsigned int reg,
                              const struct regmap_access_table *table);