diff options
Diffstat (limited to 'board/fennel')
-rw-r--r-- | board/fennel/board.c | 103 | ||||
-rw-r--r-- | board/fennel/board.h | 4 | ||||
-rw-r--r-- | board/fennel/gpio.inc | 2 |
3 files changed, 108 insertions, 1 deletions
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, |