aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/iio
diff options
context:
space:
mode:
authorGravatar David Lechner <dlechner@baylibre.com> 2023-09-29 12:23:21 -0500
committerGravatar Jonathan Cameron <Jonathan.Cameron@huawei.com> 2023-10-05 14:44:05 +0100
commit500d7640f63d557c397f74b7d5bf8c81377b50b3 (patch)
treecf64c916da050216eccb94a53c7dbf9a4f7dca38 /drivers/staging/iio
parentstaging: iio: resolver: ad2s1210: refactor setting excitation frequency (diff)
downloadlinux-500d7640f63d557c397f74b7d5bf8c81377b50b3.tar.gz
linux-500d7640f63d557c397f74b7d5bf8c81377b50b3.tar.bz2
linux-500d7640f63d557c397f74b7d5bf8c81377b50b3.zip
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@baylibre.com> Link: https://lore.kernel.org/r/20230929-ad2s1210-mainline-v3-16-fa4364281745@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r--drivers/staging/iio/resolver/ad2s1210.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
index 2b728863a3ff..67d8af0dd7ae 100644
--- a/drivers/staging/iio/resolver/ad2s1210.c
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -76,7 +76,6 @@ struct ad2s1210_state {
struct regmap *regmap;
/** The external oscillator frequency in Hz. */
unsigned long clkin_hz;
- unsigned int fexcit;
bool hysteresis;
u8 resolution;
/** For reading raw sample value via SPI. */
@@ -207,8 +206,6 @@ static int ad2s1210_reinit_excitation_frequency(struct ad2s1210_state *st,
if (ret < 0)
return ret;
- st->fexcit = fexcit;
-
/*
* Software reset reinitializes the excitation frequency output.
* It does not reset any of the configuration registers.
@@ -233,8 +230,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->clkin_hz / (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,