Re: [PATCH v3 12/12] iio: dac: ad5686: add gain control support

From: Rodrigo Alencar

Date: Fri Jun 19 2026 - 12:21:22 EST


On 16/06/26 13:47, Andy Shevchenko wrote:
> On Tue, Jun 16, 2026 at 09:21:18AM +0100, Rodrigo Alencar via B4 Relay wrote:
>
> > Most of the supported devices rely on a GAIN pin to control a 2x
> > multiplier applied to the output voltage. Other devices, e.g. the
> > single-channel ones, provides a gain control through a bit field in
> > the control register. Some designs might have the GAIN pin hardwired
> > to VDD/VLOGIC or GND, which would have no "gain-gpios" device property,
> > being able to set "adi,range-double" if it is hardwired to VDD. The
> > vref_mv field is moved down in the struct ad5686_state, so that the
> > overall size increase is reduced.
>
> ...
>
> > +static void ad5686_init_scale_avail(struct ad5686_state *st)
> > +{
> > + int realbits = st->chip_info->channels[0].scan_type.realbits;
> > + s64 tmp = 2ULL * st->vref_mv * NANO >> realbits;
>
> As Nuno noticed in other patch review, this can probably use mul_u64_u32_shr().

This would be need in case the multiplication overflows, which is not the case
here.

> > + st->scale_avail[2] = div_s64_rem(tmp, NANO, &st->scale_avail[3]);
> > + st->scale_avail[0] = div_s64_rem(tmp >> 1, NANO, &st->scale_avail[1]);
> > +}

--
Kind regards,

Rodrigo Alencar