diff options
author | Michael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com> | 2021-07-07 17:30:42 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-13 04:27:27 +0000 |
commit | b047dc4fb8a350f506ee79a2d1b9f49a901a4e42 (patch) | |
tree | 7ea8f3fa69d5bfa868b8f817a57f7237c6cd2abb | |
parent | baac50fa77ebc48cc7b8a5b0f50b7bcb6408f04e (diff) | |
download | chrome-ec-b047dc4fb8a350f506ee79a2d1b9f49a901a4e42.tar.gz |
delbin: gyro sensor add 2nd source icm-40608
gyro sensor add 2nd source icm-40608
BUG=b:192990527
BRANCH=volteer
TEST=make BOARD=delbin
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 BMI260.
Signed-off-by: Michael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com>
Change-Id: I4a9fef206cdbd49106deaa1411a3481bbd18d78c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3011103
Reviewed-by: Zhuohao Lee <zhuohao@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
(cherry picked from commit 72ccf07b499c6faa553d3da39db90a263618d2fa)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3088957
Commit-Queue: Zhuohao Lee <zhuohao@chromium.org>
-rw-r--r-- | board/delbin/board.h | 4 | ||||
-rw-r--r-- | board/delbin/gpio.inc | 2 | ||||
-rw-r--r-- | board/delbin/sensors.c | 73 |
3 files changed, 75 insertions, 4 deletions
diff --git a/board/delbin/board.h b/board/delbin/board.h index e14415bcf5..91f69a2bae 100644 --- a/board/delbin/board.h +++ b/board/delbin/board.h @@ -49,6 +49,9 @@ #define CONFIG_ACCELGYRO_BMI260 #define CONFIG_ACCELGYRO_BMI260_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) @@ -175,6 +178,7 @@ enum usbc_port { }; void board_reset_pd_mcu(void); +void motion_interrupt(enum gpio_signal signal); #endif /* !__ASSEMBLER__ */ diff --git a/board/delbin/gpio.inc b/board/delbin/gpio.inc index 143971ff65..333c638b0a 100644 --- a/board/delbin/gpio.inc +++ b/board/delbin/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, bmi260_interrupt) +GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, motion_interrupt) GPIO_INT(TABLET_MODE_L, PIN(9, 5), GPIO_INT_BOTH, gmr_tablet_switch_isr) /* * Lid g-sensor interrupt unused on Delbin, configure as regular input for diff --git a/board/delbin/sensors.c b/board/delbin/sensors.c index a2b2eb47e4..3885ae799f 100644 --- a/board/delbin/sensors.c +++ b/board/delbin/sensors.c @@ -12,6 +12,8 @@ #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_icm426xx.h" #include "keyboard_scan.h" #include "hooks.h" #include "i2c.h" @@ -24,12 +26,11 @@ 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; - -/* BMI260 private data */ static struct bmi_drv_data_t g_bmi260_data; +static struct icm_drv_data_t g_icm426xx_data; /* Rotation matrix for the lid accelerometer */ static const mat33_fp_t lid_standard_ref = { @@ -44,6 +45,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, @@ -146,6 +198,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 + bmi260_interrupt(signal); +} + static void baseboard_sensors_init(void) { if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_KX022) { @@ -154,6 +214,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 BMI260"); + /* Enable interrupt for the accel/gyro sensor */ gpio_enable_interrupt(GPIO_EC_IMU_INT_L); } |