diff --git a/board/glados/board.c b/board/glados/board.c index af1352d9c1..5fa6217eb7 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -17,6 +17,7 @@ #include "driver/als_opt3001.h" #include "driver/accel_kionix.h" #include "driver/accel_kx022.h" +#include "driver/accelgyro_bmi160.h" #include "extpower.h" #include "gpio.h" #include "hooks.h" @@ -427,10 +428,11 @@ static void board_handle_reboot(void) } DECLARE_HOOK(HOOK_INIT, board_handle_reboot, HOOK_PRIO_FIRST); -/* Motion sensors */ #ifdef HAS_TASK_MOTIONSENSE -/* Lid Sensor mutex */ +/* Motion sensors */ +/* Mutexes */ static struct mutex g_lid_mutex; +static struct mutex g_base_mutex; /* KX022 private data */ struct kionix_accel_data g_kx022_data = { @@ -438,6 +440,81 @@ struct kionix_accel_data g_kx022_data = { }; struct motion_sensor_t motion_sensors[] = { + /* + * Note: bmi160: supports accelerometer and gyro sensor + * Requirement: accelerometer sensor must init before gyro sensor + * DO NOT change the order of the following table. + */ + {.name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi160_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi160_data, + .addr = BMI160_ADDR0, + .rot_standard_ref = NULL, /* Identity matrix. */ + .default_range = 2, /* g, enough for laptop. */ + .config = { + /* AP: by default use EC settings */ + [SENSOR_CONFIG_AP] = { + .odr = 0, + .ec_rate = 0, + }, + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100, + }, + /* Sensor off in S3/S5 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 0, + .ec_rate = 0 + }, + /* Sensor off in S3/S5 */ + [SENSOR_CONFIG_EC_S5] = { + .odr = 0, + .ec_rate = 0 + }, + }, + }, + + {.name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi160_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi160_data, + .addr = BMI160_ADDR0, + .default_range = 1000, /* dps */ + .rot_standard_ref = NULL, /* Identity Matrix. */ + .config = { + /* AP: by default shutdown all sensors */ + [SENSOR_CONFIG_AP] = { + .odr = 0, + .ec_rate = 0, + }, + /* EC does not need in S0 */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 0, + .ec_rate = 0, + }, + /* Sensor off in S3/S5 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 0, + .ec_rate = 0, + }, + /* Sensor off in S3/S5 */ + [SENSOR_CONFIG_EC_S5] = { + .odr = 0, + .ec_rate = 0, + }, + }, + }, + {.name = "Lid Accel", .active_mask = SENSOR_ACTIVE_S0, .chip = MOTIONSENSE_CHIP_KX022, diff --git a/board/glados/board.h b/board/glados/board.h index 994b6d8177..28b4874520 100644 --- a/board/glados/board.h +++ b/board/glados/board.h @@ -9,6 +9,7 @@ #define __CROS_EC_BOARD_H /* Optional features */ +#define CONFIG_ACCELGYRO_BMI160 #define CONFIG_ACCEL_KX022 #define CONFIG_ADC #define CONFIG_ALS @@ -40,6 +41,9 @@ #define CONFIG_I2C #define CONFIG_KEYBOARD_PROTOCOL_8042 #define CONFIG_LED_COMMON +#define CONFIG_LID_ANGLE +#define CONFIG_LID_ANGLE_SENSOR_BASE 0 +#define CONFIG_LID_ANGLE_SENSOR_LID 2 #define CONFIG_LID_SWITCH #define CONFIG_LOW_POWER_IDLE #define CONFIG_PORT80_TASK_EN diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index 7119d0d8cf..f781313243 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -182,6 +182,7 @@ static int raw_write8(const int addr, const uint8_t reg, int data) return rv; } +#ifdef CONFIG_ACCEL_INTERRUPTS /** * Read 32bit register from accelerometer. */ @@ -201,6 +202,7 @@ static int raw_read32(const int addr, const uint8_t reg, int *data_ptr) } return rv; } +#endif /* defined(CONFIG_ACCEL_INTERRUPTS) */ /** * Read n bytes from accelerometer. @@ -485,9 +487,11 @@ static int get_offset(const struct motion_sensor_t *s, BMI160_OFFSET_GYRO_DIV_MDS; } break; +#ifdef CONFIG_MAG_BMI160_BMM150 case MOTIONSENSE_TYPE_MAG: bmm150_get_offset(s, v); break; +#endif /* defined(CONFIG_MAG_BMI160_BMM150) */ default: for (i = X; i <= Z; i++) v[i] = 0; @@ -548,9 +552,11 @@ static int set_offset(const struct motion_sensor_t *s, ret = raw_write8(s->addr, BMI160_OFFSET_EN_GYR98, val98 | BMI160_OFFSET_GYRO_EN); break; +#ifdef CONFIG_MAG_BMI160_BMM150 case MOTIONSENSE_TYPE_MAG: ret = bmm150_set_offset(s, v); break; +#endif /* defined(CONFIG_MAG_BMI160) */ default: ret = EC_RES_INVALID_PARAM; }