Re: [PATCH v7 7/7] iio: dac: ad5686: add gain control support
David Lechner <[email protected]>
| Newsgroups | org.kernel.vger.linux-hardening,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On 7/10/26 6:20 AM, Rodrigo Alencar via B4 Relay wrote: > From: Rodrigo Alencar <[email protected]> > > 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. > ... > @@ -217,6 +229,82 @@ static int ad5686_write_raw(struct iio_dev *indio_dev, > > return ad5686_write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N, > chan->address, val << chan->scan_type.shift); > + case IIO_CHAN_INFO_SCALE: > + if (val == st->scale_avail[0] && val2 == st->scale_avail[1]) > + double_scale = false; > + else if (val == st->scale_avail[2] && val2 == st->scale_avail[3]) > + double_scale = true; > + else > + return -EINVAL; > + > + if (st->double_scale == double_scale) > + return 0; /* no change */ > + > + if (st->chip_info->regmap_type == AD5686_REGMAP && !st->gain_gpio) This condition is used a couple of times. It could be nice to just add a st->pin_strapped_gain field to make it self-documenting and use that instead. > + return -EINVAL; /* GAIN pin is board-strapped */ > + > + st->double_scale = double_scale; > + switch (st->chip_info->regmap_type) { > + case AD5310_REGMAP: > + ret = ad5310_control_sync(st); > + break; > + case AD5683_REGMAP: > + ret = ad5683_control_sync(st); > + break; > + case AD5686_REGMAP: > + ret = gpiod_set_value_cansleep(st->gain_gpio, > + st->double_scale ? 1 : 0); > + break; > + default: > + ret = -EINVAL; > + } > + if (ret) > + st->double_scale = !double_scale; /* revert on failure */ > + return ret; > + default: > + return -EINVAL; > + } > +} > +