summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiyu Qin <qinsiyu@huaqin.corp-partner.google.com>2021-07-07 14:02:49 +0800
committerCommit Bot <commit-bot@chromium.org>2021-07-21 02:07:31 +0000
commit991635ce353d85e833b1e7a2110752730289d21c (patch)
treebe021bdd5553cc88cfcd209a8e65b6cc4af68ded
parenta1939eed1e33c2a50e985fc9bf52c23a439186eb (diff)
downloadchrome-ec-991635ce353d85e833b1e7a2110752730289d21c.tar.gz
Homestar: add the support for ICM42607
BMI160 is going to EOL, so we intend to import ICM42607 to make 2 sources compatible for Homestar. BUG=b:189057043 BRANCH=trogdor TEST=1.make BOARD=homestar 2.ectool motionsense can get the sensor data Change-Id: I87faabf813b9ec1a5c21092b6796542dfbe2d06f Signed-off-by: Siyu Qin <qinsiyu@huaqin.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3029801 Reviewed-by: Wai-Hong Tam <waihong@google.com>
-rw-r--r--board/homestar/board.c94
-rw-r--r--board/homestar/board.h7
-rw-r--r--board/homestar/gpio.inc2
3 files changed, 101 insertions, 2 deletions
diff --git a/board/homestar/board.c b/board/homestar/board.c
index 1311d63390..79451b4e3f 100644
--- a/board/homestar/board.c
+++ b/board/homestar/board.c
@@ -13,6 +13,8 @@
#include "extpower.h"
#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi_common.h"
+#include "driver/accelgyro_icm_common.h"
+#include "driver/accelgyro_icm42607.h"
#include "driver/ln9310.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/ps8xxx.h"
@@ -259,6 +261,15 @@ const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = {
static struct mutex g_lid_mutex;
static struct bmi_drv_data_t g_bmi160_data;
+static struct icm_drv_data_t g_icm42607_data;
+
+enum lid_accelgyro_type {
+ LID_GYRO_NONE = 0,
+ LID_GYRO_BMI160 = 1,
+ LID_GYRO_ICM42607 = 2,
+};
+
+static enum lid_accelgyro_type lid_accelgyro_config;
/* Matrix to rotate accelerometer into standard reference frame */
const mat33_fp_t lid_standard_ref = {
@@ -267,6 +278,51 @@ const mat33_fp_t lid_standard_ref = {
{ 0, 0, FLOAT_TO_FP(1)}
};
+const mat33_fp_t lid_standard_ref_icm42607 = {
+ { 0, FLOAT_TO_FP(1), 0},
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+struct motion_sensor_t icm42607_lid_accel = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_ICM42607,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &icm42607_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_icm42607_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = ICM42607_ADDR0_FLAGS,
+ .rot_standard_ref = &lid_standard_ref_icm42607,
+ .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */
+ .min_frequency = ICM42607_ACCEL_MIN_FREQ,
+ .max_frequency = ICM42607_ACCEL_MAX_FREQ,
+ .config = {
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+};
+
+struct motion_sensor_t icm42607_lid_gyro = {
+ .name = "Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_ICM42607,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &icm42607_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_icm42607_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = ICM42607_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &lid_standard_ref_icm42607,
+ .min_frequency = ICM42607_GYRO_MIN_FREQ,
+ .max_frequency = ICM42607_GYRO_MAX_FREQ,
+};
+
struct motion_sensor_t motion_sensors[] = {
/*
* Note: bmi160: supports accelerometer and gyro sensor
@@ -313,6 +369,44 @@ struct motion_sensor_t motion_sensors[] = {
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+static void board_detect_motionsensor(void)
+{
+ int val = -1;
+
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ return;
+ if (lid_accelgyro_config != LID_GYRO_NONE)
+ return;
+
+ /* Check base accelgyro chip */
+ icm_read8(&icm42607_lid_accel, ICM42607_REG_WHO_AM_I, &val);
+ if (val == ICM42607_CHIP_ICM42607P) {
+ motion_sensors[LID_ACCEL] = icm42607_lid_accel;
+ motion_sensors[LID_GYRO] = icm42607_lid_gyro;
+ lid_accelgyro_config = LID_GYRO_ICM42607;
+ CPRINTS("LID Accelgyro: ICM42607");
+ } else {
+ lid_accelgyro_config = LID_GYRO_BMI160;
+ CPRINTS("LID Accelgyro: BMI160");
+ }
+}
+DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_detect_motionsensor,
+ HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_INIT, board_detect_motionsensor, HOOK_PRIO_DEFAULT + 1);
+
+void motion_interrupt(enum gpio_signal signal)
+{
+ switch (lid_accelgyro_config) {
+ case LID_GYRO_ICM42607:
+ icm42607_interrupt(signal);
+ break;
+ case LID_GYRO_BMI160:
+ default:
+ bmi160_interrupt(signal);
+ break;
+ }
+}
+
enum battery_cell_type board_get_battery_cell_type(void)
{
return BATTERY_CELL_TYPE_2S;
diff --git a/board/homestar/board.h b/board/homestar/board.h
index 19f6ea8b20..d3fa5121d3 100644
--- a/board/homestar/board.h
+++ b/board/homestar/board.h
@@ -37,12 +37,15 @@
#define CONFIG_USBC_PPC_SN5S330
#define CONFIG_USB_PD_PORT_MAX_COUNT 2
-/* BMI160 Lid accel/gyro */
+/* Lid accel/gyro */
#define CONFIG_ACCELGYRO_BMI160
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
#define OPT3001_I2C_ADDR_FLAGS OPT3001_I2C_ADDR1_FLAGS
+#define CONFIG_ACCELGYRO_ICM42607
+#define CONFIG_ACCELGYRO_ICM42607_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
#define CONFIG_TABLET_MODE
#define CONFIG_TABLET_MODE_SWITCH
@@ -101,6 +104,8 @@ void board_set_tcpc_power_mode(int port, int mode);
/* Base detection */
void base_detect_interrupt(enum gpio_signal signal);
+void motion_interrupt(enum gpio_signal signal);
+
#endif /* !defined(__ASSEMBLER__) */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/homestar/gpio.inc b/board/homestar/gpio.inc
index 714c640a53..77a69a5faa 100644
--- a/board/homestar/gpio.inc
+++ b/board/homestar/gpio.inc
@@ -42,7 +42,7 @@ GPIO_INT(AP_EC_SPI_CS_L, PIN(5, 3), GPIO_INT_FALLING | GPIO_PULL_DOWN, shi_cs
GPIO_INT(BASE_DET_L, PIN(3, 7), GPIO_INT_BOTH, base_detect_interrupt) /* Detachable base attached? */
/* Sensor interrupts */
-GPIO_INT(ACCEL_GYRO_INT_L, PIN(A, 0), GPIO_INT_FALLING, bmi160_interrupt) /* Accelerometer/gyro interrupt */
+GPIO_INT(ACCEL_GYRO_INT_L, PIN(A, 0), GPIO_INT_FALLING, motion_interrupt) /* Accelerometer/gyro interrupt */
/* Switchcap, for LN9310, it is the interrupt line of LN9310. */
GPIO_INT(LN9310_INT, PIN(E, 2), GPIO_INT_FALLING, switchcap_interrupt)