summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Tsai <josh_tsai@compal.corp-partner.google.com>2021-07-12 08:51:32 +0800
committerCommit Bot <commit-bot@chromium.org>2021-07-21 01:26:35 +0000
commita1939eed1e33c2a50e985fc9bf52c23a439186eb (patch)
tree61a220a98517e8981344cbb43096bf06e3549300
parent18bcc95366a2b415b4a9bd74cda56bce109f9bb7 (diff)
downloadchrome-ec-a1939eed1e33c2a50e985fc9bf52c23a439186eb.tar.gz
Pompom: Support the second source sensor LIS2DWL
Need cut-in 2nd source to secure that can keep production for shipment. BUG=b:193209502 BRANCH=trogdor TEST=Both BMA253 and LIS2DWL sensor can work Signed-off-by: Josh Tsai <josh_tsai@compal.corp-partner.google.com> Change-Id: Iaf860ea4158cb2e09ad1aed1c7baaf904579cde0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3020126 Reviewed-by: Wai-Hong Tam <waihong@google.com>
-rw-r--r--board/pompom/board.c53
-rw-r--r--board/pompom/board.h1
2 files changed, 54 insertions, 0 deletions
diff --git a/board/pompom/board.c b/board/pompom/board.c
index 64a9620ba2..c4e4f02a63 100644
--- a/board/pompom/board.c
+++ b/board/pompom/board.c
@@ -11,6 +11,7 @@
#include "charge_state.h"
#include "extpower.h"
#include "driver/accel_bma2x2.h"
+#include "driver/accel_lis2dw12.h"
#include "driver/accelgyro_bmi_common.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/ps8xxx.h"
@@ -499,6 +500,7 @@ static struct mutex g_lid_mutex;
static struct bmi_drv_data_t g_bmi160_data;
static struct accelgyro_saved_data_t g_bma255_data;
+static struct stprivate_data g_lis2dwl_data;
/* Matrix to rotate accelerometer into standard reference frame */
const mat33_fp_t base_standard_ref = {
@@ -589,6 +591,57 @@ struct motion_sensor_t motion_sensors[] = {
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+struct motion_sensor_t lis2dwl_lid_accel = {
+ .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,
+ .drv_data = &g_lis2dwl_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = LIS2DWL_ADDR0_FLAGS,
+ .rot_standard_ref = &lid_standard_ref,
+ .default_range = 2, /* 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,
+ },
+ },
+};
+
+static void board_detect_motionsensor(void)
+{
+ int val = 0;
+
+ /*
+ * BMA253 and LIS2DWL have same slave address, so we check the
+ * LIS2DWL WHO AM I register to check the lid accel type
+ */
+ i2c_read8(I2C_PORT_SENSOR, LIS2DWL_ADDR0_FLAGS,
+ LIS2DW12_WHO_AM_I_REG, &val);
+
+ if (val == LIS2DW12_WHO_AM_I) {
+ motion_sensors[LID_ACCEL] = lis2dwl_lid_accel;
+ CPRINTS("Lid Accel: LIS2DWL");
+ }
+}
+
+static void board_update_sensor_config_from_sku(void)
+{
+ board_detect_motionsensor();
+}
+DECLARE_HOOK(HOOK_INIT, board_update_sensor_config_from_sku,
+ HOOK_PRIO_INIT_I2C + 2);
+
#ifndef TEST_BUILD
/* This callback disables keyboard when convertibles are fully open */
void lid_angle_peripheral_enable(int enable)
diff --git a/board/pompom/board.h b/board/pompom/board.h
index 6cbe7a4d27..c8c9476b25 100644
--- a/board/pompom/board.h
+++ b/board/pompom/board.h
@@ -45,6 +45,7 @@
/* BMA253 lid accel */
#define CONFIG_ACCEL_BMA255
+#define CONFIG_ACCEL_LIS2DWL
#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL)
#define CONFIG_LID_ANGLE