Hi, as part of migrating a project off fixed GPIO numbering, I had ended up with following script: # USAGE: gpio_legacy_index NAME [ERROR_STRING] # Prints either the sysfs gpio index associated with # NAME on success or ${ERROR_STRING:-} on failure. # This can be used in scripts as an intermediate step when migrating # away from sysfs. It decouples use of gpio-line-names in DT from # using the character device gpio_legacy_index() { local gpiod="$(gpiofind $1)" if [ "$gpiod" = "" ]; then echo "${2:-}" return 1 fi set $gpiod echo "$(($(cat /sys/bus/gpio/devices/$1/../gpio/gpio*/base) + $2))" } And migration proceeded as follows: - add gpio-line-names to DT - switch hardcoded GPIOs to use gpio_legacy_index + label, optionally with a fallback to the old number - test and adapt all device trees for devices that may run the script - drop the fallback Next step would've been dropping sysfs in favor of libgpiod. This is a bit more complicated, because of the implicit assumption at places that the GPIO state stays the same requiring some process to step up and feel responsible for it. Therefore the above script that decouples fixed numbering from /sys/class/gpio to make migration easier. My question isn't about sysfs, but about the numbering though[1]: Much to my dismay, I've learnt that my script above doesn't work when the same device registers multiple GPIO controllers. On my i.MX system with some PCA953x GPIO expanders, it works ok, but on a STM32MP, were the pinctrl device registers all GPIO chips, the glob will expand to more than once device. So my question is: What better way is there to get a legacy GPIO index from within a shell script (or an alternative way to request a sysfs GPIO by label)? P.S: I know that most GPIO fiddling should've kernel driver consumers instead. That's under way too. [1]: I appreciate links to any WIP/planned systemd-gpiod or similar patches anyway. While new projects should do more fine grained control of GPIOs, migration of most users will likely benefit benefit from a single global consumer. Thanks, Ahmad -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |