Skip to contentSkip to conversation

gpio: mmio: handle "ngpios" properly in bgpio_init()

PATCH Applied Asmaa Mnebhi 3 participants 5 messages Jul 10, 2023 – Jul 18, 2023 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 gpio: mmio: handle "ngpios" properly in bgpio_init()

bgpio_init() uses "sz" argument to populate ngpio, which is not accurate. Instead, read the "ngpios" property from the DT and if it doesn't exist, use the "sz" argument. With this change, drivers no longer need to overwrite the ngpio variable after calling bgpio_init().

---
 drivers/gpio/gpio-mmio.c |  9 +++++-
 drivers/gpio/gpiolib.c   | 68 ++++++++++++++++++++++------------------
 drivers/gpio/gpiolib.h   |  1 +
 3 files changed, 46 insertions(+), 32 deletions(-)
drivers/gpio/gpio-mmio.c +8 -1
index d9dff3dc92ae..b52a3dd511ca 100644
@@ -60,6 +60,8 @@ o        `                     ~~~~\___/~~~~    ` controller in FPGA is ,.`
 #include <linux/of.h>
 #include <linux/of_device.h>
 
+#include "gpiolib.h"
+
 static void bgpio_write8(void __iomem *reg, unsigned long data)
 {
 	writeb(data, reg);
@@ -614,10 +616,15 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
 	gc->parent = dev;
 	gc->label = dev_name(dev);
 	gc->base = -1;
-	gc->ngpio = gc->bgpio_bits;
 	gc->request = bgpio_request;
 	gc->be_bits = !!(flags & BGPIOF_BIG_ENDIAN);
 
+	ret = gpiochip_get_ngpios(gc, dev);
+	if (ret)
+		gc->ngpio = gc->bgpio_bits;
+	else
+		gc->bgpio_bits = round_up(gc->ngpio, 8);
+
 	ret = bgpio_setup_io(gc, dat, set, clr, flags);
 	if (ret)
 		return ret;
drivers/gpio/gpiolib.c +37 -31

93 lines not on this page · raw message

drivers/gpio/gpiolib.h +1 -0
index cca81375f127..8de748a16d13 100644
@@ -217,6 +217,7 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
 int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce);
 int gpiod_hog(struct gpio_desc *desc, const char *name,
 		unsigned long lflags, enum gpiod_flags dflags);
+int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev);
 
 /*
  * Return the GPIO number of the passed descriptor relative to its chip
Signature · 1 line
2.30.1
#2 lore raw
Quoted 1 line · Bartosz Golaszewski

On Mon, Jul 10, 2023 at 11:49 PM Asmaa Mnebhi <[email protected]> wrote:

...

Quoted 1 line

Applied, thanks!

This has a bug.

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

Applied, thanks!

This has a bug.

My apologies for this inconvenience. This is not the right patch to be applied. It was rejected by Andy. I just forwarded to you the patch to apply. Its only one patch an dis named:
[PATCH v2 1/1] gpio: mmio: handle "ngpios" properly in bgpio_init()

#4 lore raw
Quoted 9 lines · Asmaa Mnebhi
Quoted 6 lines
Quoted 3 lines

Applied, thanks!

This has a bug.

My apologies for this inconvenience. This is not the right patch to be applied. It was rejected by Andy. I just forwarded to you the patch to apply. Its only one patch an dis named:
[PATCH v2 1/1] gpio: mmio: handle "ngpios" properly in bgpio_init()

Yeah, I figured and backed it out.

Bart