From: "Nuno Sá" <noname.nuno@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Andy Shevchenko <andy@kernel.org>,
nuno.sa@analog.com, linux-hwmon@vger.kernel.org,
devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Bartosz Golaszewski <brgl@bgdev.pl>
Subject: Re: [PATCH v2 2/2] hwmon: ltc4282: add support for the LTC4282 chip
Date: Fri, 01 Dec 2023 16:24:35 +0100 [thread overview]
Message-ID: <b761d2497462664d541779857398b2aa893cbee5.camel@gmail.com> (raw)
In-Reply-To: <CACRpkda55HzPqus5KR-t=xEBkkdND5kYZj1sHdxK+j6QwDUPRg@mail.gmail.com>
On Fri, 2023-12-01 at 14:40 +0100, Linus Walleij wrote:
> On Fri, Dec 1, 2023 at 1:34 PM Nuno Sá <noname.nuno@gmail.com> wrote:
> > On Thu, 2023-11-30 at 21:15 +0100, Linus Walleij wrote:
>
> > I did not used libgpiod but I did tested it with gpio-sysfs. Well, I could
> > effectively see the pull down behaviour but since my eval board has no pull-ups I
> > could not drive the line high.
>
> libgpiod has the upside of offering you to set the pull down and open
> drain behaviour from userspace.
>
Yeah, I can also just come up with a minimal test driver and devicetree.
> > > The gpiolib framework assumes we can do open drain emulation by
> > > setting lines as input. It is used as fallback unless the hardware has
> > > an explicit open drain setting.
> >
> > Yeah, I did look at that after you pointed that out. There's just something I'm
> > still
> > not getting. This HW has no explicit open drain setting because open drain is all
> > that it is. So, I guess we could just specify the flag in devicetree so gpiolib
> > could
> > use the emulation
> > but I wonder how would we have things in case we have the HW setup
> > to drive the pin high (so having this as GPOs)?
>
> If another device tree node uses:
>
> foo-gpios = <&gpio0 5 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
>
> The result will be that gpiolib will emulate open drain.
>
> From userspace libgpiod can do the same request.
>
> > > > Also got me thinking if a gpi vs gpo devicetree property would make sense.
> > > > But I
> > > > would likely leave it more generic/relaxed for now (even though I think you
> > > > would
> > > > need to be creative and actually use more HW to have the possibility of using
> > > > these
> > > > pins as GPIs and GPOs at the same time).
> > >
> > > We don't define that in the device tree currently, we just make the driver
> > > not support output on input-only pins and vice versa, by returning error
> > > codes on the .set_direction() callbacks.
> >
> > I see, but in this case, the pins could be outputs depending on the HW setup but
> > there's no way for us to know that in the driver.
>
> We just specify the line in the device tree, and we just use it as
> intended in the
> driver, if it is present, whether that is as input or output.
>
> We do not try to over-protect users from misusing GPIO lines that have just
> one possible (electronic defined) mode. It would be over-engineering IMO.
>
Fair enough...
> > And given the fact that (I think)
> > it's highly unlikely for pins like this to ever be GPIs and GPOs at the same
> > time, I
> > brought the devicetree property to define input and output only. So, roughly,
> > what I
> > have in mind now for the chip is;
> >
> > .set_config() -> with PULL_DOWN and HIGH_IMPEDANCE support
> > .direction_input() -> This is important for gpio1 where we do have an hw setting
> > to
> > set the direction. On the other pins I was thinking in just forcing high-z. Or
> > maybe
> > can I just rely on gpio_set_bias()?
>
> No just write some default set-up into the registers, that's fine.
> Or leave the power-on defaults.
>
> > .direction_ouput() -> Would only matter for gpio1
>
> The just return an error code for any other GPIO where this is called.
>
> > .get/set_value() -> And in this case we just assume that high value might or
> > might
> > not be possible (depending on the hw setup). Note that reading the pin state is
> > always possible.
>
> If a pins .direction_output() fails, .set_value() will not be called
> on it either.
This is where I lost you :(. So, I'm might be overcomplicating things but... Again,
the case where someone wired up HW so that we can actually use the pin to drive the
line high (having an external pull up). In that case, If I return error, then I won't
be able to effectively set the line high (as you said, set_value will not be called
on it either).
Now, I do understand that if we have the line flagged as GPIO_OPEN_DRAIN, then
gpiolib will switch the line to input which means we will set the line in high-z
which means that if we have a pull up, then the line will be high. I mean, it works
but it would be strange if someone wants to have the line as output high and after
trying to set the it high, it sees the pin moving to input. But if this is how it
should be, fine by me.
I do understand this is the definition of open drain so I guess someone should know
what to expect when operating with pins like this.
>
> > This means that I assume we can have both directions but that is not really case
> > and
> > one needs to know what it is doing :). Or in cases like this, we just ignore the
> > possibility of having GPO's and we let gpiolib do the emulation?
> >
> > Sounds reasonable or not really how I should handle this open-drain only pins?
>
> Open drain-only pins would be pins that can be set to electric LOW (grounded)
> or High-Z. Is this what we have?
>
Yes, that is the only thing we have. Meaning that there is no hw setting to set the
pins to open drain. Open drain is what they are. That is why I'm not seeing the point
in having PIN_CONFIG_DRIVE_OPEN_DRAIN implemented.
Anyways, I'll try to have something cooked next week. I'll be slow since the winter
(not even there yet) in Germany already got me!
- Nuno Sá
next prev parent reply other threads:[~2023-12-01 15:24 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-24 14:18 [PATCH v2 0/2] Add support for LTC4282 Nuno Sa via B4 Relay
2023-11-24 14:18 ` [PATCH v2 1/2] dt-bindings: hwmon: Add LTC4282 bindings Nuno Sa via B4 Relay
2023-11-25 11:56 ` Conor Dooley
2023-11-27 7:56 ` Nuno Sá
2023-11-27 17:33 ` Conor Dooley
2023-11-28 15:37 ` Rob Herring
2023-11-28 15:49 ` Nuno Sá
2023-11-24 14:18 ` [PATCH v2 2/2] hwmon: ltc4282: add support for the LTC4282 chip Nuno Sa via B4 Relay
2023-11-24 21:54 ` kernel test robot
2023-11-24 23:39 ` kernel test robot
2023-11-27 7:53 ` Nuno Sá
2023-11-27 8:10 ` Krzysztof Kozlowski
2023-11-27 8:12 ` Krzysztof Kozlowski
2023-11-27 8:44 ` Nuno Sá
2023-11-27 16:03 ` Andy Shevchenko
2023-11-28 16:50 ` Krzysztof Kozlowski
2023-11-28 17:01 ` Andy Shevchenko
2023-11-28 18:03 ` Guenter Roeck
2023-11-29 8:35 ` Nuno Sá
2023-11-29 8:45 ` Krzysztof Kozlowski
2023-11-29 8:56 ` Nuno Sá
2023-11-29 14:10 ` Linus Walleij
2023-11-29 14:13 ` Krzysztof Kozlowski
2023-11-29 14:29 ` Nuno Sá
2023-11-29 14:47 ` Guenter Roeck
2023-11-29 16:09 ` Nuno Sá
2023-11-27 10:20 ` kernel test robot
2023-11-29 14:49 ` Linus Walleij
2023-11-29 16:08 ` Nuno Sá
2023-11-29 16:18 ` Andy Shevchenko
2023-11-29 16:21 ` Nuno Sá
2023-11-29 17:07 ` Andy Shevchenko
2023-11-29 20:55 ` Linus Walleij
2023-11-30 10:20 ` Nuno Sá
2023-11-30 13:36 ` Andy Shevchenko
2023-11-30 14:39 ` Guenter Roeck
2023-11-30 15:20 ` Nuno Sá
2023-11-30 16:28 ` Guenter Roeck
2023-11-30 20:15 ` Linus Walleij
2023-12-01 12:34 ` Nuno Sá
2023-12-01 13:40 ` Linus Walleij
2023-12-01 15:24 ` Nuno Sá [this message]
2023-12-01 15:47 ` Andy Shevchenko
2023-12-01 16:04 ` Guenter Roeck
2023-12-01 16:24 ` Andy Shevchenko
2023-12-01 16:36 ` Guenter Roeck
2023-12-01 16:29 ` Nuno Sá
2023-12-01 16:46 ` Guenter Roeck
2023-12-02 9:42 ` Nuno Sá
2023-12-03 23:08 ` Linus Walleij
2023-12-04 8:20 ` Bartosz Golaszewski
2023-12-01 16:19 ` Nuno Sá
2023-12-01 16:23 ` Andy Shevchenko
2023-12-03 23:03 ` Linus Walleij
2023-12-04 8:53 ` 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=b761d2497462664d541779857398b2aa893cbee5.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=andy@kernel.org \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--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).