staging: iio: cdc: ad7746: Use read_avail() rather than opencoding.
Switch over to the IIO core handling for _available attributes making them available for in kernel users and enforcing correct naming etc automatically. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20220626122938.582107-14-jic23@kernel.org
This commit is contained in:
parent
2d72ead25a
commit
4b717201a0
|
@ -163,6 +163,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
|
|||
.channel = 0,
|
||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.address = VIN,
|
||||
},
|
||||
[VIN_VDD] = {
|
||||
|
@ -172,6 +173,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
|
|||
.extend_name = "supply",
|
||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.address = VIN_VDD,
|
||||
},
|
||||
[TEMP_INT] = {
|
||||
|
@ -198,6 +200,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
|
|||
BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) |
|
||||
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.address = CIN1,
|
||||
},
|
||||
[CIN1_DIFF] = {
|
||||
|
@ -210,6 +213,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
|
|||
BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_ZEROPOINT),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) |
|
||||
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.address = CIN1_DIFF,
|
||||
},
|
||||
[CIN2] = {
|
||||
|
@ -220,6 +224,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
|
|||
BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) |
|
||||
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.address = CIN2,
|
||||
},
|
||||
[CIN2_DIFF] = {
|
||||
|
@ -232,6 +237,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
|
|||
BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_ZEROPOINT),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) |
|
||||
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_SAMP_FREQ),
|
||||
.address = CIN2_DIFF,
|
||||
}
|
||||
};
|
||||
|
@ -440,18 +446,12 @@ static int ad7746_store_vt_filter_rate_setup(struct ad7746_chip_info *chip,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static IIO_CONST_ATTR(in_voltage_sampling_frequency_available, "50 31 16 8");
|
||||
static IIO_CONST_ATTR(in_capacitance_sampling_frequency_available,
|
||||
"91 84 50 26 16 13 11 9");
|
||||
|
||||
static struct attribute *ad7746_attributes[] = {
|
||||
&iio_dev_attr_in_capacitance0_calibbias_calibration.dev_attr.attr,
|
||||
&iio_dev_attr_in_capacitance0_calibscale_calibration.dev_attr.attr,
|
||||
&iio_dev_attr_in_capacitance1_calibscale_calibration.dev_attr.attr,
|
||||
&iio_dev_attr_in_capacitance1_calibbias_calibration.dev_attr.attr,
|
||||
&iio_dev_attr_in_voltage0_calibscale_calibration.dev_attr.attr,
|
||||
&iio_const_attr_in_voltage_sampling_frequency_available.dev_attr.attr,
|
||||
&iio_const_attr_in_capacitance_sampling_frequency_available.dev_attr.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
@ -554,6 +554,32 @@ static int ad7746_write_raw(struct iio_dev *indio_dev,
|
|||
}
|
||||
}
|
||||
|
||||
static const int ad7746_v_samp_freq[] = { 50, 31, 16, 8, };
|
||||
static const int ad7746_cap_samp_freq[] = { 91, 84, 50, 26, 16, 13, 11, 9, };
|
||||
|
||||
static int ad7746_read_avail(struct iio_dev *indio_dev,
|
||||
struct iio_chan_spec const *chan, const int **vals,
|
||||
int *type, int *length, long mask)
|
||||
{
|
||||
if (mask != IIO_CHAN_INFO_SAMP_FREQ)
|
||||
return -EINVAL;
|
||||
|
||||
switch (chan->type) {
|
||||
case IIO_VOLTAGE:
|
||||
*vals = ad7746_v_samp_freq;
|
||||
*length = ARRAY_SIZE(ad7746_v_samp_freq);
|
||||
break;
|
||||
case IIO_CAPACITANCE:
|
||||
*vals = ad7746_cap_samp_freq;
|
||||
*length = ARRAY_SIZE(ad7746_cap_samp_freq);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
*type = IIO_VAL_INT;
|
||||
return IIO_AVAIL_LIST;
|
||||
}
|
||||
|
||||
static int ad7746_read_channel(struct iio_dev *indio_dev,
|
||||
struct iio_chan_spec const *chan,
|
||||
int *val)
|
||||
|
@ -689,6 +715,7 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
|
|||
static const struct iio_info ad7746_info = {
|
||||
.attrs = &ad7746_attribute_group,
|
||||
.read_raw = ad7746_read_raw,
|
||||
.read_avail = ad7746_read_avail,
|
||||
.write_raw = ad7746_write_raw,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue