iio: adc: at91-sama5d2_adc: handle unfinished conversions
authorEugen Hristev <eugen.hristev@microchip.com>
Tue, 28 Jan 2020 12:57:40 +0000 (12:57 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 25 Apr 2020 14:51:21 +0000 (15:51 +0100)
commit97c54cf2a4e87630eab18ad53b88348ec7296176
tree63b3a27fcd792acae12d641d5686b7a84a457763
parent77baa8d6bced7dbe67c6a9ffae749e5d77b38f80
iio: adc: at91-sama5d2_adc: handle unfinished conversions

It can happen that on IRQ trigger, not all conversions are done if
we are enabling multiple channels.
The IRQ is triggered on first EOC (end of channel), but it can happen
that not all channels are done. This leads into erroneous reports to
userspace (zero values or previous values).
To solve this, in trigger handler, check if the mask of done channels
is the same as the mask of active scan channels.
If it's the same, proceed and push to buffers. Otherwise, use usleep
to sleep until the conversion is done or we timeout.
Normally, it should happen that in a short time fashion, all channels are
ready, since the first IRQ triggered.
If a hardware fault happens (for example the clock suddently dissappears),
the handler will not be completed, in which case we do not report anything to
userspace anymore.
Also, change from using the EOC interrupts to DRDY interrupt.
This helps with the fact that not 'n' interrupt statuses are enabled,
each being able to trigger an interrupt, and instead only data ready
interrupt can wake up the CPU. Like this, when data is ready, check in
handler which and how many channels are done. While the DRDY is raised,
other IRQs cannot occur. Once the channel data is being read, we ack the
IRQ and finish the conversion.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/at91-sama5d2_adc.c