linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table
@ 2015-01-05  9:21 Daniel Baluta
  2015-01-05 23:00 ` Hartmut Knaack
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Baluta @ 2015-01-05  9:21 UTC (permalink / raw)
  To: jic23, knaack.h
  Cc: lars, pmeerw, daniel.baluta, srinivas.pandruvada, linux-iio,
	linux-kernel

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>
---
Changes since v1:
	* use ARRAY_SIZE instead of an hardcoded value
	* review is at: https://lkml.org/lkml/2015/1/1/46

 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 b60b22d..a32ddbb 100644
--- a/drivers/iio/imu/kmx61.c
+++ b/drivers/iio/imu/kmx61.c
@@ -169,19 +169,18 @@ static const 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 >= ARRAY_SIZE(kmx61_samp_freq_table))
+		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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table
  2015-01-05  9:21 [PATCH v2] iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table Daniel Baluta
@ 2015-01-05 23:00 ` Hartmut Knaack
  2015-02-01 10:11   ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Hartmut Knaack @ 2015-01-05 23:00 UTC (permalink / raw)
  To: Daniel Baluta, jic23
  Cc: lars, pmeerw, srinivas.pandruvada, linux-iio, linux-kernel

Daniel Baluta schrieb am 05.01.2015 um 10:21:
> 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>
Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
> ---
> Changes since v1:
> 	* use ARRAY_SIZE instead of an hardcoded value
> 	* review is at: https://lkml.org/lkml/2015/1/1/46
> 
>  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 b60b22d..a32ddbb 100644
> --- a/drivers/iio/imu/kmx61.c
> +++ b/drivers/iio/imu/kmx61.c
> @@ -169,19 +169,18 @@ static const 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 >= ARRAY_SIZE(kmx61_samp_freq_table))
> +		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;
>  
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table
  2015-01-05 23:00 ` Hartmut Knaack
@ 2015-02-01 10:11   ` Jonathan Cameron
  2015-02-02 11:23     ` Daniel Baluta
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2015-02-01 10:11 UTC (permalink / raw)
  To: Hartmut Knaack, Daniel Baluta
  Cc: lars, pmeerw, srinivas.pandruvada, linux-iio, linux-kernel

On 05/01/15 23:00, Hartmut Knaack wrote:
> Daniel Baluta schrieb am 05.01.2015 um 10:21:
>> 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>
> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
Applied to the togreg branch of iio.git - pushed out as testing.

Sorry, I marked this to apply when there was a messup over my
first pull request then failed to actually pick it up once that
got resolved.  Now unfortunately 3.21 material.

Ah well, not a critical change anyway, more of a cleanup ;)

Jonathan
>> ---
>> Changes since v1:
>> 	* use ARRAY_SIZE instead of an hardcoded value
>> 	* review is at: https://lkml.org/lkml/2015/1/1/46
>>
>>  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 b60b22d..a32ddbb 100644
>> --- a/drivers/iio/imu/kmx61.c
>> +++ b/drivers/iio/imu/kmx61.c
>> @@ -169,19 +169,18 @@ static const 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 >= ARRAY_SIZE(kmx61_samp_freq_table))
>> +		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;
>>  
>>
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table
  2015-02-01 10:11   ` Jonathan Cameron
@ 2015-02-02 11:23     ` Daniel Baluta
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Baluta @ 2015-02-02 11:23 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hartmut Knaack, Daniel Baluta, Lars-Peter Clausen, Peter Meerwald,
	Srinivas Pandruvada, linux-iio@vger.kernel.org,
	Linux Kernel Mailing List

On Sun, Feb 1, 2015 at 12:11 PM, Jonathan Cameron <jic23@kernel.org> wrote:
> On 05/01/15 23:00, Hartmut Knaack wrote:
>> Daniel Baluta schrieb am 05.01.2015 um 10:21:
>>> 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>
>> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
> Applied to the togreg branch of iio.git - pushed out as testing.
>
> Sorry, I marked this to apply when there was a messup over my
> first pull request then failed to actually pick it up once that
> got resolved.  Now unfortunately 3.21 material.
>
> Ah well, not a critical change anyway, more of a cleanup ;)

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-02 11:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-05  9:21 [PATCH v2] iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table Daniel Baluta
2015-01-05 23:00 ` Hartmut Knaack
2015-02-01 10:11   ` Jonathan Cameron
2015-02-02 11:23     ` Daniel Baluta

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).