summaryrefslogtreecommitdiff
path: root/board/coachz
diff options
context:
space:
mode:
authorpengjunhao5 <pengjunhao5@huaqin.corp-partner.google.com>2021-08-25 21:20:03 +0800
committerCommit Bot <commit-bot@chromium.org>2021-09-08 21:29:18 +0000
commitf3ffccd7d0fe4d0ce60434310795a7bfdaa5274c (patch)
tree914abd6d0181cbdc54d297c86b2b7277e94534c5 /board/coachz
parentad829783497e6e847fb8cc1deaae59e0c7edbfdd (diff)
downloadchrome-ec-f3ffccd7d0fe4d0ce60434310795a7bfdaa5274c.tar.gz
Coachz: MotionSensor: Combine BMI160 & BMI260
This commit is for second source BMI260, We use chip id to detect which MotionSensor is on the board(BMI160 or BMI260) and combine two different setting for different MotionSensor. BUG=b:195908820 TEST=make -j BOARD=coachz Verify build on SIT board BRANCH=Trogdor Signed-off-by: pengjunhao <pengjunhao5@huaqin.corp-partner.google.com> Reviewed-by: tongjian <tongjian@huaqin.corp-partner.google.com> Reviewed-by: yudengwu <yudengwu@huaqin.corp-partner.google.com> Change-Id: Ib12226744800a9ca2e6f620295e8c2ff762999e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3118645 Reviewed-by: Wai-Hong Tam <waihong@google.com> Reviewed-by: Jian Tong <tongjian@huaqin.corp-partner.google.com> Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'board/coachz')
-rw-r--r--board/coachz/board.c83
-rw-r--r--board/coachz/board.h5
-rw-r--r--board/coachz/gpio.inc2
3 files changed, 88 insertions, 2 deletions
diff --git a/board/coachz/board.c b/board/coachz/board.c
index 6b97944eca..377ce00939 100644
--- a/board/coachz/board.c
+++ b/board/coachz/board.c
@@ -13,6 +13,7 @@
#include "extpower.h"
#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi_common.h"
+#include "driver/accelgyro_bmi260.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
@@ -328,6 +329,9 @@ 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 bmi_drv_data_t g_bmi260_data;
+
+bool is_bmi260_present;
/* Matrix to rotate accelerometer into standard reference frame */
const mat33_fp_t lid_standard_ref = {
@@ -380,8 +384,86 @@ struct motion_sensor_t motion_sensors[] = {
.max_frequency = BMI_GYRO_MAX_FREQ,
},
};
+
+struct motion_sensor_t motion_sensors_260[] = {
+ /*
+ * Note: bmi260: supports accelerometer and gyro sensor
+ * Requirement: accelerometer sensor must init before gyro sensor
+ * DO NOT change the order of the following table.
+ */
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI260,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bmi260_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_bmi260_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS,
+ .rot_standard_ref = &lid_standard_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,
+ .config = {
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+ [LID_GYRO] = {
+ .name = "Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI260,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bmi260_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_bmi260_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &lid_standard_ref,
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
+ },
+};
+
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;
+
+ /* Check base accelgyro chip */
+ bmi_read8(motion_sensors[LID_ACCEL].port,
+ motion_sensors[LID_ACCEL].i2c_spi_addr_flags,
+ BMI260_CHIP_ID, &val);
+ if (val == BMI260_CHIP_ID_MAJOR) {
+ motion_sensors[LID_ACCEL] = motion_sensors_260[LID_ACCEL];
+ motion_sensors[LID_GYRO] = motion_sensors_260[LID_GYRO];
+ is_bmi260_present = 1;
+ } else {
+ is_bmi260_present = 0;
+ }
+}
+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)
+{
+ if (is_bmi260_present) {
+ bmi260_interrupt(signal);
+ } else {
+ bmi160_interrupt(signal);
+ }
+}
+
/* Initialize board. */
static void board_init(void)
{
@@ -657,4 +739,3 @@ int battery_set_vendor_param(uint32_t param, uint32_t value)
{
return EC_ERROR_UNIMPLEMENTED;
}
-
diff --git a/board/coachz/board.h b/board/coachz/board.h
index 9e2fc54318..7779435777 100644
--- a/board/coachz/board.h
+++ b/board/coachz/board.h
@@ -54,6 +54,9 @@
#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_BMI260
+#define CONFIG_ACCELGYRO_BMI260_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
#define CONFIG_TABLET_MODE
#define CONFIG_TABLET_MODE_SWITCH
@@ -117,6 +120,8 @@ void board_reset_pd_mcu(void);
void board_set_tcpc_power_mode(int port, int mode);
/* Base detection */
void base_detect_interrupt(enum gpio_signal signal);
+/* motion sensor interrupt */
+void motion_interrupt(enum gpio_signal signal);
#endif /* !defined(__ASSEMBLER__) */
diff --git a/board/coachz/gpio.inc b/board/coachz/gpio.inc
index 8f5f1498a1..d7ca61ac6b 100644
--- a/board/coachz/gpio.inc
+++ b/board/coachz/gpio.inc
@@ -48,7 +48,7 @@ GPIO_INT(BASE_DET_L, PIN(3, 7), GPIO_INT_BOTH, base_detect_interrupt) /*
GPIO_INT(LID_360_L, PIN(7, 3), GPIO_INT_BOTH, gmr_tablet_switch_isr)
GPIO_INT(LID_INT_N_HALL1, PIN(D, 7), GPIO_INT_BOTH, ks_interrupt) /* Kickstand attached (0) or detached (1) */
GPIO_INT(LID_INT_N_HALL2, PIN(6, 0), GPIO_INT_BOTH, ks_interrupt) /* Kickstand close (0) or open (1) */
-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 */
/*
* EC_RST_ODL acts as a wake source from hibernate mode. However, it does not