GPIO in modern Linux have two strings associated with them: name (or label) and consumer. The name is typically set at boot and remains stable, whereas the consumer is expected to be set by whatever application is currently using that specific line. Our current devicetrees configure GPIO in such a way where name is unset and consumer contains what should be in name. This is inconvenient because applications which try to look up the lines by name (e.g. oresat-c3-software) can crash if another program got to the line first and accidentally reset or changed the consumer (e.g. the AX5043 driver).
The devicetrees configure GPIO in this way because they use gpio-of-helper to set up the lines. gpio-of-helper is an out-of-tree TI kernel module that was rejected a decade ago by upstream and hasn't been maintained since. It was built for the version 1 GPIO interface, but Linux has since moved on to version 2, which is where the name/consumer split took place.
The solution to this comes in three parts:
Setting the names
Hogging
Fixing userspace.
Setting the names
I think this in isolation should be fairly easy. Using the standard devicetree GPIO configuration we can just set gpio-line-names for each gpio-controller (see for example this similar devicetree). I don't think this should conflict with gpio-of-helper but I've not tested it but I don't know for sure.
Hogging
Since gpio-of-helper is deprecated, how do we go about configuring lines at boot? Hogging. See this doc again for a description. That will reserve the lines for userspace, allow you to set default levels, pull-up/down resisters, and other things. We should eventually update our devicetrees to use hogging instead of gpio-of-helper. What hogging won't do on the other hand is set up the sysfs interface. The sysfs interface is deprecated so we should move away from it but that will require fixing up userspace.
Fixing userspace
olaf has a basic GPIO library built atop the sysfs interface. If we move to hogging this will either need to be replaced with the standard gpiod library or some userspace thing to re-set up sysfs.
GPIO in modern Linux have two strings associated with them:
name
(orlabel
) andconsumer
. Thename
is typically set at boot and remains stable, whereas theconsumer
is expected to be set by whatever application is currently using that specific line. Our current devicetrees configure GPIO in such a way wherename
is unset andconsumer
contains what should be inname
. This is inconvenient because applications which try to look up the lines by name (e.g. oresat-c3-software) can crash if another program got to the line first and accidentally reset or changed theconsumer
(e.g. the AX5043 driver).The devicetrees configure GPIO in this way because they use
gpio-of-helper
to set up the lines.gpio-of-helper
is an out-of-tree TI kernel module that was rejected a decade ago by upstream and hasn't been maintained since. It was built for the version 1 GPIO interface, but Linux has since moved on to version 2, which is where thename
/consumer
split took place.The solution to this comes in three parts:
Setting the names
I think this in isolation should be fairly easy. Using the standard devicetree GPIO configuration we can just set
gpio-line-names
for eachgpio-controller
(see for example this similar devicetree). I don't think this should conflict withgpio-of-helper
but I've not tested it but I don't know for sure.Hogging
Since
gpio-of-helper
is deprecated, how do we go about configuring lines at boot? Hogging. See this doc again for a description. That will reserve the lines for userspace, allow you to set default levels, pull-up/down resisters, and other things. We should eventually update our devicetrees to use hogging instead ofgpio-of-helper
. What hogging won't do on the other hand is set up the sysfs interface. The sysfs interface is deprecated so we should move away from it but that will require fixing up userspace.Fixing userspace
olaf has a basic GPIO library built atop the sysfs interface. If we move to hogging this will either need to be replaced with the standard gpiod library or some userspace thing to re-set up sysfs.