Setting gpiochip labels from devicetree
Hey all,
I was running in some issues with GPIO pin and chip numbering not being stable, which lead me to two suggestions to improve labeling on gpio chips. Reasoning for these suggestions follow from my journey:
- I had a script that used sysfs, which I'm converting to gpiod instead.
- I realized that /dev/gpiochipx numbering is also not stable, so using gpioset with chip and offset arguments would not solve my problem.
- I messed around a with aliases a bit, until I realized the gpio-omap driver did not support this. Then I found this 10-year-old thread that convinced me that stable chip numbering is not the solution, but proper labeling of chips and pins:
https://www.spinics.net/lists/devicetree/msg134513.html
- Often, you can use pin/line names for finding the right pin.
- However, these line names often contain (board-)specific labels or functional labels, so it would be good if you could also refer to them based on generic chip labels (which are often something like GPIO3-12 or GPIOC12). If the chips have appropriate labels (like GPIO3 or GPIOC) then the chip label + offset could be used to deterministically locate such pins. Also, if line names are ambiguous (e.g. with dynamic devices), a good chip name helps to disambiguate.
- I noticed that the gpio-omap gpiochips have meaningless labels: they are e.g. gpio-0-32 which used to refer to the global sysfs numbering, but since commit 92bf78b33b0b4 (gpio: omap: use dynamic allocation of base, 2023-01-13) is not even related to those (naming is just decided by initialization order.
- I looked at setting better labels from the devicetree, but AFAICS this is not supported currently (maybe specific gpio drivers support it, but nothing in gpiolib).
From the above journey, I had two suggestions:
1. gpio-omap should produce different labels. The current labels imply some global gpio numbering, but they do not match the sysfs numbers. I am not sure if the gpio-omap driver by itself could produce labels like GPIO0 and GPIO1 to match the datasheet. If not, maybe it should produce no labels (using the gpiolib "unknown" default) and letting DT apply the proper labels.
2. Support a generic "label" or so devicetree property on gpio controllers, letting of_gpiolib read it and use that instead of the label supplied by the gpio driver. This would allow devicetrees (which have most info on the context, I would say) to use appropriate labeling for each chip.
I do not expect I'll find the time to actually contribute these changes, but wanted to at least see kick off discussion about this (if this has not already been discussed before - could not find any threads...).
Gr.
Matthijs