* [PATCH] regmap: provide regmap_assign_bits()
@ 2020-10-26 15:10 Bartosz Golaszewski
2020-10-29 15:18 ` Mark Brown
0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2020-10-26 15:10 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-kernel, Bartosz Golaszewski, Andy Shevchenko
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Add another bits helper to regmap API: this one sets given bits if value
is true and clears them if it's false.
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
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(+)
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index e7834d98207f..62099e7a3ed6 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -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)
{
--
2.29.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] regmap: provide regmap_assign_bits()
2020-10-26 15:10 [PATCH] regmap: provide regmap_assign_bits() Bartosz Golaszewski
@ 2020-10-29 15:18 ` Mark Brown
2020-10-29 15:44 ` Bartosz Golaszewski
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2020-10-29 15:18 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: linux-kernel, Bartosz Golaszewski, Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 498 bytes --]
On Mon, Oct 26, 2020 at 04:10:15PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> 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?
> +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().
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] regmap: provide regmap_assign_bits()
2020-10-29 15:18 ` Mark Brown
@ 2020-10-29 15:44 ` Bartosz Golaszewski
2020-10-29 15:48 ` Mark Brown
0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2020-10-29 15:44 UTC (permalink / raw)
To: Mark Brown
Cc: Linux Kernel Mailing List, Bartosz Golaszewski, Andy Shevchenko
On Thu, Oct 29, 2020 at 4:18 PM Mark Brown <broonie@kernel.org> wrote:
>
> On Mon, Oct 26, 2020 at 04:10:15PM +0100, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > 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.
> > +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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] regmap: provide regmap_assign_bits()
2020-10-29 15:44 ` Bartosz Golaszewski
@ 2020-10-29 15:48 ` Mark Brown
2020-10-29 15:52 ` Bartosz Golaszewski
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2020-10-29 15:48 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linux Kernel Mailing List, Bartosz Golaszewski, Andy Shevchenko
[-- Attachment #1: Type: text/plain, Size: 651 bytes --]
On Thu, Oct 29, 2020 at 04:44:16PM +0100, Bartosz Golaszewski wrote:
> On Thu, Oct 29, 2020 at 4:18 PM Mark Brown <broonie@kernel.org> wrote:
> > On Mon, Oct 26, 2020 at 04:10:15PM +0100, Bartosz Golaszewski wrote:
> > > 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 :(
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] regmap: provide regmap_assign_bits()
2020-10-29 15:48 ` Mark Brown
@ 2020-10-29 15:52 ` Bartosz Golaszewski
0 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2020-10-29 15:52 UTC (permalink / raw)
To: Mark Brown
Cc: Linux Kernel Mailing List, Bartosz Golaszewski, Andy Shevchenko
On Thu, Oct 29, 2020 at 4:48 PM Mark Brown <broonie@kernel.org> wrote:
>
> On Thu, Oct 29, 2020 at 04:44:16PM +0100, Bartosz Golaszewski wrote:
> > On Thu, Oct 29, 2020 at 4:18 PM Mark Brown <broonie@kernel.org> wrote:
> > > On Mon, Oct 26, 2020 at 04:10:15PM +0100, Bartosz Golaszewski wrote:
>
> > > > 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 :(
Got it, I'll resend this together with the patches that need it then.
Bartosz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-10-29 15:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 15:10 [PATCH] regmap: provide regmap_assign_bits() Bartosz Golaszewski
2020-10-29 15:18 ` Mark Brown
2020-10-29 15:44 ` Bartosz Golaszewski
2020-10-29 15:48 ` Mark Brown
2020-10-29 15:52 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).