Re: [PATCH v2 2/6] iio: adc: ad4030: add driver for ad4030-24

Jonathan Cameron
2024-12-23T12:15:52Z

On Thu, 19 Dec 2024 17:10:37 +0100
Esteban Blanc <eblanc@baylibre.com> wrote:

> This adds a new driver for the Analog Devices INC. AD4030-24 ADC.
>
> The driver implements basic support for the AD4030-24 1 channel
> differential ADC with hardware gain and offset control.
>
> Signed-off-by: Esteban Blanc <eblanc@baylibre.com>

Hi Esteban,

Just a couple of really trivial things inline. Key here is Marcelo's question
about moving the mode selection into regmap callbacks.

Jonathan

> diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..feb98a0fdbeb3e48cd356d817a5dda6d23f5ed3f
> --- /dev/null
> +++ b/drivers/iio/adc/ad4030.c

> +static int ad4030_read_avail(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *channel,
> + const int **vals, int *type,
> + int *length, long mask)
> +{
> + struct ad4030_state *st = iio_priv(indio_dev);
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_CALIBBIAS:
> + *vals = st->offset_avail;
> + *type = IIO_VAL_INT;
> + return IIO_AVAIL_RANGE;
> +
> + case IIO_CHAN_INFO_CALIBSCALE:
> + *vals = (void *)ad4030_gain_avail;

Trivial but could just cast it to the right type instead of using void *
to avoid it :)

> + *type = IIO_VAL_INT_PLUS_NANO;
> + return IIO_AVAIL_RANGE;
> +
> + default:
> + return -EINVAL;
> + }
> +}

> +static int ad4030_buffer_preenable(struct iio_dev *indio_dev)
> +{
> + struct ad4030_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + ret = ad4030_set_mode(indio_dev, *indio_dev->active_scan_mask);
> + if (ret)
> + return ret;
> +
> + ret = ad4030_exit_config_mode(st);
> + if (ret)
> + return ret;
> +
> + return 0;
might as well
return ad4030_exit_config_mode(st);
and save a couple of lines with no significant loss of readability.

> +}