2022-03-22 14:16:48

by Alexandru Tachici

[permalink] [raw]
Subject: [PATCH v3 0/6] iio: adc: ad_sigma_delta: Add sequencer support

From: Alexandru Tachici <[email protected]>

Some sigma-delta chips support sampling of multiple
channels in continuous mode.

When the operating with more than one channel enabled,
the channel sequencer cycles through the enabled channels
in sequential order, from first channel to the last one.
If a channel is disabled, it is skipped by the sequencer.

If more than one channel is used in continuous mode,
instruct the device to append the status to the SPI transfer
(1 extra byte) every time we receive a sample.
All sigma-delta chips possessing a sampling sequencer have
this ability. Inside the status register there will be
the number of the converted channel. In this way, even
if the CPU won't keep up with the sampling rate, it won't
send to userspace wrong channel samples.

1. Removed the 1 byte .shift from channel spec in AD7124,
it confuses userspace apps (no need to shift right).

2. Add update_scan_mode to AD7124, it is required in order
to enable/disable multiple channels at once

3. Add update_scan_mode to AD7192, it is required in order
to enable/disable multiple channels at once

4. Add sequencer support for sigma_delta library.

5. Add sigma_delta_info values and callbacks for sequencer
support in AD7124.

6. Add sigma_delta_info values and callbacks for sequencer
support in AD7192.

Alexandru Tachici (5):
iio: adc: ad7124: Remove shift from scan_type
iio: adc: ad7124: Add update_scan_mode
iio: adc: ad7192: Add update_scan_mode
iio: adc: ad7124: add sequencer support
iio: adc: ad7192: add sequencer support

Lars-Peter Clausen (1):
iio: adc: ad_sigma_delta: Add sequencer support

Changelog V2 -> V3:
- ad_sd_buffer_postenable(), aligned (slot * storagebits) to 8 bytes
- devm_krealloc instead of krealloc for samples_buf in ad_sd_buffer_postenable()
- in ad_sigma_delta_append_status, check return value before setting .status_appended
- iio: adc: ad_sigma_delta: Add sequencer support: added explanations on
desynchronization checking and recovery
- in ad7124_append_status() modify st->adc_control after write has taken place without errors
- in ad7124_update_scan_mode() take cfg mutex only once instead of every time a
set_channel happens
- in ad7192_disable_all() modify st->conf after write taken place without errors
- in ad7192_append_status() modify st->mode after write taken place without errors

drivers/iio/adc/ad7124.c | 86 ++++++++++++++-
drivers/iio/adc/ad7192.c | 64 ++++++++++-
drivers/iio/adc/ad_sigma_delta.c | 143 +++++++++++++++++++++++--
include/linux/iio/adc/ad_sigma_delta.h | 38 +++++++
4 files changed, 315 insertions(+), 16 deletions(-)

--
2.25.1


2022-03-22 16:22:07

by Alexandru Tachici

[permalink] [raw]
Subject: [PATCH v3 1/6] iio: adc: ad7124: Remove shift from scan_type

From: Alexandru Tachici <[email protected]>

The 24 bits data is stored in 32 bits in BE. There
is no need to shift it. This confuses user-space apps.

Fixes: b3af341bbd966 ("iio: adc: Add ad7124 support")
Signed-off-by: Alexandru Tachici <[email protected]>
---
drivers/iio/adc/ad7124.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 998a342d51a6..7249db2c4422 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -188,7 +188,6 @@ static const struct iio_chan_spec ad7124_channel_template = {
.sign = 'u',
.realbits = 24,
.storagebits = 32,
- .shift = 8,
.endianness = IIO_BE,
},
};
--
2.25.1

2022-03-23 02:54:44

by Alexandru Tachici

[permalink] [raw]
Subject: [PATCH v3 2/6] iio: adc: ad7124: Add update_scan_mode

From: Alexandru Tachici <[email protected]>

The callback .set_channel cannot be used to enable and
disable multiple channels at once as they are presented
in the active_scan_mask.

By adding an update_scan_mode callback, every time the
continuous mode is activated, channels will be
enabled/disabled accordingly.

Signed-off-by: Alexandru Tachici <[email protected]>
---
drivers/iio/adc/ad7124.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 7249db2c4422..428ec3e257d7 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -669,11 +669,32 @@ static const struct attribute_group ad7124_attrs_group = {
.attrs = ad7124_attributes,
};

+static int ad7124_update_scan_mode(struct iio_dev *indio_dev,
+ const unsigned long *scan_mask)
+{
+ struct ad7124_state *st = iio_priv(indio_dev);
+ bool bit_set;
+ int ret;
+ int i;
+
+ for (i = 0; i < st->num_channels; i++) {
+ bit_set = test_bit(i, scan_mask);
+ ret = ad7124_spi_write_mask(st, AD7124_CHANNEL(i),
+ AD7124_CHANNEL_EN_MSK,
+ AD7124_CHANNEL_EN(bit_set),
+ 2);
+ if (ret < 0)
+ return ret;
+ }
+ return 0;
+}
+
static const struct iio_info ad7124_info = {
.read_raw = ad7124_read_raw,
.write_raw = ad7124_write_raw,
.debugfs_reg_access = &ad7124_reg_access,
.validate_trigger = ad_sd_validate_trigger,
+ .update_scan_mode = ad7124_update_scan_mode,
.attrs = &ad7124_attrs_group,
};

--
2.25.1

2022-03-24 08:13:03

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 0/6] iio: adc: ad_sigma_delta: Add sequencer support

On Tue, 22 Mar 2022 12:50:23 +0200
<[email protected]> wrote:

> From: Alexandru Tachici <[email protected]>

Hi Alexandru,

I just took another look at this and I'm happy with it.
Will leave it on list for a few more days for others to
take a look though before I queue it up.

Thanks,

Jonathan

>
> Some sigma-delta chips support sampling of multiple
> channels in continuous mode.
>
> When the operating with more than one channel enabled,
> the channel sequencer cycles through the enabled channels
> in sequential order, from first channel to the last one.
> If a channel is disabled, it is skipped by the sequencer.
>
> If more than one channel is used in continuous mode,
> instruct the device to append the status to the SPI transfer
> (1 extra byte) every time we receive a sample.
> All sigma-delta chips possessing a sampling sequencer have
> this ability. Inside the status register there will be
> the number of the converted channel. In this way, even
> if the CPU won't keep up with the sampling rate, it won't
> send to userspace wrong channel samples.
>
> 1. Removed the 1 byte .shift from channel spec in AD7124,
> it confuses userspace apps (no need to shift right).
>
> 2. Add update_scan_mode to AD7124, it is required in order
> to enable/disable multiple channels at once
>
> 3. Add update_scan_mode to AD7192, it is required in order
> to enable/disable multiple channels at once
>
> 4. Add sequencer support for sigma_delta library.
>
> 5. Add sigma_delta_info values and callbacks for sequencer
> support in AD7124.
>
> 6. Add sigma_delta_info values and callbacks for sequencer
> support in AD7192.
>
> Alexandru Tachici (5):
> iio: adc: ad7124: Remove shift from scan_type
> iio: adc: ad7124: Add update_scan_mode
> iio: adc: ad7192: Add update_scan_mode
> iio: adc: ad7124: add sequencer support
> iio: adc: ad7192: add sequencer support
>
> Lars-Peter Clausen (1):
> iio: adc: ad_sigma_delta: Add sequencer support
>
> Changelog V2 -> V3:
> - ad_sd_buffer_postenable(), aligned (slot * storagebits) to 8 bytes
> - devm_krealloc instead of krealloc for samples_buf in ad_sd_buffer_postenable()
> - in ad_sigma_delta_append_status, check return value before setting .status_appended
> - iio: adc: ad_sigma_delta: Add sequencer support: added explanations on
> desynchronization checking and recovery
> - in ad7124_append_status() modify st->adc_control after write has taken place without errors
> - in ad7124_update_scan_mode() take cfg mutex only once instead of every time a
> set_channel happens
> - in ad7192_disable_all() modify st->conf after write taken place without errors
> - in ad7192_append_status() modify st->mode after write taken place without errors
>
> drivers/iio/adc/ad7124.c | 86 ++++++++++++++-
> drivers/iio/adc/ad7192.c | 64 ++++++++++-
> drivers/iio/adc/ad_sigma_delta.c | 143 +++++++++++++++++++++++--
> include/linux/iio/adc/ad_sigma_delta.h | 38 +++++++
> 4 files changed, 315 insertions(+), 16 deletions(-)
>
> --
> 2.25.1

2022-03-28 15:24:33

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 0/6] iio: adc: ad_sigma_delta: Add sequencer support

On Tue, 22 Mar 2022 21:30:02 +0000
Jonathan Cameron <[email protected]> wrote:

> On Tue, 22 Mar 2022 12:50:23 +0200
> <[email protected]> wrote:
>
> > From: Alexandru Tachici <[email protected]>
>
> Hi Alexandru,
>
> I just took another look at this and I'm happy with it.
> Will leave it on list for a few more days for others to
> take a look though before I queue it up.
>
Applied to the togreg branch of iio.git though I won't push
that out, other than as testing, until I can rebase on rc1.

Thanks,

Jonathan

> Thanks,
>
> Jonathan
>
> >
> > Some sigma-delta chips support sampling of multiple
> > channels in continuous mode.
> >
> > When the operating with more than one channel enabled,
> > the channel sequencer cycles through the enabled channels
> > in sequential order, from first channel to the last one.
> > If a channel is disabled, it is skipped by the sequencer.
> >
> > If more than one channel is used in continuous mode,
> > instruct the device to append the status to the SPI transfer
> > (1 extra byte) every time we receive a sample.
> > All sigma-delta chips possessing a sampling sequencer have
> > this ability. Inside the status register there will be
> > the number of the converted channel. In this way, even
> > if the CPU won't keep up with the sampling rate, it won't
> > send to userspace wrong channel samples.
> >
> > 1. Removed the 1 byte .shift from channel spec in AD7124,
> > it confuses userspace apps (no need to shift right).
> >
> > 2. Add update_scan_mode to AD7124, it is required in order
> > to enable/disable multiple channels at once
> >
> > 3. Add update_scan_mode to AD7192, it is required in order
> > to enable/disable multiple channels at once
> >
> > 4. Add sequencer support for sigma_delta library.
> >
> > 5. Add sigma_delta_info values and callbacks for sequencer
> > support in AD7124.
> >
> > 6. Add sigma_delta_info values and callbacks for sequencer
> > support in AD7192.
> >
> > Alexandru Tachici (5):
> > iio: adc: ad7124: Remove shift from scan_type
> > iio: adc: ad7124: Add update_scan_mode
> > iio: adc: ad7192: Add update_scan_mode
> > iio: adc: ad7124: add sequencer support
> > iio: adc: ad7192: add sequencer support
> >
> > Lars-Peter Clausen (1):
> > iio: adc: ad_sigma_delta: Add sequencer support
> >
> > Changelog V2 -> V3:
> > - ad_sd_buffer_postenable(), aligned (slot * storagebits) to 8 bytes
> > - devm_krealloc instead of krealloc for samples_buf in ad_sd_buffer_postenable()
> > - in ad_sigma_delta_append_status, check return value before setting .status_appended
> > - iio: adc: ad_sigma_delta: Add sequencer support: added explanations on
> > desynchronization checking and recovery
> > - in ad7124_append_status() modify st->adc_control after write has taken place without errors
> > - in ad7124_update_scan_mode() take cfg mutex only once instead of every time a
> > set_channel happens
> > - in ad7192_disable_all() modify st->conf after write taken place without errors
> > - in ad7192_append_status() modify st->mode after write taken place without errors
> >
> > drivers/iio/adc/ad7124.c | 86 ++++++++++++++-
> > drivers/iio/adc/ad7192.c | 64 ++++++++++-
> > drivers/iio/adc/ad_sigma_delta.c | 143 +++++++++++++++++++++++--
> > include/linux/iio/adc/ad_sigma_delta.h | 38 +++++++
> > 4 files changed, 315 insertions(+), 16 deletions(-)
> >
> > --
> > 2.25.1
>