From: "Nuno Sá" <noname.nuno@gmail.com>
To: "Julien Stephan" <jstephan@baylibre.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>
Cc: kernel test robot <lkp@intel.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC v6 09/10] iio: adc: ad7380: add support for rolling average oversampling mode
Date: Mon, 06 May 2024 10:33:23 +0200 [thread overview]
Message-ID: <9cfbe67f24cf4e0f69ee7f3769d85469e0738ee2.camel@gmail.com> (raw)
In-Reply-To: <20240501-adding-new-ad738x-driver-v6-9-3c0741154728@baylibre.com>
On Wed, 2024-05-01 at 16:55 +0200, Julien Stephan wrote:
> Adds support for rolling average oversampling mode.
>
> Rolling oversampling mode uses a first in, first out (FIFO) buffer of
> the most recent samples in the averaging calculation, allowing the ADC
> throughput rate and output data rate to stay the same, since we only need
> to take only one sample for each new conversion.
>
> The FIFO length is 8, thus the available oversampling ratios are 1, 2, 4, 8
> in this mode (vs 1, 2, 4, 8, 16, 32 for the normal average)
>
> In order to be able to change the averaging mode, this commit also adds
> the new "oversampling_mode" and "oversampling_mode_available" custom
> attributes along with the according documentation file in
> Documentation/ABI/testing/sysfs-bus-iio-adc-ad7380 since no standard
> attributes correspond to this use case.
>
> Signed-off-by: Julien Stephan <jstephan@baylibre.com>
> ---
> Documentation/ABI/testing/sysfs-bus-iio-adc-ad7380 | 38 ++++++
> MAINTAINERS | 1 +
> drivers/iio/adc/ad7380.c | 143 +++++++++++++++++++--
> 3 files changed, 174 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7380
> b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7380
> new file mode 100644
> index 000000000000..0a560ef3e32a
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7380
> @@ -0,0 +1,38 @@
> +What: /sys/bus/iio/devices/iio:deviceX/oversampling_mode
> +KernelVersion: 6.9
> +Contact: Michael Hennerich <michael.hennerich@analog.com>
> +Description:
> + Writing this attribute sets the oversampling average mode.
> + Reading it, shows the configured mode.
> + Available modes can be displayed using the oversampling_mode_available
> + attribute.
> + When writing this attribute to change the oversampling mode, this will
> + have the following side effects:
> +
> + - soft reset the ADC to flush the oversampling block and FIFO
> +
> + - the available oversampling ratios depend on the oversampling mode
> + configured so to avoid misconfiguration, changing the mode will disable
> + the oversampling by setting the ratio to 1.
Hmm, can we somehow re-enable it again with a proper configuration (after the mode
change)?
> +
> + - the list of available ratios (displayed by reading the
> + oversampling_ratio_available attribute) will be updated when changing
> + the oversampling mode.
> +
> +What: /sys/bus/iio/devices/iio:deviceX/oversampling_mode_available
> +KernelVersion: 6.9
> +Contact: Michael Hennerich <michael.hennerich@analog.com>
> +Description:
> + Display the available oversampling average modes. The two available modes
> + are "normal" and "rolling" where "normal" average mode is the default one.
> +
> + - normal averaging involves taking a number of samples, adding them
> + together, and dividing the result by the number of samples taken.
> + This result is then output from the device. The sample data is cleared
> + when the process completes. Because we need more samples to output a
> + value, the data output rate decrease with the oversampling ratio.
> +
> + - rolling oversampling mode uses a first in, first out (FIFO) buffer of
> + the most recent samples in the averaging calculation, allowing the ADC
> + throughput rate and output data rate to stay the same, since we only need
> + to take only one sample for each new conversion.
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 87724a9e9f9f..ca1e115f2aff 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -434,6 +434,7 @@ R: David Lechner <dlechner@baylibre.com>
> S: Supported
> W:
> https://wiki.analog.com/resources/tools-software/linux-drivers/iio-adc/ad738x
> W: https://ez.analog.com/linux-software-drivers
> +F: Documentation/ABI/testing/sysfs-bus-iio-adc-ad7380
> F: Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml
> F: drivers/iio/adc/ad7380.c
>
> diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
> index 1e3869f5e48c..7b021bb9cf87 100644
> --- a/drivers/iio/adc/ad7380.c
> +++ b/drivers/iio/adc/ad7380.c
> @@ -51,6 +51,8 @@
> #define AD7380_REG_ADDR_ALERT_HIGH_TH 0x5
>
> #define AD7380_CONFIG1_OS_MODE BIT(9)
> +#define OS_MODE_NORMAL_AVERAGE 0
> +#define OS_MODE_ROLLING_AVERAGE 1
no AD7380 prefix?
> #define AD7380_CONFIG1_OSR GENMASK(8, 6)
> #define AD7380_CONFIG1_CRC_W BIT(5)
> #define AD7380_CONFIG1_CRC_R BIT(4)
> @@ -159,16 +161,27 @@ static const struct ad7380_timing_specs ad7380_4_timing = {
> .t_csh_ns = 20,
> };
>
...
>
> +static ssize_t oversampling_mode_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> + struct ad7380_state *st = iio_priv(indio_dev);
> + int os_mode, ret;
> +
> + ret = sysfs_match_string(ad7380_oversampling_average_modes, buf);
> + if (ret < 0)
> + return ret;
> +
> + os_mode = ret;
> +
> + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
> + ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
> + AD7380_CONFIG1_OS_MODE,
> + FIELD_PREP(AD7380_CONFIG1_OS_MODE,
> os_mode));
> +
> + if (ret)
> + return ret;
> +
> + st->oversampling_mode = os_mode;
> +
> + /*
> + * Oversampling ratio depends on oversampling mode, to avoid
> + * misconfiguration when changing oversampling mode,
> + * disable oversampling by setting OSR to 0.
> + */
Given the comment, I would expect you to disable osr before changing the mode.
> + ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
> + AD7380_CONFIG1_OSR,
> FIELD_PREP(AD7380_CONFIG1_OSR, 0));
> +
> + if (ret)
> + return ret;
> +
> + st->oversampling_ratio = 1;
> +
1?
Also, it would be nice if we could re-enabled osr. So the flow would maybe be:
1) disable osr;
2) change mode;
3) do whatever we need so configuration makes sense for new mode?
4) re-enable osr;
5) soft-reset;
Also not sure if 4) and 5) are in the correct order.
> + /*
> + * Perform a soft reset.
> + * This will flush the oversampling block and FIFO but will
> + * maintain the content of the configurable registers.
> + */
> + ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
> + AD7380_CONFIG2_RESET,
> + FIELD_PREP(AD7380_CONFIG2_RESET,
> + AD7380_CONFIG2_RESET_SOFT));
> + }
> + return ret ?: len;
> +}
> +
> +static ssize_t oversampling_mode_available_show(struct device *dev,
> + struct device_attribute *attr,
> char *buf)
> +{
> + int i;
> + size_t len = 0;
> +
> + for (i = 0; i < ARRAY_SIZE(ad7380_oversampling_average_modes); i++)
> + len += sysfs_emit_at(buf, len, "%s ",
> ad7380_oversampling_average_modes[i]);
> +
> + buf[len - 1] = '\n';
> +
> + return len;
> +}
> +
> +static IIO_DEVICE_ATTR_RW(oversampling_mode, 0);
> +static IIO_DEVICE_ATTR_RO(oversampling_mode_available, 0);
> +
> +static struct attribute *ad7380_attributes[] = {
> + &iio_dev_attr_oversampling_mode.dev_attr.attr,
> + &iio_dev_attr_oversampling_mode_available.dev_attr.attr,
> + NULL
> +};
> +
Maybe use IIO_ENUM... It allows the core to do some of the stuff you're doing for
you.
- Nuno Sá
next prev parent reply other threads:[~2024-05-06 8:33 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-01 14:55 [PATCH RFC v6 00/10] iio: adc: add new ad7380 driver Julien Stephan
2024-05-01 14:55 ` [PATCH RFC v6 01/10] dt-bindings: iio: adc: Add binding for AD7380 ADCs Julien Stephan
2024-05-01 14:55 ` [PATCH RFC v6 02/10] iio: adc: ad7380: new driver " Julien Stephan
2024-05-06 13:56 ` Jonathan Cameron
2024-05-01 14:55 ` [PATCH RFC v6 03/10] dt-bindings: iio: adc: ad7380: add pseudo-differential parts Julien Stephan
2024-05-01 14:55 ` [PATCH RFC v6 04/10] iio: adc: ad7380: add support for " Julien Stephan
2024-05-01 14:55 ` [PATCH RFC v6 05/10] iio: adc: ad7380: prepare for parts with more channels Julien Stephan
2024-05-01 14:55 ` [PATCH RFC v6 06/10] dt-bindings: iio: adc: ad7380: add support for ad738x-4 4 channels variants Julien Stephan
2024-05-01 14:55 ` [PATCH RFC v6 07/10] " Julien Stephan
2024-05-01 14:55 ` [PATCH RFC v6 08/10] iio: adc: ad7380: add oversampling support Julien Stephan
2024-05-06 8:20 ` Nuno Sá
2024-05-06 14:05 ` Jonathan Cameron
2024-05-01 14:55 ` [PATCH RFC v6 09/10] iio: adc: ad7380: add support for rolling average oversampling mode Julien Stephan
2024-05-06 8:33 ` Nuno Sá [this message]
2024-05-06 14:17 ` Jonathan Cameron
2024-05-06 15:04 ` David Lechner
2024-05-08 11:25 ` Jonathan Cameron
2024-05-09 22:01 ` David Lechner
2024-05-11 11:47 ` Jonathan Cameron
2024-05-01 14:55 ` [PATCH RFC v6 10/10] iio: adc: ad7380: add support for resolution boost Julien Stephan
2024-05-06 8:55 ` Nuno Sá
2024-05-06 13:46 ` Jonathan Cameron
2024-05-06 14:20 ` Jonathan Cameron
2024-05-06 14:44 ` David Lechner
2024-05-08 11:32 ` Jonathan Cameron
2024-05-06 15:09 ` David Lechner
2024-05-06 14:29 ` Jonathan Cameron
2024-05-06 21:45 ` David Lechner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9cfbe67f24cf4e0f69ee7f3769d85469e0738ee2.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=jstephan@baylibre.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).