summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Chen <ben.chen2@quanta.corp-partner.google.com>2020-12-31 14:05:20 +0800
committerCommit Bot <commit-bot@chromium.org>2021-01-09 05:24:57 +0000
commit0e0bbbafd7482aba297f9a681fd6869d66f48aab (patch)
tree2f80dde690a873863359064b5b1011e98fd5583f
parent251a1ee0ae893929f41c7afcd32741ea0f3805a2 (diff)
downloadchrome-ec-0e0bbbafd7482aba297f9a681fd6869d66f48aab.tar.gz
voxel: Add motion sensor config for kx022/icm-426xx
Add icm-426xx config for new second source base accel/gyro, and lid accel config for new second source. BUG=b:176039213, b:175843510 BRANCH=main TEST=Using ectool 'motionsense' verified lid angle now goes from 0 to 360 and swtiches to tablet mode after crossing 200 threshold on re-work kx022/icm-426xx DUT. Change-Id: I6815a46f01f8334f4f8c1b07deee16046566fbce Signed-off-by: Ben Chen <ben.chen2@quanta.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2607207 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--board/voxel/board.h7
-rw-r--r--board/voxel/gpio.inc2
-rw-r--r--board/voxel/sensors.c115
3 files changed, 120 insertions, 4 deletions
diff --git a/board/voxel/board.h b/board/voxel/board.h
index c868938778..f66a09becc 100644
--- a/board/voxel/board.h
+++ b/board/voxel/board.h
@@ -47,12 +47,17 @@
/* Sensors */
/* BMI160 Base accel/gyro */
#define CONFIG_ACCELGYRO_BMI160
+#define CONFIG_ACCELGYRO_ICM426XX /* Base accel second source*/
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+#define CONFIG_ACCELGYRO_ICM426XX_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+
/* Lid operates in forced mode, base in FIFO */
#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL)
/* BMA253 Lid accel */
+#define CONFIG_ACCEL_KX022 /* Lid accel */
#define CONFIG_ACCEL_BMA255
#define CONFIG_LID_ANGLE
#define CONFIG_LID_ANGLE_UPDATE
@@ -183,6 +188,8 @@ enum usbc_port {
void board_reset_pd_mcu(void);
+void motion_interrupt(enum gpio_signal signal);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/voxel/gpio.inc b/board/voxel/gpio.inc
index bd807aa399..fa3d0ffe7d 100644
--- a/board/voxel/gpio.inc
+++ b/board/voxel/gpio.inc
@@ -25,7 +25,7 @@ GPIO_INT(PG_EC_DSW_PWROK, PIN(C, 7), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(PG_EC_ALL_SYS_PWRGD, PIN(F, 4), GPIO_INT_BOTH, power_signal_interrupt)
/* Sensor Interrupts */
-GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt)
+GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, motion_interrupt)
GPIO(EC_ALS_RGB_INT_L, PIN(D, 4), GPIO_INPUT | GPIO_PULL_UP) /* unused */
GPIO_INT(TABLET_MODE_L, PIN(9, 5), GPIO_INT_BOTH, gmr_tablet_switch_isr)
/*
diff --git a/board/voxel/sensors.c b/board/voxel/sensors.c
index fab1fac66b..93c6f442c9 100644
--- a/board/voxel/sensors.c
+++ b/board/voxel/sensors.c
@@ -6,9 +6,13 @@
/* 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/accelgyro_bmi_common.h"
#include "driver/accelgyro_bmi160.h"
+#include "driver/accelgyro_icm_common.h"
+#include "driver/accelgyro_icm426xx.h"
#include "driver/als_tcs3400.h"
#include "driver/sync.h"
#include "keyboard_scan.h"
@@ -26,9 +30,11 @@ static struct mutex g_base_mutex;
/* BMA253 private data */
static struct accelgyro_saved_data_t g_bma253_data;
+static struct kionix_accel_data g_kx022_data;
/* BMI160 private data */
static struct bmi_drv_data_t g_bmi160_data;
+static struct icm_drv_data_t g_icm426xx_data;
/* Rotation matrix for the lid accelerometer */
static const mat33_fp_t lid_standard_ref = {
@@ -43,6 +49,85 @@ const mat33_fp_t base_standard_ref = {
{ 0, 0, FLOAT_TO_FP(1)}
};
+static const mat33_fp_t base_icm_ref = {
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, FLOAT_TO_FP(1), 0},
+ { 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_data,
+ .port = I2C_PORT_ACCEL,
+ .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 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_ACCEL,
+ .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS,
+ .default_range = 4, /* g, enough for laptop */
+ .rot_standard_ref = &base_icm_ref,
+ .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 * MSEC,
+ },
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ },
+};
+
+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_ACCEL,
+ .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = ICM426XX_GYRO_MIN_FREQ,
+ .max_frequency = ICM426XX_GYRO_MAX_FREQ,
+};
+
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
.name = "Lid Accel",
@@ -120,15 +205,39 @@ unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
static void board_sensors_init(void)
{
- /* Note - BMA253 interrupt unused by EC */
-
- /* Enable interrupt for the BMI160 accel/gyro sensor */
+ /* Enable interrupt for the accel/gyro sensor */
gpio_enable_interrupt(GPIO_EC_IMU_INT_L);
CPRINTS("Motion Sensor Count = %d", motion_sensor_count);
+
+ if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_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) {
+ motion_sensors[LID_ACCEL] = kx022_lid_accel;
+ ccprints("LID_ACCEL is KX022");
+ } else
+ ccprints("LID_ACCEL is BMA253");
}
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:
+ icm426xx_interrupt(signal);
+ break;
+ case SSFC_SENSOR_BMI160:
+ default:
+ bmi160_interrupt(signal);
+ break;
+ }
+}
+
#ifndef TEST_BUILD
void lid_angle_peripheral_enable(int enable)
{