Skip to content

Commit cdd03d5

Browse files
machschmittjic23
authored andcommitted
iio: adc: ad4170-4: Add support for calibration bias
Add support for ADC calibration bias/offset configuration. Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com> Link: https://patch.msgid.link/f240fce693d62ec8d587885074bf540e01919b31.1751895245.git.marcelo.schmitt@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent be2cdc5 commit cdd03d5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/iio/adc/ad4170-4.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ static const struct iio_chan_spec ad4170_channel_template = {
626626
.differential = 1,
627627
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
628628
BIT(IIO_CHAN_INFO_SCALE) |
629+
BIT(IIO_CHAN_INFO_CALIBBIAS) |
629630
BIT(IIO_CHAN_INFO_CALIBSCALE) |
630631
BIT(IIO_CHAN_INFO_OFFSET),
631632
.info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),
@@ -949,6 +950,9 @@ static int ad4170_read_raw(struct iio_dev *indio_dev,
949950
pga = FIELD_GET(AD4170_AFE_PGA_GAIN_MSK, setup->afe);
950951
*val = chan_info->offset_tbl[pga];
951952
return IIO_VAL_INT;
953+
case IIO_CHAN_INFO_CALIBBIAS:
954+
*val = setup->offset;
955+
return IIO_VAL_INT;
952956
case IIO_CHAN_INFO_CALIBSCALE:
953957
*val = setup->gain;
954958
return IIO_VAL_INT;
@@ -1066,6 +1070,18 @@ static int ad4170_set_pga(struct ad4170_state *st,
10661070
return ad4170_write_channel_setup(st, chan->address, false);
10671071
}
10681072

1073+
static int ad4170_set_calib_offset(struct ad4170_state *st,
1074+
struct iio_chan_spec const *chan, int val)
1075+
{
1076+
struct ad4170_chan_info *chan_info = &st->chan_infos[chan->address];
1077+
struct ad4170_setup *setup = &chan_info->setup;
1078+
1079+
guard(mutex)(&st->lock);
1080+
setup->offset = val;
1081+
1082+
return ad4170_write_channel_setup(st, chan->address, false);
1083+
}
1084+
10691085
static int ad4170_set_calib_gain(struct ad4170_state *st,
10701086
struct iio_chan_spec const *chan, int val)
10711087
{
@@ -1087,6 +1103,8 @@ static int __ad4170_write_raw(struct iio_dev *indio_dev,
10871103
switch (info) {
10881104
case IIO_CHAN_INFO_SCALE:
10891105
return ad4170_set_pga(st, chan, val, val2);
1106+
case IIO_CHAN_INFO_CALIBBIAS:
1107+
return ad4170_set_calib_offset(st, chan, val);
10901108
case IIO_CHAN_INFO_CALIBSCALE:
10911109
return ad4170_set_calib_gain(st, chan, val);
10921110
default:
@@ -1115,6 +1133,7 @@ static int ad4170_write_raw_get_fmt(struct iio_dev *indio_dev,
11151133
switch (info) {
11161134
case IIO_CHAN_INFO_SCALE:
11171135
return IIO_VAL_INT_PLUS_NANO;
1136+
case IIO_CHAN_INFO_CALIBBIAS:
11181137
case IIO_CHAN_INFO_CALIBSCALE:
11191138
return IIO_VAL_INT;
11201139
default:

0 commit comments

Comments
 (0)