From: Bartosz Golaszewski <bgolaszew...@baylibre.com>

In many instances regmap_update_bits() is used for simple bit setting
and clearing. In these cases the last argument is redundant and we can
hide it with a macro.

This adds three new macros for simple bit operations: set_bits,
clear_bits and test_bits.

Signed-off-by: Bartosz Golaszewski <bgolaszew...@baylibre.com>
---
 include/linux/regmap.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 40b07168fd8e..6ef829169f36 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -71,6 +71,24 @@ struct reg_sequence {
        unsigned int delay_us;
 };
 
+#define regmap_set_bits(map, reg, bits) \
+       regmap_update_bits_base(map, reg, bits, bits, NULL, false, false)
+#define regmap_clear_bits(map, reg, bits) \
+       regmap_update_bits_base(map, reg, bits, 0, NULL, false, false)
+/*
+ * Returns -1 if the underlying regmap_read() fails, 0 if at least one of the
+ * tested bits is not set and 1 if all tested bits are set.
+ */
+#define regmap_test_bits(map, reg, bits) \
+({ \
+       unsigned int __val, __ret, __bits; \
+       __bits = (bits); \
+       __ret = regmap_read(map, reg, &__val); \
+       if (__ret == 0) \
+               __ret = (__val & __bits) == __bits ? 1 : 0; \
+       __ret; \
+})
+
 #define        regmap_update_bits(map, reg, mask, val) \
        regmap_update_bits_base(map, reg, mask, val, NULL, false, false)
 #define        regmap_update_bits_async(map, reg, mask, val)\
-- 
2.25.0

Reply via email to