* [PATCH v2 01/11] lib/test_bitmap: Force argument of bitmap_parselist_user() to proper address space
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 02/11] lib/test_bitmap: Undefine macros after use Andy Shevchenko
` (10 subsequent siblings)
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
Sparse complains:
lib/test_bitmap.c:345:58: warning: incorrect type in argument 1 (different address spaces)
lib/test_bitmap.c:345:58: expected char const [noderef] <asn:1> *ubuf
lib/test_bitmap.c:345:58: got char const *const in
Force argument of bitmap_parselist_user() to proper address space.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_bitmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index dc167c13eb39..09aa29a6b562 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -330,7 +330,7 @@ static void __init __test_bitmap_parselist(int is_user)
set_fs(KERNEL_DS);
time = ktime_get();
- err = bitmap_parselist_user(ptest.in, len,
+ err = bitmap_parselist_user((__force const char __user *)ptest.in, len,
bmap, ptest.nbits);
time = ktime_get() - time;
set_fs(orig_fs);
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 02/11] lib/test_bitmap: Undefine macros after use
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 01/11] lib/test_bitmap: Force argument of bitmap_parselist_user() to proper address space Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 03/11] lib/test_bitmap: Name EXP_BYTES properly Andy Shevchenko
` (9 subsequent siblings)
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
There is no need to keep step and ptest macros defined in entire file.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_bitmap.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 09aa29a6b562..d2fa94e45a46 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -311,6 +311,8 @@ static const struct test_bitmap_parselist parselist_tests[] __initconst = {
{-EINVAL, "a-31:10/1", NULL, 8, 0},
{-EINVAL, "0-31:a/1", NULL, 8, 0},
{-EINVAL, "0-\n", NULL, 8, 0},
+
+#undef step
};
static void __init __test_bitmap_parselist(int is_user)
@@ -357,6 +359,8 @@ static void __init __test_bitmap_parselist(int is_user)
if (ptest.flags & PARSE_TIME)
pr_err("parselist%s: %d: input is '%s' OK, Time: %llu\n",
mode, i, ptest.in, time);
+
+#undef ptest
}
}
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 03/11] lib/test_bitmap: Name EXP_BYTES properly
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 01/11] lib/test_bitmap: Force argument of bitmap_parselist_user() to proper address space Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 02/11] lib/test_bitmap: Undefine macros after use Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 04/11] lib/test_bitmap: Rename exp to exp1 to avoid ambiguous name Andy Shevchenko
` (8 subsequent siblings)
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
EXP_BYTES has been wrongly named. It's a size of the exp array in bits.
While here, go ahead and rename to EXP1_IN_BITS to avoid double renaming
when exp will be renamed to exp1 in the next patch
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_bitmap.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index d2fa94e45a46..38f923411ada 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -374,17 +374,17 @@ static void __init test_bitmap_parselist_user(void)
__test_bitmap_parselist(1);
}
-#define EXP_BYTES (sizeof(exp) * 8)
+#define EXP1_IN_BITS (sizeof(exp) * 8)
static void __init test_bitmap_arr32(void)
{
unsigned int nbits, next_bit;
- u32 arr[sizeof(exp) / 4];
- DECLARE_BITMAP(bmap2, EXP_BYTES);
+ u32 arr[EXP1_IN_BITS / 32];
+ DECLARE_BITMAP(bmap2, EXP1_IN_BITS);
memset(arr, 0xa5, sizeof(arr));
- for (nbits = 0; nbits < EXP_BYTES; ++nbits) {
+ for (nbits = 0; nbits < EXP1_IN_BITS; ++nbits) {
bitmap_to_arr32(arr, exp, nbits);
bitmap_from_arr32(bmap2, arr, nbits);
expect_eq_bitmap(bmap2, exp, nbits);
@@ -396,7 +396,7 @@ static void __init test_bitmap_arr32(void)
" tail is not safely cleared: %d\n",
nbits, next_bit);
- if (nbits < EXP_BYTES - 32)
+ if (nbits < EXP1_IN_BITS - 32)
expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)],
0xa5a5a5a5);
}
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 04/11] lib/test_bitmap: Rename exp to exp1 to avoid ambiguous name
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (2 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 03/11] lib/test_bitmap: Name EXP_BYTES properly Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 05/11] lib/test_bitmap: Move exp1 and exp2 upper for others to use Andy Shevchenko
` (7 subsequent siblings)
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
One function is using exp as local variable.
Avoid ambiguous naming by rename global one to exp1.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_bitmap.c | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 38f923411ada..6b70166ac960 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -247,7 +247,7 @@ struct test_bitmap_parselist{
const int flags;
};
-static const unsigned long exp[] __initconst = {
+static const unsigned long exp1[] __initconst = {
BITMAP_FROM_U64(1),
BITMAP_FROM_U64(2),
BITMAP_FROM_U64(0x0000ffff),
@@ -271,29 +271,29 @@ static const unsigned long exp2[] __initconst = {
static const struct test_bitmap_parselist parselist_tests[] __initconst = {
#define step (sizeof(u64) / sizeof(unsigned long))
- {0, "0", &exp[0], 8, 0},
- {0, "1", &exp[1 * step], 8, 0},
- {0, "0-15", &exp[2 * step], 32, 0},
- {0, "16-31", &exp[3 * step], 32, 0},
- {0, "0-31:1/2", &exp[4 * step], 32, 0},
- {0, "1-31:1/2", &exp[5 * step], 32, 0},
- {0, "0-31:1/4", &exp[6 * step], 32, 0},
- {0, "1-31:1/4", &exp[7 * step], 32, 0},
- {0, "0-31:4/4", &exp[8 * step], 32, 0},
- {0, "1-31:4/4", &exp[9 * step], 32, 0},
- {0, "0-31:1/4,32-63:2/4", &exp[10 * step], 64, 0},
- {0, "0-31:3/4,32-63:4/4", &exp[11 * step], 64, 0},
- {0, " ,, 0-31:3/4 ,, 32-63:4/4 ,, ", &exp[11 * step], 64, 0},
+ {0, "0", &exp1[0], 8, 0},
+ {0, "1", &exp1[1 * step], 8, 0},
+ {0, "0-15", &exp1[2 * step], 32, 0},
+ {0, "16-31", &exp1[3 * step], 32, 0},
+ {0, "0-31:1/2", &exp1[4 * step], 32, 0},
+ {0, "1-31:1/2", &exp1[5 * step], 32, 0},
+ {0, "0-31:1/4", &exp1[6 * step], 32, 0},
+ {0, "1-31:1/4", &exp1[7 * step], 32, 0},
+ {0, "0-31:4/4", &exp1[8 * step], 32, 0},
+ {0, "1-31:4/4", &exp1[9 * step], 32, 0},
+ {0, "0-31:1/4,32-63:2/4", &exp1[10 * step], 64, 0},
+ {0, "0-31:3/4,32-63:4/4", &exp1[11 * step], 64, 0},
+ {0, " ,, 0-31:3/4 ,, 32-63:4/4 ,, ", &exp1[11 * step], 64, 0},
{0, "0-31:1/4,32-63:2/4,64-95:3/4,96-127:4/4", exp2, 128, 0},
{0, "0-2047:128/256", NULL, 2048, PARSE_TIME},
- {0, "", &exp[12 * step], 8, 0},
- {0, "\n", &exp[12 * step], 8, 0},
- {0, ",, ,, , , ,", &exp[12 * step], 8, 0},
- {0, " , ,, , , ", &exp[12 * step], 8, 0},
- {0, " , ,, , , \n", &exp[12 * step], 8, 0},
+ {0, "", &exp1[12 * step], 8, 0},
+ {0, "\n", &exp1[12 * step], 8, 0},
+ {0, ",, ,, , , ,", &exp1[12 * step], 8, 0},
+ {0, " , ,, , , ", &exp1[12 * step], 8, 0},
+ {0, " , ,, , , \n", &exp1[12 * step], 8, 0},
{-EINVAL, "-1", NULL, 8, 0},
{-EINVAL, "-0", NULL, 8, 0},
@@ -374,7 +374,7 @@ static void __init test_bitmap_parselist_user(void)
__test_bitmap_parselist(1);
}
-#define EXP1_IN_BITS (sizeof(exp) * 8)
+#define EXP1_IN_BITS (sizeof(exp1) * 8)
static void __init test_bitmap_arr32(void)
{
@@ -385,9 +385,9 @@ static void __init test_bitmap_arr32(void)
memset(arr, 0xa5, sizeof(arr));
for (nbits = 0; nbits < EXP1_IN_BITS; ++nbits) {
- bitmap_to_arr32(arr, exp, nbits);
+ bitmap_to_arr32(arr, exp1, nbits);
bitmap_from_arr32(bmap2, arr, nbits);
- expect_eq_bitmap(bmap2, exp, nbits);
+ expect_eq_bitmap(bmap2, exp1, nbits);
next_bit = find_next_bit(bmap2,
round_up(nbits, BITS_PER_LONG), nbits);
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 05/11] lib/test_bitmap: Move exp1 and exp2 upper for others to use
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (3 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 04/11] lib/test_bitmap: Rename exp to exp1 to avoid ambiguous name Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 06/11] lib/test_bitmap: Fix comment about this file Andy Shevchenko
` (6 subsequent siblings)
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
Some test cases may re-use predefined exp1 and exp2 bitmaps.
Move them upper in the file.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_bitmap.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 6b70166ac960..449d0882b488 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -21,6 +21,26 @@ static unsigned failed_tests __initdata;
static char pbl_buffer[PAGE_SIZE] __initdata;
+static const unsigned long exp1[] __initconst = {
+ BITMAP_FROM_U64(1),
+ BITMAP_FROM_U64(2),
+ BITMAP_FROM_U64(0x0000ffff),
+ BITMAP_FROM_U64(0xffff0000),
+ BITMAP_FROM_U64(0x55555555),
+ BITMAP_FROM_U64(0xaaaaaaaa),
+ BITMAP_FROM_U64(0x11111111),
+ BITMAP_FROM_U64(0x22222222),
+ BITMAP_FROM_U64(0xffffffff),
+ BITMAP_FROM_U64(0xfffffffe),
+ BITMAP_FROM_U64(0x3333333311111111ULL),
+ BITMAP_FROM_U64(0xffffffff77777777ULL),
+ BITMAP_FROM_U64(0),
+};
+
+static const unsigned long exp2[] __initconst = {
+ BITMAP_FROM_U64(0x3333333311111111ULL),
+ BITMAP_FROM_U64(0xffffffff77777777ULL),
+};
static bool __init
__check_eq_uint(const char *srcfile, unsigned int line,
@@ -247,27 +267,6 @@ struct test_bitmap_parselist{
const int flags;
};
-static const unsigned long exp1[] __initconst = {
- BITMAP_FROM_U64(1),
- BITMAP_FROM_U64(2),
- BITMAP_FROM_U64(0x0000ffff),
- BITMAP_FROM_U64(0xffff0000),
- BITMAP_FROM_U64(0x55555555),
- BITMAP_FROM_U64(0xaaaaaaaa),
- BITMAP_FROM_U64(0x11111111),
- BITMAP_FROM_U64(0x22222222),
- BITMAP_FROM_U64(0xffffffff),
- BITMAP_FROM_U64(0xfffffffe),
- BITMAP_FROM_U64(0x3333333311111111ULL),
- BITMAP_FROM_U64(0xffffffff77777777ULL),
- BITMAP_FROM_U64(0),
-};
-
-static const unsigned long exp2[] __initconst = {
- BITMAP_FROM_U64(0x3333333311111111ULL),
- BITMAP_FROM_U64(0xffffffff77777777ULL)
-};
-
static const struct test_bitmap_parselist parselist_tests[] __initconst = {
#define step (sizeof(u64) / sizeof(unsigned long))
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 06/11] lib/test_bitmap: Fix comment about this file
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (4 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 05/11] lib/test_bitmap: Move exp1 and exp2 upper for others to use Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 07/11] bitmap: Introduce bitmap_replace() helper Andy Shevchenko
` (5 subsequent siblings)
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
This test case file is about bitmap API, and not printf() facility.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_bitmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 449d0882b488..4544847cf81e 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
- * Test cases for printf facility.
+ * Test cases for bitmap API.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 07/11] bitmap: Introduce bitmap_replace() helper
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (5 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 06/11] lib/test_bitmap: Fix comment about this file Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-12-26 16:15 ` Guenter Roeck
2019-10-22 17:29 ` [PATCH v2 08/11] gpio: pca953x: Remove redundant variable and check in IRQ handler Andy Shevchenko
` (4 subsequent siblings)
11 siblings, 1 reply; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko, Yury Norov
In some drivers we want to have a single operation over bitmap which is
an equivalent to:
*dst = (*old & ~(*mask)) | (*new & *mask)
Introduce bitmap_replace() helper for this.
Cc: Yury Norov <ynorov@marvell.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/bitmap.h | 16 ++++++++++++++++
lib/bitmap.c | 12 ++++++++++++
lib/test_bitmap.c | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 9f046609e809..ff335b22f23c 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -53,6 +53,7 @@
* bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above
* bitmap_shift_right(dst, src, n, nbits) *dst = *src >> n
* bitmap_shift_left(dst, src, n, nbits) *dst = *src << n
+ * bitmap_replace(dst, old, new, mask, nbits) *dst = (*old & ~(*mask)) | (*new & *mask)
* bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src)
* bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit)
* bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap
@@ -140,6 +141,9 @@ extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
extern int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
+extern void __bitmap_replace(unsigned long *dst,
+ const unsigned long *old, const unsigned long *new,
+ const unsigned long *mask, unsigned int nbits);
extern int __bitmap_intersects(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
extern int __bitmap_subset(const unsigned long *bitmap1,
@@ -434,6 +438,18 @@ static inline void bitmap_shift_left(unsigned long *dst, const unsigned long *sr
__bitmap_shift_left(dst, src, shift, nbits);
}
+static inline void bitmap_replace(unsigned long *dst,
+ const unsigned long *old,
+ const unsigned long *new,
+ const unsigned long *mask,
+ unsigned int nbits)
+{
+ if (small_const_nbits(nbits))
+ *dst = (*old & ~(*mask)) | (*new & *mask);
+ else
+ __bitmap_replace(dst, old, new, mask, nbits);
+}
+
static inline int bitmap_parse(const char *buf, unsigned int buflen,
unsigned long *maskp, int nmaskbits)
{
diff --git a/lib/bitmap.c b/lib/bitmap.c
index f9e834841e94..4250519d7d1c 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -222,6 +222,18 @@ int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
}
EXPORT_SYMBOL(__bitmap_andnot);
+void __bitmap_replace(unsigned long *dst,
+ const unsigned long *old, const unsigned long *new,
+ const unsigned long *mask, unsigned int nbits)
+{
+ unsigned int k;
+ unsigned int nr = BITS_TO_LONGS(nbits);
+
+ for (k = 0; k < nr; k++)
+ dst[k] = (old[k] & ~mask[k]) | (new[k] & mask[k]);
+}
+EXPORT_SYMBOL(__bitmap_replace);
+
int __bitmap_intersects(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 4544847cf81e..e14a15ac250b 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -42,6 +42,19 @@ static const unsigned long exp2[] __initconst = {
BITMAP_FROM_U64(0xffffffff77777777ULL),
};
+/* Fibonacci sequence */
+static const unsigned long exp2_to_exp3_mask[] __initconst = {
+ BITMAP_FROM_U64(0x008000020020212eULL),
+};
+/* exp3_0_1 = (exp2[0] & ~exp2_to_exp3_mask) | (exp2[1] & exp2_to_exp3_mask) */
+static const unsigned long exp3_0_1[] __initconst = {
+ BITMAP_FROM_U64(0x33b3333311313137ULL),
+};
+/* exp3_1_0 = (exp2[1] & ~exp2_to_exp3_mask) | (exp2[0] & exp2_to_exp3_mask) */
+static const unsigned long exp3_1_0[] __initconst = {
+ BITMAP_FROM_U64(0xff7fffff77575751ULL),
+};
+
static bool __init
__check_eq_uint(const char *srcfile, unsigned int line,
const unsigned int exp_uint, unsigned int x)
@@ -257,6 +270,30 @@ static void __init test_copy(void)
expect_eq_pbl("0-108,128-1023", bmap2, 1024);
}
+#define EXP2_IN_BITS (sizeof(exp2) * 8)
+
+static void __init test_replace(void)
+{
+ unsigned int nbits = 64;
+ DECLARE_BITMAP(bmap, 1024);
+
+ bitmap_zero(bmap, 1024);
+ bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+ expect_eq_bitmap(bmap, exp3_0_1, nbits);
+
+ bitmap_zero(bmap, 1024);
+ bitmap_replace(bmap, &exp2[1], &exp2[0], exp2_to_exp3_mask, nbits);
+ expect_eq_bitmap(bmap, exp3_1_0, nbits);
+
+ bitmap_fill(bmap, 1024);
+ bitmap_replace(bmap, &exp2[0], &exp2[1], exp2_to_exp3_mask, nbits);
+ expect_eq_bitmap(bmap, exp3_0_1, nbits);
+
+ bitmap_fill(bmap, 1024);
+ bitmap_replace(bmap, &exp2[1], &exp2[0], exp2_to_exp3_mask, nbits);
+ expect_eq_bitmap(bmap, exp3_1_0, nbits);
+}
+
#define PARSE_TIME 0x1
struct test_bitmap_parselist{
@@ -476,6 +513,7 @@ static void __init selftest(void)
test_zero_clear();
test_fill_set();
test_copy();
+ test_replace();
test_bitmap_arr32();
test_bitmap_parselist();
test_bitmap_parselist_user();
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v2 07/11] bitmap: Introduce bitmap_replace() helper
2019-10-22 17:29 ` [PATCH v2 07/11] bitmap: Introduce bitmap_replace() helper Andy Shevchenko
@ 2019-12-26 16:15 ` Guenter Roeck
2020-01-08 18:10 ` Andy Shevchenko
0 siblings, 1 reply; 18+ messages in thread
From: Guenter Roeck @ 2019-12-26 16:15 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray,
Yury Norov
Hi,
On Tue, Oct 22, 2019 at 08:29:18PM +0300, Andy Shevchenko wrote:
> In some drivers we want to have a single operation over bitmap which is
> an equivalent to:
>
> *dst = (*old & ~(*mask)) | (*new & *mask)
>
> Introduce bitmap_replace() helper for this.
>
> Cc: Yury Norov <ynorov@marvell.com>
> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
This patch results in the following boot log messages on various architectures.
I have seen it on arm and mipsel, but others may be affected as well.
test_bitmap: [lib/test_bitmap.c:282] bitmaps contents differ: expected "0-1,4-5,8,12-13,16,20-21,24,28,32-33,36-37,40-41,44-45,48-49,52-53,56-57,60-61", got "0-2,4-5,8,12-13,16,20-21,24,28,32-33,36-37,40-41,44-45,48-49,52-53,55-57,60-61"
test_bitmap: [lib/test_bitmap.c:286] bitmaps contents differ: expected "0,4,8-9,12,16-17,20,24-25,28-29,32-34,36-38,40-42,44-46,48-50,52-54,56-58,60-62", got "0,4,6,8-10,12,14,16-18,20,22,24-26,28-30,32-54,56-63"
test_bitmap: [lib/test_bitmap.c:290] bitmaps contents differ: expected "0-1,4-5,8,12-13,16,20-21,24,28,32-33,36-37,40-41,44-45,48-49,52-53,56-57,60-61", got "0-2,4-5,8,12-13,16,20-21,24,28,32-33,36-37,40-41,44-45,48-49,52-53,55-57,60-61"
test_bitmap: [lib/test_bitmap.c:294] bitmaps contents differ: expected "0,4,8-9,12,16-17,20,24-25,28-29,32-34,36-38,40-42,44-46,48-50,52-54,56-58,60-62", got "0,4,6,8-10,12,14,16-18,20,22,24-26,28-30,32-54,56-63"
Guenter
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 07/11] bitmap: Introduce bitmap_replace() helper
2019-12-26 16:15 ` Guenter Roeck
@ 2020-01-08 18:10 ` Andy Shevchenko
0 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2020-01-08 18:10 UTC (permalink / raw)
To: Guenter Roeck
Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray,
Yury Norov
On Thu, Dec 26, 2019 at 08:15:59AM -0800, Guenter Roeck wrote:
> Hi,
>
> On Tue, Oct 22, 2019 at 08:29:18PM +0300, Andy Shevchenko wrote:
> > In some drivers we want to have a single operation over bitmap which is
> > an equivalent to:
> >
> > *dst = (*old & ~(*mask)) | (*new & *mask)
> >
> > Introduce bitmap_replace() helper for this.
> >
> > Cc: Yury Norov <ynorov@marvell.com>
> > Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> This patch results in the following boot log messages on various architectures.
> I have seen it on arm and mipsel, but others may be affected as well.
Thanks for report. I can reproduce on x86_32, and not on x86_64.
I'll look at it.
>
> test_bitmap: [lib/test_bitmap.c:282] bitmaps contents differ: expected "0-1,4-5,8,12-13,16,20-21,24,28,32-33,36-37,40-41,44-45,48-49,52-53,56-57,60-61", got "0-2,4-5,8,12-13,16,20-21,24,28,32-33,36-37,40-41,44-45,48-49,52-53,55-57,60-61"
> test_bitmap: [lib/test_bitmap.c:286] bitmaps contents differ: expected "0,4,8-9,12,16-17,20,24-25,28-29,32-34,36-38,40-42,44-46,48-50,52-54,56-58,60-62", got "0,4,6,8-10,12,14,16-18,20,22,24-26,28-30,32-54,56-63"
> test_bitmap: [lib/test_bitmap.c:290] bitmaps contents differ: expected "0-1,4-5,8,12-13,16,20-21,24,28,32-33,36-37,40-41,44-45,48-49,52-53,56-57,60-61", got "0-2,4-5,8,12-13,16,20-21,24,28,32-33,36-37,40-41,44-45,48-49,52-53,55-57,60-61"
> test_bitmap: [lib/test_bitmap.c:294] bitmaps contents differ: expected "0,4,8-9,12,16-17,20,24-25,28-29,32-34,36-38,40-42,44-46,48-50,52-54,56-58,60-62", got "0,4,6,8-10,12,14,16-18,20,22,24-26,28-30,32-54,56-63"
>
> Guenter
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 08/11] gpio: pca953x: Remove redundant variable and check in IRQ handler
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (6 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 07/11] bitmap: Introduce bitmap_replace() helper Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 09/11] gpio: pca953x: Use input from regs structure in pca953x_irq_pending() Andy Shevchenko
` (3 subsequent siblings)
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
We always will have at least one iteration of the loop due to
pending being guaranteed to be non-zero. That is, we may remove
extra variable and check in the IRQ handler.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpio-pca953x.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 10b669b8f27d..5eee66269a0c 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -740,7 +740,6 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
struct pca953x_chip *chip = devid;
u8 pending[MAX_BANK];
u8 level;
- unsigned nhandled = 0;
int i;
if (!pca953x_irq_pending(chip, pending))
@@ -752,11 +751,10 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
handle_nested_irq(irq_find_mapping(chip->gpio_chip.irq.domain,
level + (BANK_SZ * i)));
pending[i] &= ~(1 << level);
- nhandled++;
}
}
- return (nhandled > 0) ? IRQ_HANDLED : IRQ_NONE;
+ return IRQ_HANDLED;
}
static int pca953x_irq_setup(struct pca953x_chip *chip,
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 09/11] gpio: pca953x: Use input from regs structure in pca953x_irq_pending()
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (7 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 08/11] gpio: pca953x: Remove redundant variable and check in IRQ handler Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 17:29 ` [PATCH v2 10/11] gpio: pca953x: Convert to use bitmap API Andy Shevchenko
` (2 subsequent siblings)
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
While PCA_PCAL is defined for PCA953X type only, we still may use
an offset of the input from regs structure for sake of consistency.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpio-pca953x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 5eee66269a0c..7a57304b5c31 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -686,7 +686,7 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending)
return false;
/* Check latched inputs and clear interrupt status */
- ret = pca953x_read_regs(chip, PCA953X_INPUT, cur_stat);
+ ret = pca953x_read_regs(chip, chip->regs->input, cur_stat);
if (ret)
return false;
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v2 10/11] gpio: pca953x: Convert to use bitmap API
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (8 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 09/11] gpio: pca953x: Use input from regs structure in pca953x_irq_pending() Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-22 18:03 ` Geert Uytterhoeven
2019-10-22 17:29 ` [PATCH v2 11/11] gpio: pca953x: Tight up indentation Andy Shevchenko
2019-10-23 14:10 ` [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Linus Walleij
11 siblings, 1 reply; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko, Geert Uytterhoeven, Thomas Petazzoni, Marek Vasut
Instead of customized approach convert the driver to use bitmap API.
Depends-on: 6e9c6674d1bf ("gpio: pca953x: utilize the for_each_set_clump8 macro")
Cc: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Marek Vasut <marek.vasut+renesas@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpio-pca953x.c | 168 ++++++++++++++++--------------------
1 file changed, 73 insertions(+), 95 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 7a57304b5c31..774e4c69df03 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -9,8 +9,7 @@
*/
#include <linux/acpi.h>
-#include <linux/bits.h>
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
@@ -116,6 +115,7 @@ MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids);
#define MAX_BANK 5
#define BANK_SZ 8
+#define MAX_LINE (MAX_BANK * BANK_SZ)
#define NBANK(chip) DIV_ROUND_UP(chip->gpio_chip.ngpio, BANK_SZ)
@@ -147,10 +147,10 @@ struct pca953x_chip {
#ifdef CONFIG_GPIO_PCA953X_IRQ
struct mutex irq_lock;
- u8 irq_mask[MAX_BANK];
- u8 irq_stat[MAX_BANK];
- u8 irq_trig_raise[MAX_BANK];
- u8 irq_trig_fall[MAX_BANK];
+ DECLARE_BITMAP(irq_mask, MAX_LINE);
+ DECLARE_BITMAP(irq_stat, MAX_LINE);
+ DECLARE_BITMAP(irq_trig_raise, MAX_LINE);
+ DECLARE_BITMAP(irq_trig_fall, MAX_LINE);
struct irq_chip irq_chip;
#endif
atomic_t wakeup_path;
@@ -334,12 +334,16 @@ static u8 pca953x_recalc_addr(struct pca953x_chip *chip, int reg, int off,
return regaddr;
}
-static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
+static int pca953x_write_regs(struct pca953x_chip *chip, int reg, unsigned long *val)
{
u8 regaddr = pca953x_recalc_addr(chip, reg, 0, true, true);
- int ret;
+ u8 value[MAX_BANK];
+ int i, ret;
+
+ for (i = 0; i < NBANK(chip); i++)
+ value[i] = bitmap_get_value8(val, i * BANK_SZ);
- ret = regmap_bulk_write(chip->regmap, regaddr, val, NBANK(chip));
+ ret = regmap_bulk_write(chip->regmap, regaddr, value, NBANK(chip));
if (ret < 0) {
dev_err(&chip->client->dev, "failed writing register\n");
return ret;
@@ -348,17 +352,21 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
return 0;
}
-static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val)
+static int pca953x_read_regs(struct pca953x_chip *chip, int reg, unsigned long *val)
{
u8 regaddr = pca953x_recalc_addr(chip, reg, 0, false, true);
- int ret;
+ u8 value[MAX_BANK];
+ int i, ret;
- ret = regmap_bulk_read(chip->regmap, regaddr, val, NBANK(chip));
+ ret = regmap_bulk_read(chip->regmap, regaddr, value, NBANK(chip));
if (ret < 0) {
dev_err(&chip->client->dev, "failed reading register\n");
return ret;
}
+ for (i = 0; i < NBANK(chip); i++)
+ bitmap_set_value8(val, value[i], i * BANK_SZ);
+
return 0;
}
@@ -457,10 +465,8 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc,
unsigned long *mask, unsigned long *bits)
{
struct pca953x_chip *chip = gpiochip_get_data(gc);
- unsigned long offset;
- unsigned long bank_mask;
- int bank;
- u8 reg_val[MAX_BANK];
+ DECLARE_BITMAP(reg_val, MAX_LINE);
+ DECLARE_BITMAP(new_val, MAX_LINE);
int ret;
mutex_lock(&chip->i2c_lock);
@@ -468,13 +474,9 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc,
if (ret)
goto exit;
- for_each_set_clump8(offset, bank_mask, mask, gc->ngpio) {
- bank = offset / 8;
- reg_val[bank] &= ~bank_mask;
- reg_val[bank] |= bitmap_get_value8(bits, offset) & bank_mask;
- }
+ bitmap_replace(new_val, reg_val, bits, mask, gc->ngpio);
- pca953x_write_regs(chip, chip->regs->output, reg_val);
+ pca953x_write_regs(chip, chip->regs->output, new_val);
exit:
mutex_unlock(&chip->i2c_lock);
}
@@ -599,10 +601,10 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct pca953x_chip *chip = gpiochip_get_data(gc);
- u8 new_irqs;
- int level, i;
- u8 invert_irq_mask[MAX_BANK];
- u8 reg_direction[MAX_BANK];
+ DECLARE_BITMAP(irq_mask, MAX_LINE);
+ DECLARE_BITMAP(reg_direction, MAX_LINE);
+ DECLARE_BITMAP(new_irqs, MAX_LINE);
+ int level;
pca953x_read_regs(chip, chip->regs->direction, reg_direction);
@@ -610,25 +612,18 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
/* Enable latch on interrupt-enabled inputs */
pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask);
- for (i = 0; i < NBANK(chip); i++)
- invert_irq_mask[i] = ~chip->irq_mask[i];
+ bitmap_complement(irq_mask, chip->irq_mask, gc->ngpio);
/* Unmask enabled interrupts */
- pca953x_write_regs(chip, PCAL953X_INT_MASK, invert_irq_mask);
+ pca953x_write_regs(chip, PCAL953X_INT_MASK, irq_mask);
}
+ bitmap_or(new_irqs, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio);
+ bitmap_and(irq_mask, new_irqs, reg_direction, gc->ngpio);
+
/* Look for any newly setup interrupt */
- for (i = 0; i < NBANK(chip); i++) {
- new_irqs = chip->irq_trig_fall[i] | chip->irq_trig_raise[i];
- new_irqs &= reg_direction[i];
-
- while (new_irqs) {
- level = __ffs(new_irqs);
- pca953x_gpio_direction_input(&chip->gpio_chip,
- level + (BANK_SZ * i));
- new_irqs &= ~(1 << level);
- }
- }
+ for_each_set_bit(level, irq_mask, gc->ngpio)
+ pca953x_gpio_direction_input(&chip->gpio_chip, level);
mutex_unlock(&chip->irq_lock);
}
@@ -669,15 +664,15 @@ static void pca953x_irq_shutdown(struct irq_data *d)
chip->irq_trig_fall[d->hwirq / BANK_SZ] &= ~mask;
}
-static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending)
+static bool pca953x_irq_pending(struct pca953x_chip *chip, unsigned long *pending)
{
- u8 cur_stat[MAX_BANK];
- u8 old_stat[MAX_BANK];
- bool pending_seen = false;
- bool trigger_seen = false;
- u8 trigger[MAX_BANK];
- u8 reg_direction[MAX_BANK];
- int ret, i;
+ struct gpio_chip *gc = &chip->gpio_chip;
+ DECLARE_BITMAP(reg_direction, MAX_LINE);
+ DECLARE_BITMAP(old_stat, MAX_LINE);
+ DECLARE_BITMAP(cur_stat, MAX_LINE);
+ DECLARE_BITMAP(new_stat, MAX_LINE);
+ DECLARE_BITMAP(trigger, MAX_LINE);
+ int ret;
if (chip->driver_data & PCA_PCAL) {
/* Read the current interrupt status from the device */
@@ -690,16 +685,12 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending)
if (ret)
return false;
- for (i = 0; i < NBANK(chip); i++) {
- /* Apply filter for rising/falling edge selection */
- pending[i] = (~cur_stat[i] & chip->irq_trig_fall[i]) |
- (cur_stat[i] & chip->irq_trig_raise[i]);
- pending[i] &= trigger[i];
- if (pending[i])
- pending_seen = true;
- }
+ /* Apply filter for rising/falling edge selection */
+ bitmap_replace(new_stat, chip->irq_trig_fall, chip->irq_trig_raise, cur_stat, gc->ngpio);
+
+ bitmap_and(pending, new_stat, trigger, gc->ngpio);
- return pending_seen;
+ return !bitmap_empty(pending, gc->ngpio);
}
ret = pca953x_read_regs(chip, chip->regs->input, cur_stat);
@@ -708,51 +699,38 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending)
/* Remove output pins from the equation */
pca953x_read_regs(chip, chip->regs->direction, reg_direction);
- for (i = 0; i < NBANK(chip); i++)
- cur_stat[i] &= reg_direction[i];
- memcpy(old_stat, chip->irq_stat, NBANK(chip));
+ bitmap_copy(old_stat, chip->irq_stat, gc->ngpio);
- for (i = 0; i < NBANK(chip); i++) {
- trigger[i] = (cur_stat[i] ^ old_stat[i]) & chip->irq_mask[i];
- if (trigger[i])
- trigger_seen = true;
- }
+ bitmap_and(new_stat, cur_stat, reg_direction, gc->ngpio);
+ bitmap_xor(cur_stat, new_stat, old_stat, gc->ngpio);
+ bitmap_and(trigger, cur_stat, chip->irq_mask, gc->ngpio);
- if (!trigger_seen)
+ if (bitmap_empty(trigger, gc->ngpio))
return false;
- memcpy(chip->irq_stat, cur_stat, NBANK(chip));
+ bitmap_copy(chip->irq_stat, new_stat, gc->ngpio);
- for (i = 0; i < NBANK(chip); i++) {
- pending[i] = (old_stat[i] & chip->irq_trig_fall[i]) |
- (cur_stat[i] & chip->irq_trig_raise[i]);
- pending[i] &= trigger[i];
- if (pending[i])
- pending_seen = true;
- }
+ bitmap_and(cur_stat, chip->irq_trig_fall, old_stat, gc->ngpio);
+ bitmap_and(old_stat, chip->irq_trig_raise, new_stat, gc->ngpio);
+ bitmap_or(new_stat, old_stat, cur_stat, gc->ngpio);
+ bitmap_and(pending, new_stat, trigger, gc->ngpio);
- return pending_seen;
+ return !bitmap_empty(pending, gc->ngpio);
}
static irqreturn_t pca953x_irq_handler(int irq, void *devid)
{
struct pca953x_chip *chip = devid;
- u8 pending[MAX_BANK];
- u8 level;
- int i;
+ struct gpio_chip *gc = &chip->gpio_chip;
+ DECLARE_BITMAP(pending, MAX_LINE);
+ int level;
if (!pca953x_irq_pending(chip, pending))
return IRQ_NONE;
- for (i = 0; i < NBANK(chip); i++) {
- while (pending[i]) {
- level = __ffs(pending[i]);
- handle_nested_irq(irq_find_mapping(chip->gpio_chip.irq.domain,
- level + (BANK_SZ * i)));
- pending[i] &= ~(1 << level);
- }
- }
+ for_each_set_bit(level, pending, gc->ngpio)
+ handle_nested_irq(irq_find_mapping(gc->irq.domain, level));
return IRQ_HANDLED;
}
@@ -762,8 +740,9 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
{
struct i2c_client *client = chip->client;
struct irq_chip *irq_chip = &chip->irq_chip;
- u8 reg_direction[MAX_BANK];
- int ret, i;
+ DECLARE_BITMAP(reg_direction, MAX_LINE);
+ DECLARE_BITMAP(irq_stat, MAX_LINE);
+ int ret;
if (!client->irq)
return 0;
@@ -774,7 +753,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
if (!(chip->driver_data & PCA_INT))
return 0;
- ret = pca953x_read_regs(chip, chip->regs->input, chip->irq_stat);
+ ret = pca953x_read_regs(chip, chip->regs->input, irq_stat);
if (ret)
return ret;
@@ -784,8 +763,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
* this purpose.
*/
pca953x_read_regs(chip, chip->regs->direction, reg_direction);
- for (i = 0; i < NBANK(chip); i++)
- chip->irq_stat[i] &= reg_direction[i];
+ bitmap_and(chip->irq_stat, irq_stat, reg_direction, chip->gpio_chip.ngpio);
mutex_init(&chip->irq_lock);
ret = devm_request_threaded_irq(&client->dev, client->irq,
@@ -837,8 +815,8 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
{
+ DECLARE_BITMAP(val, MAX_LINE);
int ret;
- u8 val[MAX_BANK];
ret = regcache_sync_region(chip->regmap, chip->regs->output,
chip->regs->output + NBANK(chip));
@@ -852,9 +830,9 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
/* set platform specific polarity inversion */
if (invert)
- memset(val, 0xFF, NBANK(chip));
+ bitmap_fill(val, MAX_LINE);
else
- memset(val, 0, NBANK(chip));
+ bitmap_zero(val, MAX_LINE);
ret = pca953x_write_regs(chip, chip->regs->invert, val);
out:
@@ -863,8 +841,8 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert)
static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
{
+ DECLARE_BITMAP(val, MAX_LINE);
int ret;
- u8 val[MAX_BANK];
ret = device_pca95xx_init(chip, invert);
if (ret)
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v2 10/11] gpio: pca953x: Convert to use bitmap API
2019-10-22 17:29 ` [PATCH v2 10/11] gpio: pca953x: Convert to use bitmap API Andy Shevchenko
@ 2019-10-22 18:03 ` Geert Uytterhoeven
2019-10-23 8:01 ` Andy Shevchenko
0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2019-10-22 18:03 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
Rasmus Villemoes, Yury Norov, Linux Kernel Mailing List,
Andrew Morton, William Breathitt Gray, Geert Uytterhoeven,
Thomas Petazzoni, Marek Vasut
Hi Andy,
On Tue, Oct 22, 2019 at 7:29 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> Instead of customized approach convert the driver to use bitmap API.
>
> Depends-on: 6e9c6674d1bf ("gpio: pca953x: utilize the for_each_set_clump8 macro")
> Cc: William Breathitt Gray <vilhelm.gray@gmail.com>
> Cc: Geert Uytterhoeven <geert+renesas@glider.be>
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Cc: Marek Vasut <marek.vasut+renesas@gmail.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> --- a/drivers/gpio/gpio-pca953x.c
> +++ b/drivers/gpio/gpio-pca953x.c
> @@ -9,8 +9,7 @@
> */
>
> #include <linux/acpi.h>
> -#include <linux/bits.h>
> -#include <linux/bitops.h>
> +#include <linux/bitmap.h>
> #include <linux/gpio/driver.h>
> #include <linux/gpio/consumer.h>
> #include <linux/i2c.h>
> @@ -116,6 +115,7 @@ MODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids);
>
> #define MAX_BANK 5
> #define BANK_SZ 8
> +#define MAX_LINE (MAX_BANK * BANK_SZ)
Given (almost) everything is now bitmap (i.e. long [])-based, you might
as well increase MAX_BANK to a multiple of 4 or 8, e.g. 8.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 10/11] gpio: pca953x: Convert to use bitmap API
2019-10-22 18:03 ` Geert Uytterhoeven
@ 2019-10-23 8:01 ` Andy Shevchenko
2019-10-23 8:34 ` Geert Uytterhoeven
0 siblings, 1 reply; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-23 8:01 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Linus Walleij, Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
Rasmus Villemoes, Yury Norov, Linux Kernel Mailing List,
Andrew Morton, William Breathitt Gray, Geert Uytterhoeven,
Thomas Petazzoni, Marek Vasut
On Tue, Oct 22, 2019 at 08:03:00PM +0200, Geert Uytterhoeven wrote:
> On Tue, Oct 22, 2019 at 7:29 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > Instead of customized approach convert the driver to use bitmap API.
> > #define MAX_BANK 5
> > #define BANK_SZ 8
> > +#define MAX_LINE (MAX_BANK * BANK_SZ)
>
> Given (almost) everything is now bitmap (i.e. long [])-based, you might
> as well increase MAX_BANK to a multiple of 4 or 8, e.g. 8.
We can do it any time when we will really need it.
(Yes, I understand that we have no penalty for the change anyway)
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2 10/11] gpio: pca953x: Convert to use bitmap API
2019-10-23 8:01 ` Andy Shevchenko
@ 2019-10-23 8:34 ` Geert Uytterhoeven
0 siblings, 0 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2019-10-23 8:34 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
Rasmus Villemoes, Yury Norov, Linux Kernel Mailing List,
Andrew Morton, William Breathitt Gray, Geert Uytterhoeven,
Thomas Petazzoni, Marek Vasut
Hi Andy,
On Wed, Oct 23, 2019 at 10:01 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Tue, Oct 22, 2019 at 08:03:00PM +0200, Geert Uytterhoeven wrote:
> > On Tue, Oct 22, 2019 at 7:29 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > > Instead of customized approach convert the driver to use bitmap API.
>
> > > #define MAX_BANK 5
> > > #define BANK_SZ 8
> > > +#define MAX_LINE (MAX_BANK * BANK_SZ)
> >
> > Given (almost) everything is now bitmap (i.e. long [])-based, you might
> > as well increase MAX_BANK to a multiple of 4 or 8, e.g. 8.
>
> We can do it any time when we will really need it.
True. Especially as there's no real need to do it now.
(sorry, my mind mixed this up with gpio-74x164...)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 11/11] gpio: pca953x: Tight up indentation
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (9 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 10/11] gpio: pca953x: Convert to use bitmap API Andy Shevchenko
@ 2019-10-22 17:29 ` Andy Shevchenko
2019-10-23 14:10 ` [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Linus Walleij
11 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2019-10-22 17:29 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, linux-gpio, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
Cc: Andy Shevchenko
There is no need to split some of the lines. However,
improve the style of multi-line comment. On top of this
there is no need to have double space.
Correct above indentation issues without altering the functionality.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpio-pca953x.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 774e4c69df03..f80ed5a43614 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -421,7 +421,9 @@ static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off)
ret = regmap_read(chip->regmap, inreg, ®_val);
mutex_unlock(&chip->i2c_lock);
if (ret < 0) {
- /* NOTE: diagnostic already emitted; that's all we should
+ /*
+ * NOTE:
+ * diagnostic already emitted; that's all we should
* do unless gpio_*_value_cansleep() calls become different
* from their nonsleeping siblings (and report faults).
*/
@@ -735,8 +737,7 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
return IRQ_HANDLED;
}
-static int pca953x_irq_setup(struct pca953x_chip *chip,
- int irq_base)
+static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)
{
struct i2c_client *client = chip->client;
struct irq_chip *irq_chip = &chip->irq_chip;
@@ -786,9 +787,9 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
irq_chip->irq_set_type = pca953x_irq_set_type;
irq_chip->irq_shutdown = pca953x_irq_shutdown;
- ret = gpiochip_irqchip_add_nested(&chip->gpio_chip, irq_chip,
- irq_base, handle_simple_irq,
- IRQ_TYPE_NONE);
+ ret = gpiochip_irqchip_add_nested(&chip->gpio_chip, irq_chip,
+ irq_base, handle_simple_irq,
+ IRQ_TYPE_NONE);
if (ret) {
dev_err(&client->dev,
"could not connect irqchip to gpiochip\n");
@@ -862,7 +863,7 @@ static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
static const struct of_device_id pca953x_dt_ids[];
static int pca953x_probe(struct i2c_client *client,
- const struct i2c_device_id *i2c_id)
+ const struct i2c_device_id *i2c_id)
{
struct pca953x_platform_data *pdata;
struct pca953x_chip *chip;
@@ -871,8 +872,7 @@ static int pca953x_probe(struct i2c_client *client,
u32 invert = 0;
struct regulator *reg;
- chip = devm_kzalloc(&client->dev,
- sizeof(struct pca953x_chip), GFP_KERNEL);
+ chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (chip == NULL)
return -ENOMEM;
@@ -986,7 +986,7 @@ static int pca953x_probe(struct i2c_client *client,
if (pdata && pdata->setup) {
ret = pdata->setup(client, chip->gpio_chip.base,
- chip->gpio_chip.ngpio, pdata->context);
+ chip->gpio_chip.ngpio, pdata->context);
if (ret < 0)
dev_warn(&client->dev, "setup failed, %d\n", ret);
}
@@ -1006,7 +1006,7 @@ static int pca953x_remove(struct i2c_client *client)
if (pdata && pdata->teardown) {
ret = pdata->teardown(client, chip->gpio_chip.base,
- chip->gpio_chip.ngpio, pdata->context);
+ chip->gpio_chip.ngpio, pdata->context);
if (ret < 0)
dev_err(&client->dev, "teardown failed, %d\n", ret);
} else {
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API
2019-10-22 17:29 [PATCH v2 00/11] gpio: pca953x: Convert to bitmap (extended) API Andy Shevchenko
` (10 preceding siblings ...)
2019-10-22 17:29 ` [PATCH v2 11/11] gpio: pca953x: Tight up indentation Andy Shevchenko
@ 2019-10-23 14:10 ` Linus Walleij
11 siblings, 0 replies; 18+ messages in thread
From: Linus Walleij @ 2019-10-23 14:10 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Bartosz Golaszewski, open list:GPIO SUBSYSTEM, Rasmus Villemoes,
Yury Norov, linux-kernel, Andrew Morton, William Breathitt Gray
On Tue, Oct 22, 2019 at 7:29 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> While converting gpio-pca953x driver to bitmap API, I noticed that we have
> no function to replace bits.
>
> So, that's how patch 7 appears.
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Nice, I see that Andrew picked up the patches so no action required
from my side I guess? Else poke me.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 18+ messages in thread