diff options
Diffstat (limited to 'board/coachz/board.c')
-rw-r--r-- | board/coachz/board.c | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/board/coachz/board.c b/board/coachz/board.c index 6b97944eca..377ce00939 100644 --- a/board/coachz/board.c +++ b/board/coachz/board.c @@ -13,6 +13,7 @@ #include "extpower.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi_common.h" +#include "driver/accelgyro_bmi260.h" #include "driver/ppc/sn5s330.h" #include "driver/tcpm/ps8xxx.h" #include "driver/tcpm/tcpci.h" @@ -328,6 +329,9 @@ const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = { static struct mutex g_lid_mutex; static struct bmi_drv_data_t g_bmi160_data; +static struct bmi_drv_data_t g_bmi260_data; + +bool is_bmi260_present; /* Matrix to rotate accelerometer into standard reference frame */ const mat33_fp_t lid_standard_ref = { @@ -380,8 +384,86 @@ struct motion_sensor_t motion_sensors[] = { .max_frequency = BMI_GYRO_MAX_FREQ, }, }; + +struct motion_sensor_t motion_sensors_260[] = { + /* + * Note: bmi260: supports accelerometer and gyro sensor + * Requirement: accelerometer sensor must init before gyro sensor + * DO NOT change the order of the following table. + */ + [LID_ACCEL] = { + .name = "Lid Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI260, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &bmi260_drv, + .mutex = &g_lid_mutex, + .drv_data = &g_bmi260_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS, + .rot_standard_ref = &lid_standard_ref, + .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */ + .min_frequency = BMI_ACCEL_MIN_FREQ, + .max_frequency = BMI_ACCEL_MAX_FREQ, + .config = { + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, + }, + [LID_GYRO] = { + .name = "Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI260, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_LID, + .drv = &bmi260_drv, + .mutex = &g_lid_mutex, + .drv_data = &g_bmi260_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS, + .default_range = 1000, /* dps */ + .rot_standard_ref = &lid_standard_ref, + .min_frequency = BMI_GYRO_MIN_FREQ, + .max_frequency = BMI_GYRO_MAX_FREQ, + }, +}; + const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +static void board_detect_motionsensor(void) +{ + int val = -1; + + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + return; + + /* Check base accelgyro chip */ + bmi_read8(motion_sensors[LID_ACCEL].port, + motion_sensors[LID_ACCEL].i2c_spi_addr_flags, + BMI260_CHIP_ID, &val); + if (val == BMI260_CHIP_ID_MAJOR) { + motion_sensors[LID_ACCEL] = motion_sensors_260[LID_ACCEL]; + motion_sensors[LID_GYRO] = motion_sensors_260[LID_GYRO]; + is_bmi260_present = 1; + } else { + is_bmi260_present = 0; + } +} +DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_detect_motionsensor, + HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_INIT, board_detect_motionsensor, HOOK_PRIO_DEFAULT + 1); + +void motion_interrupt(enum gpio_signal signal) +{ + if (is_bmi260_present) { + bmi260_interrupt(signal); + } else { + bmi160_interrupt(signal); + } +} + /* Initialize board. */ static void board_init(void) { @@ -657,4 +739,3 @@ int battery_set_vendor_param(uint32_t param, uint32_t value) { return EC_ERROR_UNIMPLEMENTED; } - |