[PATCH v2 2/8] iio: adc: rzt2h: Wait for the analog part to stop after a forced stop
From: Prabhakar
Date: Fri Oct 09 2026 - 15:31:12 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>
---
v1->v2:
- Dropped using DIV_ROUND_UP_ULL to DIV_ROUND_UP
- Included time64.h
---
drivers/iio/adc/rzt2h_adc.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/iio/adc/rzt2h_adc.c b/drivers/iio/adc/rzt2h_adc.c
index 8ba7b0fde8a1..a46726b054b3 100644
--- a/drivers/iio/adc/rzt2h_adc.c
+++ b/drivers/iio/adc/rzt2h_adc.c
@@ -15,10 +15,12 @@
#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>
#include <linux/property.h>
+#include <linux/time64.h>
#define RZT2H_ADCSR_REG 0x00
#define RZT2H_ADCSR_ADIE_MASK BIT(12)
@@ -58,6 +60,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 +127,16 @@ 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. Read back
+ * ADCSR to make sure the write has reached the hardware before
+ * starting the delay.
+ */
+ readw(adc->base + RZT2H_ADCSR_REG);
+ ndelay(DIV_ROUND_UP(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