* [PATCH v1] gpio: mmio: handle "ngpios" properly in bgpio_init
@ 2023-02-24 17:40 Asmaa Mnebhi
2023-02-24 18:16 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Asmaa Mnebhi @ 2023-02-24 17:40 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 | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index d9dff3dc92ae..f317a371c529 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -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;
--
2.30.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] gpio: mmio: handle "ngpios" properly in bgpio_init
2023-02-24 17:40 [PATCH v1] gpio: mmio: handle "ngpios" properly in bgpio_init Asmaa Mnebhi
@ 2023-02-24 18:16 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2023-02-24 18:16 UTC (permalink / raw)
To: Asmaa Mnebhi; +Cc: linus.walleij, linux-gpio, linux-kernel
On Fri, Feb 24, 2023 at 7:40 PM Asmaa Mnebhi <asmaa@nvidia.com> wrote:
>
> bgpio_init uses "sz" argument to populate ngpio, which is not accurate.
bgpio_init() uses the
(Note parentheses, same for other func() mentions)
> 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!
...
> + 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.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-24 18:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-24 17:40 [PATCH v1] gpio: mmio: handle "ngpios" properly in bgpio_init Asmaa Mnebhi
2023-02-24 18:16 ` 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).