periph / host

Go·Hardware·Lean - Host drivers
https://periph.io
Apache License 2.0
53 stars 27 forks source link

sysfs-gpio: use new /sys/bus/gpio/devices/gpiochipN, also listed as /dev/gpiochipN #39

Open maruel opened 9 months ago

maruel commented 9 months ago

Ported from https://github.com/google/periph/issues/371

It's the "new" GPIO API for linux kernels above 4.8, based on ioctl on a single handle instead of having to open multiple handles. There isn't a need to support older kernels anymore so we should just switch over.

maruel commented 9 months ago

I failed to find proper documentation. Sadly, there's zero reference to PWM in libgpiod.

gsexton commented 2 months ago

@maruel I've looked over the linked ticket, but don't understand what's yet to be done. If you could give me some idea of what's needed, I could give it a go.

maruel commented 2 months ago

@gsexton In periph.io/x/host/v3/sysfs, the function driverGPIO.Init() opens the directories in /sys/class/gpio/gpiochip*. This needs to be changed to use /sys/bus/gpiochip*. There's more to it than just the discovery since the way to access each gpio is a bit different.

Copying from the original issue:

It's the "new" GPIO API for linux kernels above 4.8, based on ioctl on a single handle instead of having to open multiple handles. Now [in 2019] that devices are using later kernels (Raspbian is on 4.14), periph should enable the use of this interface when available, and fallback with the current code on older kernels.

The primary rationale is that it enables pull resistors via the constants GPIOLINE_FLAG_OPEN_DRAIN and GPIOLINE_FLAG_OPEN_SOURCE. It also enables support for reading and writing multiple lines at once. This would have many uses but the periph gpio API currently doesn't make this use-case easy to implement, so multi-pin synchronized I/O requires more thoughts.

Refs: