mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gpio: mmio: do not calculate bgpio_bits via "ngpios"
@ 2024-06-25  1:19 Shiji Yang
  2024-06-26 12:06 ` Linus Walleij
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Shiji Yang @ 2024-06-25  1:19 UTC (permalink / raw)
  To: linux-gpio
  Cc: Linus Walleij, Bartosz Golaszewski, Asmaa Mnebhi,
	Andy Shevchenko, linux-kernel, Shiji Yang, Mark Mentovai,
	Jonas Gorski, Lóránd Horváth

bgpio_bits must be aligned with the data bus width. For example, on a
32 bit big endian system and we only have 16 GPIOs. If we only assume
bgpio_bits=16 we can never control the GPIO because the base address
is the lowest address.

low address                          high address
-------------------------------------------------
|   byte3   |   byte2   |   byte1   |   byte0   |
-------------------------------------------------
|    NaN    |    NaN    |  gpio8-15 |  gpio0-7  |
-------------------------------------------------

Fixes: 55b2395e4e92 ("gpio: mmio: handle "ngpios" properly in bgpio_init()")
Fixes: https://github.com/openwrt/openwrt/issues/15739
Reported-by: Mark Mentovai <mark@mentovai.com>
Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
Suggested-By: Mark Mentovai <mark@mentovai.com>
Reviewed-by: Jonas Gorski <jonas.gorski@gmail.com>
Tested-by: Lóránd Horváth <lorand.horvath82@gmail.com>
---
 drivers/gpio/gpio-mmio.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index 71e1af7c2184..d89e78f0ead3 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -619,8 +619,6 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
 	ret = gpiochip_get_ngpios(gc, dev);
 	if (ret)
 		gc->ngpio = gc->bgpio_bits;
-	else
-		gc->bgpio_bits = roundup_pow_of_two(round_up(gc->ngpio, 8));
 
 	ret = bgpio_setup_io(gc, dat, set, clr, flags);
 	if (ret)
-- 
2.45.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-07-03 13:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-25  1:19 [PATCH] gpio: mmio: do not calculate bgpio_bits via "ngpios" Shiji Yang
2024-06-26 12:06 ` Linus Walleij
2024-06-26 14:46   ` Jonas Gorski
2024-06-26 14:59 ` Asmaa Mnebhi
2024-06-26 15:20   ` Jonas Gorski
2024-06-26 19:59     ` Asmaa Mnebhi
2024-06-26 20:25       ` Jonas Gorski
2024-06-26 21:45         ` Asmaa Mnebhi
2024-07-03 12:38 ` Linus Walleij
2024-07-03 13:28 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®