I have some basic questions around the exporting of a GPIO.
- Regarding gpio-hog mechanism:
The gpio-hog mechanism would help us to initialise a GPIO to either
high/low & in/out during bootup.
This is fine.
So my question is, if we hog a GPIO, does it also gets exported to the
userspace by default?
- With the older sysfs interface, we would be using "echo x >
/sys/class/gpio/export" to export the gpiox to userspace.
I wanted to know what would be the right way to do this with the newer
interface?
- To check if a GPIO is being exported or not, we would see the
/sys/class/gpio with the sysfs interface.
With the newer character device interface, what would be the right way
to check what GPIOs are exported to userspace?
Per 0andriy's comments:
- GPIO hog is not for that. What you describe is an (expected) side effect of using it. GPIO hog is needed to keep orphaned GPIO lines (something that OS has no driver for) in a certain states. The producer and consumer of them is the GPIO controller itself, you may not export the line which already has a consumer.
- With new character device interface you are not supposed to export anything, you need a context for GPIO line inside your program. So, the "export" will be done inside the process, when process finishes, it automatically "unexports" all consumed GPIO lines.
- With new interface your process will IOCTL to acquire a line handle and it will fail with error in case it's already being occupied.
Expanding a little the above...
With regard to checking what lines are currently in use, the lsgpio
provided in the kernel source tree reports that, as does the gpioinfo
tool provided by libgpiod.
In both cases that info is intended for users. Applications simply attempt to request a line, and that will fail with EBUSY
if that line is already in use.