summaryrefslogtreecommitdiff
path: root/board/lindar/board.c
diff options
context:
space:
mode:
authorjerry2.huang <jerry2.huang@lcfc.corp-partner.google.com>2020-09-28 19:44:24 +0800
committerCommit Bot <commit-bot@chromium.org>2020-10-07 08:10:26 +0000
commit90268827732825a4c537c40a95c0ae7fb9bcc75f (patch)
treec01a06b78c5b7420ae8ddf42e0a20a97ad8b931d /board/lindar/board.c
parent8347cde45488634cab4f60aa387a259a6dadf0b3 (diff)
downloadchrome-ec-90268827732825a4c537c40a95c0ae7fb9bcc75f.tar.gz
lindar: Add lid and base accel sensors for lindar and lillipup
Lindar uses LSM6DS3TR as base accel sensor. Lillipup uses LIS2DE12TR as lid accel sensor,and LSM6DS3TR as base accel sensor. The Lindar and Lillipup use the combination firmware, so add lid and base accel sensors at the same time. BUG=b:169530752 BRANCH=none TEST=make buildall -j Signed-off-by: jerry2.huang <jerry2.huang@lcfc.corp-partner.google.com> Change-Id: Ibc8733991f763d2f5c25112bd97ea8f18a61261e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2435170 Reviewed-by: YH Lin <yueherngl@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'board/lindar/board.c')
-rw-r--r--board/lindar/board.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/board/lindar/board.c b/board/lindar/board.c
index a4e685a837..ce30e301c9 100644
--- a/board/lindar/board.c
+++ b/board/lindar/board.c
@@ -8,6 +8,8 @@
#include "button.h"
#include "cbi_ec_fw_config.h"
#include "common.h"
+#include "driver/accel_lis2dh.h"
+#include "driver/accelgyro_lsm6dsm.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/ppc/sn5s330.h"
#include "driver/ppc/syv682x.h"
@@ -68,6 +70,17 @@ union volteer_cbi_fw_config fw_config_defaults = {
static void board_init(void)
{
+ if (ec_cfg_has_tabletmode()) {
+ /* Enable gpio interrupt for base accelgyro sensor */
+ gpio_enable_interrupt(GPIO_EC_IMU_INT_L);
+ } else {
+ motion_sensor_count = 0;
+ /* Device is clamshell only */
+ tablet_set_mode(0);
+ /* Gyro is not present, don't allow line to float */
+ gpio_set_flags(GPIO_EC_IMU_INT_L, GPIO_INPUT | GPIO_PULL_DOWN);
+ }
+
/*
* TODO: b/154447182 - Malefor will control power LED and battery LED
* independently, and keep the max brightness of power LED and battery
@@ -78,6 +91,128 @@ static void board_init(void)
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+int board_is_lid_angle_tablet_mode(void)
+{
+ return ec_cfg_has_tabletmode();
+}
+
+/* Enable or disable input devices, based on tablet mode or chipset state */
+#ifndef TEST_BUILD
+void lid_angle_peripheral_enable(int enable)
+{
+ if (ec_cfg_has_tabletmode()) {
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF) ||
+ tablet_get_mode())
+ enable = 0;
+ keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE);
+ }
+}
+#endif
+
+/******************************************************************************/
+/* Sensors */
+/* Lid and base Sensor mutex */
+static struct mutex g_lid_accel_mutex;
+static struct mutex g_base_mutex;
+
+/* Lid and base accel private data */
+static struct stprivate_data g_lis2dh_data;
+static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
+
+/* Matrix to rotate lid and base sensor into standard reference frame */
+static const mat33_fp_t lid_standard_ref = {
+ { 0, FLOAT_TO_FP(1), 0},
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(-1)}
+};
+
+static const mat33_fp_t base_standard_ref = {
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, FLOAT_TO_FP(-1), 0},
+ { 0, 0, FLOAT_TO_FP(-1)}
+};
+
+struct motion_sensor_t motion_sensors[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_LIS2DE,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &lis2dh_drv,
+ .mutex = &g_lid_accel_mutex,
+ .drv_data = &g_lis2dh_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = LIS2DH_ADDR1_FLAGS,
+ .rot_standard_ref = &lid_standard_ref,
+ .min_frequency = LIS2DH_ODR_MIN_VAL,
+ .max_frequency = LIS2DH_ODR_MAX_VAL,
+ .default_range = 2, /* g, to support tablet mode */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+
+ [BASE_ACCEL] = {
+ .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,
+ .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data,
+ MOTIONSENSE_TYPE_ACCEL),
+ .int_signal = GPIO_EC_IMU_INT_L,
+ .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS,
+ .rot_standard_ref = &base_standard_ref,
+ .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */
+ .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,
+ },
+ },
+ },
+
+ [BASE_GYRO] = {
+ .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,
+ .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data,
+ MOTIONSENSE_TYPE_GYRO),
+ .int_signal = GPIO_EC_IMU_INT_L,
+ .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS,
+ .default_range = 1000 | ROUND_UP_FLAG, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = LSM6DSM_ODR_MIN_VAL,
+ .max_frequency = LSM6DSM_ODR_MAX_VAL,
+ },
+};
+unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
/******************************************************************************/
/* Physical fans. These are logically separate from pwm_channels. */
@@ -176,6 +311,13 @@ BUILD_ASSERT(ARRAY_SIZE(mft_channels) == MFT_CH_COUNT);
/* I2C port map configuration */
const struct i2c_port_t i2c_ports[] = {
{
+ .name = "sensor",
+ .port = I2C_PORT_SENSOR,
+ .kbps = 400,
+ .scl = GPIO_EC_I2C0_SENSOR_SCL,
+ .sda = GPIO_EC_I2C0_SENSOR_SDA,
+ },
+ {
.name = "usb_c0",
.port = I2C_PORT_USB_C0,
.kbps = 1000,