summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Lu <Devin.Lu@quantatw.com>2021-03-02 18:58:54 +0800
committerCommit Bot <commit-bot@chromium.org>2021-03-04 01:53:49 +0000
commit37a64a4fcf408b9e2dfe8673fb5c6804a89ae812 (patch)
tree3af9ba9cf131b4a9b5962c38c0af3ff207ee86c7
parent8fffb7f40b72742551a343209a97a7a9add6a827 (diff)
downloadchrome-ec-37a64a4fcf408b9e2dfe8673fb5c6804a89ae812.tar.gz
burnet: Add 2nd lid/base accel source
This patch add one more source for lid/base accel. lid accel - kx022 base accel - icm-40608 BUG=b:181627606, b:173647487 BRANCH=firmware-kukui-12573.B TEST=ectool motionsense Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Change-Id: I069f1898c7454805e4475e7637432c4a8423103c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2730948 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
-rw-r--r--board/burnet/board.c123
-rw-r--r--board/burnet/board.h8
-rw-r--r--board/burnet/gpio.inc2
3 files changed, 129 insertions, 4 deletions
diff --git a/board/burnet/board.c b/board/burnet/board.c
index 6b4fc4a44f..4d1ae6e754 100644
--- a/board/burnet/board.c
+++ b/board/burnet/board.c
@@ -15,7 +15,10 @@
#include "common.h"
#include "console.h"
#include "driver/accel_bma2x2.h"
+#include "driver/accel_kionix.h"
#include "driver/accelgyro_bmi_common.h"
+#include "driver/accelgyro_icm_common.h"
+#include "driver/accelgyro_icm426xx.h"
#include "driver/battery/max17055.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/charger/isl923x.h"
@@ -308,15 +311,90 @@ static const mat33_fp_t lid_standard_ref = {
{0, 0, FLOAT_TO_FP(-1)}
};
-static const mat33_fp_t base_standard_ref = {
+static const mat33_fp_t base_bmi160_ref = {
{FLOAT_TO_FP(-1), 0, 0},
{0, FLOAT_TO_FP(1), 0},
{0, 0, FLOAT_TO_FP(-1)}
};
+static const mat33_fp_t base_icm426xx_ref = {
+ {0, FLOAT_TO_FP(-1), 0},
+ {FLOAT_TO_FP(-1), 0, 0},
+ {0, 0, FLOAT_TO_FP(-1)}
+};
+
/* sensor private data */
static struct accelgyro_saved_data_t g_bma253_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;
+
+struct motion_sensor_t lid_accel_kx022 = {
+ .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_mutex,
+ .drv_data = &g_kx022_data,
+ .port = I2C_PORT_SENSORS,
+ .i2c_spi_addr_flags = KX022_ADDR1_FLAGS,
+ .rot_standard_ref = &lid_standard_ref,
+ .default_range = 2,
+ .config = {
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+};
+
+struct motion_sensor_t base_accel_icm426xx = {
+ .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 = CONFIG_SPI_ACCEL_PORT,
+ .i2c_spi_addr_flags = SLAVE_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT),
+ .default_range = 4,
+ .rot_standard_ref = &base_icm426xx_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 use accel for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+};
+
+struct motion_sensor_t base_gyro_icm426xx = {
+ .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 = CONFIG_SPI_ACCEL_PORT,
+ .i2c_spi_addr_flags = SLAVE_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT),
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_icm426xx_ref,
+ .min_frequency = ICM426XX_GYRO_MIN_FREQ,
+ .max_frequency = ICM426XX_GYRO_MAX_FREQ,
+};
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
@@ -359,7 +437,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv_data = &g_bmi160_data,
.port = CONFIG_SPI_ACCEL_PORT,
.i2c_spi_addr_flags = SLAVE_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT),
- .rot_standard_ref = &base_standard_ref,
+ .rot_standard_ref = &base_bmi160_ref,
.default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */
.min_frequency = BMI_ACCEL_MIN_FREQ,
.max_frequency = BMI_ACCEL_MAX_FREQ,
@@ -388,13 +466,51 @@ struct motion_sensor_t motion_sensors[] = {
.port = CONFIG_SPI_ACCEL_PORT,
.i2c_spi_addr_flags = SLAVE_MK_SPI_ADDR_FLAGS(CONFIG_SPI_ACCEL_PORT),
.default_range = 1000, /* dps */
- .rot_standard_ref = &base_standard_ref,
+ .rot_standard_ref = &base_bmi160_ref,
.min_frequency = BMI_GYRO_MIN_FREQ,
.max_frequency = BMI_GYRO_MAX_FREQ,
},
};
unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+void sensor_interrupt(enum gpio_signal signal)
+{
+ switch (motion_sensors[BASE_ACCEL].chip) {
+ case MOTIONSENSE_CHIP_ICM426XX:
+ icm426xx_interrupt(signal);
+ break;
+ case MOTIONSENSE_CHIP_BMI160:
+ default:
+ bmi160_interrupt(signal);
+ break;
+ }
+}
+
+static void board_update_config(void)
+{
+ int val;
+ enum ec_error_list rv;
+
+ /* Ping for ack */
+ rv = i2c_read8(I2C_PORT_SENSORS,
+ KX022_ADDR1_FLAGS, KX022_WHOAMI, &val);
+
+ if (rv == EC_SUCCESS)
+ motion_sensors[LID_ACCEL] = lid_accel_kx022;
+
+ /* Ping for ack */
+ rv = icm_read8(&base_accel_icm426xx,
+ ICM426XX_REG_WHO_AM_I, &val);
+
+ if (rv == EC_SUCCESS) {
+ motion_sensors[BASE_ACCEL] = base_accel_icm426xx;
+ motion_sensors[BASE_GYRO] = base_gyro_icm426xx;
+ }
+
+ CPRINTS("Lid Accel Chip: %d", motion_sensors[LID_ACCEL].chip);
+ CPRINTS("Base Accel Chip: %d", motion_sensors[BASE_ACCEL].chip);
+}
+
#endif /* !VARIANT_KUKUI_NO_SENSORS */
static void board_init(void)
@@ -416,6 +532,7 @@ static void board_init(void)
gpio_enable_interrupt(GPIO_ACCEL_INT_ODL);
/* For some reason we have to do this again in case of sysjump */
board_spi_enable();
+ board_update_config();
} else {
motion_sensor_count = 0;
/* Device is clamshell only */
diff --git a/board/burnet/board.h b/board/burnet/board.h
index 9dd115ba50..f180562ff7 100644
--- a/board/burnet/board.h
+++ b/board/burnet/board.h
@@ -48,10 +48,15 @@
/* Motion Sensors */
#ifndef VARIANT_KUKUI_NO_SENSORS
#define CONFIG_ACCEL_BMA255 /* Lid accel */
+#define CONFIG_ACCEL_KX022
#define CONFIG_ACCELGYRO_BMI160 /* Base accel */
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+/* ICM426XX Base accel/gyro */
+#define CONFIG_ACCELGYRO_ICM426XX
+#define CONFIG_ACCELGYRO_ICM426XX_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
#define CONFIG_ALS
#define CONFIG_CMD_ACCEL_INFO
#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
@@ -144,6 +149,9 @@ int board_get_charger_i2c(void);
int board_is_convertible(void);
+/* Motion sensor interrupt */
+void sensor_interrupt(enum gpio_signal signal);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/burnet/gpio.inc b/board/burnet/gpio.inc
index a08ef74c3c..d46c6e7e70 100644
--- a/board/burnet/gpio.inc
+++ b/board/burnet/gpio.inc
@@ -22,7 +22,7 @@ GPIO_INT(PMIC_EC_RESETB, PIN(B, 7), GPIO_INT_BOTH | GPIO_PULL_DOWN,
GPIO_INT(WARM_RESET_REQ, PIN(A, 3), GPIO_INT_RISING | GPIO_PULL_DOWN,
chipset_reset_request_interrupt)
GPIO_INT_RW(ACCEL_INT_ODL, PIN(A, 4), GPIO_INT_FALLING | GPIO_SEL_1P8V | GPIO_PULL_UP,
- bmi160_interrupt)
+ sensor_interrupt)
GPIO_INT_RO(EMMC_CMD, PIN(B, 15), GPIO_INT_FALLING,
emmc_cmd_interrupt)
GPIO_INT(SPI1_NSS, PIN(A, 15), GPIO_INT_BOTH | GPIO_PULL_UP,