summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Ma <magf@bitland.corp-partner.google.com>2019-08-09 09:28:02 +0800
committerCommit Bot <commit-bot@chromium.org>2019-08-23 00:12:37 +0000
commitad1e0290c930777ca260315ce3c810209ec4a043 (patch)
treeefdb57466c3c25a56c7013a0e8daf2ab9cc889f5
parente9a8f2a02e1d8a0f05b17799de4ab300ff312c80 (diff)
downloadchrome-ec-ad1e0290c930777ca260315ce3c810209ec4a043.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> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1767535 Commit-Queue: Edward Hill <ecgh@chromium.org> Tested-by: Edward Hill <ecgh@chromium.org>
-rw-r--r--baseboard/grunt/baseboard.c8
-rw-r--r--board/treeya/board.c136
-rw-r--r--board/treeya/board.h8
-rw-r--r--board/treeya/gpio.inc2
4 files changed, 151 insertions, 3 deletions
diff --git a/baseboard/grunt/baseboard.c b/baseboard/grunt/baseboard.c
index d0248acef5..6147de2282 100644
--- a/baseboard/grunt/baseboard.c
+++ b/baseboard/grunt/baseboard.c
@@ -753,7 +753,9 @@ int board_is_convertible(void)
{
/* Grunt: 6 */
/* Kasumi360: 82 */
- return (sku_id == 6 || sku_id == 82);
+ /* Treeya360: a8-af */
+ return (sku_id == 6 || sku_id == 82 ||
+ ((sku_id >= 0xa8) && (sku_id <= 0xaf)));
}
int board_is_lid_angle_tablet_mode(void)
@@ -765,10 +767,12 @@ uint32_t board_override_feature_flags0(uint32_t flags0)
{
/*
* Remove keyboard backlight feature for devices that don't support it.
+ * All Treeya and Treeya360 models do not support keyboard backlight.
*/
if (sku_id == 16 || sku_id == 17 ||
sku_id == 20 || sku_id == 21 ||
- sku_id == 32 || sku_id == 33)
+ sku_id == 32 || sku_id == 33 ||
+ ((sku_id >= 0xa0) && (sku_id <= 0xaf)))
return (flags0 & ~EC_FEATURE_MASK_0(EC_FEATURE_PWM_KEYB));
else
return flags0;
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)