[PATCH 05/16] iio: frequency: ad9523: factor out the channel divider calculation
From: Nuno Sá
Date: Mon Nov 30 2026 - 12:37:56 EST
The channel divider for a given frequency is computed both when
setting the frequency and, to get the resulting output frequency, when
selecting the clock source. Add a small helper for it, so that both
stay in sync.
No functional change.
Signed-off-by: Nuno Sá <nuno.sa@xxxxxxxxxx>
---
drivers/iio/frequency/ad9523.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 92bbe4d196b5..44774577b4bf 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -415,11 +415,16 @@ static int ad9523_vco_out_map(struct iio_dev *indio_dev,
return ret;
}
+static unsigned int ad9523_chan_div(struct ad9523_state *st, unsigned int src,
+ unsigned long freq)
+{
+ return clamp(st->vco_out_freq[src] / freq, 1, 1024);
+}
+
static unsigned long ad9523_chan_freq(struct ad9523_state *st, unsigned int src,
unsigned long freq)
{
- return st->vco_out_freq[src] /
- clamp(st->vco_out_freq[src] / freq, 1, 1024);
+ return st->vco_out_freq[src] / ad9523_chan_div(st, src, freq);
}
static int ad9523_set_clock_provider(struct iio_dev *indio_dev,
@@ -685,8 +690,7 @@ static int ad9523_write_raw(struct iio_dev *indio_dev,
ret = ad9523_set_clock_provider(indio_dev, chan->channel, val);
if (ret < 0)
goto out;
- tmp = st->vco_out_freq[st->vco_out_map[chan->channel]] / val;
- tmp = clamp(tmp, 1, 1024);
+ tmp = ad9523_chan_div(st, st->vco_out_map[chan->channel], val);
reg &= ~(0x3FF << 8);
reg |= AD9523_CLK_DIST_DIV(tmp);
break;
--
2.56.0