diff options
author | Jacky Wang <jacky5_wang@pegatron.corp-partner.google.com> | 2021-07-12 10:14:14 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-07-12 05:21:03 +0000 |
commit | f1577d473684d09cfe6094dccecaebab7763c135 (patch) | |
tree | 75fd9b69ded4e73e58740f182ed9483b6ab22b6e /board/copano | |
parent | c40b4340a458721efe98514f36670ca4f03d56ee (diff) | |
download | chrome-ec-f1577d473684d09cfe6094dccecaebab7763c135.tar.gz |
copano: gyro sensor add 2nd source icm-40608
gyro sensor add 2nd source icm-40608
BUG=b:193287286
BRANCH=firmware-volteer-13672.B
TEST=make BOARD=copano
1. Set CBI SSFC 0x2 and using command
"watch ectool motionsense lid_angle" for sensor icm-40608.
2. Using command "watch ectool motionsense lid_angle" for BMI160.
Signed-off-by: Jacky Wang <jacky5_wang@pegatron.corp-partner.google.com>
Change-Id: I5964bd6e00c395da9ce8b8015137c3a9fdfb010c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3020128
Reviewed-by: Zhuohao Lee <zhuohao@chromium.org>
Diffstat (limited to 'board/copano')
-rw-r--r-- | board/copano/board.h | 5 | ||||
-rw-r--r-- | board/copano/gpio.inc | 2 | ||||
-rw-r--r-- | board/copano/sensors.c | 72 |
3 files changed, 76 insertions, 3 deletions
diff --git a/board/copano/board.h b/board/copano/board.h index 07d63ede3f..1ad6a91361 100644 --- a/board/copano/board.h +++ b/board/copano/board.h @@ -48,6 +48,10 @@ #define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#define CONFIG_ACCELGYRO_ICM426XX +#define CONFIG_ACCELGYRO_ICM426XX_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) + /* Sensors without hardware FIFO are in forced mode */ #define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL) @@ -181,6 +185,7 @@ enum usbc_port { }; void board_reset_pd_mcu(void); +void motion_interrupt(enum gpio_signal signal); #endif /* !__ASSEMBLER__ */ diff --git a/board/copano/gpio.inc b/board/copano/gpio.inc index 73990cb19e..3159821e94 100644 --- a/board/copano/gpio.inc +++ b/board/copano/gpio.inc @@ -25,7 +25,7 @@ GPIO_INT(DSW_PWROK, PIN(C, 7), GPIO_INT_BOTH, power_signal_interrupt) GPIO_INT(PG_EC_ALL_SYS_PWRGD, PIN(F, 4), GPIO_INT_BOTH, power_signal_interrupt) /* Sensor Interrupts */ -GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt) +GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, motion_interrupt) GPIO_INT(TABLET_MODE_L, PIN(D, 2), GPIO_INT_BOTH, gmr_tablet_switch_isr) /* USB-C interrupts */ diff --git a/board/copano/sensors.c b/board/copano/sensors.c index 2f26911576..4d7ccdcebb 100644 --- a/board/copano/sensors.c +++ b/board/copano/sensors.c @@ -12,6 +12,8 @@ #include "driver/accel_kionix.h" #include "driver/accelgyro_bmi_common.h" #include "driver/accelgyro_bmi160.h" +#include "driver/accelgyro_icm_common.h" +#include "driver/accelgyro_icm426xx.h" #include "driver/sync.h" #include "keyboard_scan.h" #include "hooks.h" @@ -25,12 +27,12 @@ static struct mutex g_lid_accel_mutex; static struct mutex g_base_mutex; -/* BMA253 private data */ +/* sensor private data */ static struct accelgyro_saved_data_t g_bma253_data; static struct kionix_accel_data g_kx022_data; -/* BMI160 private data */ static struct bmi_drv_data_t g_bmi160_data; +static struct icm_drv_data_t g_icm426xx_data; /* Rotation matrix for the lid accelerometer */ static const mat33_fp_t lid_standard_ref = { @@ -45,6 +47,57 @@ const mat33_fp_t base_standard_ref = { { 0, 0, FLOAT_TO_FP(-1)} }; +const mat33_fp_t base_standard_ref_icm = { + { 0, FLOAT_TO_FP(1), 0}, + { FLOAT_TO_FP(1), 0, 0}, + { 0, 0, FLOAT_TO_FP(-1)}, +}; + +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_standard_ref_icm, + .min_frequency = ICM426XX_ACCEL_MIN_FREQ, + .max_frequency = ICM426XX_ACCEL_MAX_FREQ, + .default_range = 4, /* g */ + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + /* Sensor on in S3 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, +}; + +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_standard_ref_icm, + .min_frequency = ICM426XX_GYRO_MIN_FREQ, + .max_frequency = ICM426XX_GYRO_MAX_FREQ, +}; + struct motion_sensor_t kx022_lid_accel = { .name = "Lid Accel", .active_mask = SENSOR_ACTIVE_S0_S3, @@ -147,6 +200,14 @@ struct motion_sensor_t motion_sensors[] = { }; unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +void motion_interrupt(enum gpio_signal signal) +{ + if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_ICM426XX) + icm426xx_interrupt(signal); + else + bmi160_interrupt(signal); +} + static void baseboard_sensors_init(void) { if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_KX022) { @@ -155,6 +216,13 @@ static void baseboard_sensors_init(void) } else ccprints("LID_ACCEL is BMA253"); + if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_ICM426XX) { + motion_sensors[BASE_ACCEL] = icm426xx_base_accel; + motion_sensors[BASE_GYRO] = icm426xx_base_gyro; + ccprints("BASE ACCEL is ICM426XX"); + } else + ccprints("BASE ACCEL IS BMI160"); + /* Enable interrupt for the accel/gyro sensor */ gpio_enable_interrupt(GPIO_EC_IMU_INT_L); } |