Skip to contentSkip to conversation

iio: accel: kxcjk-1013: Fix kxcjk10013_set_range

PATCH Applied Daniel Baluta 2 participants 2 messages Nov 10, 2014 – Nov 15, 2014 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: accel: kxcjk-1013: Fix kxcjk10013_set_range

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)
---
 drivers/iio/accel/kxcjk-1013.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/accel/kxcjk-1013.c +2 -0
index 98909a9..21f1279 100644
@@ -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);
 
Signature · 1 line
1.9.1
maintainer Applied
#1 lore raw
Quoted 17 lines · Daniel Baluta

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

Quoted 6 lines

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)

Applied to the fixes-togreg branch of iio.git and marked for stable. Thanks,

Quoted 18 lines
---
 drivers/iio/accel/kxcjk-1013.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iio/accel/kxcjk-1013.c +2 -0
index 98909a9..21f1279 100644
@@ -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);