]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: adc: ad4170-4: Add support for calibration gain
authorMarcelo Schmitt <marcelo.schmitt@analog.com>
Mon, 7 Jul 2025 13:51:05 +0000 (10:51 -0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 14 Jul 2025 18:20:51 +0000 (19:20 +0100)
Add support for ADC calibration gain configuration.

Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Link: https://patch.msgid.link/ea8d07cad9b7b6106f0b5664c403ed080b362a6b.1751895245.git.marcelo.schmitt@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad4170-4.c

index 2051c7339fb476f7ded8ee8e4b88fca93d1c4548..c314675a9ad1d33b61eebdf0c685847e5d9ba501 100644 (file)
@@ -626,6 +626,7 @@ static const struct iio_chan_spec ad4170_channel_template = {
        .differential = 1,
        .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
                              BIT(IIO_CHAN_INFO_SCALE) |
+                             BIT(IIO_CHAN_INFO_CALIBSCALE) |
                              BIT(IIO_CHAN_INFO_OFFSET),
        .info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),
        .scan_type = {
@@ -948,6 +949,9 @@ static int ad4170_read_raw(struct iio_dev *indio_dev,
                pga = FIELD_GET(AD4170_AFE_PGA_GAIN_MSK, setup->afe);
                *val = chan_info->offset_tbl[pga];
                return IIO_VAL_INT;
+       case IIO_CHAN_INFO_CALIBSCALE:
+               *val = setup->gain;
+               return IIO_VAL_INT;
        default:
                return -EINVAL;
        }
@@ -1062,6 +1066,18 @@ static int ad4170_set_pga(struct ad4170_state *st,
        return ad4170_write_channel_setup(st, chan->address, false);
 }
 
+static int ad4170_set_calib_gain(struct ad4170_state *st,
+                                struct iio_chan_spec const *chan, int val)
+{
+       struct ad4170_chan_info *chan_info = &st->chan_infos[chan->address];
+       struct ad4170_setup *setup = &chan_info->setup;
+
+       guard(mutex)(&st->lock);
+       setup->gain = val;
+
+       return ad4170_write_channel_setup(st, chan->address, false);
+}
+
 static int __ad4170_write_raw(struct iio_dev *indio_dev,
                              struct iio_chan_spec const *chan, int val,
                              int val2, long info)
@@ -1071,6 +1087,8 @@ static int __ad4170_write_raw(struct iio_dev *indio_dev,
        switch (info) {
        case IIO_CHAN_INFO_SCALE:
                return ad4170_set_pga(st, chan, val, val2);
+       case IIO_CHAN_INFO_CALIBSCALE:
+               return ad4170_set_calib_gain(st, chan, val);
        default:
                return -EINVAL;
        }
@@ -1097,6 +1115,8 @@ static int ad4170_write_raw_get_fmt(struct iio_dev *indio_dev,
        switch (info) {
        case IIO_CHAN_INFO_SCALE:
                return IIO_VAL_INT_PLUS_NANO;
+       case IIO_CHAN_INFO_CALIBSCALE:
+               return IIO_VAL_INT;
        default:
                return -EINVAL;
        }