diff options
-rw-r--r-- | board/shuboz/board.c | 70 | ||||
-rw-r--r-- | board/shuboz/board.h | 4 | ||||
-rw-r--r-- | board/shuboz/gpio.inc | 2 |
3 files changed, 74 insertions, 2 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 { diff --git a/board/shuboz/board.h b/board/shuboz/board.h index 5daaf46767..6c64cf5dda 100644 --- a/board/shuboz/board.h +++ b/board/shuboz/board.h @@ -39,6 +39,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_ACCEL_KX022 #define CONFIG_ACCEL_INTERRUPTS #define CONFIG_CMD_ACCELS @@ -172,6 +175,7 @@ void board_reset_pd_mcu(void); void tcpc_alert_event(enum gpio_signal signal); void bc12_interrupt(enum gpio_signal signal); void ppc_interrupt(enum gpio_signal signal); +void motion_interrupt(enum gpio_signal signal); #endif /* !__ASSEMBLER__ */ diff --git a/board/shuboz/gpio.inc b/board/shuboz/gpio.inc index ce1695ff68..b093a7e6d6 100644 --- a/board/shuboz/gpio.inc +++ b/board/shuboz/gpio.inc @@ -25,7 +25,7 @@ GPIO_INT(ACOK_OD, PIN(0, 0), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH, extpower_inter GPIO_INT(EC_WP_L, PIN(5, 0), GPIO_INT_BOTH, switch_interrupt) GPIO_INT(VOLUP_BTN_ODL, PIN(A, 6), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) GPIO_INT(VOLDN_BTN_ODL, PIN(9, 5), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) -GPIO_INT(6AXIS_INT_L, PIN(A, 0), GPIO_INT_FALLING | GPIO_PULL_UP, bmi160_interrupt) +GPIO_INT(6AXIS_INT_L, PIN(A, 0), GPIO_INT_FALLING | GPIO_PULL_UP, motion_interrupt) /* GPIO_INT_BOTH is required for PSL wake from hibernate, but we don't need an interrupt handler. */ GPIO(EC_RST_ODL, PIN(0, 2), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH) |