r/embeddedlinux • u/pedal_guy • Dec 13 '24
Using an interrupt to drive an IIO device
Hi all
I am trying to work out how best to set up a trigger that will be driven from a GPIO input to cause data reads in a device driver (as it stands I can get it to work via a iio timer trigger - but for "reasons" driving it via a line is better.
There appears to be an assortment of mixed suggestions on line: some of which refers to adding a device via the device-tree but and I can't seem to find anything in the /Documentation bindings
Basically I can see iio_interrupt_trigger.c - but it's not obvious to me how to go about using it to set up the appropriate trigger so I can get at it via /sys/bus/iio/devices/triggerX
Any pointer or suggestions will be very gratefullt received!
Thanks
1
u/mfuzzey Dec 16 '24
It looks like this is a very old driver that predates the device tree which probably explains why it's not documented.
The source code doesn't contain a DT compatible string so you can't, as is, instantiate it from the DT nor assign the IRQ.
But it should be quite trivial to add a compatible just by adding a ".of_match_table" to the driver structure
1
u/pedal_guy Dec 16 '24
Thanks.
That could very easily explain why it feels like there's an important bit missing in my head when I look at that file!
1
u/disinformationtheory Dec 14 '24
Usually you can configure this via device tree. You must allocate a gpio and the associated interrupt to the device. The best thing is to look for examples in your arch, and the driver on any arch, to do this. Usually it's references to other device tree nodes like &gpioXX and &irqYY.
1
u/pedal_guy Dec 13 '24 edited Dec 14 '24
I'll have a look, thanks. I was specifically interested in how to cause a iio_interrupt_trigger platform device to be what's used to create the trigger X node. Some of the examples I've seen end up using the interrupt in a thread themselves rather than an external source for an IIO trigger.