From: Jonathan Cameron <jic23@kernel.org>
To: Tomas Melin <tomas.melin@vaisala.com>
Cc: Michael Hennerich <Michael.Hennerich@analog.com>,
Nuno Sa <nuno.sa@analog.com>,
Lars-Peter Clausen <lars@metafoo.de>,
David Lechner <dlechner@baylibre.com>,
Andy Shevchenko <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] iio: adc: ad9467: include two's complement in default mode
Date: Sun, 21 Dec 2025 19:54:34 +0000 [thread overview]
Message-ID: <20251221195434.2bdde0e6@jic23-huawei> (raw)
In-Reply-To: <20251216-b4-ad9467-optional-backend-v1-1-83e61531ef4d@vaisala.com>
On Tue, 16 Dec 2025 11:40:05 +0000
Tomas Melin <tomas.melin@vaisala.com> wrote:
> All supported drivers currently implicitly use two's complement mode.
> Make this clear by declaring two's complement in the default
> output mode. Calibration mode uses offset binary, so change the output
> mode only when running the calibration or other test mode.
>
> Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
A few comments inline, along with the obvious build error fix
from the bot report of including linux/bitfield.h
> ---
> drivers/iio/adc/ad9467.c | 33 +++++++++++++++++++++++++--------
> 1 file changed, 25 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
> index 59c3fa3bcc9b0b8b36b78c3b54fd7977cae23496..60fc3361b2689a4c38287c613ef93fe00338e5fa 100644
> --- a/drivers/iio/adc/ad9467.c
> +++ b/drivers/iio/adc/ad9467.c
> @@ -671,10 +678,14 @@ static int ad9467_backend_testmode_off(struct ad9467_state *st,
>
> static int ad9647_calibrate_prepare(struct ad9467_state *st)
> {
> + unsigned int cmode;
> unsigned int c;
> int ret;
>
> - ret = ad9467_outputmode_set(st, st->info->default_output_mode);
> + cmode = (st->info->default_output_mode & ~AN877_ADC_OUTPUT_MODE_MASK) |
> + FIELD_PREP(AN877_ADC_OUTPUT_MODE_MASK,
> + AN877_ADC_OUTPUT_MODE_OFFSET_BINARY);
As below. Maybe copy then FIELD_MODIFY() the result.
> + ret = ad9467_outputmode_set(st, cmode);
> if (ret)
> return ret;
>
> @@ -778,7 +789,7 @@ static int ad9647_calibrate_stop(struct ad9467_state *st)
> return ret;
> }
>
> - mode = st->info->default_output_mode | AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT;
> + mode = st->info->default_output_mode;
> return ad9467_outputmode_set(st, mode);
> }
>
> @@ -1174,12 +1185,18 @@ static ssize_t ad9467_chan_test_mode_write(struct file *file,
> if (ret)
> return ret;
>
> - out_mode = st->info->default_output_mode | AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT;
> + out_mode = st->info->default_output_mode;
> ret = ad9467_outputmode_set(st, out_mode);
> if (ret)
> return ret;
> } else {
> - ret = ad9467_outputmode_set(st, st->info->default_output_mode);
> + unsigned int cmode;
> +
> + cmode = (st->info->default_output_mode &
> + ~AN877_ADC_OUTPUT_MODE_MASK) |
> + FIELD_PREP(AN877_ADC_OUTPUT_MODE_MASK,
> + AN877_ADC_OUTPUT_MODE_OFFSET_BINARY);
Might be cleaner as
unsigned int cmode = st->info->default_output_mode;
FIELD_MODIFY(AN877_ADC_OUTPUT_MODE_MASK, &cmode,
AN877_ADC_OUTPUT_MODE_OFFSET_BINARY);
I don't mind that much though if you prefer the original.
> + ret = ad9467_outputmode_set(st, cmode);
> if (ret)
> return ret;
>
>
next prev parent reply other threads:[~2025-12-21 19:54 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 11:40 [PATCH 0/2] iio: adc: ad9467: Enable operation without iio-backend Tomas Melin
2025-12-16 11:40 ` [PATCH 1/2] iio: adc: ad9467: include two's complement in default mode Tomas Melin
2025-12-18 13:43 ` Nuno Sá
2025-12-20 3:28 ` kernel test robot
2025-12-20 5:13 ` kernel test robot
2025-12-21 19:54 ` Jonathan Cameron [this message]
2025-12-16 11:40 ` [PATCH 2/2] iio: adc: ad9467: make iio backend optional Tomas Melin
2025-12-16 12:56 ` Nuno Sá
2025-12-16 15:39 ` Tomas Melin
2025-12-16 21:27 ` David Lechner
2025-12-17 5:38 ` Tomas Melin
2025-12-17 9:26 ` Nuno Sá
2025-12-17 10:39 ` Tomas Melin
2025-12-17 11:44 ` Tomas Melin
2025-12-18 13:41 ` Nuno Sá
2025-12-19 11:25 ` Tomas Melin
2025-12-18 13:49 ` Nuno Sá
2025-12-19 11:16 ` Tomas Melin
2025-12-19 14:46 ` Nuno Sá
2025-12-21 20:00 ` Jonathan Cameron
2026-01-05 11:06 ` Tomas Melin
2026-01-05 14:57 ` Nuno Sá
2026-01-11 11:41 ` Jonathan Cameron
2026-01-12 13:21 ` Nuno Sá
2026-01-13 7:47 ` Tomas Melin
2026-01-13 10:00 ` Jonathan Cameron
2026-01-13 10:52 ` Nuno Sá
2026-01-13 11:49 ` Tomas Melin
2026-01-13 12:44 ` Nuno Sá
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=20251221195434.2bdde0e6@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=tomas.melin@vaisala.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®