Re: [PATCH RFC/RFT 07/15] gpio: sysfs: add a parallel class device for each GPIO chip using device IDs

From: Linus Walleij
Date: Wed Jun 11 2025 - 04:28:19 EST


On Tue, Jun 10, 2025 at 4:38 PM Bartosz Golaszewski <brgl@xxxxxxxx> wrote:

> From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
>
> In order to enable moving away from the global GPIO numberspace-based
> exporting of lines over sysfs: add a parallel, per-chip entry under
> /sys/class/gpio/ for every registered GPIO chip, denoted by device ID
> in the file name and not its base GPIO number.
>
> Compared to the existing chip group: it does not contain the "base"
> attribute as the goal of this change is to not refer to GPIOs by their
> global number from user-space anymore. It also contains its own,
> per-chip export/unexport attribute pair which allow to export lines by
> their hardware offset within the chip.
>
> Caveat #1: the new device cannot be a link to (or be linked to by) the
> existing "gpiochip<BASE>" entry as we cannot create links in
> /sys/class/xyz/.
>
> Caveat #2: the new entry cannot be named "gpiochipX" as it could
> conflict with devices whose base is statically defined to a low number.
> Let's go with "chipX" instead.

That's unfortunate but it's good to separate them, and
gpio/gpiochip is a bit tautological so this is a better sysfs name
anyway.

> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>

> + /chipX ... for each gpiochip; #X is the gpio device ID
> + /export ... asks the kernel to export a GPIO at HW offset X to userspace
> + /unexport ... to return a GPIO at HW offset X to the kernel
> + /label ... (r/o) descriptive, not necessarily unique

Not necessarily *globally* unique, I think it's required to be unique
per-gpiochip right? Otherwise it will be hard to create these files.

> + /ngpio ... (r/o) number of GPIOs exposed by the chip

I like this approach, it's a good compromise between different
desires of the sysfs ABI.

Acked-by: Linus Walleij <linus.walleij@xxxxxxxxxx>

Yours,
Linus Walleij