summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2018-01-24 08:28:03 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-03-19 19:21:21 -0700
commit94f5413159518e798800ca41916c02af00a6e2c8 (patch)
tree76424bc8dcd3938da10fccec08e8038f0bb51547
parentb87bea3289d8ea050f0b482972f6e04ecb8823b1 (diff)
downloadchrome-ec-94f5413159518e798800ca41916c02af00a6e2c8.tar.gz
driver: lis2dh: fix gain units
Accelerometer reports accelerating in mg. Fix gain to that full range (2g, 4g or 8g) returns 2<<15. BUG=b:73546254 BRANCH=master TEST=compile Change-Id: I2873a641985fa800709a2d30b031c2b6e3fcb39e Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/924407 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--driver/accel_lis2dh.c12
-rw-r--r--driver/accel_lis2dh.h31
2 files changed, 7 insertions, 36 deletions
diff --git a/driver/accel_lis2dh.c b/driver/accel_lis2dh.c
index a02b1df1b0..3bba013b71 100644
--- a/driver/accel_lis2dh.c
+++ b/driver/accel_lis2dh.c
@@ -53,25 +53,25 @@ static int enable_fifo(const struct motion_sensor_t *s, int mode, int en_dis)
*/
static int set_range(const struct motion_sensor_t *s, int range, int rnd)
{
- int err, normalized_rate;
+ int err, normalized_range;
struct stprivate_data *data = s->drv_data;
int val;
val = LIS2DH_FS_TO_REG(range);
- normalized_rate = LIS2DH_FS_TO_NORMALIZE(range);
+ normalized_range = ST_NORMALIZE_RATE(range);
- if (rnd && (range < normalized_rate))
+ if (rnd && (range < normalized_range))
val++;
/* Adjust rounded values */
if (val > LIS2DH_FS_16G_VAL) {
val = LIS2DH_FS_16G_VAL;
- normalized_rate = 16;
+ normalized_range = 16;
}
if (val < LIS2DH_FS_2G_VAL) {
val = LIS2DH_FS_2G_VAL;
- normalized_rate = 2;
+ normalized_range = 2;
}
/* Lock accel resource to prevent another task from attempting
@@ -82,7 +82,7 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd)
/* Save Gain in range for speed up data path */
if (err == EC_SUCCESS)
- data->base.range = LIS2DH_FS_TO_GAIN(normalized_rate);
+ data->base.range = normalized_range;
mutex_unlock(s->mutex);
return EC_SUCCESS;
diff --git a/driver/accel_lis2dh.h b/driver/accel_lis2dh.h
index 48e5bb4fab..4a01cc995c 100644
--- a/driver/accel_lis2dh.h
+++ b/driver/accel_lis2dh.h
@@ -122,37 +122,8 @@ enum lis2dh_odr {
/* Full scale range Mask register */
#define LIS2DH_FS_MASK 0x30
-/* Acc FS value */
-enum lis2dh_fs {
- LIS2DH_FS_2G_VAL = 0x00,
- LIS2DH_FS_4G_VAL,
- LIS2DH_FS_8G_VAL,
- LIS2DH_FS_16G_VAL,
- LIS2DH_FS_LIST_NUM
-};
-
/* FS reg value from Full Scale */
-#define LIS2DH_FS_TO_REG(_fs) \
- (31 - __builtin_clz(_fs) - 1)
-
-/* Full Scale range real value normalized to sensor capabilities */
-#define LIS2DH_FS_TO_NORMALIZE(_fs) \
- (1 << (31 - __builtin_clz(_fs)))
-
-/* Acc Gain value */
-#define LIS2DH_FS_2G_GAIN 4
-#define LIS2DH_FS_4G_GAIN 8
-#define LIS2DH_FS_8G_GAIN 16
-#define LIS2DH_FS_16G_GAIN 48
-
-/* Return Gain from Full Scale range
- * TODO: This work only for 2, 4 and 8 G full scale */
-#define LIS2DH_FS_TO_GAIN(_fs) \
- (LIS2DH_FS_2G_GAIN << (30 - __builtin_clz(_fs)))
-
-/* Return Full Scale Range from normalized gain */
-#define LIS2DH_GAIN_TO_FS(_gain) \
- (1 << (30 - __builtin_clz(_gain)))
+#define LIS2DH_FS_TO_REG(_fs) (__fls(_fs) - 1)
/* Sensor resolution in number of bits
* This sensor has variable precision (8/10/12 bits) depending Power Mode