diff options
author | Scott Collyer <scollyer@google.com> | 2019-02-11 17:50:35 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-27 13:43:43 -0800 |
commit | 62e6e0ac57958e976fd7575febe0c8d2926a39bf (patch) | |
tree | 5d26410a88228a2b9ebed15aacbae4d044ae4dd8 | |
parent | a3c27b39fa69f280a3728a5cf24de57a5d3ccb0d (diff) | |
download | chrome-ec-62e6e0ac57958e976fd7575febe0c8d2926a39bf.tar.gz |
hatch: Add support for base accelgyro bmi160 sensor
This CL adds the motion_sensor_t table, config options, gpio interrupt
signal, and rotation matrix required for the bmi160 base accel/gyro
sensor.
BUG=b:124337208
BRANCH=none
TEST=Verfied with 'ectool motionsense' that sensor readings are
present and that values move in the expected direction as I rotated
the unit along it's X and Y axis. Also verified the gyro sensor
returns non-zero values when moving the system.
Change-Id: I57c323916662a4ee0b9aa3fc00c3a4bf18aaef40
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1464393
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Tested-by: Zack Yang <zack_yang@compal.corp-partner.google.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
-rw-r--r-- | baseboard/hatch/baseboard.h | 20 | ||||
-rw-r--r-- | board/hatch/board.c | 71 | ||||
-rw-r--r-- | board/hatch/board.h | 12 | ||||
-rw-r--r-- | board/hatch/ec.tasklist | 1 | ||||
-rw-r--r-- | board/hatch/gpio.inc | 3 |
5 files changed, 106 insertions, 1 deletions
diff --git a/baseboard/hatch/baseboard.h b/baseboard/hatch/baseboard.h index e57b9a24e4..54edc83c9a 100644 --- a/baseboard/hatch/baseboard.h +++ b/baseboard/hatch/baseboard.h @@ -48,6 +48,26 @@ #define CONFIG_KEYBOARD_PROTOCOL_8042 #define CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2 +/* Sensors */ +#define CONFIG_MKBP_EVENT +/* + * TODO(b/125933998): Remove this config and use EC_PCH_INT_L to signal AP + * instead. + */ +#define CONFIG_MKBP_USE_HOST_EVENT +#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT +/* I2C_PORT_ACCEL needs to be defined for i2c transactions */ +#define I2C_PORT_ACCEL I2C_PORT_SENSOR + +/* FIFO size is in power of 2. */ +#define CONFIG_ACCEL_FIFO 256 +/* Depends on how fast the AP boots and typical ODRs */ +#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3) + +/* Sensor console commands */ +#define CONFIG_CMD_ACCELS +#define CONFIG_CMD_ACCEL_INFO + /* Common charger defines */ #define CONFIG_CHARGE_MANAGER #define CONFIG_CHARGE_RAMP_HW diff --git a/board/hatch/board.c b/board/hatch/board.c index 9bac034d31..5648dc016e 100644 --- a/board/hatch/board.c +++ b/board/hatch/board.c @@ -8,6 +8,7 @@ #include "adc.h" #include "adc_chip.h" #include "common.h" +#include "driver/accelgyro_bmi160.h" #include "driver/ppc/sn5s330.h" #include "ec_commands.h" #include "extpower.h" @@ -110,6 +111,66 @@ const struct pwm_t pwm_channels[] = { BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); /******************************************************************************/ +/* Sensors */ +/* Base Sensor mutex */ +static struct mutex g_base_mutex; + +/* Base accel private data */ +static struct bmi160_drv_data_t g_bmi160_data; + +/* Matrix to rotate accelrator into standard reference frame */ +static const mat33_fp_t base_standard_ref = { + { 0, FLOAT_TO_FP(1), 0}, + { FLOAT_TO_FP(-1), 0, 0}, + { 0, 0, FLOAT_TO_FP(1)} +}; + +struct motion_sensor_t motion_sensors[] = { + [BASE_ACCEL] = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi160_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, + .addr = BMI160_ADDR0, + .rot_standard_ref = &base_standard_ref, + .min_frequency = BMI160_ACCEL_MIN_FREQ, + .max_frequency = BMI160_ACCEL_MAX_FREQ, + .default_range = 2, /* g, to support tablet mode */ + .config = { + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + /* Sensor on in S3 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, + }, + [BASE_GYRO] = { + .name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi160_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, + .addr = BMI160_ADDR0, + .default_range = 1000, /* dps */ + .rot_standard_ref = &base_standard_ref, + .min_frequency = BMI160_GYRO_MIN_FREQ, + .max_frequency = BMI160_GYRO_MAX_FREQ, + }, +}; +unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); + +/******************************************************************************/ /* Physical fans. These are logically separate from pwm_channels. */ const struct fan_conf fan_conf_0 = { @@ -189,7 +250,15 @@ static void setup_fans(void) thermal_params[TEMP_SENSOR_1] = thermal_a; thermal_params[TEMP_SENSOR_2] = thermal_a; } -DECLARE_HOOK(HOOK_INIT, setup_fans, HOOK_PRIO_DEFAULT); + +static void board_init(void) +{ + /* Initialize Fans */ + setup_fans(); + /* Enable gpio interrupt for base accelgyro sensor */ + gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L); +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); void board_overcurrent_event(int port, int is_overcurrented) { diff --git a/board/hatch/board.h b/board/hatch/board.h index 5dc6a0fb67..0b2de2f9d0 100644 --- a/board/hatch/board.h +++ b/board/hatch/board.h @@ -29,6 +29,12 @@ /* Keyboard features */ #define CONFIG_PWM_KBLIGHT +/* Sensors */ +#define CONFIG_ACCEL_INTERRUPTS +#define CONFIG_ACCELGYRO_BMI160 +#define CONFIG_ACCELGYRO_BMI160_INT_EVENT TASK_EVENT_CUSTOM(4) +#define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT + /* Fan features */ #define CONFIG_FANS 1 #undef CONFIG_FAN_INIT_SPEED @@ -71,6 +77,12 @@ enum adc_channel { ADC_CH_COUNT }; +enum sensor_id { + BASE_ACCEL = 0, + BASE_GYRO, + SENSOR_COUNT, +}; + enum pwm_channel { PWM_CH_KBLIGHT, PWM_CH_FAN, diff --git a/board/hatch/ec.tasklist b/board/hatch/ec.tasklist index 55f289ad47..6a09d9f7d1 100644 --- a/board/hatch/ec.tasklist +++ b/board/hatch/ec.tasklist @@ -25,6 +25,7 @@ TASK_ALWAYS(USB_CHG_P0, usb_charger_task, 0, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(USB_CHG_P1, usb_charger_task, 1, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \ TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \ diff --git a/board/hatch/gpio.inc b/board/hatch/gpio.inc index cf2fb6a840..8400b570ca 100644 --- a/board/hatch/gpio.inc +++ b/board/hatch/gpio.inc @@ -23,6 +23,9 @@ GPIO_INT(SLP_S4_L, PIN(D, 4), GPIO_INT_BOTH, power_signal_interrupt) GPIO_INT(PG_EC_RSMRST_L, PIN(E, 2), GPIO_INT_BOTH, power_signal_interrupt) GPIO_INT(PG_EC_ALL_SYS_PWRGD, PIN(F, 4), GPIO_INT_BOTH, power_signal_interrupt) +/* Sensor Interrupts */ +GPIO_INT(BASE_SIXAXIS_INT_L, PIN(5, 6), GPIO_INT_FALLING, bmi160_interrupt) + /* USB-C interrupts */ GPIO_INT(USB_C0_PPC_INT_ODL, PIN(E, 0), GPIO_INT_FALLING, ppc_interrupt) GPIO_INT(USB_C1_PPC_INT_ODL, PIN(A, 2), GPIO_INT_FALLING, ppc_interrupt) |