diff options
author | Devin Lu <Devin.Lu@quantatw.com> | 2021-07-26 15:48:04 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-03 01:30:25 +0000 |
commit | 9b35963509b0d6ea3e5fd1530f4b6dffcb301c66 (patch) | |
tree | f6eace512c221c3d3634942c2bc670b0065e4413 /board/garg/board.c | |
parent | 9010da429dc83dab3e961d76987f809cc3d4379a (diff) | |
download | chrome-ec-9b35963509b0d6ea3e5fd1530f4b6dffcb301c66.tar.gz |
garg: Add 2nd base accelerometer
This patch adds a 2nd base accelerometer icm-40608.
BUG=b:194632295
BRANCH=firmware-octopus-11297.B
TEST=watch ectool motionsense
Signed-off-by: Devin Lu <Devin.Lu@quantatw.com>
Change-Id: I99716c34b8519447db7fe9903904046d216ae7e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3067144
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'board/garg/board.c')
-rw-r--r-- | board/garg/board.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/board/garg/board.c b/board/garg/board.c index 32ea8569be..ec74c69af7 100644 --- a/board/garg/board.c +++ b/board/garg/board.c @@ -9,12 +9,15 @@ #include "adc_chip.h" #include "battery.h" #include "button.h" +#include "cbi_ssfc.h" #include "charge_manager.h" #include "charge_state.h" #include "common.h" #include "cros_board_info.h" #include "driver/accel_kionix.h" #include "driver/accelgyro_bmi_common.h" +#include "driver/accelgyro_icm426xx.h" +#include "driver/accelgyro_icm_common.h" #include "driver/charger/bd9995x.h" #include "driver/ppc/nx20p348x.h" #include "driver/tcpm/anx7447.h" @@ -127,9 +130,16 @@ const mat33_fp_t base_standard_ref = { { 0, 0, FLOAT_TO_FP(1)} }; +const mat33_fp_t base_icm_ref = { + { FLOAT_TO_FP(-1), 0, 0}, + { 0, FLOAT_TO_FP(-1), 0}, + { 0, 0, FLOAT_TO_FP(1)} +}; + /* sensor private data */ static struct kionix_accel_data g_kx022_data; static struct bmi_drv_data_t g_bmi160_data; +static struct icm_drv_data_t g_icm426xx_data; /* Drivers */ struct motion_sensor_t motion_sensors[] = { @@ -207,6 +217,52 @@ struct motion_sensor_t motion_sensors[] = { unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +struct motion_sensor_t icm426xx_base_accel = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_ICM426XX, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &icm426xx_drv, + .mutex = &g_base_mutex, + .drv_data = &g_icm426xx_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS, + .rot_standard_ref = &base_icm_ref, + .default_range = 4, /* g */ + .min_frequency = ICM426XX_ACCEL_MIN_FREQ, + .max_frequency = ICM426XX_ACCEL_MAX_FREQ, + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 13000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + /* Sensor on for angle detection */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + }, +}; + +struct motion_sensor_t icm426xx_base_gyro = { + .name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_ICM426XX, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &icm426xx_drv, + .mutex = &g_base_mutex, + .drv_data = &g_icm426xx_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS, + .default_range = 1000, /* dps */ + .rot_standard_ref = &base_icm_ref, + .min_frequency = ICM426XX_GYRO_MIN_FREQ, + .max_frequency = ICM426XX_GYRO_MAX_FREQ, +}; + static int board_is_convertible(void) { /* @@ -219,6 +275,12 @@ static int board_is_convertible(void) static void board_update_sensor_config_from_sku(void) { if (board_is_convertible()) { + if (get_cbi_ssfc_sensor() == SSFC_SENSOR_ICM426XX) { + motion_sensors[BASE_ACCEL] = icm426xx_base_accel; + motion_sensors[BASE_GYRO] = icm426xx_base_gyro; + ccprints("BASE GYRO is ICM426XX"); + } else + ccprints("BASE GYRO is BMI160"); motion_sensor_count = ARRAY_SIZE(motion_sensors); /* Enable Base Accel interrupt */ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L); @@ -231,6 +293,19 @@ static void board_update_sensor_config_from_sku(void) } } +void sensor_interrupt(enum gpio_signal signal) +{ + switch (motion_sensors[BASE_ACCEL].chip) { + case MOTIONSENSE_CHIP_ICM426XX: + icm426xx_interrupt(signal); + break; + case MOTIONSENSE_CHIP_BMI160: + default: + bmi160_interrupt(signal); + break; + } +} + /* Read CBI from i2c eeprom and initialize variables for board variants */ static void cbi_init(void) { |