Skip to content

Commit 78908f4

Browse files
committed
regmap: Let users check if a register is cached
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>
1 parent 47ee108 commit 78908f4

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

drivers/base/regmap/regcache.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,29 @@ void regcache_cache_bypass(struct regmap *map, bool enable)
561561
}
562562
EXPORT_SYMBOL_GPL(regcache_cache_bypass);
563563

564+
/**
565+
* regcache_reg_cached - Check if a register is cached
566+
*
567+
* @map: map to check
568+
* @reg: register to check
569+
*
570+
* Reports if a register is cached.
571+
*/
572+
bool regcache_reg_cached(struct regmap *map, unsigned int reg)
573+
{
574+
unsigned int val;
575+
int ret;
576+
577+
map->lock(map->lock_arg);
578+
579+
ret = regcache_read(map, reg, &val);
580+
581+
map->unlock(map->lock_arg);
582+
583+
return ret == 0;
584+
}
585+
EXPORT_SYMBOL_GPL(regcache_reg_cached);
586+
564587
void regcache_set_val(struct regmap *map, void *base, unsigned int idx,
565588
unsigned int val)
566589
{

include/linux/regmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ int regcache_drop_region(struct regmap *map, unsigned int min,
12871287
void regcache_cache_only(struct regmap *map, bool enable);
12881288
void regcache_cache_bypass(struct regmap *map, bool enable);
12891289
void regcache_mark_dirty(struct regmap *map);
1290+
bool regcache_reg_cached(struct regmap *map, unsigned int reg);
12901291

12911292
bool regmap_check_range_table(struct regmap *map, unsigned int reg,
12921293
const struct regmap_access_table *table);

0 commit comments

Comments
 (0)