Message ID | 180e702a15f.e737e37e45859.3135149506136486394@zohomail.com |
---|---|
Headers | show |
Series | Add regmap_field helpers for simple bit operations | expand |
Hi, On 5/22/22 9:23 PM, Li Chen wrote: > From: Li Chen <lchen@ambarella.com> > > We have set/clear/test operations for regmap, but not for regmap_field yet. > So let's introduce regmap_field helpers too. > > In many instances regmap_field_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 static inline function. > > This adds three new helpers for simple bit operations: set_bits, > clear_bits and test_bits (the last one defined as a regular function). > > Signed-off-by: Li Chen <lchen@ambarella.com> > --- > drivers/base/regmap/regmap.c | 22 +++++++++++++++++++++ > include/linux/regmap.h | 37 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 59 insertions(+) > > diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c > index 5e12f7cb5147..a37d6041b7bd 100644 > --- a/drivers/base/regmap/regmap.c > +++ b/drivers/base/regmap/regmap.c > @@ -2208,6 +2208,28 @@ int regmap_field_update_bits_base(struct regmap_field *field, > } > EXPORT_SYMBOL_GPL(regmap_field_update_bits_base); > > +/** > + * regmap_field_test_bits() - Check if all specified bits are set in a > + * register field. > + * > + * @field: Register field to operate on > + * @bits: Bits to test > + * > + * Returns -1 if the underlying regmap_field_read() fails, 0 if at least one of the > + * tested bits is not set and 1 if all tested bits are set. > + */ > +int regmap_field_test_bits(struct regmap_field *field, unsigned int bits) > +{ > + unsigned int val, ret; > + > + ret = regmap_field_read(field, &val); > + if (ret) > + return ret; > + > + return (val & bits) == bits; > +} > +EXPORT_SYMBOL_GPL(regmap_field_test_bits); > + > /** > * regmap_fields_update_bits_base() - Perform a read/modify/write cycle a > * register field with port ID > diff --git a/include/linux/regmap.h b/include/linux/regmap.h > index de81a94d7b30..10b410734d9e 100644 > --- a/include/linux/regmap.h > +++ b/include/linux/regmap.h > @@ -1324,6 +1324,22 @@ static inline int regmap_field_update_bits(struct regmap_field *field, > NULL, false, false); > } > > +static inline int regmap_field_set_bits(struct regmap_field *field, > + unsigned int bits) > +{ > + return regmap_field_update_bits_base(field, bits, 0, NULL, false, > + false); > +} > + > +static inline int regmap_field_clear_bits(struct regmap_field *field, > + unsigned int bits) > +{ > + return regmap_field_update_bits_base(field, bits, bits, NULL, false, > + false); The contents of these two functions are swapped when compared to their names. Regards, Samuel > +} > + > +int regmap_field_test_bits(struct regmap_field *field, unsigned int bits); > + > static inline int > regmap_field_force_update_bits(struct regmap_field *field, > unsigned int mask, unsigned int val) > @@ -1757,6 +1773,27 @@ regmap_field_force_update_bits(struct regmap_field *field, > return -EINVAL; > } > > +static inline int regmap_field_set_bits(struct regmap_field *field, > + unsigned int bits) > +{ > + WARN_ONCE(1, "regmap API is disabled"); > + return -EINVAL; > +} > + > +static inline int regmap_field_clear_bits(struct regmap_field *field, > + unsigned int bits) > +{ > + WARN_ONCE(1, "regmap API is disabled"); > + return -EINVAL; > +} > + > +static inline int regmap_field_test_bits(struct regmap_field *field, > + unsigned int bits) > +{ > + WARN_ONCE(1, "regmap API is disabled"); > + return -EINVAL; > +} > + > static inline int regmap_fields_write(struct regmap_field *field, > unsigned int id, unsigned int val) > { >
Hi Samuel, ---- On Sun, 22 May 2022 20:09:55 -0700 Samuel Holland <samuel@sholland.org> wrote ---- > Hi, > > On 5/22/22 9:23 PM, Li Chen wrote: > > From: Li Chen <lchen@ambarella.com> > > > > We have set/clear/test operations for regmap, but not for regmap_field yet. > > So let's introduce regmap_field helpers too. > > > > In many instances regmap_field_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 static inline function. > > > > This adds three new helpers for simple bit operations: set_bits, > > clear_bits and test_bits (the last one defined as a regular function). > > > > Signed-off-by: Li Chen <lchen@ambarella.com> > > --- > > drivers/base/regmap/regmap.c | 22 +++++++++++++++++++++ > > include/linux/regmap.h | 37 ++++++++++++++++++++++++++++++++++++ > > 2 files changed, 59 insertions(+) > > > > diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c > > index 5e12f7cb5147..a37d6041b7bd 100644 > > --- a/drivers/base/regmap/regmap.c > > +++ b/drivers/base/regmap/regmap.c > > @@ -2208,6 +2208,28 @@ int regmap_field_update_bits_base(struct regmap_field *field, > > } > > EXPORT_SYMBOL_GPL(regmap_field_update_bits_base); > > > > +/** > > + * regmap_field_test_bits() - Check if all specified bits are set in a > > + * register field. > > + * > > + * @field: Register field to operate on > > + * @bits: Bits to test > > + * > > + * Returns -1 if the underlying regmap_field_read() fails, 0 if at least one of the > > + * tested bits is not set and 1 if all tested bits are set. > > + */ > > +int regmap_field_test_bits(struct regmap_field *field, unsigned int bits) > > +{ > > + unsigned int val, ret; > > + > > + ret = regmap_field_read(field, &val); > > + if (ret) > > + return ret; > > + > > + return (val & bits) == bits; > > +} > > +EXPORT_SYMBOL_GPL(regmap_field_test_bits); > > + > > /** > > * regmap_fields_update_bits_base() - Perform a read/modify/write cycle a > > * register field with port ID > > diff --git a/include/linux/regmap.h b/include/linux/regmap.h > > index de81a94d7b30..10b410734d9e 100644 > > --- a/include/linux/regmap.h > > +++ b/include/linux/regmap.h > > @@ -1324,6 +1324,22 @@ static inline int regmap_field_update_bits(struct regmap_field *field, > > NULL, false, false); > > } > > > > +static inline int regmap_field_set_bits(struct regmap_field *field, > > + unsigned int bits) > > +{ > > + return regmap_field_update_bits_base(field, bits, 0, NULL, false, > > + false); > > +} > > + > > +static inline int regmap_field_clear_bits(struct regmap_field *field, > > + unsigned int bits) > > +{ > > + return regmap_field_update_bits_base(field, bits, bits, NULL, false, > > + false); > > The contents of these two functions are swapped when compared to their names. Thanks for spotting this out! Fixed in v3. Regards, Li > > Regards, > Samuel > > > +} > > + > > +int regmap_field_test_bits(struct regmap_field *field, unsigned int bits); > > + > > static inline int > > regmap_field_force_update_bits(struct regmap_field *field, > > unsigned int mask, unsigned int val) > > @@ -1757,6 +1773,27 @@ regmap_field_force_update_bits(struct regmap_field *field, > > return -EINVAL; > > } > > > > +static inline int regmap_field_set_bits(struct regmap_field *field, > > + unsigned int bits) > > +{ > > + WARN_ONCE(1, "regmap API is disabled"); > > + return -EINVAL; > > +} > > + > > +static inline int regmap_field_clear_bits(struct regmap_field *field, > > + unsigned int bits) > > +{ > > + WARN_ONCE(1, "regmap API is disabled"); > > + return -EINVAL; > > +} > > + > > +static inline int regmap_field_test_bits(struct regmap_field *field, > > + unsigned int bits) > > +{ > > + WARN_ONCE(1, "regmap API is disabled"); > > + return -EINVAL; > > +} > > + > > static inline int regmap_fields_write(struct regmap_field *field, > > unsigned int id, unsigned int val) > > { > > > >
On Sun, May 22, 2022 at 07:22:37PM -0700, Li Chen wrote: > From: Li Chen <lchen@ambarella.com> > > This series proposes to add simple bit operations for setting, clearing > and testing specific bits with regmap_field. Please don't send new patches in reply to old patches or serieses, this makes it harder for both people and tools to understand what is going on - it can bury things in mailboxes and make it difficult to keep track of what current patches are, both for the new patches and the old ones.
Hi Mark ---- On Mon, 23 May 2022 04:39:46 -0700 Mark Brown <broonie@kernel.org> wrote ---- > On Sun, May 22, 2022 at 07:22:37PM -0700, Li Chen wrote: > > From: Li Chen <lchen@ambarella.com> > > > > This series proposes to add simple bit operations for setting, clearing > > and testing specific bits with regmap_field. > > Please don't send new patches in reply to old patches or serieses, this > makes it harder for both people and tools to understand what is going > on - it can bury things in mailboxes and make it difficult to keep track > of what current patches are, both for the new patches and the old ones. > Thanks for letting me know, I won't do this again. Regards, Li
From: Li Chen <lchen@ambarella.com> This series proposes to add simple bit operations for setting, clearing and testing specific bits with regmap_field. Li Chen (4): regmap: provide regmap_field helpers for simple bit operations ASoC: sunxi: Use {regmap/regmap_field}_{set/clear}_bits helpers pinctrl: bcm: Use regmap_field_{set/clear}_bits helpers pinctrl: st: Switch to use regmap_field_test_bits drivers/base/regmap/regmap.c | 22 ++++++++ drivers/pinctrl/bcm/pinctrl-bcm6358.c | 2 +- drivers/pinctrl/pinctrl-st.c | 23 ++++---- include/linux/regmap.h | 37 +++++++++++++ sound/soc/sunxi/sun4i-codec.c | 78 +++++++++++---------------- 5 files changed, 99 insertions(+), 63 deletions(-)