Re: [PATCH v5 01/12] iio: dac: ad5686: fix ref bit initialization for single-channel parts

From: Jonathan Cameron

Date: Tue May 05 2026 - 07:21:12 EST


On Fri, 01 May 2026 10:14:54 +0100
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@xxxxxxxxxx> wrote:

> From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> The reference bit position was ignored when writing the register at the
> probe() function (!!val was used). When such bit is 1, internal voltage
> reference is disabled so that an external one can be used. For
> multi-channel devices, bit 0 of the Internal Reference Setup command
> behaves the same way, so AD5686_REF_BIT_MSK is created. The issue exists
> since support for single-channel devices were first introduced.
>
> Fixes: be1b24d24541 ("iio:dac:ad5686: Add AD5691R/AD5692R/AD5693/AD5693R support")
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
Applied this patch to the fixes-togreg branch of iio.git and marked
it for stable.

Thanks

Jonathan

> ---
> drivers/iio/dac/ad5686.c | 6 +++---
> drivers/iio/dac/ad5686.h | 1 +
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index 9a384c50929b..1fc54c38b629 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
> @@ -511,7 +511,7 @@ int ad5686_probe(struct device *dev,
> break;
> case AD5686_REGMAP:
> cmd = AD5686_CMD_INTERNAL_REFER_SETUP;
> - ref_bit_msk = 0;
> + ref_bit_msk = AD5686_REF_BIT_MSK;
> break;
> case AD5693_REGMAP:
> cmd = AD5686_CMD_CONTROL_REG;
> @@ -522,9 +522,9 @@ int ad5686_probe(struct device *dev,
> return -EINVAL;
> }
>
> - val = (has_external_vref | ref_bit_msk);
> + val = has_external_vref ? ref_bit_msk : 0;
>
> - ret = st->write(st, cmd, 0, !!val);
> + ret = st->write(st, cmd, 0, val);
> if (ret)
> return ret;
>
> diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h
> index e7d36bae3e59..36e16c5c4581 100644
> --- a/drivers/iio/dac/ad5686.h
> +++ b/drivers/iio/dac/ad5686.h
> @@ -46,6 +46,7 @@
>
> #define AD5310_REF_BIT_MSK BIT(8)
> #define AD5683_REF_BIT_MSK BIT(12)
> +#define AD5686_REF_BIT_MSK BIT(0)
> #define AD5693_REF_BIT_MSK BIT(12)
>
> /**
>