Re: [PATCH v4 10/13] iio: adc: ad4134: Support SPI 4-wire mode

From: Marcelo Schmitt

Date: Fri Oct 16 2026 - 20:56:12 EST


On 10/14, Nuno Sá wrote:
> On Tue, 06 Oct 2026 15:19:00 -0300, Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx> wrote:
> > diff --git a/drivers/iio/adc/ad4134.c b/drivers/iio/adc/ad4134.c
> > index b5207f16054e..debc2ff02705 100644
> > --- a/drivers/iio/adc/ad4134.c
> > +++ b/drivers/iio/adc/ad4134.c
> > @@ -308,14 +423,18 @@ static int ad4134_register_read(struct ad4134_state *st, unsigned int reg,
> > .len = st->crc_en ? AD4134_SPI_MAX_XFER_LEN : 2,
> > };
> > unsigned int inst;
> > - int ret;
> > + int access_ret, ret;
> > +
> > + ret = ad4134_claim_reg_access(st);
> > + if (ret)
> > + return ret;
>
> Do we really need to claim/release for every register read? Can't we
> just select register mode at probe and leave it in that position by
> default?

Yeah, we could have it that way but then the error paths get trickier to handle.
For example, we might deselect reg mode and then fail to select sample mode.
Because of that, we would need to keep track of what mux_states we hold lock to
avoid deselecting a state that is not selected.

After sample read, we are susceptible to succeed sample mode deselect and fail
reg mode select, so we actually also need to check we have reg mode selected
before register access anyway.

Not to mention we would need a driver .remove callback to check which (if any)
mode we have selected to correctly deselect any multiplexer state on driver detach.

> Then when starting to buffer, we deselect + select sample mode
> and when exiting do the reverse. Seems even more appropriate when the dt
> mode property does not want to use DOUT at all which means that all this
> select + deselect is really unneeded.
>
The select/deselect dance is not needed for minimum I/O mode (no CS wiring) so
I made it skip the multiplexer switching entirely for that mode.

Thanks,
Marcelo