summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Trumtrar <s.trumtrar@pengutronix.de>2017-10-06 11:53:02 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-10-16 10:35:26 +0200
commit25c3fb28d8017595942115d4dbffc16d96f43930 (patch)
tree229e15cc79b476c8fc8e7bf5437bc72ac6258dff
parent1cb2517f1b6715e15c5858947d5a1991b6c6c780 (diff)
downloadbarebox-25c3fb28d8017595942115d4dbffc16d96f43930.tar.gz
regmap: port regmap_update_bits from linux
Port the regmap_update_bits function from linux v4.14-rc1 to barebox. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/base/regmap/regmap.c29
-rw-r--r--include/regmap.h3
2 files changed, 31 insertions, 1 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 52b7d88..67d95fe 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -137,6 +137,35 @@ int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
}
/**
+ * regmap_update_bits() - Perform a read/modify/write cycle on a register
+ *
+ * @map: Register map to update
+ * @reg: Register to update
+ * @mask: Bitmask to change
+ * @val: New value for bitmask
+ *
+ * Returns zero for success, a negative number on error.
+ */
+int regmap_update_bits(struct regmap *map, unsigned int reg,
+ unsigned int mask, unsigned int val)
+{
+ int ret;
+ unsigned int tmp, orig;
+
+ ret = regmap_read(map, reg, &orig);
+ if (ret != 0)
+ return ret;
+
+ tmp = orig & ~mask;
+ tmp |= val & mask;
+
+ if (tmp != orig)
+ ret = regmap_write(map, reg, tmp);
+
+ return ret;
+}
+
+/**
* regmap_write_bits - write bits of a register in a map
*
* @map: The map
diff --git a/include/regmap.h b/include/regmap.h
index 9675a17..09b7b57 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -62,6 +62,7 @@ int regmap_get_reg_stride(struct regmap *map);
int regmap_write_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val);
-
+int regmap_update_bits(struct regmap *map, unsigned int reg,
+ unsigned int mask, unsigned int val);
#endif /* __REGMAP_H */