From de2867d298194743d4f8776d43430e2556b5d5bf Mon Sep 17 00:00:00 2001 From: Mike Lee Date: Sat, 7 Aug 2021 13:45:42 +0800 Subject: storo: Add motion sense config for BMI220 Add BMI220 base sensor config for second source BUG=b:188373185 BRANCH=dedede TEST=Using ectool 'motionsense' verified lid angle goes from 0 to 360 and swtiches to tablet mode after crossing 200 threshold on re-work bmi220/bmi253 DUT Signed-off-by: Mike Lee Change-Id: I9e72bb898b2dbfe68e44248f0238982921c4a198 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3077596 Reviewed-by: Henry Sun Reviewed-by: Aseda Aboagye Reviewed-by: jesen Reviewed-by: Weimin Wu Commit-Queue: Aseda Aboagye --- board/storo/board.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ board/storo/board.h | 5 ++++ board/storo/cbi_ssfc.h | 3 ++- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/board/storo/board.c b/board/storo/board.c index 4981bedc8e..f864d230c2 100644 --- a/board/storo/board.c +++ b/board/storo/board.c @@ -17,6 +17,7 @@ #include "driver/accel_bma2x2.h" #include "driver/accel_kionix.h" #include "driver/accelgyro_bmi_common.h" +#include "driver/accelgyro_bmi260.h" #include "driver/accelgyro_icm_common.h" #include "driver/accelgyro_icm42607.h" #include "driver/bc12/pi3usb9201.h" @@ -753,6 +754,57 @@ struct motion_sensor_t icm42607_base_gyro = { .max_frequency = ICM42607_GYRO_MAX_FREQ, }; + +static struct bmi_drv_data_t g_bmi220_data; +const mat33_fp_t based_ref_bmi220 = { + { 0, FLOAT_TO_FP(1), 0}, + { FLOAT_TO_FP(-1), 0, 0}, + { 0, 0, FLOAT_TO_FP(1)} +}; +struct motion_sensor_t bmi220_base_accel = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI220, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi260_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi220_data, + .port = I2C_PORT_ACCEL, + .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS, + .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs.*/ + .rot_standard_ref = &based_ref_bmi220, + .min_frequency = BMI_ACCEL_MIN_FREQ, + .max_frequency = BMI_ACCEL_MAX_FREQ, + .config = { + [SENSOR_CONFIG_EC_S0] = { + .odr = 13000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + }, +}; + +struct motion_sensor_t bmi220_base_gyro = { + .name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI220, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi260_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi220_data, + .port = I2C_PORT_ACCEL, + .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS, + .default_range = 1000, /* dps */ + .rot_standard_ref = &based_ref_bmi220, + .min_frequency = BMI_GYRO_MIN_FREQ, + .max_frequency = BMI_GYRO_MAX_FREQ, +}; + void board_init(void) { int on; @@ -794,6 +846,11 @@ void board_init(void) icm42607_base_accel; motion_sensors[BASE_GYRO] = icm42607_base_gyro; CPRINTF("BASE GYRO is ICM42607"); + } else if (get_cbi_ssfc_base_sensor() == + SSFC_SENSOR_BMI220) { + motion_sensors[BASE_ACCEL] = bmi220_base_accel; + motion_sensors[BASE_GYRO] = bmi220_base_gyro; + CPRINTF("BASE GYRO is BMI220"); } else { CPRINTF("BASE GYRO is BMI160"); } @@ -823,6 +880,10 @@ void board_init(void) motion_sensors[BASE_ACCEL] = icm42607_base_accel; motion_sensors[BASE_GYRO] = icm42607_base_gyro; CPRINTF("BASE GYRO is ICM42607"); + } else if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BMI220) { + motion_sensors[BASE_ACCEL] = bmi220_base_accel; + motion_sensors[BASE_GYRO] = bmi220_base_gyro; + CPRINTF("BASE GYRO is BMI220"); } else { CPRINTF("BASE GYRO is BMI160"); } @@ -846,6 +907,9 @@ void motion_interrupt(enum gpio_signal signal) case SSFC_SENSOR_ICM42607: icm42607_interrupt(signal); break; + case SSFC_SENSOR_BMI220: + bmi260_interrupt(signal); + break; case SSFC_SENSOR_BMI160: default: bmi160_interrupt(signal); diff --git a/board/storo/board.h b/board/storo/board.h index a89bde6fcf..cb738e8245 100644 --- a/board/storo/board.h +++ b/board/storo/board.h @@ -50,6 +50,8 @@ #define CONFIG_ACCEL_KX022 #define CONFIG_ACCELGYRO_BMI160 /* Base accel */ #define CONFIG_ACCELGYRO_ICM42607 +#define CONFIG_ACCELGYRO_BMI220 +#define CONFIG_I2C_XFER_LARGE_TRANSFER /* Lid operates in forced mode, base in FIFO */ #define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL) @@ -61,6 +63,9 @@ #define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#define CONFIG_ACCELGYRO_BMI260_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) + #define CONFIG_ACCELGYRO_ICM42607_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) diff --git a/board/storo/cbi_ssfc.h b/board/storo/cbi_ssfc.h index 935049b6ae..f4a51b8e91 100644 --- a/board/storo/cbi_ssfc.h +++ b/board/storo/cbi_ssfc.h @@ -20,7 +20,8 @@ enum ec_ssfc_base_sensor { SSFC_SENSOR_BMI160 = 1, SSFC_SENSOR_ICM426XX = 2, SSFC_SENSOR_LSM6DSM = 3, - SSFC_SENSOR_ICM42607 = 4 + SSFC_SENSOR_ICM42607 = 4, + SSFC_SENSOR_BMI220 = 5 }; /* -- cgit v1.2.1