From fbf83724e6ec93c324135c5181b5f310ad6048a3 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Tue, 21 Mar 2023 23:14:19 -0700 Subject: driver: Add support for Spoof mode to all remaining accelerometers Spoof mode was added for few accelerometers (BMI160/260). Use accelgyro_bmi_common as model and use it for all accelerometer. BUG=b:263221955 BRANCH=many TEST=In zephyr/program/nissa/program.conf, add CONFIG_PLATFORM_EC_ACCEL_SPOOF_MODE=y - Open the device at 90 degree check the sensors values: ectool motionsense: Motion sensing active Sensor 0: -592 15872 944 (raised, lid) Sensor 1: 803 -929 8134 (flat, base) Sensor 2: 0 0 0 - Spoof in place, in clamshell mode. ectool motionsense spoof -- 0 1 ectool motionsense spoof -- 1 1 - Spoof lid to be upside down: ectool motionsense spoof -- 0 1 -592 -15872 944 - Observe the screen goes in tablet mode. - Spoof lid accel back: ectool motionsense spoof -- 0 1 -592 15872 944 - Observe the screen goes in laptop mode. TEST=make buildall passes. Change-Id: Idd4632637226f9ae57416a8afe0c137780898d16 Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4358607 Reviewed-by: Daisuke Nojiri --- driver/accel_bma4xx.c | 5 ++++- driver/accel_lis2ds.c | 3 +++ driver/accel_lis2dw12.c | 3 +++ driver/accelgyro_bmi3xx.c | 5 ++++- driver/accelgyro_icm42607.c | 5 ++++- driver/accelgyro_icm426xx.c | 5 ++++- driver/accelgyro_lsm6dsm.c | 3 +++ driver/accelgyro_lsm6dso.c | 3 +++ 8 files changed, 28 insertions(+), 4 deletions(-) diff --git a/driver/accel_bma4xx.c b/driver/accel_bma4xx.c index a842b42d3a..4120f726c3 100644 --- a/driver/accel_bma4xx.c +++ b/driver/accel_bma4xx.c @@ -605,7 +605,7 @@ static void process_fifo_data(struct motion_sensor_t *s, uint8_t *data, ASSERT(data_bytes % 6 == 0); for (int i = 0; i < data_bytes; i += 6) { - intv3_t v; + int *v = s->raw_xyz; if (data[i + 1] == 0x80 && data[i] == 0) { /* 0x8000 means read overrun; out of data */ @@ -613,6 +613,9 @@ static void process_fifo_data(struct motion_sensor_t *s, uint8_t *data, } swizzle_sample_data(s, &data[i], v); + if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && + s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + v = s->spoof_xyz; if (IS_ENABLED(CONFIG_ACCEL_FIFO)) { struct ec_response_motion_sensor_data response = { .sensor_num = s - motion_sensors, diff --git a/driver/accel_lis2ds.c b/driver/accel_lis2ds.c index 2fea7524e5..db27d870e5 100644 --- a/driver/accel_lis2ds.c +++ b/driver/accel_lis2ds.c @@ -98,6 +98,9 @@ static int lis2ds_load_fifo(struct motion_sensor_t *s, uint16_t nsamples, /* Apply precision, sensitivity and rotation vector */ st_normalize(s, axis, &fifo[i]); + if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && + s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + axis = s->spoof_xyz; if (IS_ENABLED(CONFIG_ACCEL_FIFO)) { struct ec_response_motion_sensor_data vect; diff --git a/driver/accel_lis2dw12.c b/driver/accel_lis2dw12.c index f3f3ae8537..b9b4c255c2 100644 --- a/driver/accel_lis2dw12.c +++ b/driver/accel_lis2dw12.c @@ -122,6 +122,9 @@ static int lis2dw12_load_fifo(struct motion_sensor_t *s, int nsamples) /* Apply precision, sensitivity and rotation vector. */ st_normalize(s, axis, &fifo[i]); + if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && + s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + axis = s->spoof_xyz; if (IS_ENABLED(CONFIG_ACCEL_FIFO)) { struct ec_response_motion_sensor_data vect; /* Fill vector array. */ diff --git a/driver/accelgyro_bmi3xx.c b/driver/accelgyro_bmi3xx.c index 38c23f4942..179d7eb91a 100644 --- a/driver/accelgyro_bmi3xx.c +++ b/driver/accelgyro_bmi3xx.c @@ -230,7 +230,6 @@ static void bmi3_parse_fifo_data(struct motion_sensor_t *s, { struct bmi_drv_data_t *data = BMI_GET_DATA(s); uint16_t reg_data; - intv3_t v; int i; /* Start index for FIFO parsing after I2C sync word removal */ @@ -258,6 +257,7 @@ static void bmi3_parse_fifo_data(struct motion_sensor_t *s, while (fifo_size > 0) { for (i = 0; i < NUM_OF_PRIMARY_SENSOR; i++) { struct motion_sensor_t *sens_output = s + i; + int *v = sens_output->raw_xyz; if (data->flags & BIT(i + BMI_FIFO_FLAG_OFFSET)) { /* @@ -292,6 +292,9 @@ static void bmi3_parse_fifo_data(struct motion_sensor_t *s, rotate(v, *sens_output->rot_standard_ref, v); + if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && + s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + v = sens_output->spoof_xyz; if (IS_ENABLED(CONFIG_ACCEL_FIFO)) { struct ec_response_motion_sensor_data vect; diff --git a/driver/accelgyro_icm42607.c b/driver/accelgyro_icm42607.c index f57f11fae2..e0ed5b0d9d 100644 --- a/driver/accelgyro_icm42607.c +++ b/driver/accelgyro_icm42607.c @@ -313,12 +313,15 @@ static void __maybe_unused icm42607_push_fifo_data(struct motion_sensor_t *s, const uint8_t *raw, uint32_t ts) { - intv3_t v; struct ec_response_motion_sensor_data vect; + int *v = s->raw_xyz; if (icm42607_normalize(s, v, raw) != EC_SUCCESS) return; + if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && + s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + v = s->spoof_xyz; if (IS_ENABLED(CONFIG_ACCEL_FIFO)) { vect.data[X] = v[X]; vect.data[Y] = v[Y]; diff --git a/driver/accelgyro_icm426xx.c b/driver/accelgyro_icm426xx.c index c3c9e2225f..f82cb2d718 100644 --- a/driver/accelgyro_icm426xx.c +++ b/driver/accelgyro_icm426xx.c @@ -186,12 +186,15 @@ static void __maybe_unused icm426xx_push_fifo_data(struct motion_sensor_t *s, const uint8_t *raw, uint32_t ts) { - intv3_t v; struct ec_response_motion_sensor_data vect; + int *v = s->raw_xyz; if (icm426xx_normalize(s, v, raw) != EC_SUCCESS) return; + if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && + s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + v = s->spoof_xyz; if (IS_ENABLED(CONFIG_ACCEL_FIFO)) { vect.data[X] = v[X]; vect.data[Y] = v[Y]; diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c index 3cf76c5095..52966ddd2d 100644 --- a/driver/accelgyro_lsm6dsm.c +++ b/driver/accelgyro_lsm6dsm.c @@ -306,6 +306,9 @@ static void push_fifo_data(struct motion_sensor_t *accel, uint8_t *fifo, st_normalize(s, axis, fifo); } + if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && + s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + axis = s->spoof_xyz; if (IS_ENABLED(CONFIG_ACCEL_FIFO)) { struct ec_response_motion_sensor_data vect; diff --git a/driver/accelgyro_lsm6dso.c b/driver/accelgyro_lsm6dso.c index 3123d8f114..58679dbed9 100644 --- a/driver/accelgyro_lsm6dso.c +++ b/driver/accelgyro_lsm6dso.c @@ -149,6 +149,9 @@ static void push_fifo_data(struct motion_sensor_t *main_s, uint8_t *fifo, /* Apply precision, sensitivity and rotation. */ st_normalize(sensor, axis, ptr); + if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) && + sensor->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) + axis = sensor->spoof_xyz; if (IS_ENABLED(CONFIG_ACCEL_FIFO)) { struct ec_response_motion_sensor_data vect; -- cgit v1.2.1