summaryrefslogtreecommitdiff
path: root/board/malefor
diff options
context:
space:
mode:
authorxiong.huang <xiong.huang@bitland.corp-partner.google.com>2020-03-24 19:43:56 +0800
committerCommit Bot <commit-bot@chromium.org>2020-03-26 18:40:53 +0000
commitc61fb94432340c1b2531d5d4ab23e46bcac8bc77 (patch)
tree2d69cdb317e47b7f351db12bd21bd329ae6aca6e /board/malefor
parent39088753b33270156592866df2a21927f0f2b653 (diff)
downloadchrome-ec-c61fb94432340c1b2531d5d4ab23e46bcac8bc77.tar.gz
malefor: Add lid and base accel sensors
Malefor uses LIS2DE12TR as lid accel sensor and LSM6DS3TR as base accel sensor. AT the same time, remove unused sensor driver, like ALS sensor. BUG=b:150653745, b:152434719 BRANCH=none TEST=make buildall Signed-off-by: xiong.huang <xiong.huang@bitland.corp-partner.google.com> Change-Id: I13364c3883940b7c9360f133763f00f316dfddc5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2118031 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'board/malefor')
-rw-r--r--board/malefor/board.c128
-rw-r--r--board/malefor/board.h31
-rw-r--r--board/malefor/build.mk1
-rw-r--r--board/malefor/gpio.inc2
-rw-r--r--board/malefor/sensors.c184
5 files changed, 144 insertions, 202 deletions
diff --git a/board/malefor/board.c b/board/malefor/board.c
index c0466dec76..d439533a70 100644
--- a/board/malefor/board.c
+++ b/board/malefor/board.c
@@ -7,9 +7,8 @@
#include "button.h"
#include "common.h"
-#include "accelgyro.h"
-#include "driver/accel_bma2x2.h"
-#include "driver/als_tcs3400.h"
+#include "driver/accel_lis2dh.h"
+#include "driver/accelgyro_lsm6dsm.h"
#include "driver/sync.h"
#include "extpower.h"
#include "gpio.h"
@@ -29,7 +28,11 @@
static void board_init(void)
{
- /* TODO */
+ /* Enable gpio interrupt for base accelgyro sensor */
+ gpio_enable_interrupt(GPIO_EC_IMU_INT_L);
+
+ /* Enable gpio interrupt for camera vsync */
+ gpio_enable_interrupt(GPIO_EC_CAM_VSYN_SLP_S0IX);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
@@ -58,3 +61,120 @@ __override bool board_is_tbt_usb4_port(int port)
*/
return port == USBC_PORT_C1;
}
+
+/******************************************************************************/
+/* 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,
+ },
+
+ [VSYNC] = {
+ .name = "Camera VSYNC",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_GPIO,
+ .type = MOTIONSENSE_TYPE_SYNC,
+ .location = MOTIONSENSE_LOC_CAMERA,
+ .drv = &sync_drv,
+ .default_range = 0,
+ .min_frequency = 0,
+ .max_frequency = 1,
+ },
+};
+unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
diff --git a/board/malefor/board.h b/board/malefor/board.h
index af82faaf28..49082742ab 100644
--- a/board/malefor/board.h
+++ b/board/malefor/board.h
@@ -22,19 +22,26 @@
/* Keyboard features */
/* Sensors */
-/* BMA253 accelerometer in base */
-#define CONFIG_ACCEL_BMA255
-
-/* TCS3400 ALS */
-#define CONFIG_ALS
-#define ALS_COUNT 1
-#define CONFIG_ALS_TCS3400
-#define CONFIG_ALS_TCS3400_INT_EVENT \
- TASK_EVENT_MOTION_SENSOR_INTERRUPT(CLEAR_ALS)
+#define CONFIG_ACCEL_LIS2DE /* Lid accel */
+#define CONFIG_ACCELGYRO_LSM6DSM /* Base accel */
/* Sensors without hardware FIFO are in forced mode */
#define CONFIG_ACCEL_FORCE_MODE_MASK \
- (BIT(LID_ACCEL) | BIT(CLEAR_ALS))
+ BIT(LID_ACCEL)
+
+/*
+ * TODO: b/152434719 - Malefor will support 360-degree rotation of the
+ * lid on some SKUs, these macros will be enabled once covers are ready.
+ */
+#if 0
+#define CONFIG_LID_ANGLE
+#define CONFIG_LID_ANGLE_UPDATE
+#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
+#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
+#endif
+
+#define CONFIG_ACCEL_LSM6DSM_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
/* USB Type C and USB PD defines */
/*
@@ -98,8 +105,8 @@ enum battery_type {
enum sensor_id {
LID_ACCEL = 0,
- CLEAR_ALS,
- RGB_ALS,
+ BASE_ACCEL,
+ BASE_GYRO,
VSYNC,
SENSOR_COUNT,
};
diff --git a/board/malefor/build.mk b/board/malefor/build.mk
index d9d20ff7c7..5a2ccd3d79 100644
--- a/board/malefor/build.mk
+++ b/board/malefor/build.mk
@@ -30,4 +30,3 @@ ENV_VARS := VOLTEER_POWER_SEQUENCE
board-y=board.o
board-y+=battery.o
board-$(VOLTEER_POWER_SEQUENCE)+=power_sequence.o
-board-y+=sensors.o
diff --git a/board/malefor/gpio.inc b/board/malefor/gpio.inc
index 93f48572e1..b80350e97f 100644
--- a/board/malefor/gpio.inc
+++ b/board/malefor/gpio.inc
@@ -31,7 +31,7 @@ GPIO_INT(PG_EC_ALL_SYS_PWRGD, PIN(F, 4), GPIO_INT_BOTH, power_signal_interrupt
/* Sensor Interrupts */
GPIO_INT(EC_CAM_VSYN_SLP_S0IX, PIN(7, 2), GPIO_INT_RISING, sync_interrupt)
-GPIO_INT(EC_ALS_RGB_INT_L, PIN(D, 4), GPIO_INT_FALLING, tcs3400_interrupt)
+GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, lsm6dsm_interrupt)
GPIO_INT(TABLET_MODE_L, PIN(9, 5), GPIO_INT_BOTH, gmr_tablet_switch_isr)
/* USB-C interrupts */
diff --git a/board/malefor/sensors.c b/board/malefor/sensors.c
deleted file mode 100644
index e13d7fd57e..0000000000
--- a/board/malefor/sensors.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/* Copyright 2020 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Volteer family-specific sensor configuration */
-#include "common.h"
-#include "accelgyro.h"
-#include "driver/accel_bma2x2.h"
-#include "driver/als_tcs3400.h"
-#include "driver/sync.h"
-#include "keyboard_scan.h"
-#include "hooks.h"
-#include "task.h"
-#include "util.h"
-
-/******************************************************************************/
-/* Sensors */
-static struct mutex g_lid_accel_mutex;
-
-/* BMA253 private data */
-static struct accelgyro_saved_data_t g_bma253_data;
-
-/* TCS3400 private data */
-static struct als_drv_data_t g_tcs3400_data = {
- .als_cal.scale = 1,
- .als_cal.uscale = 0,
- .als_cal.offset = 0,
- .als_cal.channel_scale = {
- .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kc from VPD */
- .cover_scale = ALS_CHANNEL_SCALE(1.0), /* CT */
- },
-};
-
-/*
- * TODO: b/146166425 need to calibrate ALS/RGB sensor. At default settings,
- * shining phone flashlight on sensor pegs all readings at 0xFFFF.
- */
-static struct tcs3400_rgb_drv_data_t g_tcs3400_rgb_data = {
- .calibration.rgb_cal[X] = {
- .offset = 0,
- .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0),
- .scale = {
- .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kr */
- .cover_scale = ALS_CHANNEL_SCALE(1.0)
- }
- },
- .calibration.rgb_cal[Y] = {
- .offset = 0,
- .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0),
- .scale = {
- .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kg */
- .cover_scale = ALS_CHANNEL_SCALE(1.0)
- },
- },
- .calibration.rgb_cal[Z] = {
- .offset = 0,
- .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(0),
- .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0),
- .scale = {
- .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kb */
- .cover_scale = ALS_CHANNEL_SCALE(1.0)
- }
- },
- .calibration.irt = INT_TO_FP(1),
- .saturation.again = TCS_DEFAULT_AGAIN,
- .saturation.atime = TCS_DEFAULT_ATIME,
-};
-
-/* Rotation matrix for the lid accelerometer */
-/* TODO: b/146144170 - the accelerometer is on the motherboard for proto1
- * for testing. Once the sensor moves to the lid, the rotation matrix needs
- * to be updated for correct behavior.
- */
-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)}
-};
-
-struct motion_sensor_t motion_sensors[] = {
- [LID_ACCEL] = {
- .name = "Lid Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_BMA255,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &bma2x2_accel_drv,
- .mutex = &g_lid_accel_mutex,
- .drv_data = &g_bma253_data,
- .port = I2C_PORT_SENSOR,
- .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS,
- .rot_standard_ref = &lid_standard_ref,
- .min_frequency = BMA255_ACCEL_MIN_FREQ,
- .max_frequency = BMA255_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,
- },
- /* Sensor on in S3 */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- },
- },
-
- [CLEAR_ALS] = {
- .name = "Clear Light",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_TCS3400,
- .type = MOTIONSENSE_TYPE_LIGHT,
- .location = MOTIONSENSE_LOC_BASE,
- .drv = &tcs3400_drv,
- .drv_data = &g_tcs3400_data,
- .port = I2C_PORT_SENSOR,
- .i2c_spi_addr_flags = TCS3400_I2C_ADDR_FLAGS,
- .rot_standard_ref = NULL,
- .default_range = 0x10000, /* scale = 1x, uscale = 0 */
- .min_frequency = TCS3400_LIGHT_MIN_FREQ,
- .max_frequency = TCS3400_LIGHT_MAX_FREQ,
- .config = {
- /* Run ALS sensor in S0 */
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 1000,
- },
- },
- },
-
- [RGB_ALS] = {
- /*
- * RGB channels read by CLEAR_ALS and so the i2c port and
- * address do not need to be defined for RGB_ALS.
- */
- .name = "RGB Light",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_TCS3400,
- .type = MOTIONSENSE_TYPE_LIGHT_RGB,
- .location = MOTIONSENSE_LOC_BASE,
- .drv = &tcs3400_rgb_drv,
- .drv_data = &g_tcs3400_rgb_data,
- .rot_standard_ref = NULL,
- .default_range = 0x10000, /* scale = 1x, uscale = 0 */
- },
-
- [VSYNC] = {
- .name = "Camera VSYNC",
- .active_mask = SENSOR_ACTIVE_S0,
- .chip = MOTIONSENSE_CHIP_GPIO,
- .type = MOTIONSENSE_TYPE_SYNC,
- .location = MOTIONSENSE_LOC_CAMERA,
- .drv = &sync_drv,
- .default_range = 0,
- .min_frequency = 0,
- .max_frequency = 1,
- },
-};
-unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
-
-/* ALS instances when LPC mapping is needed. Each entry directs to a sensor. */
-const struct motion_sensor_t *motion_als_sensors[] = {
- &motion_sensors[CLEAR_ALS],
-};
-BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT);
-
-static void baseboard_sensors_init(void)
-{
- /* Note - BMA253 interrupt unused by EC */
-
- /* Enable gpio interrupt for camera vsync */
- gpio_enable_interrupt(GPIO_EC_CAM_VSYN_SLP_S0IX);
- /* Enable interrupt for the TCS3400 color light sensor */
- gpio_enable_interrupt(GPIO_EC_ALS_RGB_INT_L);
-}
-DECLARE_HOOK(HOOK_INIT, baseboard_sensors_init, HOOK_PRIO_DEFAULT);