Skip to contentSkip to conversation

gpio: mmio: fix calculation of bgpio_bits

PATCH Superseded Asmaa Mnebhi 4 participants 7 messages Mar 23, 2023 – Jul 10, 2023 GPIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: mmio: fix calculation of bgpio_bits

If the "ngpios" property is specified, bgpio_bits is calculated as the round up value of ngpio. At the moment, the only requirement specified is that the round up value must be a multiple of 8 but it should also be a power of 2 because we provide accessors based on the bank size in bgpio_setup_accessors().

---
 drivers/gpio/gpio-mmio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-mmio.c +1 -1
index b52a3dd511ca..74fdf0d87b2c 100644
@@ -623,7 +623,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
 	if (ret)
 		gc->ngpio = gc->bgpio_bits;
 	else
-		gc->bgpio_bits = round_up(gc->ngpio, 8);
+		gc->bgpio_bits = roundup_pow_of_two(round_up(gc->ngpio, 8));
 
 	ret = bgpio_setup_io(gc, dat, set, clr, flags);
 	if (ret)
Signature · 1 line
2.30.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Asmaa Mnebhi

If the "ngpios" property is specified, bgpio_bits is calculated as the round up value of ngpio. At the moment, the only requirement specified is that the round up value must be a multiple of 8 but it should also be a power of 2 because we provide accessors based on the bank size in bgpio_setup_accessors().

Quoted 21 lines
---
 drivers/gpio/gpio-mmio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-mmio.c +1 -2
index b52a3dd511ca..74fdf0d87b2c 100644
@@ -623,7 +623,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
        if (ret)
                gc->ngpio = gc->bgpio_bits;
        else
-               gc->bgpio_bits = round_up(gc->ngpio, 8);
+               gc->bgpio_bits = roundup_pow_of_two(round_up(gc->ngpio, 8));
 
        ret = bgpio_setup_io(gc, dat, set, clr, flags);
        if (ret)
--

2.30.1

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · Asmaa Mnebhi

If the "ngpios" property is specified, bgpio_bits is calculated as the round up value of ngpio. At the moment, the only requirement specified is that the round up value must be a multiple of 8 but it should also be a power of 2 because we provide accessors based on the bank size in bgpio_setup_accessors().

Btw, I do not see the initial patch in Bart's tree. I suppose you may simply send a v5 of the original one with this fix applied inplace.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

If the "ngpios" property is specified, bgpio_bits is calculated as the round up value of ngpio. At the moment, the only requirement specified is that the round up value must be a multiple of 8 but it should also be a power of 2 because we provide accessors based on the bank size in bgpio_setup_accessors().

Quoted 5 lines
Quoted 1 line

Btw, I do not see the initial patch in Bart's tree. I suppose you may simply send a v5 of the original one with this fix applied inplace.

Yes I was not able to find it on any branch yet so I just sent this patch based the other one.

Reviewed-by on v1 1/1
#6 lore raw
In reply to Asmaa Mnebhi
Quoted 7 lines · Asmaa Mnebhi

If the "ngpios" property is specified, bgpio_bits is calculated as the round up value of ngpio. At the moment, the only requirement specified is that the round up value must be a multiple of 8 but it should also be a power of 2 because we provide accessors based on the bank size in bgpio_setup_accessors().

Neat fixup,

Yours,
Linus Walleij