diff options
author | Michael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com> | 2021-09-24 10:56:30 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-09-28 05:06:04 +0000 |
commit | 9fc70659ae9cc8350e8734471bcffb55b2580f74 (patch) | |
tree | 0fe81f0649c0e221bb664314df9fce9bb150210c | |
parent | 93523a0a6084efc5319a471bc7af3e5de989e510 (diff) | |
download | chrome-ec-9fc70659ae9cc8350e8734471bcffb55b2580f74.tar.gz |
rammus: gryo sensor add 2nd source ICM40608
gryo sensor add 2nd source icm40608
BUG=b:192817920
BRANCH=rammus
TEST=make BOARD=rammus
Set CBI SSFC 0x10 and using command
"watch ectool motionsense lid_angle" for icm-40608.
Signed-off-by: Michael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com>
Change-Id: If64ee373c0c63e074b11b8a37c9d67c70d409f40
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3180700
Reviewed-by: Zhuohao Lee <zhuohao@chromium.org>
Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
-rw-r--r-- | board/rammus/board.c | 70 | ||||
-rw-r--r-- | board/rammus/board.h | 4 | ||||
-rw-r--r-- | board/rammus/cbi_ssfc.c | 5 | ||||
-rw-r--r-- | board/rammus/cbi_ssfc.h | 19 | ||||
-rw-r--r-- | board/rammus/gpio.inc | 2 |
5 files changed, 98 insertions, 2 deletions
diff --git a/board/rammus/board.c b/board/rammus/board.c index 1f88cf4388..c4e32a9791 100644 --- a/board/rammus/board.c +++ b/board/rammus/board.c @@ -19,6 +19,8 @@ #include "console.h" #include "cros_board_info.h" #include "driver/accelgyro_bmi_common.h" +#include "driver/accelgyro_icm_common.h" +#include "driver/accelgyro_icm426xx.h" #include "driver/accel_bma2x2.h" #include "driver/accel_kionix.h" #include "driver/accel_kx022.h" @@ -586,6 +588,7 @@ static struct mutex g_lid_mutex; static struct mutex g_base_mutex; static struct bmi_drv_data_t g_bmi160_data; +static struct icm_drv_data_t g_icm426xx_data; /* private data */ static struct accelgyro_saved_data_t g_bma255_data; @@ -598,12 +601,64 @@ const mat33_fp_t base_standard_ref = { { 0, 0, FLOAT_TO_FP(-1) } }; +const mat33_fp_t base_standard_ref_icm = { + { 0, FLOAT_TO_FP(1), 0 }, + { FLOAT_TO_FP(1), 0, 0 }, + { 0, 0, FLOAT_TO_FP(-1) } +}; + const mat33_fp_t lid_standard_ref = { { FLOAT_TO_FP(-1), 0, 0 }, { 0, FLOAT_TO_FP(1), 0 }, { 0, 0, FLOAT_TO_FP(-1) } }; +struct motion_sensor_t base_accel_icm = { + .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_ACCEL, + .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS, + .rot_standard_ref = &base_standard_ref_icm, + .min_frequency = ICM426XX_ACCEL_MIN_FREQ, + .max_frequency = ICM426XX_ACCEL_MAX_FREQ, + .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */ + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + /* Sensor on in S3 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 0, + }, + }, +}; + +struct motion_sensor_t base_gyro_icm = { + .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_ACCEL, + .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS, + .default_range = 1000, /* dps */ + .rot_standard_ref = &base_standard_ref_icm, + .min_frequency = ICM426XX_GYRO_MIN_FREQ, + .max_frequency = ICM426XX_GYRO_MAX_FREQ, +}; + struct motion_sensor_t lid_accel_kx022 = { .name = "Lid Accel", .active_mask = SENSOR_ACTIVE_S0_S3, @@ -709,6 +764,14 @@ struct motion_sensor_t motion_sensors[] = { }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +void motion_interrupt(enum gpio_signal signal) +{ + if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_ICM426XX) + icm426xx_interrupt(signal); + else + bmi160_interrupt(signal); +} + static void board_detect_motionsense(void) { if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_KX022) { @@ -716,6 +779,13 @@ static void board_detect_motionsense(void) ccprints("LID_ACCEL is KX022"); } else ccprints("LID_ACCEL is BMA253"); + + if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_ICM426XX) { + motion_sensors[BASE_ACCEL] = base_accel_icm; + motion_sensors[BASE_GYRO] = base_gyro_icm; + ccprints("BASE_ACCEL is ICM426XX"); + } else + ccprints("BASE_ACCEL is BMI160"); } DECLARE_HOOK(HOOK_INIT, board_detect_motionsense, HOOK_PRIO_DEFAULT); diff --git a/board/rammus/board.h b/board/rammus/board.h index cebb453eb2..dc2ae71de8 100644 --- a/board/rammus/board.h +++ b/board/rammus/board.h @@ -112,6 +112,9 @@ #define CONFIG_ACCELGYRO_BMI160 #define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#define CONFIG_ACCELGYRO_ICM426XX +#define CONFIG_ACCELGYRO_ICM426XX_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) #define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT #define CONFIG_ACCEL_BMA255 #define CONFIG_ACCEL_KX022 @@ -269,6 +272,7 @@ enum pwm_channel { /* Board specific handlers */ void board_reset_pd_mcu(void); void board_set_tcpc_power_mode(int port, int mode); +void motion_interrupt(enum gpio_signal signal); /* Sensors without hardware FIFO are in forced mode */ #define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL) diff --git a/board/rammus/cbi_ssfc.c b/board/rammus/cbi_ssfc.c index 18954c6e68..e1f6fa4bd2 100644 --- a/board/rammus/cbi_ssfc.c +++ b/board/rammus/cbi_ssfc.c @@ -29,3 +29,8 @@ enum ec_ssfc_lid_sensor get_cbi_ssfc_lid_sensor(void) { return cached_ssfc.lid_sensor; } + +enum ec_ssfc_base_sensor get_cbi_ssfc_base_sensor(void) +{ + return cached_ssfc.base_sensor; +} diff --git a/board/rammus/cbi_ssfc.h b/board/rammus/cbi_ssfc.h index 09a1d49714..2ca20f2376 100644 --- a/board/rammus/cbi_ssfc.h +++ b/board/rammus/cbi_ssfc.h @@ -21,10 +21,20 @@ enum ec_ssfc_lid_sensor { SSFC_SENSOR_LID_KX022 = 2 }; +/* + * Base Sensor (Bits 5-3) + */ +enum ec_ssfc_base_sensor { + SSFC_SENSOR_BASE_DEFAULT = 0, + SSFC_SENSOR_BASE_BMI160 = 1, + SSFC_SENSOR_BASE_ICM426XX = 2, +}; + union rammus_cbi_ssfc { struct { enum ec_ssfc_lid_sensor lid_sensor : 3; - uint32_t reserved_2 : 29; + enum ec_ssfc_base_sensor base_sensor : 3; + uint32_t reserved_2 : 26; }; uint32_t raw_value; }; @@ -36,4 +46,11 @@ union rammus_cbi_ssfc { */ enum ec_ssfc_lid_sensor get_cbi_ssfc_lid_sensor(void); +/** + * Get the base sensor type form SSFC_CONFIG. + * + * @return the base sensor board type. + */ +enum ec_ssfc_base_sensor get_cbi_ssfc_base_sensor(void); + #endif /* _RAMMUS_CBI_SSFC__H_ */ diff --git a/board/rammus/gpio.inc b/board/rammus/gpio.inc index b55fe6b47c..1e05cbe9a7 100644 --- a/board/rammus/gpio.inc +++ b/board/rammus/gpio.inc @@ -26,7 +26,7 @@ GPIO_INT(USB_C0_VBUS_DET_L, PIN(9, 3), GPIO_INT_BOTH | GPIO_PULL_UP, vbus0_ GPIO_INT(USB_C1_VBUS_DET_L, PIN(9, 7), GPIO_INT_BOTH | GPIO_PULL_UP, vbus1_evt) GPIO_INT(USB_C0_BC12_INT_L, PIN(D, 3), GPIO_INT_FALLING, usb0_evt) GPIO_INT(USB_C1_BC12_INT_L, PIN(3, 3), GPIO_INT_FALLING, usb1_evt) -GPIO_INT(BASE_SIXAXIS_INT_L, PIN(7, 3), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt) +GPIO_INT(BASE_SIXAXIS_INT_L, PIN(7, 3), GPIO_INT_FALLING | GPIO_SEL_1P8V, motion_interrupt) GPIO_INT(TABLET_MODE, PIN(C, 6), GPIO_INT_BOTH, gmr_tablet_switch_isr) GPIO(EN_PP3300_TRACKPAD, PIN(4, 5), GPIO_OUT_LOW) /* Enable TouchPad */ |