From 88b521505f967d58da29d07a015830284def54af Mon Sep 17 00:00:00 2001 From: wen zhang Date: Thu, 22 Jul 2021 16:35:05 +0800 Subject: Fennel: add the support for ICM42607 Bosh notice that BMI160 are going EOL, so we intend to import ICM42607 for Fennel BUG=b:194251601 BRANCH=kukui TEST=1.make BOARD=fennel 2.ectool motionsense can get the sensor data 3.rotate the DUT and check the direction of the frame Change-Id: I87e8b78078c2fe74246e2ce03d67315df7e9cab8 Signed-off-by: wen zhang Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3045032 Reviewed-by: Ting Shen --- board/fennel/board.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ board/fennel/board.h | 4 ++ board/fennel/gpio.inc | 2 +- 3 files changed, 108 insertions(+), 1 deletion(-) (limited to 'board/fennel') diff --git a/board/fennel/board.c b/board/fennel/board.c index 92b23e3dfc..32decaac0c 100644 --- a/board/fennel/board.c +++ b/board/fennel/board.c @@ -16,6 +16,8 @@ #include "console.h" #include "driver/accel_lis2dw12.h" #include "driver/accelgyro_bmi_common.h" +#include "driver/accelgyro_icm_common.h" +#include "driver/accelgyro_icm42607.h" #include "driver/battery/max17055.h" #include "driver/bc12/pi3usb9201.h" #include "driver/charger/isl923x.h" @@ -350,6 +352,61 @@ static const mat33_fp_t lid_standard_ref = { static struct stprivate_data g_lis2dwl_data; /* Base accel private data */ static struct bmi_drv_data_t g_bmi160_data; +static struct icm_drv_data_t g_icm42607_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; + +struct motion_sensor_t icm42607_base_accel = { + .name = "Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_ICM42607, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &icm42607_drv, + .mutex = &g_base_mutex, + .drv_data = &g_icm42607_data, + .port = CONFIG_SPI_ACCEL_PORT, + .i2c_spi_addr_flags = ACCEL_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT), + .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs.*/ + .rot_standard_ref = NULL, + .min_frequency = ICM42607_ACCEL_MIN_FREQ, + .max_frequency = ICM42607_ACCEL_MAX_FREQ, + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | 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 icm42607_base_gyro = { + .name = "Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_ICM42607, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &icm42607_drv, + .mutex = &g_base_mutex, + .drv_data = &g_icm42607_data, + .port = CONFIG_SPI_ACCEL_PORT, + .i2c_spi_addr_flags = ACCEL_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT), + .default_range = 1000, /* dps */ + .rot_standard_ref = NULL, + .min_frequency = ICM42607_GYRO_MIN_FREQ, + .max_frequency = ICM42607_GYRO_MAX_FREQ, +}; struct motion_sensor_t motion_sensors[] = { [LID_ACCEL] = { @@ -430,6 +487,52 @@ struct motion_sensor_t motion_sensors[] = { }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +static void board_detect_motionsensor(void) +{ + int ret; + int val; + + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + return; + if (base_accelgyro_config != BASE_GYRO_NONE) + return; + /* Check base accelgyro chip */ + ret = icm_read8(&icm42607_base_accel, + ICM42607_REG_WHO_AM_I, &val); + if (ret) + ccprints("Get ICM fail."); + if (val == ICM42607_CHIP_ICM42607P) { + motion_sensors[BASE_ACCEL] = icm42607_base_accel; + motion_sensors[BASE_GYRO] = icm42607_base_gyro; + } + base_accelgyro_config = (val == ICM42607_CHIP_ICM42607P) + ? BASE_GYRO_ICM426XX : BASE_GYRO_BMI160; + ccprints("BASE Accelgyro: %s", (val == ICM42607_CHIP_ICM42607P) + ? "ICM42607" : "BMI160"); +} +DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_detect_motionsensor, + HOOK_PRIO_DEFAULT); +/* + * board_spi_enable() will be called in the board_init() when sysjump to rw + * the board_init() is DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT) + * the board_detect_motionsensor() reads data via sensor SPI + * so the priority of board_detect_motionsensor should be HOOK_PRIO_DEFAULT+1 + */ +DECLARE_HOOK(HOOK_INIT, board_detect_motionsensor, HOOK_PRIO_DEFAULT + 1); + +void motion_interrupt(enum gpio_signal signal) +{ + switch (base_accelgyro_config) { + case BASE_GYRO_ICM426XX: + icm42607_interrupt(signal); + break; + case BASE_GYRO_BMI160: + default: + bmi160_interrupt(signal); + break; + } +} + const struct it8801_pwm_t it8801_pwm_channels[] = { [IT8801_PWM_CH_KBLIGHT] = {.index = 4}, }; diff --git a/board/fennel/board.h b/board/fennel/board.h index 71a7c91e28..448c7debf0 100644 --- a/board/fennel/board.h +++ b/board/fennel/board.h @@ -57,6 +57,9 @@ #define CONFIG_ACCEL_INTERRUPTS #define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#define CONFIG_ACCELGYRO_ICM42607 /* Base accel second source*/ +#define CONFIG_ACCELGYRO_ICM42607_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL) #define CONFIG_ALS #define CONFIG_CMD_ACCEL_INFO @@ -143,6 +146,7 @@ void emmc_cmd_interrupt(enum gpio_signal signal); void bc12_interrupt(enum gpio_signal signal); void board_reset_pd_mcu(void); int board_get_version(void); +void motion_interrupt(enum gpio_signal signal); /* returns the i2c port number of charger/battery */ int board_get_charger_i2c(void); diff --git a/board/fennel/gpio.inc b/board/fennel/gpio.inc index 28d4035031..29518fbc4e 100644 --- a/board/fennel/gpio.inc +++ b/board/fennel/gpio.inc @@ -22,7 +22,7 @@ GPIO_INT(PMIC_EC_RESETB, PIN(B, 7), GPIO_INT_BOTH | GPIO_PULL_DOWN, GPIO_INT(WARM_RESET_REQ, PIN(A, 3), GPIO_INT_RISING | GPIO_PULL_DOWN, chipset_reset_request_interrupt) GPIO_INT_RW(ACCEL_INT_ODL, PIN(A, 4), GPIO_INT_FALLING | GPIO_SEL_1P8V | GPIO_PULL_UP, - bmi160_interrupt) + motion_interrupt) GPIO_INT_RO(EMMC_CMD, PIN(B, 15), GPIO_INT_FALLING, emmc_cmd_interrupt) GPIO_INT(SPI1_NSS, PIN(A, 15), GPIO_INT_BOTH | GPIO_PULL_UP, -- cgit v1.2.1