Message ID | 20200528123459.21168-2-brgl@bgdev.pl (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | regmap: provide simple bitops and use them in a driver | expand |
On Thu, May 28, 2020 at 02:34:58PM +0200, Bartosz Golaszewski wrote: > This adds three new macros for simple bit operations: set_bits, > clear_bits and test_bits. Why macros and not static inlines?
czw., 28 maj 2020 o 15:29 Mark Brown <broonie@kernel.org> napisał(a): > > On Thu, May 28, 2020 at 02:34:58PM +0200, Bartosz Golaszewski wrote: > > > This adds three new macros for simple bit operations: set_bits, > > clear_bits and test_bits. > > Why macros and not static inlines? The existing regmap_update_bits_*() helpers are macros too, so I tried to stay consistent. Any reason why they are macros and not static inlines? If there's none, then why not convert them too? Otherwise we'd have a static inline expanding a macro which in turn is calling a function (regmap_update_bits_base()). Bartosz
On Thu, May 28, 2020 at 03:32:40PM +0200, Bartosz Golaszewski wrote: > czw., 28 maj 2020 o 15:29 Mark Brown <broonie@kernel.org> napisał(a): > > Why macros and not static inlines? > The existing regmap_update_bits_*() helpers are macros too, so I tried > to stay consistent. Any reason why they are macros and not static > inlines? If there's none, then why not convert them too? Otherwise > we'd have a static inline expanding a macro which in turn is calling a > function (regmap_update_bits_base()). Not really, I think it was just that they're argument tables. It'd be good to convert them.
czw., 28 maj 2020 o 15:48 Mark Brown <broonie@kernel.org> napisał(a): > > On Thu, May 28, 2020 at 03:32:40PM +0200, Bartosz Golaszewski wrote: > > czw., 28 maj 2020 o 15:29 Mark Brown <broonie@kernel.org> napisał(a): > > > > Why macros and not static inlines? > > > The existing regmap_update_bits_*() helpers are macros too, so I tried > > to stay consistent. Any reason why they are macros and not static > > inlines? If there's none, then why not convert them too? Otherwise > > we'd have a static inline expanding a macro which in turn is calling a > > function (regmap_update_bits_base()). > > Not really, I think it was just that they're argument tables. It'd be > good to convert them. Ok. So I'm seeing there are a lot of macros in regmap.h that could become static inlines but given the amount of regmap users: how about we do it separately and in the meantime I'll just modify this series to use static inlines? Bartosz
On Thu, May 28, 2020 at 03:57:24PM +0200, Bartosz Golaszewski wrote: > Ok. So I'm seeing there are a lot of macros in regmap.h that could > become static inlines but given the amount of regmap users: how about > we do it separately and in the meantime I'll just modify this series > to use static inlines? Sure.
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)\