From 285cbcf97f2b1dcadedb6835b3e9662c7fba0fe2 Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Fri, 27 Apr 2018 11:56:14 +0200 Subject: 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 --- drivers/core/regmap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'drivers') diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index fabcc5f53a8..8e5c3bcf61b 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); +} -- cgit v1.3.1