diff options
-rw-r--r-- | baseboard/volteer/cbi_ssfc.h | 9 | ||||
-rw-r--r-- | board/voema/board.h | 1 | ||||
-rw-r--r-- | board/voema/sensors.c | 73 | ||||
-rw-r--r-- | board/voxel/sensors.c | 8 |
4 files changed, 81 insertions, 10 deletions
diff --git a/baseboard/volteer/cbi_ssfc.h b/baseboard/volteer/cbi_ssfc.h index 1583d74729..3039f3040c 100644 --- a/baseboard/volteer/cbi_ssfc.h +++ b/baseboard/volteer/cbi_ssfc.h @@ -17,8 +17,9 @@ */ enum ec_ssfc_base_sensor { SSFC_SENSOR_BASE_DEFAULT = 0, - SSFC_SENSOR_BMI160 = 1, - SSFC_SENSOR_ICM426XX = 2 + SSFC_SENSOR_BASE_BMI160 = 1, + SSFC_SENSOR_BASE_ICM426XX = 2, + SSFC_SENSOR_BASE_KX022 = 3 }; /* @@ -26,8 +27,8 @@ enum ec_ssfc_base_sensor { */ enum ec_ssfc_lid_sensor { SSFC_SENSOR_LID_DEFAULT = 0, - SSFC_SENSOR_BMA255 = 1, - SSFC_SENSOR_KX022 = 2 + SSFC_SENSOR_LID_BMA255 = 1, + SSFC_SENSOR_LID_KX022 = 2 }; /* diff --git a/board/voema/board.h b/board/voema/board.h index b2d401f69a..19a5ed83a0 100644 --- a/board/voema/board.h +++ b/board/voema/board.h @@ -35,6 +35,7 @@ /* Sensors */ /* BMA253 accelerometer in base */ #define CONFIG_ACCEL_BMA255 +#define CONFIG_ACCEL_KX022 /* TCS3400 ALS */ #define CONFIG_ALS diff --git a/board/voema/sensors.c b/board/voema/sensors.c index 818cda1a79..9328685a5f 100644 --- a/board/voema/sensors.c +++ b/board/voema/sensors.c @@ -6,7 +6,9 @@ /* Volteer family-specific sensor configuration */ #include "common.h" #include "accelgyro.h" +#include "cbi_ssfc.h" #include "driver/accel_bma2x2.h" +#include "driver/accel_kionix.h" #include "driver/als_tcs3400.h" #include "driver/sync.h" #include "keyboard_scan.h" @@ -25,6 +27,9 @@ static struct mutex g_base_mutex; static struct accelgyro_saved_data_t g_bma253_base_data; static struct accelgyro_saved_data_t g_bma253_lid_data; +static struct kionix_accel_data g_kx022_base_data; +static struct kionix_accel_data g_kx022_lid_data; + /* TCS3400 private data */ static struct als_drv_data_t g_tcs3400_data = { .als_cal.scale = 1, @@ -92,6 +97,60 @@ const mat33_fp_t base_standard_ref = { { 0, 0, FLOAT_TO_FP(-1)} }; +struct motion_sensor_t kx022_lid_accel = { + .name = "Lid Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_KX022, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &kionix_accel_drv, + .mutex = &g_lid_accel_mutex, + .drv_data = &g_kx022_lid_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = KX022_ADDR0_FLAGS, + .rot_standard_ref = &lid_standard_ref, + .min_frequency = KX022_ACCEL_MIN_FREQ, + .max_frequency = KX022_ACCEL_MAX_FREQ, + .default_range = 2, /* g, to support tablet mode */ + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, +}; + +struct motion_sensor_t kx022_basse_accel = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_KX022, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &kionix_accel_drv, + .mutex = &g_lid_accel_mutex, + .drv_data = &g_kx022_base_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = KX022_ADDR1_FLAGS, + .rot_standard_ref = &base_standard_ref, + .min_frequency = KX022_ACCEL_MIN_FREQ, + .max_frequency = KX022_ACCEL_MAX_FREQ, + .default_range = 2, /* g, to support tablet mode */ + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, +}; + struct motion_sensor_t motion_sensors[] = { [LID_ACCEL] = { .name = "Lid Accel", @@ -193,10 +252,20 @@ BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT); static void baseboard_sensors_init(void) { - /* Note - BMA253 interrupt unused by EC */ - /* Enable interrupt for the TCS3400 color light sensor */ gpio_enable_interrupt(GPIO_EC_ALS_RGB_INT_L); + + if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_KX022) { + motion_sensors[BASE_ACCEL] = kx022_basse_accel; + ccprints("BASE_ACCEL is KX022"); + } else + ccprints("BASE_ACCEL is BMA253"); + + if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_KX022) { + motion_sensors[LID_ACCEL] = kx022_lid_accel; + ccprints("LID_ACCEL is KX022"); + } else + ccprints("LID_ACCEL is BMA253"); } DECLARE_HOOK(HOOK_INIT, baseboard_sensors_init, HOOK_PRIO_DEFAULT); diff --git a/board/voxel/sensors.c b/board/voxel/sensors.c index e9d3545284..abb0ced9ac 100644 --- a/board/voxel/sensors.c +++ b/board/voxel/sensors.c @@ -207,14 +207,14 @@ unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); static void board_sensors_init(void) { if (ec_cfg_has_tabletmode()) { - if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_ICM426XX) { + if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_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"); - if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_KX022) { + if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_KX022) { motion_sensors[LID_ACCEL] = kx022_lid_accel; ccprints("LID_ACCEL is KX022"); } else @@ -236,10 +236,10 @@ DECLARE_HOOK(HOOK_INIT, board_sensors_init, HOOK_PRIO_DEFAULT); void motion_interrupt(enum gpio_signal signal) { switch (get_cbi_ssfc_base_sensor()) { - case SSFC_SENSOR_ICM426XX: + case SSFC_SENSOR_BASE_ICM426XX: icm426xx_interrupt(signal); break; - case SSFC_SENSOR_BMI160: + case SSFC_SENSOR_BASE_BMI160: default: bmi160_interrupt(signal); break; |