Skip to contentSkip to conversation

gpio: mmio: handle "ngpios" properly in bgpio_init

PATCH Superseded Asmaa Mnebhi 2 participants 2 messages Feb 24, 2023 GPIO

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpio/gpio-mmio.c +7 -1
index d9dff3dc92ae..f317a371c529 100644
@@ -601,6 +601,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
 	       void __iomem *clr, void __iomem *dirout, void __iomem *dirin,
 	       unsigned long flags)
 {
+	u32 ngpios = 0;
 	int ret;
 
 	if (!is_power_of_2(sz))
@@ -614,10 +615,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 = device_property_read_u32(dev, "ngpios", &ngpios);
+	if (!ret)
+		gc->ngpio = ngpios;
+	else
+		gc->ngpio = gc->bgpio_bits;
+
 	ret = bgpio_setup_io(gc, dat, set, clr, flags);
 	if (ret)
 		return ret;
Signature · 1 line
2.30.1
#1 lore raw
Quoted 2 lines · Asmaa Mnebhi

bgpio_init uses "sz" argument to populate ngpio, which is not accurate.

bgpio_init() uses the

(Note parentheses, same for other func() mentions)

Quoted 3 lines

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.

Thank you!

...

drivers/gpio/gpio-mmio.c int bgpio_init(struct gpio_chip *gc, struct device *dev, · line 625

Quoted 5 lines
drivers/gpio/gpio-mmio.c +5 -0
+       ret = device_property_read_u32(dev, "ngpios", &ngpios);
+       if (!ret)
+               gc->ngpio = ngpios;
+       else
+               gc->ngpio = gc->bgpio_bits;

This duplicates the GPIO library. What probably better to have is to just check the property existence

device_property_present() and do accordingly.

Signature · 2 lines
With Best Regards,
Andy Shevchenko