From d28c10498cdbf007b97b5c0a9a951373574d4eea Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Sun, 17 May 2020 16:43:02 -0700 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2215751 Reviewed-by: Yuval Peress --- driver/accelgyro_bmi_common.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'driver/accelgyro_bmi_common.c') diff --git a/driver/accelgyro_bmi_common.c b/driver/accelgyro_bmi_common.c index 75447d54f8..d699c34cf0 100644 --- a/driver/accelgyro_bmi_common.c +++ b/driver/accelgyro_bmi_common.c @@ -536,15 +536,14 @@ int bmi_load_fifo(struct motion_sensor_t *s, uint32_t last_ts) return EC_SUCCESS; } -int bmi_set_range(const struct motion_sensor_t *s, int range, int rnd) +int bmi_set_range(struct motion_sensor_t *s, int range, int rnd) { int ret, range_tbl_size; uint8_t reg_val, ctrl_reg; const struct bmi_accel_param_pair *ranges; - struct accelgyro_saved_data_t *data = BMI_GET_SAVED_DATA(s); if (s->type == MOTIONSENSE_TYPE_MAG) { - data->range = range; + s->current_range = range; return EC_SUCCESS; } @@ -556,18 +555,11 @@ int bmi_set_range(const struct motion_sensor_t *s, int range, int rnd) ctrl_reg, reg_val); /* Now that we have set the range, update the driver's value. */ if (ret == EC_SUCCESS) - data->range = bmi_get_engineering_val(reg_val, ranges, - range_tbl_size); + s->current_range = bmi_get_engineering_val(reg_val, ranges, + range_tbl_size); return ret; } -int bmi_get_range(const struct motion_sensor_t *s) -{ - struct accelgyro_saved_data_t *data = BMI_GET_SAVED_DATA(s); - - return data->range; -} - int bmi_get_data_rate(const struct motion_sensor_t *s) { struct accelgyro_saved_data_t *data = BMI_GET_SAVED_DATA(s); -- cgit v1.2.1