summaryrefslogtreecommitdiff
path: root/driver/accelgyro_icm426xx.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2020-05-17 16:43:02 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-12 03:23:26 +0000
commitd28c10498cdbf007b97b5c0a9a951373574d4eea (patch)
tree3d66ca06837aae98ff747fff85b439976e563045 /driver/accelgyro_icm426xx.c
parent9676f9291f60efdfb31373aeb77385ebb6e9f6e5 (diff)
downloadchrome-ec-d28c10498cdbf007b97b5c0a9a951373574d4eea.tar.gz
motion_sense: Make change in range permanent
When AP changes range, unlike offset or ODR, it was not surviving init() call. If the sensor is powered off in S3, at resume the range would be back to the default. To make it consistent with other attributes, remember range change until EC powers down. - remove get_range - add current_range to store the range currently used. This is modifiable by the AP - when the AP shutdown, revert current_range to default_range - Remove const attribute for sensor structure when init and set_range is called. BUG=chromium:1083791 BRANCH=none TEST=One eve branch, check range is preserved even after 'shutdown -h 0' Change-Id: Ia7126ac0cc9c3fef60b4464d95d6dd15e64b0fc4 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2215751 Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'driver/accelgyro_icm426xx.c')
-rw-r--r--driver/accelgyro_icm426xx.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/driver/accelgyro_icm426xx.c b/driver/accelgyro_icm426xx.c
index b83c166084..4f231fdcac 100644
--- a/driver/accelgyro_icm426xx.c
+++ b/driver/accelgyro_icm426xx.c
@@ -501,7 +501,7 @@ static int icm426xx_set_range(const struct motion_sensor_t *s, int range,
ret = icm_field_update8(s, reg, ICM426XX_FS_MASK,
ICM426XX_FS_SEL(reg_val));
if (ret == EC_SUCCESS)
- data->range = newrange;
+ s->current_range = newrange;
mutex_unlock(s->mutex);
@@ -661,7 +661,7 @@ static int icm426xx_set_offset(const struct motion_sensor_t *s,
{
struct accelgyro_saved_data_t *data = ICM_GET_SAVED_DATA(s);
intv3_t v = { offset[X], offset[Y], offset[Z] };
- int range, div1, div2;
+ int div1, div2;
int i;
/* unscale values and rotate back to chip frame */
@@ -670,16 +670,15 @@ static int icm426xx_set_offset(const struct motion_sensor_t *s,
rotate_inv(v, *s->rot_standard_ref, v);
/* convert raw data to hardware offset units */
- range = icm_get_range(s);
switch (s->type) {
case MOTIONSENSE_TYPE_ACCEL:
/* hardware offset is 1/2048g by LSB */
- div1 = range * 2048;
+ div1 = s->current_range * 2048;
div2 = 32768;
break;
case MOTIONSENSE_TYPE_GYRO:
/* hardware offset is 1/32dps by LSB */
- div1 = range * 32;
+ div1 = s->current_range * 32;
div2 = 32768;
break;
default:
@@ -696,7 +695,7 @@ static int icm426xx_get_offset(const struct motion_sensor_t *s, int16_t *offset,
{
struct accelgyro_saved_data_t *data = ICM_GET_SAVED_DATA(s);
intv3_t v;
- int range, div1, div2;
+ int div1, div2;
int i, ret;
ret = icm426xx_get_hw_offset(s, v);
@@ -704,17 +703,16 @@ static int icm426xx_get_offset(const struct motion_sensor_t *s, int16_t *offset,
return ret;
/* transform offset to raw data */
- range = icm_get_range(s);
switch (s->type) {
case MOTIONSENSE_TYPE_ACCEL:
/* hardware offset is 1/2048g by LSB */
div1 = 32768;
- div2 = 2048 * range;
+ div2 = 2048 * s->current_range;
break;
case MOTIONSENSE_TYPE_GYRO:
/* hardware offset is 1/32dps by LSB */
div1 = 32768;
- div2 = 32 * range;
+ div2 = 32 * s->current_range;
break;
default:
return EC_ERROR_INVAL;
@@ -954,7 +952,6 @@ const struct accelgyro_drv icm426xx_drv = {
.read = icm426xx_read,
.read_temp = icm426xx_read_temp,
.set_range = icm426xx_set_range,
- .get_range = icm_get_range,
.get_resolution = icm_get_resolution,
.set_data_rate = icm426xx_set_data_rate,
.get_data_rate = icm_get_data_rate,