linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Hans de Goede <hdegoede@redhat.com>
Cc: Marc Zyngier <maz@kernel.org>,
	linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Jonathan Corbet <corbet@lwn.net>
Subject: Re: [PATCH v1 2/3] Documentation: gpio: Add a section on what to return in ->get() callback
Date: Wed, 30 Nov 2022 18:20:57 +0200	[thread overview]
Message-ID: <Y4eC6W/wstJFLrEr@smile.fi.intel.com> (raw)
In-Reply-To: <8a53e88b-1e74-bf34-62a1-780a1b29bcbc@redhat.com>

On Wed, Nov 30, 2022 at 05:12:13PM +0100, Hans de Goede wrote:
> On 11/30/22 16:55, Andy Shevchenko wrote:
> > The ->get() callback depending on other settings and hardware support
> > may return different values, while the line outside the chip is kept
> > in the same state. Let's discuss that in the documentation.

...

> > +Considerations of the ->get() returned value
> > +--------------------------------------------
> > +
> > +Due to different possible electrical configurations and software applications
> > +the value that ->get() callback returns may vary depending on the other settings.
> > +This will allow to use pins in the I2C emulation mode or other not so standard
> > +uses.
> > +
> > +The below table gathered the most used cases.
> > +
> > +==========  ==========  ===============  =======================
> > +  Input       Output         State        What value to return?
> > +==========  ==========  ===============  =======================
> > + Disabled    Disabled    Hi-Z             input buffer
> > + Disabled    OS/OD/etc   Single ended     [cached] output buffer
> 
> You need to clarify what single-ended means here. You mean a pin
> which is only capable of output I guess ?  So now way to figure
> out if another participant in the OS/OD bus has its transistor
> in the "on" state this pulling the bus high / low agains the bias
> resistor(s) which determine the state of the bus in rest ?
> 
> Or you mean that the bus is uni-directional, even then being
> able to detect a short-circuit is useful.

It's described in the previous chapter(s).

> > +    x        Push-Pull   Out              [cached] output buffer
> 
> Why, most GPIO drivers are protected against short-circuit to
> GND / Vdd and actually reading the input-buffer here will allow
> GPIO API consumers to detect such short-circuits if they are
> interested in this.  This would e.g. be useful to detect
> mis-wiring on devices like the Raspberry Pi were users often
> connect extra peripherals through breadboards.

I think it is nonsense from electronics point of view.

> IMHO for pins with an input buffer get() should simply
> always return the contents of the input buffer. This is what
> I believe almost all GPIO drivers currently do and also
> keeps the get() methods KISS.

As you can see, I disagree on this.

> Actually implementing the behavior you suggest here requires
> the get() method to differentiate between push-pull and
> other mode. This makes the get() method implementation
> needlessly complicated and will likely be a source of bugs
> as people will get this wrong in some cases and people
> will very likely not test all possible combinations from
> this big table you are adding here.

People already are getting wrong this and here is no documentation
on what to do to get it right.

> IHMO the rules for get() should simply be:
> 
> 1. Device has an input buffer:
>    Return input-buffer value for the pin.

I disagree on this. It makes no sense to read real hw wire state when output
is enabled. If somebody does a short circuit, it's not a Linux issue and
should be recognized on the PCB side (using oscilloscope, multi-meter, etc).

> 2. Devices does not have an input buffer:
>    Return last set output-buffer value

> > + Enabled     Disabled    In               input buffer
> > + Enabled     OS/OD/etc   Bidirectional    input buffer
> > +==========  ==========  ===============  =======================
> > +
> > +The [cached] here is used in a broader sense: either pure software cache, or
> > +read back value from the GPIO output buffer (not all hardware support that).

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2022-11-30 16:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30 15:55 [PATCH v1 1/3] Documentation: gpio: Input mode is not true Hi-Z Andy Shevchenko
2022-11-30 15:55 ` [PATCH v1 2/3] Documentation: gpio: Add a section on what to return in ->get() callback Andy Shevchenko
2022-11-30 16:12   ` Hans de Goede
2022-11-30 16:14     ` Hans de Goede
2022-11-30 16:22       ` Andy Shevchenko
2022-11-30 16:20     ` Andy Shevchenko [this message]
2022-12-01 11:18       ` Hans de Goede
2022-12-03  9:38   ` Linus Walleij
2022-12-03 12:09     ` Hans de Goede
2022-12-05  1:43     ` Kent Gibson
2022-12-05 12:08       ` Andy Shevchenko
2022-12-05 15:35         ` Kent Gibson
2022-12-07  0:06       ` Linus Walleij
2022-12-07  9:55         ` Andy Shevchenko
2022-12-07 10:11           ` Kent Gibson
2022-12-07 13:49           ` Linus Walleij
2022-11-30 15:55 ` [PATCH v1 3/3] Documentation: gpio: Replace leading TABs by spaces in the code blocks Andy Shevchenko
2022-12-03  9:35   ` Linus Walleij
2022-12-03  9:33 ` [PATCH v1 1/3] Documentation: gpio: Input mode is not true Hi-Z Linus Walleij
2023-03-10 17:25   ` Andy Shevchenko
2023-03-15 10:07     ` Bartosz Golaszewski

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=Y4eC6W/wstJFLrEr@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=corbet@lwn.net \
    --cc=hdegoede@redhat.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@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).