devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Stefan Popa <stefan.popa@analog.com>
Cc: robh+dt@kernel.org, Michael.Hennerich@analog.com,
	knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 4/7] iio: imu: adis16480: Calculate the sampling frequency in a generic way
Date: Sun, 3 Mar 2019 12:51:03 +0000	[thread overview]
Message-ID: <20190303125103.5d9b5e5a@archlinux> (raw)
In-Reply-To: <1551284068-4882-5-git-send-email-stefan.popa@analog.com>

On Wed, 27 Feb 2019 18:14:25 +0200
Stefan Popa <stefan.popa@analog.com> wrote:

> The adis1648x devices have an internal clock of 2.46 kSPS. The sampling
> frequency is calculated by applying a decimation rate which can take the
> maximum value of 2047.
> 
> Although all adis1648x devices are similar in this regard, devices that
> will use this feature will be added in the future.
> 
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Straight forward refactor so fine.

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

A comment inline about something in the old code!

Thanks,

Jonathan

> ---
>  drivers/iio/imu/adis16480.c | 18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
> index 5a2864a..92abc95 100644
> --- a/drivers/iio/imu/adis16480.c
> +++ b/drivers/iio/imu/adis16480.c
> @@ -125,6 +125,8 @@ struct adis16480_chip_info {
>  	unsigned int accel_max_val;
>  	unsigned int accel_max_scale;
>  	unsigned int temp_scale;
> +	unsigned int int_clk;
> +	unsigned int max_dec_rate;
>  };
>  
>  enum adis16480_int_pin {
> @@ -299,9 +301,9 @@ static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
>  	if (t <= 0)
>  		return -EINVAL;
>  
> -	t = 2460000 / t;
> -	if (t > 2048)
> -		t = 2048;
> +	t = st->chip_info->int_clk / t;
> +	if (t > st->chip_info->max_dec_rate)
> +		t = st->chip_info->max_dec_rate;
>  
>  	if (t != 0)
>  		t--;
> @@ -320,7 +322,7 @@ static int adis16480_get_freq(struct iio_dev *indio_dev, int *val, int *val2)
>  	if (ret < 0)
>  		return ret;
>  
> -	freq = 2460000 / (t + 1);
> +	freq = st->chip_info->int_clk / (t + 1);

I'm a little curious about why t + 1?  Presumably to avoid weird rounding
issues, but maybe a nice addition would be a comment explaining this.

>  	*val = freq / 1000;
>  	*val2 = (freq % 1000) * 1000;
>  
> @@ -726,6 +728,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
>  		.accel_max_val = IIO_M_S_2_TO_G(21973),
>  		.accel_max_scale = 18,
>  		.temp_scale = 5650, /* 5.65 milli degree Celsius */
> +		.int_clk = 2460000,
> +		.max_dec_rate = 2048,
>  	},
>  	[ADIS16480] = {
>  		.channels = adis16480_channels,
> @@ -735,6 +739,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
>  		.accel_max_val = IIO_M_S_2_TO_G(12500),
>  		.accel_max_scale = 10,
>  		.temp_scale = 5650, /* 5.65 milli degree Celsius */
> +		.int_clk = 2460000,
> +		.max_dec_rate = 2048,
>  	},
>  	[ADIS16485] = {
>  		.channels = adis16485_channels,
> @@ -744,6 +750,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
>  		.accel_max_val = IIO_M_S_2_TO_G(20000),
>  		.accel_max_scale = 5,
>  		.temp_scale = 5650, /* 5.65 milli degree Celsius */
> +		.int_clk = 2460000,
> +		.max_dec_rate = 2048,
>  	},
>  	[ADIS16488] = {
>  		.channels = adis16480_channels,
> @@ -753,6 +761,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
>  		.accel_max_val = IIO_M_S_2_TO_G(22500),
>  		.accel_max_scale = 18,
>  		.temp_scale = 5650, /* 5.65 milli degree Celsius */
> +		.int_clk = 2460000,
> +		.max_dec_rate = 2048,
>  	},
>  };
>  

  reply	other threads:[~2019-03-03 12:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 16:14 [PATCH v3 0/7] iio: imu: adis16480: Add support for ADIS1649x family of devices Stefan Popa
2019-02-27 16:14 ` [PATCH v3 1/7] iio: imu: adis16480: Add support for configurable drdy indicator Stefan Popa
2019-03-03 12:46   ` Jonathan Cameron
2019-02-27 16:14 ` [PATCH v3 2/7] iio: imu: adis16480: Add OF device ID table Stefan Popa
2019-03-03 12:46   ` Jonathan Cameron
2019-02-27 16:14 ` [PATCH v3 3/7] iio: imu: adis16480: Treat temperature scale in a generic way Stefan Popa
2019-03-03 12:47   ` Jonathan Cameron
2019-02-27 16:14 ` [PATCH v3 4/7] iio: imu: adis16480: Calculate the sampling frequency " Stefan Popa
2019-03-03 12:51   ` Jonathan Cameron [this message]
2019-02-27 16:14 ` [PATCH v3 5/7] iio: imu: adis16480: Deal with filter freq " Stefan Popa
2019-03-03 12:52   ` Jonathan Cameron
2019-02-27 16:14 ` [PATCH v3 6/7] iio: imu: adis16480: Add support for ADIS1649x family of devices Stefan Popa
2019-03-03 12:53   ` Jonathan Cameron
2019-02-27 16:14 ` [PATCH v3 7/7] iio: imu: adis16480: Add docs for ADIS16480 IMU Stefan Popa
2019-03-03 12:54   ` Jonathan Cameron

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=20190303125103.5d9b5e5a@archlinux \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=stefan.popa@analog.com \
    /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 NNTP newsgroup(s).