Skip to content

Commit 98a563d

Browse files
dumitruceclanjic23
authored andcommitted
iio: adc: ad_sigma_delta: add disable_one callback
Sigma delta ADCs with a sequencer need to disable the previously enabled channel when reading using ad_sigma_delta_single_conversion(). This was done manually in drivers for devices with sequencers. This patch implements handling of single channel disabling after a single conversion. Reviewed-by: Nuno Sa <nuno.sa@analog.com> Signed-off-by: Dumitru Ceclan <dumitru.ceclan@analog.com> Reviewed-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20240607-ad4111-v7-3-97e3855900a0@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 561b5d5 commit 98a563d

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

drivers/iio/adc/ad7124.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,18 @@ static int ad7124_disable_all(struct ad_sigma_delta *sd)
555555
return 0;
556556
}
557557

558+
static int ad7124_disable_one(struct ad_sigma_delta *sd, unsigned int chan)
559+
{
560+
struct ad7124_state *st = container_of(sd, struct ad7124_state, sd);
561+
562+
return ad7124_spi_write_mask(st, AD7124_CHANNEL(chan), AD7124_CHANNEL_EN_MSK, 0, 2);
563+
}
564+
558565
static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
559566
.set_channel = ad7124_set_channel,
560567
.append_status = ad7124_append_status,
561568
.disable_all = ad7124_disable_all,
569+
.disable_one = ad7124_disable_one,
562570
.set_mode = ad7124_set_mode,
563571
.has_registers = true,
564572
.addr_shift = 0,
@@ -582,12 +590,6 @@ static int ad7124_read_raw(struct iio_dev *indio_dev,
582590
if (ret < 0)
583591
return ret;
584592

585-
/* After the conversion is performed, disable the channel */
586-
ret = ad_sd_write_reg(&st->sd, AD7124_CHANNEL(chan->address), 2,
587-
st->channels[chan->address].ain | AD7124_CHANNEL_EN(0));
588-
if (ret < 0)
589-
return ret;
590-
591593
return IIO_VAL_INT;
592594
case IIO_CHAN_INFO_SCALE:
593595
mutex_lock(&st->cfgs_lock);

drivers/iio/adc/ad7173.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,16 @@ static int ad7173_disable_all(struct ad_sigma_delta *sd)
569569
return 0;
570570
}
571571

572+
static int ad7173_disable_one(struct ad_sigma_delta *sd, unsigned int chan)
573+
{
574+
return ad_sd_write_reg(sd, AD7173_REG_CH(chan), 2, 0);
575+
}
576+
572577
static struct ad_sigma_delta_info ad7173_sigma_delta_info = {
573578
.set_channel = ad7173_set_channel,
574579
.append_status = ad7173_append_status,
575580
.disable_all = ad7173_disable_all,
581+
.disable_one = ad7173_disable_one,
576582
.set_mode = ad7173_set_mode,
577583
.has_registers = true,
578584
.addr_shift = 0,
@@ -668,11 +674,6 @@ static int ad7173_read_raw(struct iio_dev *indio_dev,
668674
if (ret < 0)
669675
return ret;
670676

671-
/* disable channel after single conversion */
672-
ret = ad_sd_write_reg(&st->sd, AD7173_REG_CH(chan->address), 2, 0);
673-
if (ret < 0)
674-
return ret;
675-
676677
return IIO_VAL_INT;
677678
case IIO_CHAN_INFO_SCALE:
678679
if (chan->type == IIO_TEMP) {

drivers/iio/adc/ad_sigma_delta.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
321321

322322
sigma_delta->keep_cs_asserted = false;
323323
ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
324+
ad_sigma_delta_disable_one(sigma_delta, chan->address);
324325
sigma_delta->bus_locked = false;
325326
spi_bus_unlock(sigma_delta->spi->controller);
326327
iio_device_release_direct_mode(indio_dev);

include/linux/iio/adc/ad_sigma_delta.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ struct iio_dev;
3737
* @append_status: Will be called to enable status append at the end of the sample, may be NULL.
3838
* @set_mode: Will be called to select the current mode, may be NULL.
3939
* @disable_all: Will be called to disable all channels, may be NULL.
40+
* @disable_one: Will be called to disable a single channel after
41+
* ad_sigma_delta_single_conversion(), may be NULL.
42+
* Usage of this callback expects iio_chan_spec.address to contain
43+
* the value required for the driver to identify the channel.
4044
* @postprocess_sample: Is called for each sampled data word, can be used to
4145
* modify or drop the sample data, it, may be NULL.
4246
* @has_registers: true if the device has writable and readable registers, false
@@ -55,6 +59,7 @@ struct ad_sigma_delta_info {
5559
int (*append_status)(struct ad_sigma_delta *, bool append);
5660
int (*set_mode)(struct ad_sigma_delta *, enum ad_sigma_delta_mode mode);
5761
int (*disable_all)(struct ad_sigma_delta *);
62+
int (*disable_one)(struct ad_sigma_delta *, unsigned int chan);
5863
int (*postprocess_sample)(struct ad_sigma_delta *, unsigned int raw_sample);
5964
bool has_registers;
6065
unsigned int addr_shift;
@@ -140,6 +145,15 @@ static inline int ad_sigma_delta_disable_all(struct ad_sigma_delta *sd)
140145
return 0;
141146
}
142147

148+
static inline int ad_sigma_delta_disable_one(struct ad_sigma_delta *sd,
149+
unsigned int chan)
150+
{
151+
if (sd->info->disable_one)
152+
return sd->info->disable_one(sd, chan);
153+
154+
return 0;
155+
}
156+
143157
static inline int ad_sigma_delta_set_mode(struct ad_sigma_delta *sd,
144158
unsigned int mode)
145159
{

0 commit comments

Comments
 (0)