iio: adc: max1027: complete the EOC wait when using an external trigger
Jonathan Cameron
maintainerPATCH 1/1 iio: adc: max1027: complete the EOC wait when using an external trigger
From: Jonathan Cameron <[email protected]>
When an external trigger is in use, max1027_trigger_handler() starts the conversion and then waits in max1027_wait_eoc() for the end of conversion interrupt to complete(&st->complete). However max1027_handler() only completes it when the buffer is disabled. With the buffer enabled it instead polls the current trigger, which is the external trigger that is still being handled, so the poll does nothing,
the wait times out and every sample fails with -ETIMEDOUT.
Complete the wait when the buffer is enabled but the device's own trigger is not in use, as the comment above the check already describes.
---
The comment clearly states that we should just complete for triggers other than the one provided by this device, but the code doesn't do this. Ideal would be if someone has the part and can test this.
LLM spotted the issue whilst doing some other cleanup and prepared the patch.
I think the reason this got past testing was that the code was fixed to actually return an error on timeout whereas a bug previously meant it always dropped through and carried on.
--- drivers/iio/adc/max1027.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/max1027.c +1 -1
@@ -478,7 +478,7 @@ static irqreturn_t max1027_handler(int irq, void *private)* with another device. The core will then call the relevant handler to * perform the data processing step. */ -if (!iio_buffer_enabled (indio_dev)) +if (!iio_buffer_enabled (indio_dev) || !iio_trigger_using_own (indio_dev))complete (&st->complete);else iio_trigger_poll (st->trig);
Signature · 1 line
2.56.1
Hi Jonathan,
Quoted 17 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
When an external trigger is in use,
max1027_trigger_handler()starts the conversion and then waits inmax1027_wait_eoc()for the end of conversion interrupt tocomplete(&st->complete). Howevermax1027_handler()only completes it when the buffer is disabled. With the buffer enabled it instead polls the current trigger, which is the external trigger that is still being handled, so the poll does nothing,
the wait times out and every sample fails with-ETIMEDOUT.Complete the wait when the buffer is enabled but the device's own trigger is not in use, as the comment above the check already describes.
Fixes 075d3280b4a1 ("iio: adc: max1027: Allow all kind of triggers to be used")Signed-off-by Jonathan Cameron <[email protected]>
Quoted 6 lines
---
The comment clearly states that we should just complete for triggers other than the one provided by this device, but the code doesn't do this. Ideal would be if someone has the part and can test this.
I no longer have an easy way to run that code, but looking at it 5 years later, I agree with your description of the problem as well as your solution.
Quoted 6 lines
LLM spotted the issue whilst doing some other cleanup and prepared the patch.
I think the reason this got past testing was that the code was fixed to actually return an error on timeout whereas a bug previously meant it always dropped through and carried on.
Ah, right, intersting, I guess you talk about2021ef060900 ("iio: adc: max1027: fix error code in max1027_wait_eoc()")
Quoted 9 lines
--- drivers/iio/adc/max1027.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/max1027.c +0
-0
drivers/iio/adc/max1027.c static irqreturn_t max1027_handler(int irq, void *private) · line 484
Quoted 8 lines
drivers/iio/adc/max1027.c +1
-1@@ -478,7 +478,7 @@ static irqreturn_t max1027_handler(int irq, void *private)* with another device. The core will then call the relevant handler to * perform the data processing step. */ -if (!iio_buffer_enabled (indio_dev)) +if (!iio_buffer_enabled (indio_dev) || !iio_trigger_using_own (indio_dev))complete (&st->complete);else iio_trigger_poll (st->trig);
In case you want to make it closer to what other drivers do, you may invert the condition to simplify the reading:
if (iio_buffer_enabled(indio_dev) && iio_trigger_using_own(indio_dev))
iio_trigger_poll(st->trig);
else
complete(&st->complete);
Regardless of that change,
Thanks,
Miquèl
Jonathan Cameron
maintainerQuoted 63 lines · On Tue, 17 Nov 2026 11:52:46 +0100 Miquel Raynal <[email protected]>…
Hi Jonathan,
Quoted 17 lines · Jonathan Cameron
From: Jonathan Cameron <[email protected]>
When an external trigger is in use,
max1027_trigger_handler()starts the conversion and then waits inmax1027_wait_eoc()for the end of conversion interrupt tocomplete(&st->complete). Howevermax1027_handler()only completes it when the buffer is disabled. With the buffer enabled it instead polls the current trigger, which is the external trigger that is still being handled, so the poll does nothing,
the wait times out and every sample fails with-ETIMEDOUT.Complete the wait when the buffer is enabled but the device's own trigger is not in use, as the comment above the check already describes.
Fixes 075d3280b4a1 ("iio: adc: max1027: Allow all kind of triggers to be used")Signed-off-by Jonathan Cameron <[email protected]>Quoted 6 lines
---
The comment clearly states that we should just complete for triggers other than the one provided by this device, but the code doesn't do this. Ideal would be if someone has the part and can test this.
I no longer have an easy way to run that code, but looking at it 5 years later, I agree with your description of the problem as well as your solution.
Quoted 6 lines
LLM spotted the issue whilst doing some other cleanup and prepared the patch.
I think the reason this got past testing was that the code was fixed to actually return an error on timeout whereas a bug previously meant it always dropped through and carried on.
Ah, right, intersting, I guess you talk about
2021ef060900("iio: adc: max1027: fix error code inmax1027_wait_eoc()")Quoted 9 lines
--- drivers/iio/adc/max1027.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/max1027.c +0
-0drivers/iio/adc/max1027.c static irqreturn_t max1027_handler(int irq, void *private) · line 484
Quoted 8 lines
drivers/iio/adc/max1027.c +1
-1@@ -478,7 +478,7 @@ static irqreturn_t max1027_handler(int irq, void *private)* with another device. The core will then call the relevant handler to * perform the data processing step. */ -if (!iio_buffer_enabled (indio_dev)) +if (!iio_buffer_enabled (indio_dev) || !iio_trigger_using_own (indio_dev))complete (&st->complete);else iio_trigger_poll (st->trig);In case you want to make it closer to what other drivers do, you may invert the condition to simplify the reading:
Quoted 4 lines
if (iio_buffer_enabled(indio_dev) && iio_trigger_using_own(indio_dev))
iio_trigger_poll(st->trig);
else
complete(&st->complete);
That is indeed more natural so done what you suggest and applied. We are fairly late in the cycle so I'm not going to rush this in.
Applied to the testing branch of iio.git, so targeting next merge window.
Thanks,
Jonathan
Quoted 7 lines
Regardless of that change,
Reviewed-by Miquel Raynal <[email protected]>Thanks,
Miquèl