summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com>2021-08-18 10:06:20 +0800
committerCommit Bot <commit-bot@chromium.org>2021-09-13 03:15:21 +0000
commit6f181321c0a3268f59394863239d6c774c754d6e (patch)
treeb7cc91b6d7810adec13041f7e2f25499b0ff9f7b
parenta6d79daf925706c1169b8b0ef1e1032b18c0578b (diff)
downloadchrome-ec-6f181321c0a3268f59394863239d6c774c754d6e.tar.gz
rammus: Add accelerometer 2nd source KX022.
Add accelerometer 2nd source KX022. BUG=b:197005105 BRANCH=rammus TEST=make BOARD=rammus Using command "watch ectool motionsense lid_angle". Signed-off-by: Michael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com> Change-Id: Iea7fee7766730a8c054217877abb76facb55976a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3102685 Reviewed-by: Zhuohao Lee <zhuohao@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Commit-Queue: Zhuohao Lee <zhuohao@chromium.org> (cherry picked from commit e7de2313be106dc09fdc2c67eda7c190be5fa3e4) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3156305
-rw-r--r--board/rammus/board.c45
-rw-r--r--board/rammus/board.h1
-rw-r--r--board/rammus/build.mk2
-rw-r--r--board/rammus/cbi_ssfc.c31
-rw-r--r--board/rammus/cbi_ssfc.h39
5 files changed, 116 insertions, 2 deletions
diff --git a/board/rammus/board.c b/board/rammus/board.c
index 4fc874a2f9..d21968e468 100644
--- a/board/rammus/board.c
+++ b/board/rammus/board.c
@@ -11,6 +11,7 @@
#include "bd99992gw.h"
#include "board_config.h"
#include "button.h"
+#include "cbi_ssfc.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "charge_ramp.h"
@@ -20,6 +21,8 @@
#include "cros_board_info.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/accel_bma2x2.h"
+#include "driver/accel_kionix.h"
+#include "driver/accel_kx022.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
#include "driver/tcpm/tcpm.h"
@@ -601,8 +604,9 @@ static struct mutex g_base_mutex;
static struct bmi160_drv_data_t g_bmi160_data;
-/* BMA255 private data */
+/* private data */
static struct accelgyro_saved_data_t g_bma255_data;
+static struct kionix_accel_data g_kx022_data;
/* Matrix to rotate accelrator into standard reference frame */
const mat33_fp_t base_standard_ref = {
@@ -617,6 +621,35 @@ const mat33_fp_t lid_standard_ref = {
{ 0, 0, FLOAT_TO_FP(-1) }
};
+struct motion_sensor_t lid_accel_kx022 = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_KX022,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &kionix_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_kx022_data,
+ .port = I2C_PORT_ACCEL,
+ .addr = KX022_ADDR1,
+ .rot_standard_ref = &lid_standard_ref,
+ .min_frequency = KX022_ACCEL_MIN_FREQ,
+ .max_frequency = KX022_ACCEL_MAX_FREQ,
+ .default_range = 2, /* g, to support lid angle calculation. */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 0,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 0,
+ },
+ },
+};
+
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
.name = "Lid Accel",
@@ -693,6 +726,16 @@ struct motion_sensor_t motion_sensors[] = {
};
unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+static void board_detect_motionsense(void)
+{
+ if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_KX022) {
+ motion_sensors[LID_ACCEL] = lid_accel_kx022;
+ ccprints("LID_ACCEL is KX022");
+ } else
+ ccprints("LID_ACCEL is BMA253");
+}
+DECLARE_HOOK(HOOK_INIT, board_detect_motionsense, HOOK_PRIO_DEFAULT);
+
/* Enable or disable input devices, based on chipset state and tablet mode */
#ifndef TEST_BUILD
void lid_angle_peripheral_enable(int enable)
diff --git a/board/rammus/board.h b/board/rammus/board.h
index acd15753cb..4f0e7090d1 100644
--- a/board/rammus/board.h
+++ b/board/rammus/board.h
@@ -114,6 +114,7 @@
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT TASK_EVENT_CUSTOM(4)
#define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT
#define CONFIG_ACCEL_BMA255
+#define CONFIG_ACCEL_KX022
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_LID_ANGLE
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
diff --git a/board/rammus/build.mk b/board/rammus/build.mk
index 21f6e4c99e..5a9cabdcae 100644
--- a/board/rammus/build.mk
+++ b/board/rammus/build.mk
@@ -9,7 +9,7 @@
CHIP:=npcx
CHIP_VARIANT:=npcx5m6g
-board-y=board.o
+board-y=board.o cbi_ssfc.o
board-$(CONFIG_BATTERY_SMART)+=battery.o
board-$(CONFIG_LED_COMMON)+=led.o
board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
diff --git a/board/rammus/cbi_ssfc.c b/board/rammus/cbi_ssfc.c
new file mode 100644
index 0000000000..18954c6e68
--- /dev/null
+++ b/board/rammus/cbi_ssfc.c
@@ -0,0 +1,31 @@
+/* Copyright 2021 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 "console.h"
+#include "cros_board_info.h"
+#include "hooks.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 rammus_cbi_ssfc cached_ssfc;
+BUILD_ASSERT(sizeof(cached_ssfc) == sizeof(uint32_t));
+
+static void cbi_ssfc_init(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);
+}
+DECLARE_HOOK(HOOK_INIT, cbi_ssfc_init, HOOK_PRIO_INIT_I2C+1);
+
+enum ec_ssfc_lid_sensor get_cbi_ssfc_lid_sensor(void)
+{
+ return cached_ssfc.lid_sensor;
+}
diff --git a/board/rammus/cbi_ssfc.h b/board/rammus/cbi_ssfc.h
new file mode 100644
index 0000000000..09a1d49714
--- /dev/null
+++ b/board/rammus/cbi_ssfc.h
@@ -0,0 +1,39 @@
+/* Copyright 2021 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 _RAMMUS_CBI_SSFC__H_
+#define _RAMMUS_CBI_SSFC__H_
+
+#include "stdint.h"
+
+/****************************************************************************
+ * Rammus CBI Second Source Factory Cache
+ */
+
+/*
+ * Lid Sensor (Bits 2-0)
+ */
+enum ec_ssfc_lid_sensor {
+ SSFC_SENSOR_LID_DEFAULT = 0,
+ SSFC_SENSOR_LID_BMA255 = 1,
+ SSFC_SENSOR_LID_KX022 = 2
+};
+
+union rammus_cbi_ssfc {
+ struct {
+ enum ec_ssfc_lid_sensor lid_sensor : 3;
+ uint32_t reserved_2 : 29;
+ };
+ 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 /* _RAMMUS_CBI_SSFC__H_ */