linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Dahl <ada@thorsis.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Linus Walleij <linus.walleij@linaro.org>
Subject: Re: setting gpio-line-names in dts for sama5d2 SoC
Date: Thu, 18 Mar 2021 10:50:14 +0100 (CET)	[thread overview]
Message-ID: <854891727.11376.1616061014891@seven.thorsis.com> (raw)
In-Reply-To: <CAHp75VczovYQB70HVEmDA=xfTBcNuSm2f8x9Mnbj0P0Z4UHRMQ@mail.gmail.com>

Hei hei,

meanwhile I tried to proof my hypothesis. See below.

> Andy Shevchenko <andy.shevchenko@gmail.com> hat am 17.03.2021 13:33 geschrieben:
> 
>  
> +Cc: Bart, Linus
> 
> On Wed, Mar 17, 2021 at 1:22 AM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> >
> >
> > On Tuesday, March 16, 2021, Alexander Dahl <ada@thorsis.com> wrote:
> >>
> >> Hei hei,
> >>
> >> for a Microchip SAMA5D2 SoC based device I try to set gpio-line-names in .dts file like this:
> >>
> >> 257 &pioA {
> >> 258         gpio-line-names = "",                   /* PA0  */
> >> 259                           "",                   /* PA1  */
> >> 260                           "",                   /* PA2  */
> >> 261                           "FOO",                /* PA3  */
> >> 262                           "BAR",                /* PA4  */
> >> 263                           "",                   /* PA5  */
> >>
> >> … and so on for all 4 * 32 GPIO Pins. However when calling `gpioinfo` in userspace, I always get this:
> >>
> >> $ gpioinfo
> >> gpiochip0 - 128 lines:
> >>         line   0:        "PA0"       unused   input  active-high
> >>         line   1:        "PA1"       unused   input  active-high
> >>         line   2:        "PA2"       unused   input  active-high
> >>         line   3:        "PA3"       unused   input  active-high
> >>         line   4:        "PA4"       unused   input  active-high
> >>         line   5:        "PA5"       unused   input  active-high
> >>
> >> … and so on. Those "PA0" line names are set by the pinctrl driver in drivers/pinctrl/pinctrl-at91-pio4.c before calling gpiochip_add_data() and from reading the code in drivers/gpio/gpiolib.c I suspect devprop_gpiochip_set_names() is never called then, so those names in .dts are simply ignored.
> >>
> >> Those default names from the at91 pio4 pinctrl driver are certainly correct speaking of pin names, but from a userspace point of view it would be better if I could override those from dts, so an application using libgpiod could look for a name like e.g. "VALVE7_EN" without caring to which pin that's actually connected. Can I override those with a currently present kernel? 

I don't think I can override with a recent kernel.

>>> Or is it a problem in either the at91 pio4 driver or the gpiolib core? Or is that no real usecase and should I do it differently?

If I disable the name assignment in the pinctrl-at91-pio4 driver, I get the line names from the dts. I used the following diff:


diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c
index 578b387100d9..f994a2468cc3 100644
--- a/drivers/pinctrl/pinctrl-at91-pio4.c
+++ b/drivers/pinctrl/pinctrl-at91-pio4.c
@@ -1095,7 +1095,9 @@ static int atmel_pinctrl_probe(struct platform_device *pdev)
        atmel_pioctrl->gpio_chip->ngpio = atmel_pioctrl->npins;
        atmel_pioctrl->gpio_chip->label = dev_name(dev);
        atmel_pioctrl->gpio_chip->parent = dev;
+#if 0
        atmel_pioctrl->gpio_chip->names = atmel_pioctrl->group_names;
+#endif
 
        atmel_pioctrl->pm_wakeup_sources = devm_kcalloc(dev,
                        atmel_pioctrl->nbanks,


Now gpioinfo shows what I set in dts, more or less similar to this:

gpiochip0 - 128 lines:
        line   0:      unnamed       unused   input  active-high 
        line   1:      unnamed       unused   input  active-high 
        line   2:      unnamed       unused   input  active-high 
        line   3:        "FOO"       unused   input  active-high 
        line   4:        "BAR"       unused   input  active-high 
        line   5:      unnamed       unused   input  active-high 

> >
> >
> > I would like to know the consequences if allow this, but to me it sounds like a bug in the gpiolib.c.

At least the documentation recommends to not use pin names: https://www.kernel.org/doc/Documentation/devicetree/bindings/gpio/gpio.txt

If anyone has an idea how to fix this, let me know. I can try to make a patch then. Currently however, I'm not familiar enough with the gpio subsystem to just start that.

Greets
Alex

  reply	other threads:[~2021-03-18  9:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 13:07 setting gpio-line-names in dts for sama5d2 SoC Alexander Dahl
     [not found] ` <CAHp75Vf05NN0dXUrMSOXBRuYRnQRHO_92itZ3ndOyX1oERWt=g@mail.gmail.com>
2021-03-17 12:33   ` Andy Shevchenko
2021-03-18  9:50     ` Alexander Dahl [this message]
2021-03-18 12:40       ` Andy Shevchenko
2021-03-18 13:56         ` Alexander Dahl
2021-03-18 14:59           ` Andy Shevchenko
2021-03-20 11:20             ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=854891727.11376.1616061014891@seven.thorsis.com \
    --to=ada@thorsis.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).