Re: [PATCH 1/2] iio: adc: ad9467: include two's complement in default mode
From: Jonathan Cameron
Date: Sun Dec 21 2025 - 14:54:43 EST
On Tue, 16 Dec 2025 11:40:05 +0000
Tomas Melin <tomas.melin@xxxxxxxxxxx> 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@xxxxxxxxxxx>
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;
>
>