linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	linux-acpi@vger.kernel.org, devicetree@vger.kernel.org,
	linux-gpio@vger.kernel.org,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>
Subject: Re: [PATCH 0/4] add support for bias pull-disable
Date: Fri, 15 Jul 2022 14:20:46 +0200	[thread overview]
Message-ID: <88114aeb10f7316cf3c1396179949f2fc351ad8f.camel@gmail.com> (raw)
In-Reply-To: <YtFYFbP+xqAUUHZa@smile.fi.intel.com>

On Fri, 2022-07-15 at 15:05 +0300, Andy Shevchenko wrote:
> On Fri, Jul 15, 2022 at 12:20:56PM +0200, Nuno Sá wrote:
> > On Thu, 2022-07-14 at 21:57 +0300, Andy Shevchenko wrote:
> > > On Thu, Jul 14, 2022 at 05:43:41PM +0200, Nuno Sá wrote:
> > > > On Thu, 2022-07-14 at 17:58 +0300, Andy Shevchenko wrote:
> > > > > On Wed, Jul 13, 2022 at 03:14:17PM +0200, Nuno Sá wrote:
> > > > > > The gpio core looks at 'FLAG_BIAS_DISABLE' in preparation
> > > > > > of
> > > > > > calling the
> > > > > > gpiochip 'set_config()' hook. However, AFAICT, there's no
> > > > > > way
> > > > > > that
> > > > > > this
> > > > > > flag is set because there's no support for it in firwmare
> > > > > > code.
> > > > > > Moreover,
> > > > > > in 'gpiod_configure_flags()', only pull-ups and pull-downs
> > > > > > are
> > > > > > being
> > > > > > handled.
> > > > > > 
> > > > > > On top of this, there are some users that are looking at
> > > > > > 'PIN_CONFIG_BIAS_DISABLE' in the 'set_config()' hook. So,
> > > > > > unless
> > > > > > I'm
> > > > > > missing something, it looks like this was never working for
> > > > > > these
> > > > > > chips.
> > > > > > 
> > > > > > Note that the ACPI case is only compiled tested. At first
> > > > > > glance,
> > > > > > it seems
> > > > > > the current patch is enough but i'm not really sure...
> > > > > 
> > > > > So, I looked closer to the issue you are trying to describe
> > > > > here.
> > > > > 
> > > > > As far as I understand we have 4 state of BIAS in the
> > > > > hardware:
> > > > > 1/ AS IS (defined by firnware)
> > > > > 2/ Disabled (neither PU, not PD)
> > > > > 3/ PU
> > > > > 4/ PD
> > > > > 
> > > > > The case when the default of bias is not disabled (for
> > > > > example
> > > > > specific, and I
> > > > > think very special, hardware may reset it to PD or PU), it's
> > > > > a
> > > > > hardware driver
> > > > > responsibility to inform the framework about the real state
> > > > > of
> > > > > the
> > > > > lines and
> > > > > synchronize it.
> > > > > 
> > > > > Another case is when the firmware sets the line in non-
> > > > > disabled
> > > > > state
> > > > > and
> > > > > by some reason you need to disable it. The question is, why?
> > > > 
> > > > Not getting this point... 
> > > 
> > > I understand that in your case "firmware" is what DTB provides.
> > > So taking into account that the default of hardware is PU, it
> > > needs
> > > a mechanism to override that, correct?
> > > 
> > 
> > Exactly...
> > 
> > > > > > As a side note, this came to my attention during this
> > > > > > patchset
> > > > > > [1]
> > > > > > (and, ofr OF,  was tested with it).
> > > > > > 
> > > > > > [1]:
> > > > > > https://lore.kernel.org/linux-input/20220708093448.42617-5-nuno.sa@analog.com/
> > > > > 
> > > > > Since this provides a GPIO chip, correct?, it's
> > > > > responsibility of
> > > > > the
> > > > > driver to
> > > > > synchronize it, no? Basically if you really don't trust
> > > > > firmware,
> > > > > you
> > > > > may
> > > > 
> > > > What do you mean by synchronize?
> > > 
> > > Full duplex sync, i.e. setting flag to PU for the pins that
> > > should
> > > stay PU:ed
> > > and disabling bias for the ones, that want it to be disabled. (PD
> > > accordingly)
> > > 
> > > > > go via all GPIO lines and switch them to the known (in
> > > > > software)
> > > > > state. This
> > > > > approach on the other hand is error prone, because firmware
> > > > > should
> > > > > know better
> > > > > which pin is used for which purpose, no? If you don't trust
> > > > > firwmare
> > > > > (in some
> > > > > cases), then it's a matter of buggy platform that has to be
> > > > > quirked
> > > > > out.
> > > > 
> > > > I'm not getting what you mean by "firmware should know better"?
> > > > So,
> > > > basically, and let's take OF as example, you can request a GPIO
> > > > in
> > > > OF
> > > > by doing something like:
> > > > 
> > > >         foo-gpios = <&gpio 1 GPIO_PULL_UP>;
> > > > 
> > > > In this way, when the consumer driver gets the gpio, all the
> > > > flags
> > > > will
> > > > be properly set so that when we set a direction (for example)
> > > > the
> > > > gpiochip's 'set_config()' will be called and the driver does
> > > > what
> > > > it
> > > > needs to setup the pull-up. If we want BIAS_DISABLED on the
> > > > pin,
> > > > there's no way to the same as the above. So basically, this can
> > > > ever
> > > > happen:
> > > > 
> > > > https://elixir.bootlin.com/linux/latest/source/drivers/gpio/gpiolib.c#L2227
> > > > 
> > > > (only possible from the gpiochip cdev interface)
> > > > 
> > > > So, what I'm proposing is to be possible to do from OF:
> > > > 
> > > >         foo-gpios = <&gpio 1 GPIO_PULL_DISABLE>;
> > > > 
> > > > And then we will get into the gpiochip's 'set_config()' to
> > > > disable
> > > > the
> > > > pull-up or pull-down.
> > > > 
> > > > As I said, my device is an input keymap that can export pins as
> > > > GPIOs
> > > > (to be consumed by gpio_keys). The pins by default have pull-
> > > > ups
> > > > that
> > > > can be disabled by doing a device i2c write. I'm just trying to
> > > > use
> > > > the
> > > > infrastructure that already exists in gpiolib (for pull-
> > > > up|down) to
> > > > accomplish this. There's no pinctrl driver controlling the
> > > > pins.
> > > > The
> > > > device itself controls them and having this device as a pinctrl
> > > > one
> > > > is
> > > > not really applicable.
> > > 
> > > Yes, I have got it eventually. The root cause is that after reset
> > > you
> > > have a
> > > hardware that doesn't disable bias.
> > > 
> > > Now, we have DT properties for PD and PU, correct?
> > > For each requested pin you decide either to leave the state as it
> > > is,
> > > or
> > > apply bias.
> > > 
> > > in ->probe() of your GPIO you reset hardware and for each GPIO
> > > descriptor you
> > > set PU flag.
> > > In ->request(), don;t know the name by heart, you disable BIAS
> > > based
> > > on absence
> > > of flags, it can be done without an additional properties, purely
> > > in
> > > the GPIO
> > > OF code. Do I understand this correctly?
> > > 
> > 
> > Alright, I think now you got it and we are on the same page. If I
> > understood your suggestion, users would just use GPIO_PULL_UP in
> > dtb if
> > wanting the default behavior. I would then use the gpiochip
> > 'request()'
> > callback to test the for pull-up flag right?
> 
> Something like this, yes.
> 
> > If I'm getting this right, there's a problem with it...
> > gpiod_configure_flags() is called after gpiod_request() which means
> > that the gpiod descriptor won't still have the BIAS flags set. And
> > I
> > don't think there's a way (at least clean and easy) to get the
> > firmware
> > lookup flags from the request callback?
> > 
> > So, honestly the only option I see to do it without changing
> > gpioblib
> > would be to hook this change in output/input callbacks which is far
> > from being optimal...
> > 
> > So, in the end having this explicitly like this feels the best
> > option
> > to me. Sure, I can find some workaround in my driver but that does
> > not
> > change this...
> 
> Ok, let me think about it. Meanwhile, maybe others have better ideas
> already?
> 

Sure, I'm still thinking that having this extra property and explicitly
set it from OF is not that bad :)

> > "
> > git grep "PIN_CONFIG_BIAS_DISABLE" drivers/gpio/
> 
> Hint: `git grep -lw "PIN_CONFIG_BIAS_DISABLE" -- drivers/gpio`
> 

nice..

> > drivers/gpio/gpio-aspeed.c:963: else if (param ==
> > PIN_CONFIG_BIAS_DISABLE ||
> > drivers/gpio/gpio-merrifield.c:197:     if
> > ((pinconf_to_config_param(config) == PIN_CONFIG_BIAS_DISABLE) ||
> > drivers/gpio/gpio-omap.c:903:   case PIN_CONFIG_BIAS_DISABLE:
> > drivers/gpio/gpio-pca953x.c:573:        if (config ==
> > PIN_CONFIG_BIAS_DISABLE)
> > drivers/gpio/gpio-pca953x.c:592:        case
> > PIN_CONFIG_BIAS_DISABLE:
> > "
> > 
> > AFAICT, the only way this path is possible for these drivers is
> > through
> > gpiolib cdev which might not be what the authors of the drivers
> > were
> > expecting...
> 
> gpio-merrifield is bad example, it has a pin control.
> gpio-pca953x as I said should effectively be a pin control driver.
> 
> For the two left it might be the case.
> 

Well the thing is that even if we have pinctrl like for example,
gpio-omap, it is still true that there's no way to get into
'omap_gpio_set_config()' for 'PIN_CONFIG_BIAS_DISABLE' and call
'gpiochip_generic_config()'.

(naturally in this case, one can directly use pinctrl properties to
control the pin but still...)


- Nuno Sá


  reply	other threads:[~2022-07-15 12:19 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-13 13:14 [PATCH 0/4] add support for bias pull-disable Nuno Sá
2022-07-13 13:14 ` [PATCH 1/4] gpiolib: add support for bias pull disable Nuno Sá
2022-07-13 17:36   ` Andy Shevchenko
2022-07-14  4:20     ` Kent Gibson
2022-07-14  7:14       ` Nuno Sá
2022-07-14  8:27         ` Kent Gibson
2022-07-14  8:47           ` Nuno Sá
2022-07-14 12:00             ` Kent Gibson
2022-07-14 13:02               ` Nuno Sá
2022-07-14 15:08                 ` Andy Shevchenko
2022-07-14 15:47                   ` Nuno Sá
2022-07-18 10:44     ` Linus Walleij
2022-07-13 13:14 ` [PATCH 2/4] gpiolib: of: support " Nuno Sá
2022-07-18 10:30   ` Linus Walleij
2022-07-13 13:14 ` [PATCH 3/4] gpiolib: acpi: " Nuno Sá
2022-07-18 10:32   ` Linus Walleij
2022-07-18 10:49     ` Nuno Sá
2022-07-18 13:49       ` Linus Walleij
2022-07-18 18:25   ` Andy Shevchenko
2022-07-13 13:14 ` [PATCH 4/4] dt-bindings: gpio: add pull-disable flag Nuno Sá
2022-07-18 10:33   ` Linus Walleij
2022-07-18 20:52   ` Rob Herring
2022-07-13 17:39 ` [PATCH 0/4] add support for bias pull-disable Andy Shevchenko
2022-07-14  7:09   ` Nuno Sá
2022-07-14  9:12     ` Andy Shevchenko
2022-07-14  9:49       ` Nuno Sá
2022-07-14 14:58 ` Andy Shevchenko
2022-07-14 15:43   ` Nuno Sá
2022-07-14 18:57     ` Andy Shevchenko
2022-07-15 10:20       ` Nuno Sá
2022-07-15 12:05         ` Andy Shevchenko
2022-07-15 12:20           ` Nuno Sá [this message]
2022-07-15 19:31             ` Bartosz Golaszewski
2022-07-18  7:51               ` Nuno Sá
2022-07-18 10:29                 ` Linus Walleij
2022-07-18 10:46                   ` Nuno Sá
2022-07-18 10:25               ` Linus Walleij
2022-07-19  8:25 ` Bartosz Golaszewski
2022-07-19  8:52   ` Nuno Sá
2022-07-19  9:14     ` Bartosz Golaszewski
2022-07-19 10:21       ` Nuno Sá

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=88114aeb10f7316cf3c1396179949f2fc351ad8f.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=nuno.sa@analog.com \
    --cc=robh+dt@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).