[PATCH 2/8] iio: adc: rzt2h: Wait for the analog part to stop after a forced stop

From: Prabhakar

Date: Tue Sep 29 2026 - 08:47:27 EST


From: Lad Prabhakar <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>

When ADCSR.ADST is cleared to forcibly stop a conversion, the analog part
of the A/D converter can take up to 2 ADCLK cycles to stop operating.

Wait for the write to ADCSR to complete and allow the analog part to stop
before reconfiguring or restarting the converter.

Fixes: fc3b97dd71ab ("iio: adc: add RZ/T2H / RZ/N2H ADC driver")
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>
---
drivers/iio/adc/rzt2h_adc.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/iio/adc/rzt2h_adc.c b/drivers/iio/adc/rzt2h_adc.c
index 8ba7b0fde8a1..d53888730f00 100644
--- a/drivers/iio/adc/rzt2h_adc.c
+++ b/drivers/iio/adc/rzt2h_adc.c
@@ -15,6 +15,7 @@
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/kthread.h>
+#include <linux/math.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
@@ -58,6 +59,7 @@
#define RZT2H_ADC_DMA_BUFFER_SIZE (RZT2H_ADC_DMA_BUFFER_SAMPLES * \
RZT2H_ADC_MAX_CHANNELS * \
RZT2H_ADC_CHANNEL_BYTES)
+#define RZT2H_ADC_STOP_CYCLES 2

struct rzt2h_adc_dma {
struct dma_chan *chan;
@@ -124,6 +126,13 @@ static void rzt2h_adc_stop(struct rzt2h_adc *adc)
reg &= ~(RZT2H_ADCSR_ADIE_MASK | RZT2H_ADCSR_ADST_MASK);

writew(reg, adc->base + RZT2H_ADCSR_REG);
+
+ /*
+ * When a conversion is forcibly stopped, the analog part of the A/D
+ * converter takes up to 2 ADCLK cycles to stop operating.
+ */
+ ndelay(DIV_ROUND_UP_ULL((u64)RZT2H_ADC_STOP_CYCLES * NSEC_PER_SEC,
+ adc->adclk_rate));
}

static void rzt2h_adc_set_sst(struct rzt2h_adc *adc, unsigned int ch, u8 sst)
--
2.55.0