diff options
author | Inno.Park <ih.yoo.park@samsung.corp-partner.google.com> | 2020-06-15 16:50:44 +0900 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-30 16:10:40 +0000 |
commit | c8f9edd807133b07b988936bf68216bc33092aa0 (patch) | |
tree | a9e46516e22ea5dcb02b171c970a51cc77da73fe | |
parent | 7dbc5ba08a80e53c41ab720749a2637ffea486f4 (diff) | |
download | chrome-ec-c8f9edd807133b07b988936bf68216bc33092aa0.tar.gz |
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 <ih.yoo.park@samsung.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2256967
Reviewed-by: Bob Moragues <moragues@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Commit-Queue: Bob Moragues <moragues@chromium.org>
(cherry picked from commit 6c131d859105c3e699cbc4df17e10b3e332ebc93)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2275717
-rw-r--r-- | driver/accelgyro_bmi160.c | 22 |
1 files 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; } |