Skip to contentSkip to conversation

regmap: provide regmap_assign_bits()

PATCH Superseded Bartosz Golaszewski 2 participants 5 messages Oct 26, 2020 – Oct 29, 2020 Register map abstraction

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regmap: provide regmap_assign_bits()

From: Bartosz Golaszewski <[email protected]>

Add another bits helper to regmap API: this one sets given bits if value is true and clears them if it's false.

---
Hi Mark,

I'm sending this patch without any user yet but we have a use-case over in the GPIO subsystem where this will come in handy soon.

Bartosz

 include/linux/regmap.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/regmap.h +16 -0
index e7834d98207f..62099e7a3ed6 100644
@@ -1148,6 +1148,15 @@ static inline int regmap_clear_bits(struct regmap *map,
 	return regmap_update_bits_base(map, reg, bits, 0, NULL, false, false);
 }
 
+static inline int regmap_assign_bits(struct regmap *map, unsigned int reg,
+				     unsigned int bits, bool value)
+{
+	if (value)
+		return regmap_set_bits(map, reg, bits);
+	else
+		return regmap_clear_bits(map, reg, bits);
+}
+
 int regmap_test_bits(struct regmap *map, unsigned int reg, unsigned int bits);
 
 /**
@@ -1554,6 +1563,13 @@ static inline int regmap_clear_bits(struct regmap *map,
 	return -EINVAL;
 }
 
+static inline int regmap_assign_bits(struct regmap *map, unsigned int reg,
+				     unsigned int bits, bool value)
+{
+	WARN_ONCE(1, "regmap API is disabled");
+	return -EINVAL;
+}
+
 static inline int regmap_test_bits(struct regmap *map,
 				   unsigned int reg, unsigned int bits)
 {
Signature · 1 line
2.29.1
maintainer
#1 lore raw
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add another bits helper to regmap API: this one sets given bits if value is true and clears them if it's false.

What's the use case?

Review

Quoted 2 lines
(quoted diff) +2 -0
+static inline int regmap_assign_bits(struct regmap *map, unsigned int reg,
+				     unsigned int bits, bool value)

I don't have a great suggestion but this naming feels prone to confusion with _update_bits().

#2 lore raw
Quoted 9 lines · Mark Brown
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add another bits helper to regmap API: this one sets given bits if value is true and clears them if it's false.

What's the use case?

Basically what the function does: set bits if a condition is true, clear them if false. I think this is a common enough use-case to warrant a helper.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static inline int regmap_assign_bits(struct regmap *map, unsigned int reg,
+                                  unsigned int bits, bool value)

I don't have a great suggestion but this naming feels prone to confusion with _update_bits().

This is already used in bitops - we have set_bit(), clear_bit() and assign_bit(). People are used to it and I thought I'd stay consistent with this naming.

Bartosz

maintainer
#3 lore raw
Quoted 11 lines · Bartosz Golaszewski
Quoted 6 lines · Mark Brown
Quoted 2 lines · Bartosz Golaszewski

Add another bits helper to regmap API: this one sets given bits if value is true and clears them if it's false.

What's the use case?

Basically what the function does: set bits if a condition is true, clear them if false. I think this is a common enough use-case to warrant a helper.

I can tell what the function does, I can't tell why you'd want it and simply stating that it's common isn't helping me here :(

#4 lore raw
Quoted 8 lines · Mark Brown
Quoted 5 lines · Bartosz Golaszewski
Quoted 4 lines · Mark Brown
Quoted 2 lines · Bartosz Golaszewski

Add another bits helper to regmap API: this one sets given bits if value is true and clears them if it's false.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What's the use case?

Basically what the function does: set bits if a condition is true, clear them if false. I think this is a common enough use-case to warrant a helper.

I can tell what the function does, I can't tell why you'd want it and simply stating that it's common isn't helping me here :(

Got it, I'll resend this together with the patches that need it then.

Bartosz