lkml.org 
[lkml]   [2021]   [Jul]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patches in this message
/
From
Date
SubjectRe: [PATCH v2] gpio: mt7621: support gpio-line-names property
Hi Linus,

On Fri, Jul 2, 2021 at 1:30 PM Sergio Paracuellos
<sergio.paracuellos@gmail.com> wrote:
>
> Hi Linus,
>
> On Fri, Jul 2, 2021 at 12:18 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> >
> > On Fri, Jul 2, 2021 at 11:40 AM Sergio Paracuellos
> > <sergio.paracuellos@gmail.com> wrote:
> > > On Fri, Jul 2, 2021 at 11:27 AM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> >
> > > > > There are no child nodes, all the stuff is in the same parent node
> > > > > and, as I said, belongs to the same device but internally uses three
> > > > > gpiochips.
> > > >
> > > > And it can't be split into three children in the overlay?
> > >
> > > Original code before this being mainlined was using three children and
> > > I was told in the review that three children were not allowed:
> > >
> > > See https://patchwork.ozlabs.org/project/linux-gpio/patch/1527924610-13135-3-git-send-email-sergio.paracuellos@gmail.com/#1932827
> >
> > Yeah this is one of those unfortunate cases where the DT representation
> > (or ACPI for that matter) of the device and the Linux internal representation
> > differs.
> >
> > > > Let's assume it can't, then the GPIO library function should be
> > > > refactored in a way that it takes parameters like base index for the
> > > > names and tries to satisfy the caller.
> > >
> > > Bartosz, Linus, any thoughts on this?
> >
> > This would be ideal, is there a reasonably simple way to get to this helper?
> >
> > In gpiolib.c devprop_gpiochip_set_names() need to be refactored to
> > take a base number, devprop_gpiochip_set_names_base() that
> > function exposed in <linux/gpio/driver.h> and then the old function
> > devprop_gpiochip_set_names() wrapped in the new
> > one so all old users continue to work without modification.
> > Sprinkle some kerneldoc on top so we do not make mistakes
> > in the future.
> >
> > This should work I think.

If I am understanding correctly what you mean is something like follows:

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6e3c4d7a7d14..5a88a305bc59 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -361,13 +361,14 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
/*
* devprop_gpiochip_set_names - Set GPIO line names using device properties
* @chip: GPIO chip whose lines should be named, if possible
+ * @base: starting index in names array to start copying from
*
* Looks for device property "gpio-line-names" and if it exists assigns
* GPIO line names for the chip. The memory allocated for the assigned
* names belong to the underlying software node and should not be released
* by the caller.
*/
-static int devprop_gpiochip_set_names(struct gpio_chip *chip)
+static int devprop_gpiochip_set_names(struct gpio_chip *chip, int base)
{
// WHATEVER CHANGES TO TAKE base into account

+int devprop_gpiochip_set_names_base(struct gpio_chip *gc, int base)
+{
+ return devprop_gpiochip_set_names(gc, base);
+}
+EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names_base);
+
static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc)
{
unsigned long *p;
@@ -684,7 +706,7 @@ int gpiochip_add_data_with_key(struct gpio_chip
*gc, void *data,
if (gc->names)
ret = gpiochip_set_desc_names(gc);
else
- ret = devprop_gpiochip_set_names(gc);
+ ret = devprop_gpiochip_set_names(gc, 0);
if (ret)
goto err_remove_from_list;

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 4a7e295c3640..ad145ab0794c 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -537,6 +537,8 @@ extern int gpiochip_add_data_with_key(struct
gpio_chip *gc, void *data,
devm_gpiochip_add_data_with_key(dev, gc, data, NULL, NULL)
#endif /* CONFIG_LOCKDEP */

+extern int devprop_gpiochip_set_names_base(struct gpio_chip *gc, int base);
+

The problem I see with this approach is that
'devprop_gpiochip_set_names' already trusts in gpio_device already
created and this happens in 'gpiochip_add_data_with_key'. So doing in
this way force "broken drivers" to call this new
'devprop_gpiochip_set_names_base' function after
'devm_gpiochip_add_data' is called so the core code has already set up
the friendly names repeated for all gpio chip banks and the approach
would be to "overwrite" those in a second pass which sounds more like
a hack than a solution.

But maybe I am missing something in what you were pointing out here.

Best regards,
Sergio Paracuellos
> >
> > Any similar drivers (several gpio_chip per FW node) that want to
> > set line names need to do the same thing.
>
> Thanks for the advices. I'll try to make a bit of time to try to
> handle this in the way you are pointing out here.
>
> Best regards,
> Sergio Paracuellos
>
> >
> > Sorry that you ran into this, I hate it when I'm first at hairy stuff
> > like this.
> >
> > Yours,
> > Linus Walleij

\
 
 \ /
  Last update: 2021-07-03 13:08    [W:1.199 / U:0.604 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site