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

Jonathan Cameron
2026-04-23T17:59:34Z

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

> From: Rodrigo Alencar <rodrigo.alencar@analog.com>
>
> 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@analog.com>
>
> 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;
...