From: Jonathan Cameron <jic23@kernel.org>
To: Guillaume Stols <gstols@baylibre.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Nuno Sa <nuno.sa@analog.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, dlechner@baylibre.com,
jstephan@baylibre.com, aardelean@baylibre.com,
adureghello@baylibre.com
Subject: Re: [PATCH v2 1/9] iio: adc: ad7606: Fix hardcoded offset in the ADC channels
Date: Sat, 14 Dec 2024 18:26:40 +0000 [thread overview]
Message-ID: <20241214182640.6ee2c085@jic23-huawei> (raw)
In-Reply-To: <20241210-ad7606_add_iio_backend_software_mode-v2-1-6619c3e50d81@baylibre.com>
On Tue, 10 Dec 2024 10:46:41 +0000
Guillaume Stols <gstols@baylibre.com> wrote:
> When introducing num_adc_channels, I overlooked some new functions
> created in a meanwhile that had also the hardcoded offset. This commit
> adds the new logic to these functions.
>
> Fixes: 7a671afeb592 ("iio: adc: ad7606: Introduce num_adc_channels")
> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
Applied this patch to the fixes-togreg branch of iio.git.
That may well stall the rest for a while though whilst that works its
way around into the upstream for the togreg branch.
Thanks,
Jonathan
> ---
> drivers/iio/adc/ad7606.c | 48 ++++++++++++++++++++++++++++--------------------
> drivers/iio/adc/ad7606.h | 2 +-
> 2 files changed, 29 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index e35d55d03d86..d8e3c7a43678 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -175,17 +175,17 @@ static const struct iio_chan_spec ad7616_channels[] = {
> AD7606_CHANNEL(15, 16),
> };
>
> -static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
> +static int ad7606c_18bit_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch);
> -static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
> +static int ad7606c_16bit_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch);
> -static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st,
> +static int ad7606_16bit_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch);
> -static int ad7607_chan_scale_setup(struct ad7606_state *st,
> +static int ad7607_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch);
> -static int ad7608_chan_scale_setup(struct ad7606_state *st,
> +static int ad7608_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch);
> -static int ad7609_chan_scale_setup(struct ad7606_state *st,
> +static int ad7609_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch);
>
> const struct ad7606_chip_info ad7605_4_info = {
> @@ -323,9 +323,10 @@ int ad7606_reset(struct ad7606_state *st)
> }
> EXPORT_SYMBOL_NS_GPL(ad7606_reset, "IIO_AD7606");
>
> -static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st,
> +static int ad7606_16bit_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch)
> {
> + struct ad7606_state *st = iio_priv(indio_dev);
> struct ad7606_chan_scale *cs = &st->chan_scales[ch];
>
> if (!st->sw_mode_en) {
> @@ -345,10 +346,12 @@ static int ad7606_16bit_chan_scale_setup(struct ad7606_state *st,
> return 0;
> }
>
> -static int ad7606_get_chan_config(struct ad7606_state *st, int ch,
> +static int ad7606_get_chan_config(struct iio_dev *indio_dev, int ch,
> bool *bipolar, bool *differential)
> {
> - unsigned int num_channels = st->chip_info->num_channels - 1;
> + struct ad7606_state *st = iio_priv(indio_dev);
> + unsigned int num_channels = st->chip_info->num_adc_channels;
> + unsigned int offset = indio_dev->num_channels - st->chip_info->num_adc_channels;
> struct device *dev = st->dev;
> int ret;
>
> @@ -364,7 +367,7 @@ static int ad7606_get_chan_config(struct ad7606_state *st, int ch,
> continue;
>
> /* channel number (here) is from 1 to num_channels */
> - if (reg == 0 || reg > num_channels) {
> + if (reg < offset || reg > num_channels) {
> dev_warn(dev,
> "Invalid channel number (ignoring): %d\n", reg);
> continue;
> @@ -399,9 +402,10 @@ static int ad7606_get_chan_config(struct ad7606_state *st, int ch,
> return 0;
> }
>
> -static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
> +static int ad7606c_18bit_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch)
> {
> + struct ad7606_state *st = iio_priv(indio_dev);
> struct ad7606_chan_scale *cs = &st->chan_scales[ch];
> bool bipolar, differential;
> int ret;
> @@ -413,7 +417,7 @@ static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
> return 0;
> }
>
> - ret = ad7606_get_chan_config(st, ch, &bipolar, &differential);
> + ret = ad7606_get_chan_config(indio_dev, ch, &bipolar, &differential);
> if (ret)
> return ret;
>
> @@ -455,9 +459,10 @@ static int ad7606c_18bit_chan_scale_setup(struct ad7606_state *st,
> return 0;
> }
>
> -static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
> +static int ad7606c_16bit_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch)
> {
> + struct ad7606_state *st = iio_priv(indio_dev);
> struct ad7606_chan_scale *cs = &st->chan_scales[ch];
> bool bipolar, differential;
> int ret;
> @@ -469,7 +474,7 @@ static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
> return 0;
> }
>
> - ret = ad7606_get_chan_config(st, ch, &bipolar, &differential);
> + ret = ad7606_get_chan_config(indio_dev, ch, &bipolar, &differential);
> if (ret)
> return ret;
>
> @@ -512,9 +517,10 @@ static int ad7606c_16bit_chan_scale_setup(struct ad7606_state *st,
> return 0;
> }
>
> -static int ad7607_chan_scale_setup(struct ad7606_state *st,
> +static int ad7607_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch)
> {
> + struct ad7606_state *st = iio_priv(indio_dev);
> struct ad7606_chan_scale *cs = &st->chan_scales[ch];
>
> cs->range = 0;
> @@ -523,9 +529,10 @@ static int ad7607_chan_scale_setup(struct ad7606_state *st,
> return 0;
> }
>
> -static int ad7608_chan_scale_setup(struct ad7606_state *st,
> +static int ad7608_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch)
> {
> + struct ad7606_state *st = iio_priv(indio_dev);
> struct ad7606_chan_scale *cs = &st->chan_scales[ch];
>
> cs->range = 0;
> @@ -534,9 +541,10 @@ static int ad7608_chan_scale_setup(struct ad7606_state *st,
> return 0;
> }
>
> -static int ad7609_chan_scale_setup(struct ad7606_state *st,
> +static int ad7609_chan_scale_setup(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch)
> {
> + struct ad7606_state *st = iio_priv(indio_dev);
> struct ad7606_chan_scale *cs = &st->chan_scales[ch];
>
> cs->range = 0;
> @@ -1146,8 +1154,8 @@ static int ad7606_sw_mode_setup(struct iio_dev *indio_dev)
>
> static int ad7606_chan_scales_setup(struct iio_dev *indio_dev)
> {
> - unsigned int num_channels = indio_dev->num_channels - 1;
> struct ad7606_state *st = iio_priv(indio_dev);
> + unsigned int offset = indio_dev->num_channels - st->chip_info->num_adc_channels;
> struct iio_chan_spec *chans;
> size_t size;
> int ch, ret;
> @@ -1161,8 +1169,8 @@ static int ad7606_chan_scales_setup(struct iio_dev *indio_dev)
> memcpy(chans, indio_dev->channels, size);
> indio_dev->channels = chans;
>
> - for (ch = 0; ch < num_channels; ch++) {
> - ret = st->chip_info->scale_setup_cb(st, &chans[ch + 1], ch);
> + for (ch = 0; ch < st->chip_info->num_adc_channels; ch++) {
> + ret = st->chip_info->scale_setup_cb(indio_dev, &chans[ch + offset], ch);
> if (ret)
> return ret;
> }
> diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
> index 998814a92b82..8778ffe515b3 100644
> --- a/drivers/iio/adc/ad7606.h
> +++ b/drivers/iio/adc/ad7606.h
> @@ -69,7 +69,7 @@
>
> struct ad7606_state;
>
> -typedef int (*ad7606_scale_setup_cb_t)(struct ad7606_state *st,
> +typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev,
> struct iio_chan_spec *chan, int ch);
>
> /**
>
next prev parent reply other threads:[~2024-12-14 18:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 10:46 [PATCH v2 0/9] Add support for Software mode on AD7606's iio backend driver Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 1/9] iio: adc: ad7606: Fix hardcoded offset in the ADC channels Guillaume Stols
2024-12-14 18:26 ` Jonathan Cameron [this message]
2024-12-10 10:46 ` [PATCH v2 2/9] dt-bindings: iio: dac: adi-axi-adc: Add ad7606 variant Guillaume Stols
2024-12-10 12:31 ` Rob Herring (Arm)
2024-12-11 22:01 ` David Lechner
2024-12-10 10:46 ` [PATCH v2 3/9] iio:adc: ad7606: Move the software mode configuration Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 4/9] iio: adc: ad7606: Move software functions into common file Guillaume Stols
2024-12-15 11:51 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 5/9] iio: adc: adi-axi-adc: Add platform children support Guillaume Stols
2024-12-15 11:57 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 6/9] iio: adc: adi-axi-adc: Add support for AD7606 register writing Guillaume Stols
2024-12-15 12:05 ` Jonathan Cameron
2024-12-10 10:46 ` [PATCH v2 7/9] iio: adc: ad7606: change r/w_register signature Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 8/9] iio: adc: ad7606: Change channel macros parameters Guillaume Stols
2024-12-10 10:46 ` [PATCH v2 9/9] iio: adc: ad7606: Add support for writing registers when using backend Guillaume Stols
2024-12-15 12:12 ` Jonathan Cameron
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=20241214182640.6ee2c085@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=aardelean@baylibre.com \
--cc=adureghello@baylibre.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=gstols@baylibre.com \
--cc=jstephan@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.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