[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230921144400.62380-16-dlechner@baylibre.com>
Date: Thu, 21 Sep 2023 09:43:56 -0500
From: David Lechner <dlechner@...libre.com>
To: linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
linux-staging@...ts.linux.dev
Cc: linux-kernel@...r.kernel.org, Jonathan Cameron <jic23@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Conor Dooley <conor+dt@...nel.org>,
Michael Hennerich <Michael.Hennerich@...log.com>,
Nuno Sá <nuno.sa@...log.com>,
Axel Haslam <ahaslam@...libre.com>,
Philip Molloy <pmolloy@...libre.com>,
David Lechner <dlechner@...libre.com>
Subject: [PATCH v2 15/19] staging: iio: resolver: ad2s1210: read excitation frequency from control register
This modifies the ad2s1210_show_fexcit() function to read the excitation
frequency from the control register. This way we don't have to keep
track of the value and don't risk returning a stale value.
Signed-off-by: David Lechner <dlechner@...libre.com>
---
drivers/staging/iio/resolver/ad2s1210.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
index f1ffee34ebbc..27294eff99ef 100644
--- a/drivers/staging/iio/resolver/ad2s1210.c
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -78,7 +78,6 @@ struct ad2s1210_state {
struct regmap *regmap;
/** The external oscillator frequency in Hz. */
unsigned long fclkin;
- unsigned int fexcit;
u8 resolution;
u8 rx[2] __aligned(IIO_DMA_MINALIGN);
u8 tx[2];
@@ -202,8 +201,6 @@ static int ad2s1210_set_excitation_frequency(struct ad2s1210_state *st,
if (ret < 0)
return ret;
- st->fexcit = fexcit;
-
/* software reset reinitializes the excitation frequency output */
return regmap_write(st->regmap, AD2S1210_REG_SOFT_RESET, 0);
}
@@ -225,8 +222,22 @@ static ssize_t ad2s1210_show_fexcit(struct device *dev,
char *buf)
{
struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev));
+ unsigned int value;
+ u16 fexcit;
+ int ret;
- return sprintf(buf, "%u\n", st->fexcit);
+ mutex_lock(&st->lock);
+ ret = regmap_read(st->regmap, AD2S1210_REG_EXCIT_FREQ, &value);
+ if (ret < 0)
+ goto error_ret;
+
+ fexcit = value * st->fclkin / (1 << 15);
+
+ ret = sprintf(buf, "%u\n", fexcit);
+
+error_ret:
+ mutex_unlock(&st->lock);
+ return ret;
}
static ssize_t ad2s1210_store_fexcit(struct device *dev,
--
2.34.1
Powered by blists - more mailing lists