summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Huang <david.huang@quanta.corp-partner.google.com>2020-12-15 11:45:37 +0800
committerCommit Bot <commit-bot@chromium.org>2021-01-13 07:04:34 +0000
commit86b52c3f6f4a916ba069f22650a5898ad848b858 (patch)
tree63fd7141457303dabd05c5490389240e6160993d
parent3d8b04c3db6e1fe8f62e3cbbc67db8a142fbd57b (diff)
downloadchrome-ec-86b52c3f6f4a916ba069f22650a5898ad848b858.tar.gz
bobba: Add base accel/gyro config for icm-426xx
Add icm-426xx config for new second source base accel/gyro. BUG=b:174628541 BRANCH=octopus TEST=Check ectool motionsense and get x,y,z data. Change-Id: I7ba4bd4b90e270cc39c4b01c5aab24d5d1c3f097 Signed-off-by: David Huang <david.huang@quanta.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2592529 Reviewed-by: Zhuohao Lee <zhuohao@chromium.org> Commit-Queue: Zhuohao Lee <zhuohao@chromium.org>
-rw-r--r--baseboard/octopus/cbi_ssfc.c5
-rw-r--r--baseboard/octopus/cbi_ssfc.h16
-rw-r--r--board/bobba/board.c78
-rw-r--r--board/bobba/board.h7
-rw-r--r--board/bobba/gpio.inc2
5 files changed, 106 insertions, 2 deletions
diff --git a/baseboard/octopus/cbi_ssfc.c b/baseboard/octopus/cbi_ssfc.c
index e515bf0d6b..e7f8177baa 100644
--- a/baseboard/octopus/cbi_ssfc.c
+++ b/baseboard/octopus/cbi_ssfc.c
@@ -42,3 +42,8 @@ enum ssfc_charger get_cbi_ssfc_charger(void)
{
return ((cached_ssfc & SSFC_CHARGER_MASK) >> SSFC_CHARGER_OFFSET);
}
+
+enum ssfc_sensor get_cbi_ssfc_sensor(void)
+{
+ return ((cached_ssfc & SSFC_SENSOR_MASK) >> SSFC_SENSOR_OFFSET);
+}
diff --git a/baseboard/octopus/cbi_ssfc.h b/baseboard/octopus/cbi_ssfc.h
index 326072f68e..b762336e59 100644
--- a/baseboard/octopus/cbi_ssfc.h
+++ b/baseboard/octopus/cbi_ssfc.h
@@ -43,8 +43,24 @@ enum ssfc_charger {
#define SSFC_CHARGER_OFFSET 6
#define SSFC_CHARGER_MASK GENMASK(8, 6)
+/*
+ * Audio (Bits 11-9)
+ */
+
+/*
+ * Sensor (Bits 14-12)
+ */
+enum ssfc_sensor {
+ SSFC_SENSOR_DEFAULT,
+ SSFC_SENSOR_BMI160,
+ SSFC_SENSOR_ICM426XX,
+};
+#define SSFC_SENSOR_OFFSET 12
+#define SSFC_SENSOR_MASK GENMASK(14, 12)
+
enum ssfc_tcpc_p1 get_cbi_ssfc_tcpc_p1(void);
enum ssfc_ppc_p1 get_cbi_ssfc_ppc_p1(void);
enum ssfc_charger get_cbi_ssfc_charger(void);
+enum ssfc_sensor get_cbi_ssfc_sensor(void);
#endif /* _OCTOPUS_CBI_SSFC__H_ */
diff --git a/board/bobba/board.c b/board/bobba/board.c
index 9caa1d617f..cd75140fd8 100644
--- a/board/bobba/board.c
+++ b/board/bobba/board.c
@@ -9,12 +9,15 @@
#include "adc_chip.h"
#include "battery.h"
#include "button.h"
+#include "cbi_ssfc.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "common.h"
#include "cros_board_info.h"
#include "driver/accel_kionix.h"
#include "driver/accelgyro_bmi160.h"
+#include "driver/accelgyro_icm426xx.h"
+#include "driver/accelgyro_icm_common.h"
#include "driver/charger/bd9995x.h"
#include "driver/ppc/nx20p348x.h"
#include "driver/ppc/syv682x.h"
@@ -156,6 +159,12 @@ const mat33_fp_t base_standard_ref = {
{ 0, 0, FLOAT_TO_FP(1)}
};
+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)}
+};
+
/*
* Sparky360 SKU ID 26 has AR Cam, and move base accel/gryo to AR Cam board.
* AR Cam board has about 16° bias with motherboard through Y axis.
@@ -177,6 +186,7 @@ const mat33_fp_t base_ar_cam_ref = {
/* sensor private data */
static struct kionix_accel_data g_kx022_data;
static struct bmi160_drv_data_t g_bmi160_data;
+static struct icm_drv_data_t g_icm426xx_data;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
@@ -265,6 +275,52 @@ struct motion_sensor_t motion_sensors[] = {
unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+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_SENSOR,
+ .addr = ICM426XX_ADDR0_FLAGS,
+ .rot_standard_ref = &base_icm_ref,
+ .default_range = 4, /* g */
+ .min_frequency = ICM426XX_ACCEL_MIN_FREQ,
+ .max_frequency = ICM426XX_ACCEL_MAX_FREQ,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 13000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on 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_SENSOR,
+ .addr = ICM426XX_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_icm_ref,
+ .min_frequency = ICM426XX_GYRO_MIN_FREQ,
+ .max_frequency = ICM426XX_GYRO_MAX_FREQ,
+};
+
static int board_is_convertible(void)
{
/*
@@ -282,9 +338,18 @@ static int board_with_ar_cam(void)
return sku_id == 26;
}
+static int base_gyro_config;
+
static void board_update_sensor_config_from_sku(void)
{
if (board_is_convertible()) {
+ base_gyro_config = get_cbi_ssfc_sensor();
+ if (base_gyro_config == 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");
motion_sensor_count = ARRAY_SIZE(motion_sensors);
/* Enable Base Accel interrupt */
gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
@@ -309,6 +374,19 @@ static void board_update_sensor_config_from_sku(void)
}
}
+void motion_interrupt(enum gpio_signal signal)
+{
+ switch (base_gyro_config) {
+ case SSFC_SENSOR_ICM426XX:
+ icm426xx_interrupt(signal);
+ break;
+ case SSFC_SENSOR_BMI160:
+ default:
+ bmi160_interrupt(signal);
+ break;
+ }
+}
+
static int board_has_keypad(void)
{
return sku_id == 41 || sku_id == 42 || sku_id == 43 || sku_id == 44;
diff --git a/board/bobba/board.h b/board/bobba/board.h
index 3960ed63ff..27d5369f86 100644
--- a/board/bobba/board.h
+++ b/board/bobba/board.h
@@ -33,7 +33,8 @@
/* Sensors */
#define CONFIG_ACCEL_KX022 /* Lid accel */
-#define CONFIG_ACCELGYRO_BMI160 /* Base accel */
+#define CONFIG_ACCELGYRO_BMI160 /* Base accel main source*/
+#define CONFIG_ACCELGYRO_ICM426XX /* Base accel second source*/
#define CONFIG_SYNC /* Camera VSYNC */
#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
@@ -43,6 +44,8 @@
/* Motion Sense Task Events */
#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)
#define CONFIG_SYNC_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(VSYNC)
@@ -129,6 +132,8 @@ enum battery_type {
BATTERY_TYPE_COUNT,
};
+void motion_interrupt(enum gpio_signal signal);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/bobba/gpio.inc b/board/bobba/gpio.inc
index e05298c656..1bea82c972 100644
--- a/board/bobba/gpio.inc
+++ b/board/bobba/gpio.inc
@@ -37,7 +37,7 @@ GPIO_INT(TABLET_MODE_L, PIN(8, 6), GPIO_INT_BOTH, hall_sensor_isr)
GPIO_INT(EC_VOLUP_BTN_ODL, PIN(7, 5), GPIO_INT_BOTH, button_interrupt)
GPIO_INT(EC_VOLDN_BTN_ODL, PIN(4, 0), GPIO_INT_BOTH, button_interrupt)
-GPIO_INT(BASE_SIXAXIS_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt)
+GPIO_INT(BASE_SIXAXIS_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, motion_interrupt)
GPIO_INT(WFCAM_VSYNC, PIN(0, 3), GPIO_INT_RISING , sync_interrupt)
GPIO(LID_ACCEL_INT_L, PIN(5, 0), GPIO_INPUT | GPIO_SEL_1P8V)