linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
	"Ahmad Fatoum" <a.fatoum@pengutronix.de>,
	"Jan Lübbe" <jlu@pengutronix.de>, "Marek Vasut" <marex@denx.de>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: Replacing global GPIO numbers in sysfs with hardware offsets
Date: Mon, 24 Feb 2025 09:49:36 +0800	[thread overview]
Message-ID: <20250224014936.GA12854@rigel> (raw)
In-Reply-To: <CAMRc=McUCeZcU6co1aN54rTudo+JfPjjForu4iKQ5npwXk6GXA@mail.gmail.com>

On Sun, Feb 02, 2025 at 01:45:58PM +0100, Bartosz Golaszewski wrote:
> Hi!

Sorry for being late to the party - was AFK for a bit.

>
> I'll allow myself to start a thread about it before anyone invests a
> significant amount of work into it. Yesterday (01.02.2025) during the
> "embedded dinner" after the FOSDEM 2025 embedded devroom concluded, we
> discussed the motivation behind my wish to remove /sys/class/gpio and
> the reasons why many users prefer it over libgpiod or even a
> user-space compatibility layer I presented during my talk earlier that
> day[1].
>
> The gist of it is: some people need to play with GPIOs very early, for
> example in an initramfs that is very limited in size and doesn't
> contain anything other than busybox so echoing into sysfs attributes
> is preferable over trying to cram additional tools or even the entire
> python interpreter into the limited system. An alternative to consider
> is of course adding some limited GPIO functionality to busybox.
>
> The main thing that bothers me in the GPIO sysfs class is not its
> existence per se but the fact that it identifies individual GPIOs by
> their global numbers and not hardware offsets which is the biggest
> obstacle to removing the global numberspace and the legacy GPIO API
> from the kernel.
>
> I think it was Ahmad or Marek who suggested that users aren't really
> attached to the global numbering but to the ease of use of sysfs.
>
> I floated an idea of introducing a backward compatible change to sysfs
> that would allow users to identify GPIOs by the label of their parent
> chip and the hardware offset of the line within that chip (like what
> we do for the character device) in the form of the export/unexport
> pair of attributes inside the gpiochipXYZ directory associated with
> given controller. These attributes, unlike the "global"
> export/unexport would take the hardware offset and create the line
> directory within the chip directory of which the layout would be the
> same as that of its global counterpart (in fact: it could point to the
> same directory in sysfs as a single line can only be requested once).
>
> We could then encourage users to switch to using the chip-local
> exports and eventually at least remove the global export/unexport pair
> if we cannot make the entire sysfs class go away.
>
> Please let me know what you think about it?
>

TBH, I think you will have trouble getting users to adopt it - they
require a solution no more complex than what they already have or they
will resist the change for as long as they possibly can.  So if you want
them to migrate before removing the global numberspace then that will
never happen.

As it stands the user needs to search the gpiochipXYZs looking for the
matching label. It would be easier if the chip was identified in sysfs by
its label, rather than (as well as) its base address.
So no searching required.

Aside: Speaking of which, once the global numberspace is removed does
exposing the base address serve any purpose?

Similarly, it would be even simpler if the line could be exported by
name, so the user wouldn't need to pull magic chip labels and offsets out
of the air.
Though that would be a much more extensive change.

Btw, I am well aware that line names are not guaranteed unique, so this
approach would only be viable/enabled (potentially on a line by line
basis) where they are - and that would provide some incentive for them to
be made unique downstream, if not in mainline.

> Bart
>
> [1] https://fosdem.org/2025/schedule/event/fosdem-2025-5288-the-status-of-removing-sys-class-gpio-and-the-global-gpio-numberspace-from-the-kernel/

My primary takeaway from your talk is that you are more of a thrill
seeker than I am comfortable with - making jokes about Rust in a
live forum - THAT is living on the edge ;).

Wrt the Q&A at 19:42 - the Pi BCM driver with its module parameter and
"why only this one driver is allowed to have it and the others not" and
the suggestion that there be some flag that can be passed to the driver
to request persistence:  I don't like your answer - it conflates specifying
the default/safe state, generally defined at boot time, with an ability to
override that at runtime.
Extending the driver API to allow the gpio_chip user to request that the
driver NOT reset an output to its default state when released seems like a
viable solution to me.  Am I missing something?

It also didn't address the fact that, even at FOSDEM, there are developers
out there that think that some drivers are getting special treatment.
In this case the Pi devs have pushed their own downstream solution
upstream to reduce their own maintenance burden.  And that was accepted as
it didn't conflict with anything in mainline.
There is nothing preventing other drivers doing the same, though no one
has AFAIAA.
Though the module parameter solution is rather crude - if we are going to
start touching all the drivers then why not address it via the API?

Cheers,
Kent.


  parent reply	other threads:[~2025-02-24  1:49 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-02 12:45 Replacing global GPIO numbers in sysfs with hardware offsets Bartosz Golaszewski
2025-02-03 14:23 ` Geert Uytterhoeven
2025-02-07 20:18   ` Bartosz Golaszewski
2025-02-09  9:40     ` Geert Uytterhoeven
2025-02-25 18:25       ` Ayush Singh
2025-02-25 20:20         ` Linus Walleij
2025-02-26  6:25           ` Ayush Singh
2025-02-14  9:14 ` Linus Walleij
2025-02-21 18:01   ` Marek Vasut
2025-02-25 19:54     ` Linus Walleij
2025-02-26 12:36       ` Marek Vasut
2025-02-26 19:07         ` Bartosz Golaszewski
2025-02-28  7:49         ` Linus Walleij
2025-02-28  8:49           ` Geert Uytterhoeven
2025-02-28  8:55             ` Linus Walleij
2025-02-28  9:53               ` Geert Uytterhoeven
2025-03-05  8:22                 ` Linus Walleij
2025-03-05  8:41                   ` Kent Gibson
2025-03-11 10:28                 ` Bartosz Golaszewski
2025-03-11 10:52                   ` Geert Uytterhoeven
2025-03-11 11:53                     ` Bartosz Golaszewski
2025-03-11 15:26                       ` Geert Uytterhoeven
2025-02-21 19:56   ` Ahmad Fatoum
2025-02-25 19:56     ` Linus Walleij
2025-02-24  1:49 ` Kent Gibson [this message]
2025-02-24  8:28   ` Geert Uytterhoeven
2025-02-26  9:23   ` Bartosz Golaszewski
2025-02-26 10:58     ` Kent Gibson

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=20250224014936.GA12854@rigel \
    --to=warthog618@gmail.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=brgl@bgdev.pl \
    --cc=geert+renesas@glider.be \
    --cc=jlu@pengutronix.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=marex@denx.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).