summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiyu Qin <qinsiyu@huaqin.corp-partner.google.com>2021-08-12 14:56:09 +0800
committerCommit Bot <commit-bot@chromium.org>2021-08-18 13:11:40 +0000
commit79fd35ee861617cc6268d5dd8010ba58b4c87fd4 (patch)
treeb7752a88729849ccb888a3dce04650e4f5c4042e
parentd30ec2f1ca23782050341e52abf0430f5d8a20f0 (diff)
downloadchrome-ec-79fd35ee861617cc6268d5dd8010ba58b4c87fd4.tar.gz
Mrbland: Add the support for ICM42607
BMI160 is going to EOL, so we intend to import ICM42607 to make 2 sources compatible for Mrbland. BUG=b:196287196 BRANCH=trogdor TEST=1.make BOARD=mrbland 2.ectool motionsense can get the sensor data Change-Id: Ie1b4c6722b460339a38ef48aeae1018f6c008949 Signed-off-by: Siyu Qin <qinsiyu@huaqin.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3089082 Reviewed-by: Bob Moragues <moragues@chromium.org> Reviewed-by: Wai-Hong Tam <waihong@google.com>
-rw-r--r--board/mrbland/board.c98
-rw-r--r--board/mrbland/board.h7
-rw-r--r--board/mrbland/gpio.inc2
3 files changed, 103 insertions, 4 deletions
diff --git a/board/mrbland/board.c b/board/mrbland/board.c
index 86924907f2..e1f9c4740b 100644
--- a/board/mrbland/board.c
+++ b/board/mrbland/board.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* Homestar board-specific configuration */
+/* Mrbland board-specific configuration */
#include "adc_chip.h"
#include "button.h"
@@ -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,14 +261,68 @@ 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 = {
- { FLOAT_TO_FP(-1), 0, 0},
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, FLOAT_TO_FP(1), 0},
+ { 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/mrbland/board.h b/board/mrbland/board.h
index 3d29ac3686..c0d983b533 100644
--- a/board/mrbland/board.h
+++ b/board/mrbland/board.h
@@ -46,12 +46,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
@@ -113,6 +116,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/mrbland/gpio.inc b/board/mrbland/gpio.inc
index 714c640a53..77a69a5faa 100644
--- a/board/mrbland/gpio.inc
+++ b/board/mrbland/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)