From 6c131d859105c3e699cbc4df17e10b3e332ebc93 Mon Sep 17 00:00:00 2001 From: "Inno.Park" Date: Mon, 15 Jun 2020 16:50:44 +0900 Subject: driver: bmi160: Increase the deadline for gyro calibration Current calibration timeout, 400ms, is not enough for gyro. Accel has done calibration under 100ms, whereas gyro usually takes 300ms ~ 700ms. So we need to increase timeout to 800ms in case of gyro. In addition, temporary set the least range during calibration to perform with full sensitivity. BUG=b:159557101 BRANCH=none TEST=check if gyro calibrated well without an error. 'echo 1 > /sys/bus/iio/devices/iio:device[gyro-index]/calibrate' Change-Id: Ib8c190d2969f6295e70cadd990999dfddf7a1b53 Signed-off-by: Inno.Park Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2256967 Reviewed-by: Bob Moragues Reviewed-by: Gwendal Grignou Commit-Queue: Bob Moragues --- driver/accelgyro_bmi160.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index 7beaa0de04..7959ac42ba 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -213,13 +213,14 @@ static int set_offset(const struct motion_sensor_t *s, static int perform_calib(const struct motion_sensor_t *s, int enable) { - int ret, val, en_flag, status, rate; - timestamp_t deadline; + int ret, val, en_flag, status, rate, range; + timestamp_t deadline, timeout; if (!enable) return EC_SUCCESS; rate = bmi_get_data_rate(s); + range = bmi_get_range(s); /* * Temporary set frequency to 100Hz to get enough data in a short * period of time. @@ -238,10 +239,24 @@ static int perform_calib(const struct motion_sensor_t *s, int enable) (BMI160_FOC_ACC_0G << BMI160_FOC_ACC_Y_OFFSET) | (val << BMI160_FOC_ACC_Z_OFFSET); en_flag = BMI160_OFFSET_ACC_EN; + /* + * Temporary set range to minimum to run calibration with + * full sensitivity + */ + bmi_set_range(s, 2, 0); + /* Timeout for accelerometer calibration */ + timeout.val = 400 * MSEC; break; case MOTIONSENSE_TYPE_GYRO: val = BMI160_FOC_GYRO_EN; en_flag = BMI160_OFFSET_GYRO_EN; + /* + * Temporary set range to minimum to run calibration with + * full sensitivity + */ + bmi_set_range(s, 125, 0); + /* Timeout for gyroscope calibration */ + timeout.val = 800 * MSEC; break; default: /* Not supported on Magnetometer */ @@ -252,7 +267,7 @@ static int perform_calib(const struct motion_sensor_t *s, int enable) BMI160_FOC_CONF, val); ret = bmi_write8(s->port, s->i2c_spi_addr_flags, BMI160_CMD_REG, BMI160_CMD_START_FOC); - deadline.val = get_time().val + 400 * MSEC; + deadline.val = get_time().val + timeout.val; do { if (timestamp_expired(deadline, NULL)) { ret = EC_RES_TIMEOUT; @@ -268,6 +283,7 @@ static int perform_calib(const struct motion_sensor_t *s, int enable) /* Calibration is successful, and loaded, use the result */ ret = bmi_enable_reg8(s, BMI160_OFFSET_EN_GYR98, en_flag, 1); end_perform_calib: + bmi_set_range(s, range, 0); set_data_rate(s, rate, 0); return ret; } -- cgit v1.2.1