linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Matthias Urlichs <matthias@urlichs.de>
Cc: linux-gpio@vger.kernel.org
Subject: Re: Open-collector GPIO usage question
Date: Sat, 22 Nov 2025 12:03:00 +0800	[thread overview]
Message-ID: <20251122040300.GA9997@rigel> (raw)
In-Reply-To: <fa30998c-db6e-4ff3-b327-d8b6270979fa@urlichs.de>

On Fri, Nov 21, 2025 at 07:59:47PM +0100, Matthias Urlichs wrote:
> Hi,
> 
> so I want to efficiently implement a bit-bang-ish protocol, meaning I'd like
> to use events instead of busy-looping.
> 
> The hardware uses open-collector wiring.
> 
> This doesn't seem possible with Linux GPIO.
> 
> I cannot set input and output flags at the same time. Getting events
> requires the input flag while the open-drain output flag requires, well,
> output. Owch.
> 

The uAPI supports either a receiver role (input) or transmitter role
(output).  You are not locked into either role - the requested line can be
switched between the two as necessary [1].  So half-duplex.
But, as you say, it doesn't support both simultaneously, so no full-duplex
transceiver.

Should you require that you have two options, either a use a second
pin, an option you reject, or write an in-kernel driver for your
protocol.

> AFAICS all of this is enforced by
> drivers/gpio/gpiolib-cdev.c::gpio_v2_line_flags_validate(), so not gpio
> driver specific.

cdev is user facing and is validating user input.
It does not follow that it is the source of the restriction.

> 
> As some hardware seems capable enough to trigger an interrupt on raw port
> levels even if configured for "output", this seems overly restrictive …
> also, I happen to not have enough GPIO ports to use two per wire.

Some.  Not most.
This is functionality that the vast majority of users do not require, but
if you think it would be benificial then you can always submit a patch.
But, to be clear, this will require more than removing that check in cdev.

Cheers,
Kent.

[1] https://www.kernel.org/doc/html/latest/userspace-api/gpio/gpio-v2-line-set-config-ioctl.html




      reply	other threads:[~2025-11-22  4:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21 18:59 Open-collector GPIO usage question Matthias Urlichs
2025-11-22  4:03 ` Kent Gibson [this message]

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=20251122040300.GA9997@rigel \
    --to=warthog618@gmail.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=matthias@urlichs.de \
    /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).