diff options
author | Michael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com> | 2021-08-12 15:43:38 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-24 17:36:11 +0000 |
commit | 147c35724eeaf2527e4feffcab4cf483678be37c (patch) | |
tree | c9be5a21860748a740d79851941a11b5970a6554 | |
parent | 98bd2f530200a22cc34cb1a8001617dcf0f00b27 (diff) | |
download | chrome-ec-147c35724eeaf2527e4feffcab4cf483678be37c.tar.gz |
helios: gyro sensor add 2nd source icm40608
gyro sensor add 2nd source icm-40608
BUG=b:196286603
BRANCH=hatch
TEST=make BAORD=helios
Using command "watch ectool motionsense lid_angle".
Signed-off-by: Michael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com>
Change-Id: I06c1ea21b353959f07dd16a3732d23c638d031bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3089086
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Jacky Wang <jacky5_wang@pegatron.corp-partner.google.com>
Commit-Queue: Tim Wawrzynczak <twawrzynczak@chromium.org>
(cherry picked from commit c97daf56d5d5d57594bf61a7a316b6e26c143179)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3115808
-rw-r--r-- | board/helios/board.c | 94 | ||||
-rw-r--r-- | board/helios/board.h | 5 | ||||
-rw-r--r-- | board/helios/gpio.inc | 2 |
3 files changed, 100 insertions, 1 deletions
diff --git a/board/helios/board.c b/board/helios/board.c index c6e6ceacff..2144dbdc13 100644 --- a/board/helios/board.c +++ b/board/helios/board.c @@ -12,6 +12,8 @@ #include "cros_board_info.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi160.h" +#include "driver/accelgyro_icm_common.h" +#include "driver/accelgyro_icm426xx.h" #include "driver/als_opt3001.h" #include "driver/bc12/pi3usb9201.h" #include "driver/ppc/sn5s330.h" @@ -198,10 +200,19 @@ static struct mutex g_lid_mutex; /* Base accel private data */ static struct bmi160_drv_data_t g_bmi160_data; +static struct icm_drv_data_t g_icm426xx_data; /* BMA255 private data */ static struct accelgyro_saved_data_t g_bma255_data; +enum base_accelgyro_type { + BASE_GYRO_NONE = 0, + BASE_GYRO_BMI160 = 1, + BASE_GYRO_ICM426XX = 2, +}; + +static enum base_accelgyro_type base_accelgyro_config; + /* Matrix to rotate accelrator into standard reference frame */ static const mat33_fp_t base_standard_ref = { { 0, FLOAT_TO_FP(1), 0}, @@ -215,6 +226,57 @@ static const mat33_fp_t lid_standard_ref = { { 0, 0, FLOAT_TO_FP(-1)} }; +static const mat33_fp_t base_standard_ref_icm = { + { FLOAT_TO_FP(-1), 0, 0}, + { 0, FLOAT_TO_FP(1), 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_ACCEL, + .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, to meet CDD 7.3.1/C-1-4 reqs. */ + .config = { + [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, + .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_ACCEL, + .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 motion_sensors[] = { [LID_ACCEL] = { .name = "Lid Accel", @@ -288,6 +350,38 @@ struct motion_sensor_t motion_sensors[] = { }; unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +void motion_interrupt(enum gpio_signal signal) +{ + if (base_accelgyro_config == BASE_GYRO_ICM426XX) + icm426xx_interrupt(signal); + else + bmi160_interrupt(signal); +} + +static void board_detect_motionsense(void) +{ + int val; + + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + return; + if (base_accelgyro_config != BASE_GYRO_NONE) + return; + + icm_read8(&icm426xx_base_accel, ICM426XX_REG_WHO_AM_I, &val); + if (val == ICM426XX_CHIP_ICM40608) { + motion_sensors[BASE_ACCEL] = icm426xx_base_accel; + motion_sensors[BASE_GYRO] = icm426xx_base_gyro; + base_accelgyro_config = BASE_GYRO_ICM426XX; + ccprints("Base Accelgyro: ICM40608"); + } else { + base_accelgyro_config = BASE_GYRO_BMI160; + ccprints("Base Accelgyro: BMI160"); + } +} +DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_detect_motionsense, + HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_INIT, board_detect_motionsense, HOOK_PRIO_INIT_I2C + 1); + /******************************************************************************/ /* Physical fans. These are logically separate from pwm_channels. */ diff --git a/board/helios/board.h b/board/helios/board.h index e1445394c3..d2a0538e6a 100644 --- a/board/helios/board.h +++ b/board/helios/board.h @@ -32,6 +32,9 @@ #define CONFIG_ACCELGYRO_BMI160 #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) #define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT /* BMA253 Lid accel */ #define CONFIG_ACCEL_BMA255 @@ -150,6 +153,8 @@ enum battery_type { BATTERY_TYPE_COUNT, }; +void motion_interrupt(enum gpio_signal signal); + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/helios/gpio.inc b/board/helios/gpio.inc index ab8d9f4388..d16e1643be 100644 --- a/board/helios/gpio.inc +++ b/board/helios/gpio.inc @@ -28,7 +28,7 @@ GPIO_INT(PG_EC_ALL_SYS_PWRGD, PIN(F, 4), GPIO_INT_BOTH, power_signal_interrupt) GPIO_INT(PP5000_A_PG_OD, PIN(D, 7), GPIO_INT_BOTH, power_signal_interrupt) /* Sensor Interrupts */ -GPIO_INT(BASE_SIXAXIS_INT_L, PIN(5, 6), GPIO_INT_FALLING, bmi160_interrupt) +GPIO_INT(BASE_SIXAXIS_INT_L, PIN(5, 6), GPIO_INT_FALLING, motion_interrupt) /* USB-C interrupts */ GPIO_INT(USB_C0_PPC_INT_ODL, PIN(E, 0), GPIO_INT_FALLING, ppc_interrupt) |