diff options
-rw-r--r-- | baseboard/guybrush/base_fw_config.h | 1 | ||||
-rw-r--r-- | baseboard/guybrush/baseboard.h | 1 | ||||
-rw-r--r-- | board/guybrush/board.c | 132 | ||||
-rw-r--r-- | board/guybrush/board.h | 9 | ||||
-rw-r--r-- | board/guybrush/board_fw_config.c | 7 | ||||
-rw-r--r-- | board/guybrush/board_fw_config.h | 2 |
6 files changed, 125 insertions, 27 deletions
diff --git a/baseboard/guybrush/base_fw_config.h b/baseboard/guybrush/base_fw_config.h index 25463384af..2eea7a158f 100644 --- a/baseboard/guybrush/base_fw_config.h +++ b/baseboard/guybrush/base_fw_config.h @@ -46,5 +46,6 @@ bool board_has_kblight(void); enum board_usb_a1_retimer board_get_usb_a1_retimer(void); enum board_usb_c1_mux board_get_usb_c1_mux(void); enum board_form_factor board_get_form_factor(void); +bool board_is_convertible(void); #endif /* _GUYBRUSH_BASE_FW_CONFIG__H_ */ diff --git a/baseboard/guybrush/baseboard.h b/baseboard/guybrush/baseboard.h index 0aa01c7602..5c88843d64 100644 --- a/baseboard/guybrush/baseboard.h +++ b/baseboard/guybrush/baseboard.h @@ -113,6 +113,7 @@ #define CONFIG_TABLET_MODE #define CONFIG_GMR_TABLET_MODE #define GMR_TABLET_MODE_GPIO_L GPIO_TABLET_MODE +#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT /* Battery Config */ #define CONFIG_BATTERY_PRESENT_GPIO GPIO_EC_BATT_PRES_ODL diff --git a/board/guybrush/board.c b/board/guybrush/board.c index 09406e481c..917d2c4613 100644 --- a/board/guybrush/board.c +++ b/board/guybrush/board.c @@ -5,10 +5,14 @@ /* Guybrush board-specific configuration */ +#include "base_fw_config.h" +#include "board_fw_config.h" #include "button.h" #include "common.h" +#include "cros_board_info.h" #include "driver/accelgyro_bmi_common.h" #include "driver/accelgyro_bmi160.h" +#include "driver/accelgyro_bmi323.h" #include "driver/accel_bma422.h" #include "driver/retimer/ps8811.h" #include "driver/retimer/ps8818.h" @@ -26,24 +30,25 @@ #include "gpio_list.h" /* Must come after other header files. */ -/* Lid Sensor mutex */ +/* Motion sensor mutex */ static struct mutex g_lid_mutex; static struct mutex g_base_mutex; -/* Lid accel private data */ +/* Motion sensor private data */ static struct bmi_drv_data_t g_bmi160_data; +static struct bmi3xx_drv_data g_bmi323_data; static struct accelgyro_saved_data_t g_bma422_data; /* Matrix to rotate accelrator into standard reference frame */ const mat33_fp_t base_standard_ref = { - { 0, FLOAT_TO_FP(-1), 0}, - { FLOAT_TO_FP(1), 0, 0}, - { 0, 0, FLOAT_TO_FP(1)} + { FLOAT_TO_FP(-1), 0, 0}, + { 0, FLOAT_TO_FP(1), 0}, + { 0, 0, FLOAT_TO_FP(-1)} }; const mat33_fp_t lid_standard_ref = { - { FLOAT_TO_FP(-1), 0, 0}, - { 0, FLOAT_TO_FP(-1), 0}, + { 0, FLOAT_TO_FP(1), 0}, + { FLOAT_TO_FP(-1), 0, 0}, { 0, 0, FLOAT_TO_FP(1)} }; @@ -51,14 +56,14 @@ struct motion_sensor_t motion_sensors[] = { [BASE_ACCEL] = { .name = "Base Accel", .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_BMI160, + .chip = MOTIONSENSE_CHIP_BMI323, .type = MOTIONSENSE_TYPE_ACCEL, .location = MOTIONSENSE_LOC_BASE, - .drv = &bmi160_drv, + .drv = &bmi3xx_drv, .mutex = &g_base_mutex, - .drv_data = &g_bmi160_data, + .drv_data = &g_bmi323_data, .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, + .i2c_spi_addr_flags = BMI3_ADDR_I2C_PRIM, .rot_standard_ref = &base_standard_ref, .min_frequency = BMI_ACCEL_MIN_FREQ, .max_frequency = BMI_ACCEL_MAX_FREQ, @@ -107,27 +112,67 @@ struct motion_sensor_t motion_sensors[] = { [BASE_GYRO] = { .name = "Base Gyro", .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_BMI160, + .chip = MOTIONSENSE_CHIP_BMI323, .type = MOTIONSENSE_TYPE_GYRO, .location = MOTIONSENSE_LOC_BASE, - .drv = &bmi160_drv, + .drv = &bmi3xx_drv, .mutex = &g_base_mutex, - .drv_data = &g_bmi160_data, + .drv_data = &g_bmi323_data, .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, + .i2c_spi_addr_flags = BMI3_ADDR_I2C_PRIM, .default_range = 1000, /* dps */ .rot_standard_ref = &base_standard_ref, .min_frequency = BMI_GYRO_MIN_FREQ, .max_frequency = BMI_GYRO_MAX_FREQ, }, }; -const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); -static void board_init(void) -{ - /* TODO */ -} -DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); +struct motion_sensor_t bmi160_base_accel = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi160_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, + .rot_standard_ref = &base_standard_ref, + .min_frequency = BMI_ACCEL_MIN_FREQ, + .max_frequency = BMI_ACCEL_MAX_FREQ, + .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */ + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + /* Sensor on in S3 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 0, + }, + }, +}; + +struct motion_sensor_t bmi160_base_gyro = { + .name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi160_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, + .default_range = 1000, /* dps */ + .rot_standard_ref = &base_standard_ref, + .min_frequency = BMI_GYRO_MIN_FREQ, + .max_frequency = BMI_GYRO_MAX_FREQ, +}; __override enum ec_error_list board_a1_ps8811_retimer_init(const struct usb_mux *me) @@ -241,19 +286,54 @@ uint16_t board_anx7451_get_usb_i2c_addr(const struct usb_mux *me) return 0x2a; } +/* + * Base Gyro Sensor dynamic configuration + */ +static int base_gyro_config; + +static void board_update_motion_sensor_config(void) +{ + if (board_is_convertible()) { + if (get_board_version() == 1) { + motion_sensors[BASE_ACCEL] = bmi160_base_accel; + motion_sensors[BASE_GYRO] = bmi160_base_gyro; + base_gyro_config = BASE_GYRO_BMI160; + ccprints("BASE GYRO is BMI160"); + } else { + base_gyro_config = BASE_GYRO_BMI323; + ccprints("BASE GYRO is BMI323"); + } + + motion_sensor_count = ARRAY_SIZE(motion_sensors); + /* Enable Base Accel and Gyro interrupt */ + gpio_enable_interrupt(GPIO_6AXIS_INT_L); + } else { + motion_sensor_count = 0; + gmr_tablet_switch_disable(); + /* Base accel is not stuffed, don't allow line to float */ + gpio_set_flags(GPIO_6AXIS_INT_L, GPIO_INPUT | GPIO_PULL_DOWN); + } +} + void motion_interrupt(enum gpio_signal signal) { - switch (signal) { - case GPIO_3AXIS_INT_L: - /* TODO */ + switch (base_gyro_config) { + case BASE_GYRO_BMI160: + bmi160_interrupt(signal); break; - case GPIO_6AXIS_INT_L: + case BASE_GYRO_BMI323: default: - bmi160_interrupt(signal); + bmi3xx_interrupt(signal); break; } } +static void board_init(void) +{ + board_update_motion_sensor_config(); +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); + static void board_chipset_startup(void) { if (get_board_version() > 1) diff --git a/board/guybrush/board.h b/board/guybrush/board.h index 5c6bc9bbcb..49c0537983 100644 --- a/board/guybrush/board.h +++ b/board/guybrush/board.h @@ -19,6 +19,9 @@ #define CONFIG_ACCELGYRO_BMI160 #define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#define CONFIG_ACCELGYRO_BMI3XX +#define CONFIG_ACCELGYRO_BMI3XX_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) #define CONFIG_ACCEL_INTERRUPTS #define CONFIG_ACCEL_BMA4XX @@ -64,6 +67,12 @@ enum battery_type { BATTERY_TYPE_COUNT, }; +enum base_accelgyro_type { + BASE_GYRO_NONE = 0, + BASE_GYRO_BMI160 = 1, + BASE_GYRO_BMI323 = 2, +}; + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/guybrush/board_fw_config.c b/board/guybrush/board_fw_config.c index b971ad7301..c919d82851 100644 --- a/board/guybrush/board_fw_config.c +++ b/board/guybrush/board_fw_config.c @@ -6,6 +6,13 @@ #include "base_fw_config.h" #include "board_fw_config.h" +bool board_is_convertible(void) +{ + return (get_fw_config_field(FW_CONFIG_FORM_FACTOR_OFFSET, + FW_CONFIG_FORM_FACTOR_WIDTH) + == FW_CONFIG_FORM_FACTOR_CONVERTIBLE); +} + bool board_has_kblight(void) { return (get_fw_config_field(FW_CONFIG_KBLIGHT_OFFSET, diff --git a/board/guybrush/board_fw_config.h b/board/guybrush/board_fw_config.h index 80098d8eff..1de417d77a 100644 --- a/board/guybrush/board_fw_config.h +++ b/board/guybrush/board_fw_config.h @@ -24,7 +24,7 @@ #define FW_CONFIG_FORM_FACTOR_OFFSET 2 #define FW_CONFIG_FORM_FACTOR_WIDTH 1 #define FW_CONFIG_FORM_FACTOR_CLAMSHELL 0 -#define FW_CONFIG_FORM_FACTOR_CONVERTIABLE 1 +#define FW_CONFIG_FORM_FACTOR_CONVERTIBLE 1 /* * Keyboard Backlight (1 bit) |