mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-12 19:04:59 +00:00
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>
This commit is contained in:
committed by
chrome-bot
parent
b87bea3289
commit
94f5413159
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user