aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorDaniel Baluta <daniel.baluta@intel.com>2015-01-05 04:21:42 -0500
committerJonathan Cameron <jic23@kernel.org>2015-02-03 16:03:20 -0500
commita36385a2613c0755164ec53e8b7a42d4d11f65b9 (patch)
tree8f1df9886acfd94f0176bd8413f9770bc6a2865c /drivers/iio
parent1e716a15ce5e5840cac0fb4cd6ca79d70d3568a9 (diff)
iio: imu: kmx61: Drop odr_bits from kmx61_samp_freq_table
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> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/imu/kmx61.c64
1 files changed, 26 insertions, 38 deletions
diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
index 5cc3692acf37..32e5f96a6477 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};
169static const struct { 169static const struct {
170 int val; 170 int val;
171 int val2; 171 int val2;
172 u8 odr_bits; 172} kmx61_samp_freq_table[] = { {12, 500000},
173} kmx61_samp_freq_table[] = { {12, 500000, 0x00}, 173 {25, 0},
174 {25, 0, 0x01}, 174 {50, 0},
175 {50, 0, 0x02}, 175 {100, 0},
176 {100, 0, 0x03}, 176 {200, 0},
177 {200, 0, 0x04}, 177 {400, 0},
178 {400, 0, 0x05}, 178 {800, 0},
179 {800, 0, 0x06}, 179 {1600, 0},
180 {1600, 0, 0x07}, 180 {0, 781000},
181 {0, 781000, 0x08}, 181 {1, 563000},
182 {1, 563000, 0x09}, 182 {3, 125000},
183 {3, 125000, 0x0A}, 183 {6, 250000} };
184 {6, 250000, 0x0B} };
185 184
186static const struct { 185static const struct {
187 int val; 186 int val;
@@ -302,24 +301,10 @@ static int kmx61_convert_freq_to_bit(int val, int val2)
302 for (i = 0; i < ARRAY_SIZE(kmx61_samp_freq_table); i++) 301 for (i = 0; i < ARRAY_SIZE(kmx61_samp_freq_table); i++)
303 if (val == kmx61_samp_freq_table[i].val && 302 if (val == kmx61_samp_freq_table[i].val &&
304 val2 == kmx61_samp_freq_table[i].val2) 303 val2 == kmx61_samp_freq_table[i].val2)
305 return kmx61_samp_freq_table[i].odr_bits; 304 return i;
306 return -EINVAL;
307}
308
309static int kmx61_convert_bit_to_freq(u8 odr_bits, int *val, int *val2)
310{
311 int i;
312
313 for (i = 0; i < ARRAY_SIZE(kmx61_samp_freq_table); i++)
314 if (odr_bits == kmx61_samp_freq_table[i].odr_bits) {
315 *val = kmx61_samp_freq_table[i].val;
316 *val2 = kmx61_samp_freq_table[i].val2;
317 return 0;
318 }
319 return -EINVAL; 305 return -EINVAL;
320} 306}
321 307
322
323static int kmx61_convert_wake_up_odr_to_bit(int val, int val2) 308static int kmx61_convert_wake_up_odr_to_bit(int val, int val2)
324{ 309{
325 int i; 310 int i;
@@ -478,7 +463,7 @@ static int kmx61_set_odr(struct kmx61_data *data, int val, int val2, u8 device)
478 463
479static int kmx61_get_odr(struct kmx61_data *data, int *val, int *val2, 464static int kmx61_get_odr(struct kmx61_data *data, int *val, int *val2,
480 u8 device) 465 u8 device)
481{ int i; 466{
482 u8 lodr_bits; 467 u8 lodr_bits;
483 468
484 if (device & KMX61_ACC) 469 if (device & KMX61_ACC)
@@ -490,13 +475,13 @@ static int kmx61_get_odr(struct kmx61_data *data, int *val, int *val2,
490 else 475 else
491 return -EINVAL; 476 return -EINVAL;
492 477
493 for (i = 0; i < ARRAY_SIZE(kmx61_samp_freq_table); i++) 478 if (lodr_bits >= ARRAY_SIZE(kmx61_samp_freq_table))
494 if (lodr_bits == kmx61_samp_freq_table[i].odr_bits) { 479 return -EINVAL;
495 *val = kmx61_samp_freq_table[i].val; 480
496 *val2 = kmx61_samp_freq_table[i].val2; 481 *val = kmx61_samp_freq_table[lodr_bits].val;
497 return 0; 482 *val2 = kmx61_samp_freq_table[lodr_bits].val2;
498 } 483
499 return -EINVAL; 484 return 0;
500} 485}
501 486
502static int kmx61_set_range(struct kmx61_data *data, u8 range) 487static int kmx61_set_range(struct kmx61_data *data, u8 range)
@@ -580,8 +565,11 @@ static int kmx61_chip_init(struct kmx61_data *data)
580 } 565 }
581 data->odr_bits = ret; 566 data->odr_bits = ret;
582 567
583 /* set output data rate for wake up (motion detection) function */ 568 /*
584 ret = kmx61_convert_bit_to_freq(data->odr_bits, &val, &val2); 569 * set output data rate for wake up (motion detection) function
570 * to match data rate for accelerometer sampling
571 */
572 ret = kmx61_get_odr(data, &val, &val2, KMX61_ACC);
585 if (ret < 0) 573 if (ret < 0)
586 return ret; 574 return ret;
587 575