From: Neil Armstrong Date: Fri, 27 Apr 2018 09:56:14 +0000 (+0200) Subject: regmap: add regmap_update_bits() helper X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=285cbcf97f2b1dcadedb6835b3e9662c7fba0fe2;p=u-boot.git regmap: add regmap_update_bits() helper Add the regmap_update_bits() to simply the read/modify/write of registers in a single command. The function is taken from Linux regmap implementation. Signed-off-by: Neil Armstrong Reviewed-by: Simon Glass --- diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index fabcc5f53a..8e5c3bcf61 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -132,3 +132,17 @@ int regmap_write(struct regmap *map, uint offset, uint val) return 0; } + +int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val) +{ + uint reg; + int ret; + + ret = regmap_read(map, offset, ®); + if (ret) + return ret; + + reg &= ~mask; + + return regmap_write(map, offset, reg | val); +} diff --git a/include/regmap.h b/include/regmap.h index e96c79dd26..6a574eaa41 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -42,6 +42,16 @@ int regmap_read(struct regmap *map, uint offset, uint *valp); #define regmap_read32(map, ptr, member, valp) \ regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp) +/** + * regmap_update_bits() - Perform a read/modify/write using a mask + * + * @map: The map returned by regmap_init_mem*() + * @offset: Offset of the memory + * @mask: Mask to apply to the read value + * @val: Value to apply to the value to write + */ +int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val); + /** * regmap_init_mem() - Set up a new register map that uses memory access *