Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 182bc49

Browse files
dumitruceclanjic23
authored andcommitted
iio: adc: ad7173: Fix sampling frequency setting
This patch fixes two issues regarding the sampling frequency setting: -The attribute was set as per device, not per channel. As such, when setting the sampling frequency, the configuration was always done for the slot 0, and the correct configuration was applied on the next channel configuration call by the LRU mechanism. -The LRU implementation does not take into account external settings of the slot registers. When setting the sampling frequency directly to a slot register in write_raw(), there is no guarantee that other channels were not also using that slot and now incorrectly retain their config as live. Set the sampling frequency attribute as separate in the channel templates. Do not set the sampling directly to the slot register in write_raw(), just mark the config as not live and let the LRU mechanism handle it. As the reg variable is no longer used, remove it. Fixes: 76a1e6a ("iio: adc: ad7173: add AD7173 driver") Signed-off-by: Dumitru Ceclan <dumitru.ceclan@analog.com> Link: https://lore.kernel.org/r/20240530-ad7173-fixes-v3-5-b85f33079e18@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 18befe4 commit 182bc49

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

drivers/iio/adc/ad7173.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ static int ad7173_write_raw(struct iio_dev *indio_dev,
717717
{
718718
struct ad7173_state *st = iio_priv(indio_dev);
719719
struct ad7173_channel_config *cfg;
720-
unsigned int freq, i, reg;
720+
unsigned int freq, i;
721721
int ret;
722722

723723
ret = iio_device_claim_direct_mode(indio_dev);
@@ -733,16 +733,7 @@ static int ad7173_write_raw(struct iio_dev *indio_dev,
733733

734734
cfg = &st->channels[chan->address].cfg;
735735
cfg->odr = i;
736-
737-
if (!cfg->live)
738-
break;
739-
740-
ret = ad_sd_read_reg(&st->sd, AD7173_REG_FILTER(cfg->cfg_slot), 2, &reg);
741-
if (ret)
742-
break;
743-
reg &= ~AD7173_FILTER_ODR0_MASK;
744-
reg |= FIELD_PREP(AD7173_FILTER_ODR0_MASK, i);
745-
ret = ad_sd_write_reg(&st->sd, AD7173_REG_FILTER(cfg->cfg_slot), 2, reg);
736+
cfg->live = false;
746737
break;
747738

748739
default:
@@ -804,8 +795,7 @@ static const struct iio_chan_spec ad7173_channel_template = {
804795
.type = IIO_VOLTAGE,
805796
.indexed = 1,
806797
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
807-
BIT(IIO_CHAN_INFO_SCALE),
808-
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
798+
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ),
809799
.scan_type = {
810800
.sign = 'u',
811801
.realbits = 24,
@@ -819,8 +809,8 @@ static const struct iio_chan_spec ad7173_temp_iio_channel_template = {
819809
.channel = AD7173_AIN_TEMP_POS,
820810
.channel2 = AD7173_AIN_TEMP_NEG,
821811
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
822-
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),
823-
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
812+
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET) |
813+
BIT(IIO_CHAN_INFO_SAMP_FREQ),
824814
.scan_type = {
825815
.sign = 'u',
826816
.realbits = 24,

0 commit comments

Comments
 (0)