From 8241946f5082d5b03c4ec109434ea8a7a43d02cb Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 7 May 2020 14:55:30 +0200 Subject: [PATCH] Support regmap_update_bits*() stuff Signed-off-by: Takashi Iwai --- include/linux/regmap.h | 6 ++++++ include/wrapper.h | 1 + lib/hdac_regmap.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/include/linux/regmap.h b/include/linux/regmap.h index b0278f0..27d3294 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -56,4 +56,10 @@ 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); +int regmap_update_bits(struct regmap *map, unsigned int reg, + unsigned int mask, unsigned int val); +int regmap_update_bits_check(struct regmap *map, unsigned int reg, + unsigned int mask, unsigned int val, + bool *change); + #endif /* __LINUX_REGMAP_H */ diff --git a/include/wrapper.h b/include/wrapper.h index f40cab7..cd1bf55 100644 --- a/include/wrapper.h +++ b/include/wrapper.h @@ -154,6 +154,7 @@ typedef unsigned int uuid_le; #define __user #define __bitwise #define __iomem +#define __must_check #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/lib/hdac_regmap.c b/lib/hdac_regmap.c index 3f02f7c..81bcb57 100644 --- a/lib/hdac_regmap.c +++ b/lib/hdac_regmap.c @@ -183,3 +183,34 @@ void regcache_mark_dirty(struct regmap *map) map->cache_dirty = true; } +int regmap_update_bits(struct regmap *map, unsigned int reg, + unsigned int mask, unsigned int val) +{ + return regmap_update_bits_check(map, reg, mask, val, NULL); +} + +int regmap_update_bits_check(struct regmap *map, unsigned int reg, + unsigned int mask, unsigned int val, + bool *change) +{ + unsigned int tmp, orig; + int ret; + + if (change) + *change = false; + + ret = map->config->reg_read(map->bus_context, reg, &orig); + if (ret != 0) + return ret; + + tmp = orig & ~mask; + tmp |= val & mask; + + if (tmp != orig) { + ret = map->config->reg_write(map->bus_context, reg, tmp); + if (ret == 0 && change) + *change = true; + } + + return ret; +}