linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Baluta <daniel.baluta@intel.com>
To: jic23@kernel.org, knaack.h@gmx.de
Cc: lars@metafoo.de, pmeerw@pmeerw.net, daniel.baluta@intel.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	srinivas.pandruvada@linux.intel.com
Subject: [PATCH 09/10] iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table
Date: Tue, 23 Dec 2014 15:22:32 +0200	[thread overview]
Message-ID: <1419340953-23161-10-git-send-email-daniel.baluta@intel.com> (raw)
In-Reply-To: <1419340953-23161-1-git-send-email-daniel.baluta@intel.com>

odr_bits values are between 0 and 11, so we can use the index
in kmx61_samp_freq_table instead of odr_bits structure member.

Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
---
 drivers/iio/imu/kmx61.c | 64 ++++++++++++++++++++-----------------------------
 1 file changed, 26 insertions(+), 38 deletions(-)

diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
index eb3900e..98369eb 100644
--- a/drivers/iio/imu/kmx61.c
+++ b/drivers/iio/imu/kmx61.c
@@ -169,19 +169,18 @@ u16 kmx61_uscale_table[] = {9582, 19163, 38326};
 static const struct {
 	int val;
 	int val2;
-	u8 odr_bits;
-} kmx61_samp_freq_table[] = { {12, 500000, 0x00},
-			{25, 0, 0x01},
-			{50, 0, 0x02},
-			{100, 0, 0x03},
-			{200, 0, 0x04},
-			{400, 0, 0x05},
-			{800, 0, 0x06},
-			{1600, 0, 0x07},
-			{0, 781000, 0x08},
-			{1, 563000, 0x09},
-			{3, 125000, 0x0A},
-			{6, 250000, 0x0B} };
+} kmx61_samp_freq_table[] = { {12, 500000},
+			{25, 0},
+			{50, 0},
+			{100, 0},
+			{200, 0},
+			{400, 0},
+			{800, 0},
+			{1600, 0},
+			{0, 781000},
+			{1, 563000},
+			{3, 125000},
+			{6, 250000} };
 
 static const struct {
 	int val;
@@ -302,24 +301,10 @@ static int kmx61_convert_freq_to_bit(int val, int val2)
 	for (i = 0; i < ARRAY_SIZE(kmx61_samp_freq_table); i++)
 		if (val == kmx61_samp_freq_table[i].val &&
 		    val2 == kmx61_samp_freq_table[i].val2)
-			return kmx61_samp_freq_table[i].odr_bits;
-	return -EINVAL;
-}
-
-static int kmx61_convert_bit_to_freq(u8 odr_bits, int *val, int *val2)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(kmx61_samp_freq_table); i++)
-		if (odr_bits == kmx61_samp_freq_table[i].odr_bits) {
-			*val = kmx61_samp_freq_table[i].val;
-			*val2 = kmx61_samp_freq_table[i].val2;
-			return 0;
-		}
+			return i;
 	return -EINVAL;
 }
 
-
 static int kmx61_convert_wake_up_odr_to_bit(int val, int val2)
 {
 	int i;
@@ -478,7 +463,7 @@ static int kmx61_set_odr(struct kmx61_data *data, int val, int val2, u8 device)
 
 static int kmx61_get_odr(struct kmx61_data *data, int *val, int *val2,
 			 u8 device)
-{	int i;
+{
 	u8 lodr_bits;
 
 	if (device & KMX61_ACC)
@@ -490,13 +475,13 @@ static int kmx61_get_odr(struct kmx61_data *data, int *val, int *val2,
 	else
 		return -EINVAL;
 
-	for (i = 0; i < ARRAY_SIZE(kmx61_samp_freq_table); i++)
-		if (lodr_bits == kmx61_samp_freq_table[i].odr_bits) {
-			*val = kmx61_samp_freq_table[i].val;
-			*val2 = kmx61_samp_freq_table[i].val2;
-			return 0;
-		}
-	return -EINVAL;
+	if (lodr_bits > 0xB)
+		return -EINVAL;
+
+	*val = kmx61_samp_freq_table[lodr_bits].val;
+	*val2 = kmx61_samp_freq_table[lodr_bits].val2;
+
+	return 0;
 }
 
 static int kmx61_set_range(struct kmx61_data *data, u8 range)
@@ -580,8 +565,11 @@ static int kmx61_chip_init(struct kmx61_data *data)
 	}
 	data->odr_bits = ret;
 
-	/* set output data rate for wake up (motion detection) function */
-	ret = kmx61_convert_bit_to_freq(data->odr_bits, &val, &val2);
+	/*
+	 * set output data rate for wake up (motion detection) function
+	 * to match data rate for accelerometer sampling
+	 */
+	ret = kmx61_get_odr(data, &val, &val2, KMX61_ACC);
 	if (ret < 0)
 		return ret;
 
-- 
1.9.1


  parent reply	other threads:[~2014-12-23 13:21 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-23 13:22 [PATCH 00/10] iio: KMX61 fixes Daniel Baluta
2014-12-23 13:22 ` [PATCH 01/10] iio: imu: kmx61: Save odr_bits for later use Daniel Baluta
2015-01-01 13:45   ` Hartmut Knaack
2015-01-04 10:41     ` Jonathan Cameron
2014-12-23 13:22 ` [PATCH 02/10] iio: imu: kmx61: Don't ignore kmx61_set_power_state errors Daniel Baluta
2015-01-01 13:45   ` Hartmut Knaack
2015-01-04 10:42     ` Jonathan Cameron
2014-12-23 13:22 ` [PATCH 03/10] iio: imu: kmx61: Enhance error handling Daniel Baluta
2015-01-01 13:47   ` Hartmut Knaack
2015-01-04 10:45     ` Jonathan Cameron
2015-01-05  8:57       ` Daniel Baluta
2014-12-23 13:22 ` [PATCH 04/10] iio: imu: kmx61: Fixup parameters alignment Daniel Baluta
2015-01-01 13:47   ` Hartmut Knaack
2015-01-04 10:47     ` Jonathan Cameron
2014-12-23 13:22 ` [PATCH 05/10] iio: imu: kmx61: Drop unused device parameter Daniel Baluta
2015-01-01 13:49   ` Hartmut Knaack
2014-12-23 13:22 ` [PATCH 06/10] iio: imu: kmx61: Use false instead of 0 for ev_enable_state Daniel Baluta
2015-01-01 13:50   ` Hartmut Knaack
2015-01-04 10:49     ` Jonathan Cameron
2014-12-23 13:22 ` [PATCH 07/10] iio: imu: kmx61: Fix device initialization when setting trigger state Daniel Baluta
2015-01-01 13:51   ` Hartmut Knaack
2015-01-04 10:51     ` Jonathan Cameron
2014-12-23 13:22 ` [PATCH 08/10] iio: imu: kmx61: Remove unnecessary REG_INS1 read Daniel Baluta
2015-01-01 13:51   ` Hartmut Knaack
2015-01-04 10:54     ` Jonathan Cameron
2014-12-23 13:22 ` Daniel Baluta [this message]
2015-01-01 13:53   ` [PATCH 09/10] iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table Hartmut Knaack
2015-01-04 10:55     ` Jonathan Cameron
2015-01-04 11:19       ` Hartmut Knaack
2014-12-23 13:22 ` [PATCH 10/10] iio: imu: kmx61: Use correct base when reading data Daniel Baluta
2015-01-01 13:54   ` Hartmut Knaack
2014-12-26  9:57 ` [PATCH 00/10] iio: KMX61 fixes 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=1419340953-23161-10-git-send-email-daniel.baluta@intel.com \
    --to=daniel.baluta@intel.com \
    --cc=jic23@kernel.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=srinivas.pandruvada@linux.intel.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).