From: "Nuno Sá" <noname.nuno@gmail.com>
To: Ramona Gradinariu <ramona.bolboaca13@gmail.com>,
linux-kernel@vger.kernel.org, jic23@kernel.org,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
conor+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
robh@kernel.org, nuno.sa@analog.com
Subject: Re: [PATCH v4 06/10] drivers: iio: imu: adis16475: generic computation for sample rate
Date: Fri, 24 May 2024 12:59:12 +0200 [thread overview]
Message-ID: <7be63d9ed78848cb1ee43edae0d97720641daf44.camel@gmail.com> (raw)
In-Reply-To: <20240524090030.336427-7-ramona.bolboaca13@gmail.com>
On Fri, 2024-05-24 at 12:00 +0300, Ramona Gradinariu wrote:
> Currently adis16475 supports a sample rate between 1900 and 2100 Hz.
> This patch changes the setting of sample rate from hardcoded values to
> a generic computation based on the internal clock frequency.
> This is a preparatory patch for adding support for adis1657x family
> devices which allow sample rates between 3900 and 4100 Hz.
>
> Signed-off-by: Ramona Gradinariu <ramona.bolboaca13@gmail.com>
> ---
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> no changes in v4
> drivers/iio/imu/adis16475.c | 39 +++++++++++++++++++++----------------
> 1 file changed, 22 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/iio/imu/adis16475.c b/drivers/iio/imu/adis16475.c
> index ab955efdad92..c589f214259b 100644
> --- a/drivers/iio/imu/adis16475.c
> +++ b/drivers/iio/imu/adis16475.c
> @@ -310,6 +310,9 @@ static int adis16475_set_freq(struct adis16475 *st, const u32
> freq)
> u16 dec;
> int ret;
> u32 sample_rate = st->clk_freq;
> + /* The optimal sample rate for the supported IMUs is between int_clk - 100
> and int_clk + 100. */
> + u32 max_sample_rate = st->info->int_clk * 1000 + 100000;
> + u32 min_sample_rate = st->info->int_clk * 1000 - 100000;
>
> if (!freq)
> return -EINVAL;
> @@ -317,8 +320,9 @@ static int adis16475_set_freq(struct adis16475 *st, const u32
> freq)
> adis_dev_lock(&st->adis);
> /*
> * When using sync scaled mode, the input clock needs to be scaled so that
> we have
> - * an IMU sample rate between (optimally) 1900 and 2100. After this, we
> can use the
> - * decimation filter to lower the sampling rate in order to get what the
> user wants.
> + * an IMU sample rate between (optimally) int_clk - 100 and int_clk + 100.
> + * After this, we can use the decimation filter to lower the sampling rate
> in order
> + * to get what the user wants.
> * Optimally, the user sample rate is a multiple of both the IMU sample
> rate and
> * the input clock. Hence, calculating the sync_scale dynamically gives us
> better
> * chances of achieving a perfect/integer value for DEC_RATE. The math
> here is:
> @@ -336,23 +340,24 @@ static int adis16475_set_freq(struct adis16475 *st, const u32
> freq)
> * solution. In this case, we get the highest multiple of the
> input clock
> * lower than the IMU max sample rate.
> */
> - if (scaled_rate > 2100000)
> - scaled_rate = 2100000 / st->clk_freq * st->clk_freq;
> + if (scaled_rate > max_sample_rate)
> + scaled_rate = max_sample_rate / st->clk_freq * st-
> >clk_freq;
> else
> - scaled_rate = 2100000 / scaled_rate * scaled_rate;
> + scaled_rate = max_sample_rate / scaled_rate * scaled_rate;
>
> /*
> * This is not an hard requirement but it's not advised to run the
> IMU
> - * with a sample rate lower than 1900Hz due to possible
> undersampling
> - * issues. However, there are users that might really want to take
> the risk.
> - * Hence, we provide a module parameter for them. If set, we allow
> sample
> - * rates lower than 1.9KHz. By default, we won't allow this and we
> just roundup
> - * the rate to the next multiple of the input clock bigger than
> 1.9KHz. This
> - * is done like this as in some cases (when DEC_RATE is 0) might
> give
> - * us the closest value to the one desired by the user...
> + * with a sample rate lower than internal clock frequency, due to
> possible
> + * undersampling issues. However, there are users that might
> really want
> + * to take the risk. Hence, we provide a module parameter for
> them. If set,
> + * we allow sample rates lower than internal clock frequency.
> + * By default, we won't allow this and we just roundup the rate to
> the next
> + * multiple of the input clock. This is done like this as in some
> cases
> + * (when DEC_RATE is 0) might give us the closest value to the one
> desired
> + * by the user...
> */
> - if (scaled_rate < 1900000 && !low_rate_allow)
> - scaled_rate = roundup(1900000, st->clk_freq);
> + if (scaled_rate < min_sample_rate && !low_rate_allow)
> + scaled_rate = roundup(min_sample_rate, st->clk_freq);
>
> sync_scale = scaled_rate / st->clk_freq;
> ret = __adis_write_reg_16(&st->adis, ADIS16475_REG_UP_SCALE,
> sync_scale);
> @@ -1359,6 +1364,7 @@ static int adis16475_config_sync_mode(struct adis16475 *st)
> struct device *dev = &st->adis.spi->dev;
> const struct adis16475_sync *sync;
> u32 sync_mode;
> + u16 max_sample_rate = st->info->int_clk + 100;
>
> /* default to internal clk */
> st->clk_freq = st->info->int_clk * 1000;
> @@ -1398,10 +1404,9 @@ static int adis16475_config_sync_mode(struct adis16475 *st)
> /*
> * In sync scaled mode, the IMU sample rate is the
> clk_freq * sync_scale.
> * Hence, default the IMU sample rate to the highest
> multiple of the input
> - * clock lower than the IMU max sample rate. The optimal
> range is
> - * 1900-2100 sps...
> + * clock lower than the IMU max sample rate.
> */
> - up_scale = 2100 / st->clk_freq;
> + up_scale = max_sample_rate / st->clk_freq;
>
> ret = __adis_write_reg_16(&st->adis,
> ADIS16475_REG_UP_SCALE,
> --
> 2.34.1
>
next prev parent reply other threads:[~2024-05-24 10:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-24 9:00 [PATCH v4 00/10] adis16501 and adis1657x support Ramona Gradinariu
2024-05-24 9:00 ` [PATCH v4 01/10] dt-bindings: iio: imu: Add ADIS16501 compatibles Ramona Gradinariu
2024-05-24 9:00 ` [PATCH v4 02/10] drivers: iio: imu: Add support for ADIS16501 Ramona Gradinariu
2024-05-24 10:58 ` Nuno Sá
2024-05-24 9:00 ` [PATCH v4 03/10] iio: imu: adis16475: Re-define ADIS16475_DATA Ramona Gradinariu
2024-05-24 9:00 ` [PATCH v4 04/10] iio: imu: adis_buffer: Add buffer setup API with buffer attributes Ramona Gradinariu
2024-05-24 10:58 ` Nuno Sá
2024-05-26 12:38 ` Jonathan Cameron
2024-05-24 9:00 ` [PATCH v4 05/10] iio: imu: adis16475: Create push single sample API Ramona Gradinariu
2024-05-24 10:58 ` Nuno Sá
2024-05-24 9:00 ` [PATCH v4 06/10] drivers: iio: imu: adis16475: generic computation for sample rate Ramona Gradinariu
2024-05-24 10:59 ` Nuno Sá [this message]
2024-05-24 9:00 ` [PATCH v4 07/10] iio: imu: adis_trigger: Allow level interrupts for FIFO readings Ramona Gradinariu
2024-05-24 10:59 ` Nuno Sá
2024-05-24 9:00 ` [PATCH v4 08/10] iio: imu: adis16475: Re-define ADIS16475_DATA Ramona Gradinariu
2024-05-24 10:47 ` Nuno Sá
2024-05-26 12:43 ` Jonathan Cameron
2024-05-24 9:00 ` [PATCH v4 09/10] dt-bindings: iio: imu: Add ADIS1657X family devices compatibles Ramona Gradinariu
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=7be63d9ed78848cb1ee43edae0d97720641daf44.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=ramona.bolboaca13@gmail.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