[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241021130221.1469099-3-aardelean@baylibre.com>
Date: Mon, 21 Oct 2024 16:02:17 +0300
From: Alexandru Ardelean <aardelean@...libre.com>
To: linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org,
devicetree@...r.kernel.org
Cc: jic23@...nel.org,
krzk+dt@...nel.org,
robh@...nel.org,
lars@...afoo.de,
michael.hennerich@...log.com,
gstols@...libre.com,
dlechner@...libre.com,
Alexandru Ardelean <aardelean@...libre.com>
Subject: [PATCH 2/6] iio: adc: ad7606: fix issue/quirk with find_closest() for oversampling
There's a small issue with setting oversampling-ratio that seems to have
been there since the driver was in staging.
Trying to set an oversampling value of '2' will set an oversampling value
of '1'. This is because find_closest() does an average + rounding of 1 + 2,
and we get '1'.
This is the only issue with find_closest(), at least in this setup. The
other values (above 2) work reasonably well. Setting 3, rounds to 2, so a
quick fix is to round 'val' to 3 (if userspace provides 2).
Fixes 41f71e5e7daf: ("staging: iio: adc: ad7606: Use find_closest() macro")
Signed-off-by: Alexandru Ardelean <aardelean@...libre.com>
---
drivers/iio/adc/ad7606.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index ae49f4ba50d9..d0fe9fd65f3f 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -748,6 +748,9 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
if (val2)
return -EINVAL;
+ /* Minor trick, so that OS of 2, doesn't get rounded to 1 */
+ if (val == 2)
+ val++;
i = find_closest(val, st->oversampling_avail,
st->num_os_ratios);
ret = st->write_os(indio_dev, i);
--
2.46.1
Powered by blists - more mailing lists