From: Nuno Sa <nuno.sa@analog.com>
To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Alexandru Ardelean <alexandru.ardelean@analog.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Jonathan Cameron <jic23@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Olivier Moysan <olivier.moysan@foss.st.com>,
Nuno Sa <nuno.sa@analog.com>
Subject: [PATCH 7/8] iio: adc: ad9467: cache the sample rate
Date: Fri, 19 Apr 2024 17:36:50 +0200 [thread overview]
Message-ID: <20240419-ad9467-new-features-v1-7-3e7628ff6d5e@analog.com> (raw)
In-Reply-To: <20240419-ad9467-new-features-v1-0-3e7628ff6d5e@analog.com>
Since we allow to change the sampling frequency and do it with
clk_round_rate(), we can cache it and use on the read_raw() interface.
This will also be useful in a following patch supporting interface
calibration.
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
drivers/iio/adc/ad9467.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
index 7475ec2a56c72..7db87ccc1ea4b 100644
--- a/drivers/iio/adc/ad9467.c
+++ b/drivers/iio/adc/ad9467.c
@@ -117,6 +117,7 @@ struct ad9467_state {
struct iio_backend *back;
struct spi_device *spi;
struct clk *clk;
+ unsigned long sample_rate;
unsigned int output_mode;
unsigned int (*scales)[2];
@@ -331,7 +332,7 @@ static int ad9467_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_SCALE:
return ad9467_get_scale(st, val, val2);
case IIO_CHAN_INFO_SAMP_FREQ:
- *val = clk_get_rate(st->clk);
+ *val = st->sample_rate;
return IIO_VAL_INT;
default:
@@ -346,6 +347,7 @@ static int ad9467_write_raw(struct iio_dev *indio_dev,
struct ad9467_state *st = iio_priv(indio_dev);
const struct ad9467_chip_info *info = st->info;
long r_clk;
+ int ret;
switch (mask) {
case IIO_CHAN_INFO_SCALE:
@@ -358,7 +360,12 @@ static int ad9467_write_raw(struct iio_dev *indio_dev,
return -EINVAL;
}
- return clk_set_rate(st->clk, r_clk);
+ ret = clk_set_rate(st->clk, r_clk);
+ if (ret)
+ return ret;
+
+ st->sample_rate = r_clk;
+ return 0;
default:
return -EINVAL;
}
@@ -543,6 +550,8 @@ static int ad9467_probe(struct spi_device *spi)
if (IS_ERR(st->clk))
return PTR_ERR(st->clk);
+ st->sample_rate = clk_get_rate(st->clk);
+
st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
GPIOD_OUT_LOW);
if (IS_ERR(st->pwrdown_gpio))
--
2.44.0
next prev parent reply other threads:[~2024-04-19 15:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 15:36 [PATCH 0/8] iio: ad9467: support interface tuning Nuno Sa
2024-04-19 15:36 ` [PATCH 1/8] iio: backend: add API for " Nuno Sa
2024-04-19 15:36 ` [PATCH 2/8] iio: adc: adi-axi-adc: only error out in major version mismatch Nuno Sa
2024-04-19 15:36 ` [PATCH 3/8] dt-bindings: adc: axi-adc: add clocks property Nuno Sa
2024-04-19 15:36 ` [PATCH 4/8] iio: adc: axi-adc: make sure AXI clock is enabled Nuno Sa
2024-04-19 15:36 ` [PATCH 5/8] iio: adc: adi-axi-adc: remove regmap max register Nuno Sa
2024-04-19 15:36 ` [PATCH 6/8] iio: adc: adi-axi-adc: support digital interface calibration Nuno Sa
2024-04-19 15:36 ` Nuno Sa [this message]
2024-04-19 15:36 ` [PATCH 8/8] iio: adc: ad9467: " Nuno Sa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240419-ad9467-new-features-v1-7-3e7628ff6d5e@analog.com \
--to=nuno.sa@analog.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=alexandru.ardelean@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=olivier.moysan@foss.st.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).