summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Lu <Devin.Lu@quantatw.com>2022-02-14 17:23:27 +0800
committerCommit Bot <commit-bot@chromium.org>2022-02-17 05:24:07 +0000
commiteedacab7c0c34a4b170cd5497c3325e9cec60510 (patch)
treec8e01a8af01ab400d0f641d92ed31e50f74b67d6
parent547d8f2ea1a7819de022c72d3b4d2a6b3a68d412 (diff)
downloadchrome-ec-eedacab7c0c34a4b170cd5497c3325e9cec60510.tar.gz
redrix: Add SSFC field for 2nd LID sensor
This patch adds SSFC field to support the 2nd LID sensor. BUG=b:219450750 BRANCH=none TEST=On Redix. Set SSFC and make sure the LID sensor works normally. Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Change-Id: I5435f3d8c44745c7e53d6e8838ed31b6d798d9ef Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3459595 Reviewed-by: caveh jalali <caveh@chromium.org>
-rw-r--r--board/redrix/board.h1
-rw-r--r--board/redrix/build.mk1
-rw-r--r--board/redrix/cbi_ssfc.c30
-rw-r--r--board/redrix/cbi_ssfc.h39
-rw-r--r--board/redrix/sensors.c40
5 files changed, 111 insertions, 0 deletions
diff --git a/board/redrix/board.h b/board/redrix/board.h
index 5b3cff0065..89f297b148 100644
--- a/board/redrix/board.h
+++ b/board/redrix/board.h
@@ -24,6 +24,7 @@
/* Sensors */
#define CONFIG_ACCEL_BMA255 /* Lid accel */
+#define CONFIG_ACCEL_BMA4XX /* 2nd source Lid accel */
#define CONFIG_ACCELGYRO_LSM6DSM /* Base accel */
#define CONFIG_ACCEL_LSM6DSM_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
diff --git a/board/redrix/build.mk b/board/redrix/build.mk
index 0c5e8e6182..7177a844ad 100644
--- a/board/redrix/build.mk
+++ b/board/redrix/build.mk
@@ -14,6 +14,7 @@ BASEBOARD:=brya
board-y=
board-y+=battery.o
board-y+=board.o
+board-y+=cbi_ssfc.o
board-y+=charger.o
board-y+=fans.o
board-y+=fw_config.o
diff --git a/board/redrix/cbi_ssfc.c b/board/redrix/cbi_ssfc.c
new file mode 100644
index 0000000000..364b3d96fe
--- /dev/null
+++ b/board/redrix/cbi_ssfc.c
@@ -0,0 +1,30 @@
+/* Copyright 2022 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.
+ */
+
+#include "cbi_ssfc.h"
+#include "common.h"
+#include "compile_time_macros.h"
+#include "console.h"
+#include "cros_board_info.h"
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
+
+/* Cache SSFC on init since we don't expect it to change in runtime */
+static union redrix_cbi_ssfc cached_ssfc;
+BUILD_ASSERT(sizeof(cached_ssfc) == sizeof(uint32_t));
+
+void board_init_ssfc(void)
+{
+ if (cbi_get_ssfc(&cached_ssfc.raw_value) != EC_SUCCESS)
+ /* Default to 0 when CBI isn't populated */
+ cached_ssfc.raw_value = 0;
+
+ CPRINTS("Read CBI SSFC : 0x%04X", cached_ssfc.raw_value);
+}
+
+enum ec_ssfc_lid_sensor get_cbi_ssfc_lid_sensor(void)
+{
+ return cached_ssfc.lid_sensor;
+}
diff --git a/board/redrix/cbi_ssfc.h b/board/redrix/cbi_ssfc.h
new file mode 100644
index 0000000000..ddcfbb9281
--- /dev/null
+++ b/board/redrix/cbi_ssfc.h
@@ -0,0 +1,39 @@
+/* Copyright 2022 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.
+ */
+
+#ifndef _REDRIX_CBI_SSFC_H_
+#define _REDRIX_CBI_SSFC_H_
+
+#include "stdint.h"
+
+/****************************************************************************
+ * Redrix CBI Second Source Factory Cache
+ */
+
+/*
+ * Lid Sensor (Bits 0-1)
+ */
+enum ec_ssfc_lid_sensor {
+ SSFC_SENSOR_LID_DEFAULT = 0,
+ SSFC_SENSOR_LID_BMA253 = 1,
+ SSFC_SENSOR_LID_BMA422 = 2
+};
+
+union redrix_cbi_ssfc {
+ struct {
+ enum ec_ssfc_lid_sensor lid_sensor : 2;
+ uint32_t reserved_1 : 30;
+ };
+ uint32_t raw_value;
+};
+
+/**
+ * Get the Lid sensor type from SSFC_CONFIG.
+ *
+ * @return the Lid sensor board type.
+ */
+enum ec_ssfc_lid_sensor get_cbi_ssfc_lid_sensor(void);
+
+#endif /* _REDRIX_CBI_SSFC_H_ */
diff --git a/board/redrix/sensors.c b/board/redrix/sensors.c
index df152b8d1c..5d02b1633d 100644
--- a/board/redrix/sensors.c
+++ b/board/redrix/sensors.c
@@ -6,7 +6,9 @@
#include "common.h"
#include "accelgyro.h"
#include "adc_chip.h"
+#include "cbi_ssfc.h"
#include "driver/accel_bma2x2.h"
+#include "driver/accel_bma422.h"
#include "driver/accelgyro_lsm6dsm.h"
#include "driver/als_tcs3400_public.h"
#include "hooks.h"
@@ -51,6 +53,7 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
K_MUTEX_DEFINE(g_lid_accel_mutex);
K_MUTEX_DEFINE(g_base_accel_mutex);
static struct accelgyro_saved_data_t g_bma253_data;
+static struct accelgyro_saved_data_t g_bma422_data;
static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
static const mat33_fp_t lid_standard_ref = {
@@ -233,6 +236,41 @@ struct motion_sensor_t motion_sensors[] = {
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+struct motion_sensor_t bma422_lid_accel = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMA422,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bma4_accel_drv,
+ .mutex = &g_lid_accel_mutex,
+ .drv_data = &g_bma422_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMA4_I2C_ADDR_PRIMARY,
+ .rot_standard_ref = &lid_standard_ref,
+ .default_range = 2, /* g, enough for laptop. */
+ .min_frequency = BMA4_ACCEL_MIN_FREQ,
+ .max_frequency = BMA4_ACCEL_MAX_FREQ,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 12500 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 12500 | ROUND_UP_FLAG,
+ .ec_rate = 0,
+ },
+ },
+};
+
+static void board_update_motion_sensor_config(void)
+{
+ if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_BMA422)
+ motion_sensors[LID_ACCEL] = bma422_lid_accel;
+}
+
/* 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],
@@ -245,6 +283,8 @@ static void board_sensors_init(void)
gpio_enable_interrupt(GPIO_EC_ALS_RGB_INT_R_L);
/* Enable gpio interrupt for base accelgyro sensor */
gpio_enable_interrupt(GPIO_EC_IMU_INT_R_L);
+
+ board_update_motion_sensor_config();
}
DECLARE_HOOK(HOOK_INIT, board_sensors_init, HOOK_PRIO_INIT_I2C + 1);