linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] gpio: mmio: handle "ngpios" properly in bgpio_init()
@ 2023-02-24 19:20 Asmaa Mnebhi
  2023-02-24 20:48 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Asmaa Mnebhi @ 2023-02-24 19:20 UTC (permalink / raw)
  To: andy.shevchenko, linus.walleij, linux-gpio, linux-kernel; +Cc: Asmaa Mnebhi

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.

Signed-off-by: Asmaa Mnebhi <asmaa@nvidia.com>
---
 drivers/gpio/gpio-mmio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index d9dff3dc92ae..448fefc4468c 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -614,10 +614,13 @@ 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_present(dev, "ngpios");
+	if (!ret)
+		gc->ngpio = gc->bgpio_bits;
+
 	ret = bgpio_setup_io(gc, dat, set, clr, flags);
 	if (ret)
 		return ret;
-- 
2.30.1


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

* Re: [PATCH v2] gpio: mmio: handle "ngpios" properly in bgpio_init()
  2023-02-24 19:20 [PATCH v2] gpio: mmio: handle "ngpios" properly in bgpio_init() Asmaa Mnebhi
@ 2023-02-24 20:48 ` Andy Shevchenko
  2023-02-24 21:31   ` Asmaa Mnebhi
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2023-02-24 20:48 UTC (permalink / raw)
  To: Asmaa Mnebhi; +Cc: linus.walleij, linux-gpio, linux-kernel

On Fri, Feb 24, 2023 at 9:20 PM Asmaa Mnebhi <asmaa@nvidia.com> wrote:
>
> 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.

...

> +       ret = device_property_present(dev, "ngpios");
> +       if (!ret)

ret is not of the correct type for this call.

Why not simply

    if (!device_property_present(dev, "ngpios"))

> +               gc->ngpio = gc->bgpio_bits;

...

The problem with this change is that you need to provide bgpio_bits.

So, if there is a property when bgpio_bits will be updated?

That's said what you need is something like this:
1) split "ngpios" handling code (lines ~718-744 in gpiolib.c)  into a
helper function that is available inside drivers/gpio;
2) use it in bgpio_init() by overriding bgpio_bits.

ret = new_helper();
if (ret)
    gc->bgpio_bits = sz * 8;
else
    ... = gc->ngpio;


-- 
With Best Regards,
Andy Shevchenko

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

* RE: [PATCH v2] gpio: mmio: handle "ngpios" properly in bgpio_init()
  2023-02-24 20:48 ` Andy Shevchenko
@ 2023-02-24 21:31   ` Asmaa Mnebhi
  2023-02-24 22:39     ` andy.shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Asmaa Mnebhi @ 2023-02-24 21:31 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linus.walleij, linux-gpio, linux-kernel

> > 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.
> 
> ...
> 
> > +       ret = device_property_present(dev, "ngpios");
> > +       if (!ret)
> 
> ret is not of the correct type for this call.
> 
> Why not simply
> 
>     if (!device_property_present(dev, "ngpios"))
> 
> > +               gc->ngpio = gc->bgpio_bits;
> 
> ...
> 
> The problem with this change is that you need to provide bgpio_bits.
> 
> So, if there is a property when bgpio_bits will be updated?
> 
> That's said what you need is something like this:
> 1) split "ngpios" handling code (lines ~718-744 in gpiolib.c)  into a helper
> function that is available inside drivers/gpio;
> 2) use it in bgpio_init() by overriding bgpio_bits.
> 
> ret = new_helper();
> if (ret)
>     gc->bgpio_bits = sz * 8;
> else
>     ... = gc->ngpio;

So this new_helper() which reads the ngpios property, would be called from bgpio_init() and 
From gpiochip_add_data_with_key() correct? Since there are some drivers that don’t use
bgpio_init().
Also, shouldn't "gc->bgpio_bits = = sz * 8;" be independent of new_helper() function?
"bgpio_bits" is described as "number of register bits used for a generic GPIO i.e. <register width> * 8" 
which seems different from "ngpio" described as "the number of GPIOs handled by this controller"




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

* Re: [PATCH v2] gpio: mmio: handle "ngpios" properly in bgpio_init()
  2023-02-24 21:31   ` Asmaa Mnebhi
@ 2023-02-24 22:39     ` andy.shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: andy.shevchenko @ 2023-02-24 22:39 UTC (permalink / raw)
  To: Asmaa Mnebhi; +Cc: Andy Shevchenko, linus.walleij, linux-gpio, linux-kernel

Fri, Feb 24, 2023 at 09:31:23PM +0000, Asmaa Mnebhi kirjoitti:

...

> > The problem with this change is that you need to provide bgpio_bits.
> > 
> > So, if there is a property when bgpio_bits will be updated?
> > 
> > That's said what you need is something like this:
> > 1) split "ngpios" handling code (lines ~718-744 in gpiolib.c)  into a helper
> > function that is available inside drivers/gpio;
> > 2) use it in bgpio_init() by overriding bgpio_bits.
> > 
> > ret = new_helper();
> > if (ret)
> >     gc->bgpio_bits = sz * 8;
> > else
> >     ... = gc->ngpio;
> 
> So this new_helper() which reads the ngpios property, would be called from
> bgpio_init() and From gpiochip_add_data_with_key() correct? Since there are
> some drivers that don’t use bgpio_init().

Correct.

> Also, shouldn't "gc->bgpio_bits = = sz * 8;" be independent of new_helper()

Nope. You need to link them anyway.

> function?  "bgpio_bits" is described as "number of register bits used for a
> generic GPIO i.e. <register width> * 8" which seems different from "ngpio"
> described as "the number of GPIOs handled by this controller"

But you are right, this should be = round_up(gc->ngpio, 8); to match the logic
with sz.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2023-02-24 22:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 19:20 [PATCH v2] gpio: mmio: handle "ngpios" properly in bgpio_init() Asmaa Mnebhi
2023-02-24 20:48 ` Andy Shevchenko
2023-02-24 21:31   ` Asmaa Mnebhi
2023-02-24 22:39     ` andy.shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).