From: David Lechner <dlechner@baylibre.com>
To: "Pop Ioan Daniel" <pop.ioan-daniel@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Sergiu Cuciurean" <sergiu.cuciurean@analog.com>,
"Dragos Bogdan" <dragos.bogdan@analog.com>,
"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
"Olivier Moysan" <olivier.moysan@foss.st.com>,
"Javier Carrasco" <javier.carrasco.cruz@gmail.com>,
"Matti Vaittinen" <mazziesaccount@gmail.com>,
"Tobias Sperling" <tobias.sperling@softing.com>,
"Alisa-Dariana Roman" <alisadariana@gmail.com>,
"Marcelo Schmitt" <marcelo.schmitt@analog.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver
Date: Mon, 19 May 2025 10:18:11 -0500 [thread overview]
Message-ID: <c95fb95d-f892-4dda-abb1-0b5ac98454c8@baylibre.com> (raw)
In-Reply-To: <20250519140220.81489-7-pop.ioan-daniel@analog.com>
On 5/19/25 9:02 AM, Pop Ioan Daniel wrote:
> Add support for the AD7405/ADUM770x, a high performance isolated ADC,
> 1-channel, 16-bit with a second-order Σ-Δ modulator that converts an
> analog input signal into a high speed, single-bit data stream.
>
> Signed-off-by: Pop Ioan Daniel <pop.ioan-daniel@analog.com>
> ---
...
> +static int ad7405_set_dec_rate(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + unsigned int dec_rate)
> +{
> + struct ad7405_state *st = iio_priv(indio_dev);
> + int ret;
We probably want some range checking here to make sure dec_rate is exactly one of
ad7405_dec_rates before passing it to the backend.
> +
> + ret = iio_backend_oversampling_ratio_set(st->back, chan->scan_index, dec_rate);
> + if (ret)
> + return ret;
> +
> + st->dec_rate = dec_rate;
Otherwise, this will report back a wrong value to userspace in ad7405_read_raw().
> +
> + return 0;
> +}
> +
> +static int ad7405_get_scale(struct ad7405_state *st, int *val, int *val2)
> +{
> + *val = st->info->full_scale_mv;
> + *val2 = st->info->channel.scan_type.realbits - 1;
> +
> + return IIO_VAL_FRACTIONAL_LOG2;
Probably not worth having a separate function for this. Can just do it inline.
> +}
> +
> +static int ad7405_read_raw(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan, int *val,
> + int *val2, long info)
> +{
> + struct ad7405_state *st = iio_priv(indio_dev);
> +
> + switch (info) {
> + case IIO_CHAN_INFO_SCALE:
> + return ad7405_get_scale(st, val, val2);
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + *val = st->dec_rate;
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *val = DIV_ROUND_CLOSEST_ULL(st->ref_frequency, st->dec_rate);
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_OFFSET:
> + *val = 2 << (st->info->channel.scan_type.realbits - 1);
Isn't this supposed to be:
*val = -(1 << (st->info->channel.scan_type.realbits - 1));
2 was a typo by me, but hopefully, you are testing this and doing the
math to double-check it is correct! I.e. generate a constant voltage signal
and capture some data, then convert it to mV with (raw + offset) * scale to
make sure it matches the voltage being applied to the input.
(I'm only human, so believe the math if disagrees with what I say. :-p)
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int ad7405_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int val,
> + int val2, long info)
> +{
> + switch (info) {
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
val can be negative here, which can cause it to turn into a large positive
number when it gets changed to unsigned since the last parameter of
ad7405_set_dec_rate has unsigned type. So we should either check for negative
first here or change the parameter to signed and check in the function.
> + return ad7405_set_dec_rate(indio_dev, chan, val);
> + default:
> + return -EINVAL;
> + }
> +}
> +
next prev parent reply other threads:[~2025-05-19 15:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-19 14:02 [PATCH v4 0/6] Add support for AD7405/ADUM770x Pop Ioan Daniel
2025-05-19 14:02 ` [PATCH v4 1/6] iio: adc: ad4851: ad4851_set_oversampling_ratio parameters update Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-19 14:02 ` [PATCH v4 2/6] iio: backend: update iio_backend_oversampling_ratio_set Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-26 9:54 ` Nuno Sá
2025-05-19 14:02 ` [PATCH v4 3/6] iio: adc: adi-axi-adc: add axi_adc_oversampling_ratio_set Pop Ioan Daniel
2025-05-19 15:15 ` David Lechner
2025-05-26 9:53 ` Nuno Sá
2025-05-26 9:54 ` Nuno Sá
2025-05-19 14:02 ` [PATCH v4 4/6] dt-bindings: iio: adc: add ad7405 Pop Ioan Daniel
2025-05-19 15:16 ` David Lechner
2025-05-20 6:41 ` Krzysztof Kozlowski
2025-05-19 14:02 ` [PATCH v4 5/6] dt-bindings: iio: adc: adi-axi-adc: add ad7405 example Pop Ioan Daniel
2025-05-19 15:19 ` David Lechner
2025-05-20 6:39 ` Krzysztof Kozlowski
2025-05-19 14:02 ` [PATCH v4 6/6] iio: adc: ad7405: add ad7405 driver Pop Ioan Daniel
2025-05-19 15:18 ` David Lechner [this message]
2025-05-25 11:03 ` Jonathan Cameron
2025-05-26 10:00 ` Nuno Sá
2025-05-19 15:22 ` [PATCH v4 0/6] Add support for AD7405/ADUM770x David Lechner
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=c95fb95d-f892-4dda-abb1-0b5ac98454c8@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=alisadariana@gmail.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dragos.bogdan@analog.com \
--cc=javier.carrasco.cruz@gmail.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt@analog.com \
--cc=mazziesaccount@gmail.com \
--cc=nuno.sa@analog.com \
--cc=olivier.moysan@foss.st.com \
--cc=pop.ioan-daniel@analog.com \
--cc=robh@kernel.org \
--cc=sergiu.cuciurean@analog.com \
--cc=tobias.sperling@softing.com \
/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
all inboxes | Powered by JetHome®