iio: accel: kxcjk-1013: Fix kxcjk10013_set_range
authorDaniel Baluta <daniel.baluta@intel.com>
Mon, 10 Nov 2014 08:20:16 +0000 (10:20 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sat, 15 Nov 2014 16:11:28 +0000 (16:11 +0000)
Currently, we get the new GSEL bits by OR-ing the old values
with the new ones. This only works first time when the old
values are 0.

Startup:
* GSEL0 = 0, GSEL1 = 0

Set range to 4G: (GSEL0 = 1, GSEL1 = 0)
* GSEL0 = 0 | 1 = 1
* GSEL1 = 0 | 0 = 0
* correct

Change range to 2G: (GSEL0 = 0, GSEL1 = 0)
* GSEL0 = 1 | 0 = 1
* GSEL1 = 0 | 0 = 0
* wrong, GSEL0 should be 0

This has the nice effect that we can use the full scale range,
exported in in_accel_scale_available.

Fixes: a735e3d7f03 (iio: accel: kxcjk-1013: Set adjustable range)
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/accel/kxcjk-1013.c

index a23e58c4ed99b222b674ce2386c9c36a3809efbe..320aa72c0349ecabeae7ea4a0bdb59d2c84cd63d 100644 (file)
@@ -269,6 +269,8 @@ static int kxcjk1013_set_range(struct kxcjk1013_data *data, int range_index)
                return ret;
        }
 
+       ret &= ~(KXCJK1013_REG_CTRL1_BIT_GSEL0 |
+                KXCJK1013_REG_CTRL1_BIT_GSEL1);
        ret |= (KXCJK1013_scale_table[range_index].gsel_0 << 3);
        ret |= (KXCJK1013_scale_table[range_index].gsel_1 << 4);
 
This page took 0.026237 seconds and 5 git commands to generate.