diff options
author | Ben Chen <ben.chen2@quanta.corp-partner.google.com> | 2021-01-15 10:46:08 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-22 20:35:50 +0000 |
commit | 099240ecf4ebd3032285a6bafe9c106141e9bc91 (patch) | |
tree | 247f93e76cd179b8f3905e3c1f69abe86ab2d112 /board/magolor | |
parent | 35c3160422d5b9e4fd5f6d81034bf44f86b62245 (diff) | |
download | chrome-ec-099240ecf4ebd3032285a6bafe9c106141e9bc91.tar.gz |
magolor: Add motion sensor config for kx022/icm-426xx
Add icm-426xx config for new second source base accel/gyro,
and lid accel config for new second source.
BUG=b:176314158, b:176314157
BRANCH=main
TEST=Using ectool 'motionsense' verified lid angle now goes
from 0 to 360 and swtiches to tablet mode after crossing 200
threshold on re-work kx022/icm-426xx DUT.
Change-Id: I157ca9313f24726f51b829bc6da2dddbf7feeb49
Signed-off-by: Ben Chen <ben.chen2@quanta.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2631888
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'board/magolor')
-rw-r--r-- | board/magolor/board.c | 170 | ||||
-rw-r--r-- | board/magolor/board.h | 11 | ||||
-rw-r--r-- | board/magolor/gpio.inc | 2 |
3 files changed, 160 insertions, 23 deletions
diff --git a/board/magolor/board.c b/board/magolor/board.c index 0fb7f72db3..1ef86724a1 100644 --- a/board/magolor/board.c +++ b/board/magolor/board.c @@ -7,6 +7,7 @@ #include "adc_chip.h" #include "button.h" +#include "cbi_ssfc.h" #include "charge_manager.h" #include "charge_state_v2.h" #include "charger.h" @@ -15,6 +16,9 @@ #include "compile_time_macros.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi_common.h" +#include "driver/accelgyro_icm_common.h" +#include "driver/accelgyro_icm426xx.h" +#include "driver/accel_kionix.h" #include "driver/temp_sensor/thermistor.h" #include "temp_sensor.h" #include "driver/bc12/pi3usb9201.h" @@ -220,28 +224,6 @@ static void setup_thermal(void) thermal_params[TEMP_SENSOR_2] = thermal_b; } -void board_init(void) -{ - int on; - - gpio_enable_interrupt(GPIO_USB_C0_INT_ODL); - gpio_enable_interrupt(GPIO_SUB_USB_C1_INT_ODL); - check_c0_line(); - check_c1_line(); - - /* Enable gpio interrupt for base accelgyro sensor */ - gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L); - - /* Turn on 5V if the system is on, otherwise turn it off. */ - on = chipset_in_state(CHIPSET_STATE_ON | CHIPSET_STATE_ANY_SUSPEND | - CHIPSET_STATE_SOFT_OFF); - board_power_5v_enable(on); - - /* Initialize THERMAL */ - setup_thermal(); -} -DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); - void board_hibernate(void) { /* @@ -432,9 +414,99 @@ static const mat33_fp_t base_standard_ref = { { 0, 0, FLOAT_TO_FP(-1)} }; + +/* BMA253 private data */ static struct accelgyro_saved_data_t g_bma253_data; + +/* BMI160 private data */ static struct bmi_drv_data_t g_bmi160_data; +#ifdef BOARD_MAGOLOR +static const mat33_fp_t base_icm_ref = { + { 0, FLOAT_TO_FP(-1), 0}, + { FLOAT_TO_FP(1), 0, 0}, + { 0, 0, FLOAT_TO_FP(-1)} +}; + +/* ICM426 private data */ +static struct icm_drv_data_t g_icm426xx_data; +/* KX022 private data */ +static struct kionix_accel_data g_kx022_data; + +struct motion_sensor_t kx022_lid_accel = { + .name = "Lid Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_KX022, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &kionix_accel_drv, + .mutex = &g_lid_mutex, + .drv_data = &g_kx022_data, + .port = I2C_PORT_ACCEL, + .i2c_spi_addr_flags = KX022_ADDR0_FLAGS, + .rot_standard_ref = &lid_standard_ref, + .min_frequency = KX022_ACCEL_MIN_FREQ, + .max_frequency = KX022_ACCEL_MAX_FREQ, + .default_range = 2, /* g, to support tablet mode */ + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, +}; + +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_ACCEL, + .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS, + .default_range = 4, /* g, enough for laptop */ + .rot_standard_ref = &base_icm_ref, + .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, + }, + /* EC use accel 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_ACCEL, + .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS, + .default_range = 1000, /* dps */ + .rot_standard_ref = &base_standard_ref, + .min_frequency = ICM426XX_GYRO_MIN_FREQ, + .max_frequency = ICM426XX_GYRO_MAX_FREQ, +}; +#endif + struct motion_sensor_t motion_sensors[] = { [LID_ACCEL] = { .name = "Lid Accel", @@ -506,6 +578,60 @@ struct motion_sensor_t motion_sensors[] = { const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +void board_init(void) +{ + int on; + + gpio_enable_interrupt(GPIO_USB_C0_INT_ODL); + gpio_enable_interrupt(GPIO_SUB_USB_C1_INT_ODL); + check_c0_line(); + check_c1_line(); + + /* Enable gpio interrupt for base accelgyro sensor */ + gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L); + + /* Turn on 5V if the system is on, otherwise turn it off. */ + on = chipset_in_state(CHIPSET_STATE_ON | CHIPSET_STATE_ANY_SUSPEND | + CHIPSET_STATE_SOFT_OFF); + board_power_5v_enable(on); + + /* Initialize THERMAL */ + setup_thermal(); + + #ifdef BOARD_MAGOLOR + if (get_cbi_ssfc_base_sensor() == 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"); + + if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_KX022) { + motion_sensors[LID_ACCEL] = kx022_lid_accel; + ccprints("LID_ACCEL is KX022"); + } else + ccprints("LID_ACCEL is BMA253"); + #endif +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); + +void motion_interrupt(enum gpio_signal signal) +{ + #ifdef BOARD_MAGOLOR + switch (get_cbi_ssfc_base_sensor()) { + case SSFC_SENSOR_ICM426XX: + icm426xx_interrupt(signal); + break; + case SSFC_SENSOR_BMI160: + default: + bmi160_interrupt(signal); + break; + } + #else + bmi160_interrupt(signal); + #endif +} + __override void ocpc_get_pid_constants(int *kp, int *kp_div, int *ki, int *ki_div, int *kd, int *kd_div) diff --git a/board/magolor/board.h b/board/magolor/board.h index 2a9aecefea..cab934da2b 100644 --- a/board/magolor/board.h +++ b/board/magolor/board.h @@ -116,6 +116,11 @@ #define CONFIG_ACCEL_BMA255 /* Lid accel */ #define CONFIG_ACCELGYRO_BMI160 /* Base accel */ +#ifdef BOARD_MAGOLOR +#define CONFIG_ACCEL_KX022 /* Lid accel */ +#define CONFIG_ACCELGYRO_ICM426XX /* Base accel second source*/ +#endif + /* Lid operates in forced mode, base in FIFO */ #define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL) #define CONFIG_ACCEL_FIFO @@ -126,6 +131,11 @@ #define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#ifdef BOARD_MAGOLOR +#define CONFIG_ACCELGYRO_ICM426XX_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#endif + #define CONFIG_LID_ANGLE #define CONFIG_LID_ANGLE_UPDATE #define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL @@ -190,5 +200,6 @@ enum battery_type { }; int board_is_sourcing_vbus(int port); +void motion_interrupt(enum gpio_signal signal); #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/magolor/gpio.inc b/board/magolor/gpio.inc index d648b4245b..1fc059143e 100644 --- a/board/magolor/gpio.inc +++ b/board/magolor/gpio.inc @@ -34,7 +34,7 @@ GPIO_INT(H1_EC_PWR_BTN_ODL, PIN(0, 1), GPIO_INT_BOTH | GPIO_PULL_UP, power_butt /* Other interrupts */ GPIO_INT(LID_OPEN, PIN(D, 2), GPIO_INT_BOTH, lid_interrupt) GPIO_INT(EC_WP_OD, PIN(A, 1), GPIO_INT_BOTH, switch_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(LID_360_L, PIN(9, 5), GPIO_INT_BOTH, gmr_tablet_switch_isr) /* I2C Ports */ |