2013-10-31 12:02:45

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: [PATCH RFC 0/2] Introduce BITS_MASK macro

From: Srinivas Kandagatla <[email protected]>

This patch series introduces BITS_MASK macro which creates a mask for a given
lsb and msb bit locations. The usage of masks spread over mutiple bits is
becoming very common for example with regmap_update_bits kind of apis. Having a
common macro for this makes much sense and is clean and readable way to encode
the mask rather than having an hex number for a mask.

Second patch is to show an example usage of this new macro in regmap.

Comments ?

Thanks,
srini

Srinivas Kandagatla (2):
bitops: introduce BITS_MASK macro
regmap: move to using BITS_MASK macro

drivers/base/regmap/regmap.c | 3 +--
include/linux/bitops.h | 1 +
2 files changed, 2 insertions(+), 2 deletions(-)

--
1.7.6.5


2013-10-31 12:02:59

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: [PATCH RFC 1/2] bitops: introduce BITS_MASK macro

From: Srinivas Kandagatla <[email protected]>

This patch introduces BITS_MASK macro which creates a mask for a given
lsb and msb bit locations. The usage of masks spread over mutiple bits
is becoming very common for example with regmap_update_bits kind of
apis. Having a common macro for this makes much sense and is clean and
readable way to encode the mask rather than having an hex number for a
mask.

Signed-off-by: Srinivas Kandagatla <[email protected]>
---
include/linux/bitops.h | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index a3b6b82..3ddce97 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -5,6 +5,7 @@
#ifdef __KERNEL__
#define BIT(nr) (1UL << (nr))
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
+#define BITS_MASK(lsb, msb) ((BIT(msb - lsb + 1) - 1) << lsb)
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define BITS_PER_BYTE 8
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
--
1.7.6.5

2013-10-31 12:03:10

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: [PATCH RFC 2/2] regmap: move to using BITS_MASK macro

From: Srinivas Kandagatla <[email protected]>

This patch uses the new BITS_MASK macro for generating mask for multiple
bits.

Signed-off-by: Srinivas Kandagatla <[email protected]>
---
drivers/base/regmap/regmap.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 7d689a1..7433939 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -816,11 +816,10 @@ EXPORT_SYMBOL_GPL(devm_regmap_init);
static void regmap_field_init(struct regmap_field *rm_field,
struct regmap *regmap, struct reg_field reg_field)
{
- int field_bits = reg_field.msb - reg_field.lsb + 1;
rm_field->regmap = regmap;
rm_field->reg = reg_field.reg;
rm_field->shift = reg_field.lsb;
- rm_field->mask = ((BIT(field_bits) - 1) << reg_field.lsb);
+ rm_field->mask = BITS_MASK(reg_field.lsb, reg_field.msb);
}

/**
--
1.7.6.5

2013-10-31 15:38:53

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH RFC 2/2] regmap: move to using BITS_MASK macro

On Thu, Oct 31, 2013 at 11:54:01AM +0000, [email protected] wrote:
> From: Srinivas Kandagatla <[email protected]>
>
> This patch uses the new BITS_MASK macro for generating mask for multiple
> bits.

Acked-by: Mark Brown <[email protected]>

Or I can apply both. There's plenty of other places this could be used.


Attachments:
(No filename) (336.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-10-31 15:57:39

by Srinivas KANDAGATLA

[permalink] [raw]
Subject: Re: [PATCH RFC 2/2] regmap: move to using BITS_MASK macro

On 31/10/13 15:38, Mark Brown wrote:
> On Thu, Oct 31, 2013 at 11:54:01AM +0000, [email protected] wrote:
>> From: Srinivas Kandagatla <[email protected]>
>>
>> This patch uses the new BITS_MASK macro for generating mask for multiple
>> bits.
>
> Acked-by: Mark Brown <[email protected]>
Thanks Mark,
>
> Or I can apply both. There's plenty of other places this could be used.
>
It makes sense to take it via regmap tree as there is dependency on the
first patch.

Thanks,
srini