diff options
author | Paul Ma <magf@bitland.corp-partner.google.com> | 2019-08-09 09:28:02 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-08-21 05:46:33 +0000 |
commit | e1debcba165515eae87ea36034c43a8b58bff58f (patch) | |
tree | a55b55b92a3586460ec55bbe8d1e60913242b4c8 /board/treeya | |
parent | 0e894c6d4ae0426c9690a763a4ccd910226b5973 (diff) | |
download | chrome-ec-e1debcba165515eae87ea36034c43a8b58bff58f.tar.gz |
treeya: enable motion sensor drivers and fix ec feature flag
Treeya use two sets of base/lid sensors, one is BMI160/KX022 which
is supported by baseboard, another is LSM6DS3TR/LIS2DWL. This patch
will enable one of them according to sku_id.
This patch also remove keyboard backlight feature from ec feature
flags according to sku_id since both Treeya and Treeya360 do not
support keyboard backlight.
BUG=b:138744661, b:137945787, b:137849739
BRANCH=none
TEST=boot treeya boards which mounted BMI160/KX022 or
LSM6DS3TR/LIS2DWL, use 'accelinfo on' to enable sensor output,
make sure that their x/y/x value are correct.
Cq-Depend: chromium:1741598, chromium:1751302
Change-Id: I213a2073c2232ef0f2f70be788f859a264e09425
Signed-off-by: Paul Ma <magf@bitland.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1746006
Tested-by: Martin Roth <martinroth@chromium.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
Reviewed-by: Martin Roth <martinroth@chromium.org>
Commit-Queue: Martin Roth <martinroth@chromium.org>
Diffstat (limited to 'board/treeya')
-rw-r--r-- | board/treeya/board.c | 136 | ||||
-rw-r--r-- | board/treeya/board.h | 8 | ||||
-rw-r--r-- | board/treeya/gpio.inc | 2 |
3 files changed, 145 insertions, 1 deletions
diff --git a/board/treeya/board.c b/board/treeya/board.c index 3e341553fb..61c7180632 100644 --- a/board/treeya/board.c +++ b/board/treeya/board.c @@ -6,15 +6,19 @@ /* Treeya board-specific configuration */ #include "button.h" +#include "driver/accel_lis2dw12.h" #include "driver/accelgyro_bmi160.h" +#include "driver/accelgyro_lsm6dsm.h" #include "extpower.h" #include "i2c.h" #include "lid_switch.h" #include "power.h" #include "power_button.h" #include "pwm.h" +#include "system.h" #include "switch.h" #include "tablet_mode.h" +#include "task.h" #include "gpio_list.h" @@ -36,10 +40,131 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); +#ifdef HAS_TASK_MOTIONSENSE +/* Motion sensors */ +static struct mutex g_lid_mutex_1; +static struct mutex g_base_mutex_1; + +/* Lid accel private data */ +static struct stprivate_data g_lis2dwl_data; +/* Base accel private data */ +static struct lsm6dsm_data g_lsm6dsm_data; + + +/* Matrix to rotate accelrator into standard reference frame */ +static const mat33_fp_t lsm6dsm_base_standard_ref = { + { 0, FLOAT_TO_FP(1), 0}, + { FLOAT_TO_FP(-1), 0, 0}, + { 0, 0, FLOAT_TO_FP(1)} +}; + +/* just a placeholder, will revise when board is out */ +static const mat33_fp_t lis2dwl_lid_standard_ref = { + { 0, FLOAT_TO_FP(-1), 0}, + { FLOAT_TO_FP(-1), 0, 0}, + { 0, 0, FLOAT_TO_FP(-1)} +}; + +struct motion_sensor_t lid_accel_1 = { + .name = "Lid Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_LIS2DWL, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &lis2dw12_drv, + .mutex = &g_lid_mutex_1, + .drv_data = &g_lis2dwl_data, + .port = I2C_PORT_ACCEL, + .i2c_spi_addr_flags = LIS2DWL_ADDR1_FLAGS, + .rot_standard_ref = &lis2dwl_lid_standard_ref, + .default_range = 4, /* g */ + .min_frequency = LIS2DW12_ODR_MIN_VAL, + .max_frequency = LIS2DW12_ODR_MAX_VAL, + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 12500 | ROUND_UP_FLAG, + }, + /* Sensor on for lid angle detection */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, +}; + +struct motion_sensor_t base_accel_1 = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_LSM6DSM, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &lsm6dsm_drv, + .mutex = &g_base_mutex_1, + .drv_data = LSM6DSM_ST_DATA(g_lsm6dsm_data, + MOTIONSENSE_TYPE_ACCEL), + .int_signal = GPIO_6AXIS_INT_L, + .flags = MOTIONSENSE_FLAG_INT_SIGNAL, + .port = I2C_PORT_ACCEL, + .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS, + .rot_standard_ref = &lsm6dsm_base_standard_ref, + .default_range = 4, /* g */ + .min_frequency = LSM6DSM_ODR_MIN_VAL, + .max_frequency = LSM6DSM_ODR_MAX_VAL, + .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 base_gyro_1 = { + .name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_LSM6DSM, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &lsm6dsm_drv, + .mutex = &g_base_mutex_1, + .drv_data = LSM6DSM_ST_DATA(g_lsm6dsm_data, + MOTIONSENSE_TYPE_GYRO), + .int_signal = GPIO_6AXIS_INT_L, + .flags = MOTIONSENSE_FLAG_INT_SIGNAL, + .port = I2C_PORT_ACCEL, + .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS, + .default_range = 1000 | ROUND_UP_FLAG, /* dps */ + .rot_standard_ref = &lsm6dsm_base_standard_ref, + .min_frequency = LSM6DSM_ODR_MIN_VAL, + .max_frequency = LSM6DSM_ODR_MAX_VAL, +}; + +/* sku_id a8-a9 use ST sensors */ +static int board_use_st_sensor(void) +{ + uint32_t sku_id = system_get_sku_id(); + return sku_id == 0xa8 || sku_id == 0xa9; +} + +/* treeya board will use two sets of lid/base sensor, we need update + * sensors info according to sku id. + */ void board_update_sensor_config_from_sku(void) { if (board_is_convertible()) { + /* sku_id a8-a9 use ST sensors */ + if (board_use_st_sensor()) { + motion_sensors[LID_ACCEL] = lid_accel_1; + motion_sensors[BASE_ACCEL] = base_accel_1; + motion_sensors[BASE_GYRO] = base_gyro_1; + } + /* Enable Gyro interrupts */ gpio_enable_interrupt(GPIO_6AXIS_INT_L); } else { @@ -51,3 +176,14 @@ void board_update_sensor_config_from_sku(void) GPIO_INPUT | GPIO_PULL_DOWN); } } + +/* bmi160 or lsm6dsm need differenct interrupt function */ +void board_bmi160_lsm6dsm_interrupt(enum gpio_signal signal) +{ + if (board_use_st_sensor()) + lsm6dsm_interrupt(signal); + else + bmi160_interrupt(signal); +} + +#endif diff --git a/board/treeya/board.h b/board/treeya/board.h index 5f27d2e9d7..da0de296ec 100644 --- a/board/treeya/board.h +++ b/board/treeya/board.h @@ -52,6 +52,12 @@ #undef CONFIG_MOTION_SENSE_RESUME_DELAY_US #define CONFIG_MOTION_SENSE_RESUME_DELAY_US (10 * MSEC) +/* Second set of sensor drivers */ +#define CONFIG_ACCELGYRO_LSM6DSM +#define CONFIG_ACCEL_LSM6DSM_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#define CONFIG_ACCEL_LIS2DWL + #ifndef __ASSEMBLER__ @@ -62,6 +68,8 @@ enum battery_type { BATTERY_TYPE_COUNT, }; +void board_bmi160_lsm6dsm_interrupt(enum gpio_signal signal); + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/treeya/gpio.inc b/board/treeya/gpio.inc index 20f9cb6396..3ccdbfaf7f 100644 --- a/board/treeya/gpio.inc +++ b/board/treeya/gpio.inc @@ -22,7 +22,7 @@ GPIO_INT(AC_PRESENT, PIN(0, 0), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH, extpower_in GPIO_INT(WP_L, PIN(A, 1), GPIO_INT_BOTH, switch_interrupt) GPIO_INT(VOLUME_DOWN_L, PIN(7, 0), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) GPIO_INT(VOLUME_UP_L, PIN(7, 5), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) -GPIO_INT(6AXIS_INT_L, PIN(8, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt) +GPIO_INT(6AXIS_INT_L, PIN(8, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, board_bmi160_lsm6dsm_interrupt) /* GPIO_INT_BOTH is required for PSL wake from hibernate, but we don't need an interrupt handler. */ GPIO(EC_RST_ODL, PIN(0, 2), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH) |