linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@cam.ac.uk>
Cc: linux-iio@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 13/15] iio:adis16400: Add support for the 52.85 Hz base sampling rate
Date: Wed, 16 Jan 2013 13:48:49 +0100	[thread overview]
Message-ID: <1358340531-31350-13-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1358340531-31350-1-git-send-email-lars@metafoo.de>

The adis16400 and similar have two different base sampling rate available, from
which the actual sampling rate is derived. 1638 Hz and 52.85 Hz, switching to
the lower base sampling rate allows to support lower sampling rates.

This patch adds support for switching to the lower base sampling rate if the
requested sampling frequency is outside of the range which can be supported by
the higher base sampling rate.

The function which is used to read the current sampling rate already has support
for the lower sampling rate, so no changes are required there.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/imu/adis16400_core.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
index 8551fde..58699ac 100644
--- a/drivers/iio/imu/adis16400_core.c
+++ b/drivers/iio/imu/adis16400_core.c
@@ -92,18 +92,26 @@ static int adis16400_get_freq(struct adis16400_state *st)
 static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq)
 {
 	unsigned int t;
+	uint8_t val = 0;
 
 	t = 1638404 / freq;
-	if (t > 0)
+	if (t >= 128) {
+		val |= ADIS16400_SMPL_PRD_TIME_BASE;
+		t = 52851 / freq;
+		if (t >= 128)
+			t = 127;
+	} else if (t != 0) {
 		t--;
-	t &= ADIS16400_SMPL_PRD_DIV_MASK;
+	}
+
+	val |= t;
 
-	if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A)
+	if (t >= 0x0A || (val & ADIS16400_SMPL_PRD_TIME_BASE))
 		st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW;
 	else
 		st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST;
 
-	return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, t);
+	return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val);
 }
 
 static ssize_t adis16400_read_frequency(struct device *dev,
-- 
1.8.0


  parent reply	other threads:[~2013-01-16 12:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-16 12:48 [PATCH 01/15] staging:iio:adis16400: Don't pass 0 to ilog2 Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 02/15] staging:iio:adis16400: Fix and cleanup 3db filter setting Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 03/15] staging:iio:adis16400: Remove unused default_scan_mask Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 04/15] staging:iio:adis16400: Use adis library Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 05/15] staging:iio:adis16400: Use triggered buffer setup helper function Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 06/15] staging:iio:adis16400: Add helper macros for channel declaration Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 07/15] staging:iio:adis16400: Preallocate transfer message Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 08/15] staging:iio:adis16400: Remove unit suffix from samplerate attribute Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 09/15] staging:iio:adis16400: Remove samplerate_available attribute Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 10/15] staging:iio:adis16400: Code style cleanup Lars-Peter Clausen
2013-01-16 12:58   ` Jonathan Cameron
2013-01-16 13:11     ` Lars-Peter Clausen
2013-01-16 13:57       ` Manuel Stahl
2013-01-16 14:07         ` Lars-Peter Clausen
2013-01-16 14:09           ` Manuel Stahl
2013-01-16 18:34             ` Jonathan Cameron
2013-01-17  9:18               ` Manuel Stahl
2013-01-16 12:48 ` [PATCH 11/15] staging:iio: Move adis16400 out of staging Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 12/15] iio:adis16400: Increase samplerate precession Lars-Peter Clausen
2013-01-16 12:48 ` Lars-Peter Clausen [this message]
2013-01-16 12:48 ` [PATCH 14/15] iio:adis16400: Expose some debug information in debugfs Lars-Peter Clausen
2013-01-16 12:48 ` [PATCH 15/15] iio:adis16400: Add support for the adis16448 Lars-Peter Clausen
2013-01-19 13:50 ` [PATCH 01/15] staging:iio:adis16400: Don't pass 0 to ilog2 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=1358340531-31350-13-git-send-email-lars@metafoo.de \
    --to=lars@metafoo.de \
    --cc=jic23@cam.ac.uk \
    --cc=linux-iio@vger.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 NNTP newsgroup(s).