summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorEric Yilun Lin <yllin@chromium.org>2022-07-07 12:01:00 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-31 10:10:48 +0000
commit549d8c341ff0b91263fabdc1032ce40eab676498 (patch)
treeff4e1baf65621e190d3b664881d4a49024f8cadd /driver
parent62be401c46f7e24b9b483bf616a4302ba02485c3 (diff)
downloadchrome-ec-549d8c341ff0b91263fabdc1032ce40eab676498.tar.gz
bmi3xx: loop querying the written calibrated value
The critical path of writing the calibration value to the delay for writing calibrated data will be added up to 240ms, and this will exceed the EC/AP SPI communication timeout 200ms. This CL loops the querying the result for an early return. BUG=b:237953471 TEST=echo -n "0" \ > /sys/bus/iio/devices/iio\:device3/in_anglvel_x_calibbias and doesn't complain the timeout. BRANCH=none Change-Id: Ic14e54c53d8bd5c0d83bd1f3eac20a17c98a1bdc Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3750539 Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Commit-Queue: Gwendal Grignou <gwendal@chromium.org> Tested-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Huanhuan Liu <huanhuanl@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/accelgyro_bmi3xx.c60
1 files changed, 23 insertions, 37 deletions
diff --git a/driver/accelgyro_bmi3xx.c b/driver/accelgyro_bmi3xx.c
index cd17004810..5549a6eb7b 100644
--- a/driver/accelgyro_bmi3xx.c
+++ b/driver/accelgyro_bmi3xx.c
@@ -31,6 +31,8 @@
#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ##args)
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ##args)
+#define OFFSET_UPDATE_PER_TRY 10
+
/* Sensor definition */
STATIC_IF(CONFIG_BMI_ORIENTATION_SENSOR)
void irq_set_orientation(struct motion_sensor_t *s);
@@ -379,6 +381,24 @@ static int read_temp(const struct motion_sensor_t *s, int *temp_ptr)
return EC_ERROR_UNIMPLEMENTED;
}
+static int poll_offset(const struct motion_sensor_t *s, uint8_t *reg_data)
+{
+ /* Delay time for offset update */
+ for (int i = 0; i < OFFSET_UPDATE_DELAY; i += OFFSET_UPDATE_PER_TRY) {
+ msleep(OFFSET_UPDATE_PER_TRY);
+
+ /* Read the configuration from the feature engine register */
+ RETURN_ERROR(bmi3_read_n(s, BMI3_FEATURE_IO_1, reg_data, 4));
+
+ if ((reg_data[3] & BMI3_UGAIN_OFFS_UPD_COMPLETE) &&
+ ((reg_data[2] & BMI3_FEATURE_IO_1_ERROR_MASK) ==
+ BMI3_FEATURE_IO_1_NO_ERROR)) {
+ return EC_SUCCESS;
+ }
+ }
+ return EC_ERROR_NOT_CALIBRATED;
+}
+
static int reset_offset(const struct motion_sensor_t *s, uint8_t offset_en)
{
uint8_t offset_sel[2] = { BMI3_REG_UGAIN_OFF_SEL, 0 };
@@ -402,19 +422,7 @@ static int reset_offset(const struct motion_sensor_t *s, uint8_t offset_en)
8);
RETURN_ERROR(bmi3_write_n(s, BMI3_REG_CMD, reg_data, 2));
- /* Delay time for offset update */
- msleep(OFFSET_UPDATE_DELAY);
-
- /* Read the configuration from the feature engine register */
- RETURN_ERROR(bmi3_read_n(s, BMI3_FEATURE_IO_1, reg_data, 4));
-
- if ((reg_data[3] & BMI3_UGAIN_OFFS_UPD_COMPLETE) &&
- ((reg_data[2] & BMI3_FEATURE_IO_1_ERROR_MASK) ==
- BMI3_FEATURE_IO_1_NO_ERROR)) {
- return EC_SUCCESS;
- }
-
- return EC_ERROR_NOT_CALIBRATED;
+ return poll_offset(s, reg_data);
}
int get_gyro_offset(const struct motion_sensor_t *s, intv3_t v)
@@ -478,18 +486,7 @@ static int write_gyro_offset(const struct motion_sensor_t *s, int *val)
8);
RETURN_ERROR(bmi3_write_n(s, BMI3_REG_CMD, reg_data, 2));
- msleep(OFFSET_UPDATE_DELAY);
-
- /* Read the configuration from the feature engine register */
- RETURN_ERROR(bmi3_read_n(s, BMI3_FEATURE_IO_1, reg_data, 4));
-
- if ((reg_data[3] & BMI3_UGAIN_OFFS_UPD_COMPLETE) &&
- ((reg_data[2] & BMI3_FEATURE_IO_1_ERROR_MASK) ==
- BMI3_FEATURE_IO_1_NO_ERROR)) {
- return EC_SUCCESS;
- }
-
- return EC_ERROR_NOT_CALIBRATED;
+ return poll_offset(s, reg_data);
}
int set_gyro_offset(const struct motion_sensor_t *s, intv3_t v)
@@ -594,18 +591,7 @@ static int write_accel_offsets(const struct motion_sensor_t *s, int *val)
RETURN_ERROR(bmi3_write_n(s, BMI3_REG_CMD, reg_data, 2));
- msleep(OFFSET_UPDATE_DELAY);
-
- /* Read the configuration from the feature engine register */
- RETURN_ERROR(bmi3_read_n(s, BMI3_FEATURE_IO_1, reg_data, 4));
-
- if ((reg_data[3] & BMI3_UGAIN_OFFS_UPD_COMPLETE) &&
- ((reg_data[2] & BMI3_FEATURE_IO_1_ERROR_MASK) ==
- BMI3_FEATURE_IO_1_NO_ERROR)) {
- return EC_SUCCESS;
- }
-
- return EC_ERROR_NOT_CALIBRATED;
+ return poll_offset(s, reg_data);
}
int set_accel_offset(const struct motion_sensor_t *s, intv3_t v,