Re: [PATCH 12/22] iio: dac: ad5686: fix powerdown control

From: Jonathan Cameron

Date: Thu Apr 23 2026 - 13:59:56 EST


On Wed, 22 Apr 2026 15:45:46 +0100
Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@xxxxxxxxxx> wrote:

> From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> This patch fixes powerdown control issues by protecting the cached
> powerdown states with mutex access, and by using a proper bit shift for
> the powerdown mask values. During initialization, powerdown bits are
> initialized so that unused bits are set to 1 and the correct bit shift is
> used.
>

Mostly avoiding repeating stuff Andy raised already.

> Dual-channel devices use one-hot encondig in the address and that reflects

encoding.

> on the position of the powerdown bits, which are not channel-index based
> for that case. Quad-channel devices also use one-hot encondig for the
> channel address but the result of log2(address) coincides with the channel
> index value.
>
> Signed-off-by: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
>
> static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev,
> const struct iio_chan_spec *chan)
> {
> struct ad5686_state *st = iio_priv(indio_dev);
> + int mode, shift = ad5686_pd_mask_shift(chan);
Split that into two lines.
int shift = ...
int mode;

Having a mixture of initialized and not is not good for readability.

>
> - return ((st->pwr_down_mode >> (chan->channel * 2)) & 0x3) - 1;
> + mutex_lock(&st->lock);
> + mode = ((st->pwr_down_mode >> shift) & 0x3) - 1;
> + mutex_unlock(&st->lock);
> +
> + return mode;
...