libre-computer-project / libretech-linux

Upstream and Mainline Linux Stable Fork for Libre Computer
https://libre.computer/
Other
49 stars 23 forks source link

gpiochip driver doesn't report falling edge transitions correctly #19

Open chrishamm opened 9 months ago

chrishamm commented 9 months ago

I've been trying to get my application running on a Le Potato AML-S905X-CC but after some debugging I found out that the gpiochip driver does not report high -> low transitions correctly.

It's easy to reproduce e.g. for pin 22 on the main header:

gpiomon /dev/gpiochip1 79
event:  RISING EDGE offset: 79 timestamp: [    1295.720182495]
event:  RISING EDGE offset: 79 timestamp: [    1295.720806423]
event:  RISING EDGE offset: 79 timestamp: [    1297.570469634]
event:  RISING EDGE offset: 79 timestamp: [    1298.608008469]
event:  RISING EDGE offset: 79 timestamp: [    1299.416658994]
event:  RISING EDGE offset: 79 timestamp: [    1301.248827348]

When I play with a standard jumper cable, I get a few FALLING EDGE reports here and there but not always between RISING EDGE messages as I'd expect.

I'm using an up-to-date Debian 12 base image from Libre Computer.

dsx724 commented 9 months ago

Can you report the kernel version you are using?

chrishamm commented 8 months ago

Yes:

Linux ender5pro 6.1.74-12781-g74961fb0a5d2 #1 SMP PREEMPT_DYNAMIC Wed Jan 24 02:05:32 EST 2024 aarch64 GNU/Linux
dsx724 commented 6 months ago

So the hardware itself is only able to handle level based interrupts. The edge based interrupts are emulated and is not very good. We are checking to see if we can improve the emulation.

For hardware expansion, we recommend writing an hardware overlay attached to the GPIO binded to a gpio-key or some other driver with level-based sensing. This is more reliable in capturing GPIO voltage changes.

chrishamm commented 6 months ago

Thanks, an improvement would be helpful. This feature works flawlessly on Raspberry Pi boards.

dsx724 commented 6 months ago

Can you let us know what you're trying to do? Like PPS or something else?

chrishamm commented 1 month ago

I maintain software that is notified whenever it can start an SPI transaction using a GPIO pin. I observe changes to this pin using the gpiochip device because that's pretty fast and way faster than the classic sysfs interface (which is now deprecated anyway AFAIR). These transactions are performed multiple times per second.

dsx724 commented 1 month ago

You can set static level-based interrupts in the device tree rather than software-emulated dual-edge GPIO via gpiod_to_irq function. Level-based interrupts are far more reliable on this platform than edge based ones, especially at high frequency.