summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorNeil Armstrong <narmstrong@baylibre.com>2018-04-27 11:56:14 +0200
committerTom Rini <trini@konsulko.com>2018-05-08 09:07:40 -0400
commit285cbcf97f2b1dcadedb6835b3e9662c7fba0fe2 (patch)
treee4ddd9047b0afea65ffc4422a56974efa2cfd389 /drivers/core
parentdbe2fcb87d7d2a64e5ed3661e19b79f7014e5165 (diff)
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 <narmstrong@baylibre.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/regmap.c14
1 files changed, 14 insertions, 0 deletions
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, &reg);
+ if (ret)
+ return ret;
+
+ reg &= ~mask;
+
+ return regmap_write(map, offset, reg | val);
+}