diff options
Diffstat (limited to 'board/shuboz/board.c')
-rw-r--r-- | board/shuboz/board.c | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/board/shuboz/board.c b/board/shuboz/board.c index d752f291a9..1d73e19a63 100644 --- a/board/shuboz/board.c +++ b/board/shuboz/board.c @@ -5,8 +5,11 @@ #include "battery_smart.h" #include "button.h" +#include "cbi_ssfc.h" #include "cros_board_info.h" #include "driver/accelgyro_bmi_common.h" +#include "driver/accelgyro_icm_common.h" +#include "driver/accelgyro_icm426xx.h" #include "driver/accel_kionix.h" #include "driver/accel_kx022.h" #include "driver/bc12/pi3usb9201.h" @@ -50,6 +53,7 @@ static struct mutex g_base_mutex; /* sensor private data */ static struct kionix_accel_data g_kx022_data; static struct bmi_drv_data_t g_bmi160_data; +static struct icm_drv_data_t g_icm426xx_data; /* Matrix to rotate accelrator into standard reference frame */ static const mat33_fp_t lid_standard_ref = { @@ -62,9 +66,54 @@ static const mat33_fp_t base_standard_ref = { { FLOAT_TO_FP(-1), 0, 0}, { 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)}, +}; /* TODO(gcc >= 5.0) Remove the casts to const pointer at rot_standard_ref */ +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, + .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs. */ + .rot_standard_ref = &base_standard_ref_icm, + .min_frequency = ICM426XX_ACCEL_MIN_FREQ, + .max_frequency = ICM426XX_ACCEL_MAX_FREQ, + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100, + }, + }, +}; + +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 motion_sensors[] = { [LID_ACCEL] = { .name = "Lid Accel", @@ -143,6 +192,24 @@ struct motion_sensor_t motion_sensors[] = { unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +static void setup_base_gyro_config(void) +{ + if (get_cbi_ssfc_base_sensor() == SSFC_BASE_GYRO_ICM426XX) { + motion_sensors[BASE_ACCEL] = icm426xx_base_accel; + motion_sensors[BASE_GYRO] = icm426xx_base_gyro; + ccprints("BASE GYRO is ICM426XX"); + } else + ccprints("BASE GYRO is BMI160"); +} + +void motion_interrupt(enum gpio_signal signal) +{ + if (get_cbi_ssfc_base_sensor() == SSFC_BASE_GYRO_ICM426XX) + icm426xx_interrupt(signal); + else + bmi160_interrupt(signal); +} + /***************************************************************************** * Board suspend / resume */ @@ -503,6 +570,7 @@ static void setup_fw_config(void) ioex_enable_interrupt(IOEX_USB_C1_SBU_FAULT_DB_ODL); if (ec_config_has_lid_angle_tablet_mode()) { + setup_base_gyro_config(); /* Enable Gyro interrupts */ gpio_enable_interrupt(GPIO_6AXIS_INT_L); } else { |