summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@google.com>2021-06-02 10:54:52 -0600
committerCommit Bot <commit-bot@chromium.org>2021-06-07 18:15:22 +0000
commitecbd1339befef5b17e85751e4c075df5d45bdc26 (patch)
tree1b698db2ee1ca18edf84fb9e6fc17abc0284b361
parent4df10f7b2b0e67d1c36bb69285436ec0d5e3fdfd (diff)
downloadchrome-ec-ecbd1339befef5b17e85751e4c075df5d45bdc26.tar.gz
zephyr: asurada: Enable MotionSense
BUG=b:189857004 BRANCH=none TEST=zmake testall TEST=Flash on hayato and check sensors Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I9426b5a9cb2673da0ec8280aa15768815f47014c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2934359 Tested-by: Denis Brockus <dbrockus@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Yuval Peress <peress@chromium.org> Commit-Queue: Yuval Peress <peress@chromium.org>
-rw-r--r--zephyr/projects/asurada/hayato/CMakeLists.txt4
-rw-r--r--zephyr/projects/asurada/hayato/gpio.dts4
-rw-r--r--zephyr/projects/asurada/hayato/include/gpio_map.h12
-rw-r--r--zephyr/projects/asurada/hayato/motionsense.dts157
-rw-r--r--zephyr/projects/asurada/hayato/prj.conf19
-rw-r--r--zephyr/projects/asurada/hayato/src/sensors.c29
-rw-r--r--zephyr/projects/asurada/hayato/zmake.yaml1
7 files changed, 223 insertions, 3 deletions
diff --git a/zephyr/projects/asurada/hayato/CMakeLists.txt b/zephyr/projects/asurada/hayato/CMakeLists.txt
index 3d660fb8a5..979e1f7bf5 100644
--- a/zephyr/projects/asurada/hayato/CMakeLists.txt
+++ b/zephyr/projects/asurada/hayato/CMakeLists.txt
@@ -18,3 +18,7 @@ set(PLATFORM_EC_BOARD "${PLATFORM_EC}/board/hayato" CACHE PATH
zephyr_library_sources(
"${PLATFORM_EC_BASEBOARD}/board_chipset.c")
+
+# Board specific sensor implementation
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_MOTIONSENSE
+ "src/sensors.c")
diff --git a/zephyr/projects/asurada/hayato/gpio.dts b/zephyr/projects/asurada/hayato/gpio.dts
index 6782a35b2d..89b221acd3 100644
--- a/zephyr/projects/asurada/hayato/gpio.dts
+++ b/zephyr/projects/asurada/hayato/gpio.dts
@@ -44,9 +44,9 @@
enum-name = "GPIO_PMIC_EC_PWRGD";
label = "PMIC_EC_PWRGD";
};
- base_imu_int_l {
+ gpio_accel_gyro_int_l: base_imu_int_l {
gpios = <&gpioj 2 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>;
- enum-name = "GPIO_BASE_IMU_INT_L";
+ enum-name = "GPIO_EC_IMU_INT_L";
label = "BASE_IMU_INT_L";
};
lid_accel_int_l {
diff --git a/zephyr/projects/asurada/hayato/include/gpio_map.h b/zephyr/projects/asurada/hayato/include/gpio_map.h
index 180134049a..c8504425d7 100644
--- a/zephyr/projects/asurada/hayato/include/gpio_map.h
+++ b/zephyr/projects/asurada/hayato/include/gpio_map.h
@@ -12,6 +12,10 @@
#define GPIO_ENTERING_RW GPIO_UNIMPLEMENTED
#define GPIO_WP_L GPIO_UNIMPLEMENTED
+#ifdef CONFIG_PLATFORM_EC_GMR_TABLET_MODE
+#define GMR_TABLET_MODE_GPIO_L GPIO_TABLET_MODE_L
+#endif
+
/*
* Set EC_CROS_GPIO_INTERRUPTS to a space-separated list of GPIO_INT items.
*
@@ -31,7 +35,13 @@
GPIO_INT(GPIO_LID_OPEN, \
GPIO_INT_EDGE_BOTH, lid_interrupt) \
GPIO_INT(GPIO_POWER_BUTTON_L, \
- GPIO_INT_EDGE_BOTH, power_button_interrupt)
+ GPIO_INT_EDGE_BOTH, power_button_interrupt) \
+ GPIO_INT(GPIO_EC_IMU_INT_L, \
+ GPIO_INT_EDGE_FALLING, bmi160_interrupt) \
+ GPIO_INT(GPIO_LID_ACCEL_INT_L, \
+ GPIO_INT_EDGE_FALLING, lis2dw12_interrupt) \
+ GPIO_INT(GPIO_TABLET_MODE_L, \
+ GPIO_INT_EDGE_BOTH, gmr_tablet_switch_isr)
diff --git a/zephyr/projects/asurada/hayato/motionsense.dts b/zephyr/projects/asurada/hayato/motionsense.dts
new file mode 100644
index 0000000000..10128b0838
--- /dev/null
+++ b/zephyr/projects/asurada/hayato/motionsense.dts
@@ -0,0 +1,157 @@
+/* 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.
+ */
+
+#include <dt-bindings/motionsense/utils.h>
+
+
+/ {
+ aliases {
+ /*
+ * motion sense's <>_INT_EVENT is handled
+ * by alias. Using the alias, each driver creates
+ * its own <>_INT_EVENT.
+ */
+ bmi160-int = &base_accel;
+ lis2dw12-int = &lid_accel;
+ };
+
+ /*
+ * Declare mutexes used by sensor drivers.
+ * A mutex node is used to create an instance of mutex_t.
+ * A mutex node is referenced by a sensor node if the
+ * corresponding sensor driver needs to use the
+ * instance of the mutex.
+ */
+ motionsense-mutex {
+ compatible = "cros-ec,motionsense-mutex";
+ lid_mutex: lid-mutex {
+ label = "LID_MUTEX";
+ };
+
+ mutex_bmi160: bmi160-mutex {
+ label = "BMI160_MUTEX";
+ };
+ };
+
+ /* Rotation matrix used by drivers. */
+ motionsense-rotation-ref {
+ compatible = "cros-ec,motionsense-rotation-ref";
+ lid_rot_ref: lid-rotation-ref {
+ mat33 = <(-1) 0 0
+ 0 (-1) 0
+ 0 0 1>;
+ };
+
+ base_rot_ref: base-rotation-ref {
+ mat33 = <1 0 0
+ 0 (-1) 0
+ 0 0 (-1)>;
+ };
+ };
+
+ /*
+ * Driver specific data. A driver-specific data can be shared with
+ * different motion sensors while they are using the same driver.
+ *
+ * If a node's compatible starts with "cros-ec,accelgyro-", it is for
+ * a common structure defined in accelgyro.h.
+ * e.g) compatible = "cros-ec,accelgyro-als-drv-data" is for
+ * "struct als_drv_data_t" in accelgyro.h
+ */
+ motionsense-sensor-data {
+ bmi160_data: bmi160-drv-data {
+ compatible = "cros-ec,drvdata-bmi160";
+ status = "okay";
+ };
+
+ lis2dw12_data: lis2dw12-drv-data {
+ compatible = "cros-ec,drvdata-lis2dw12";
+ status = "okay";
+ };
+ };
+
+ /*
+ * List of motion sensors that creates motion_sensors array.
+ * The label "lid_accel" and "base_accel" are used to indicate
+ * motion sensor IDs for lid angle calculation.
+ */
+ motionsense-sensor {
+ lid_accel: lid-accel {
+ compatible = "cros-ec,lis2dw12";
+ status = "okay";
+
+ label = "Lid Accel";
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_LID";
+ mutex = <&lid_mutex>;
+ port = <&i2c_sensor>;
+ rot-standard-ref = <&lid_rot_ref>;
+ default-range = <2>;
+ drv-data = <&lis2dw12_data>;
+ configs {
+ compatible =
+ "cros-ec,motionsense-sensor-config";
+ ec-s0 {
+ label = "SENSOR_CONFIG_EC_S0";
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ ec-s3 {
+ label = "SENSOR_CONFIG_EC_S3";
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ };
+ };
+
+ base_accel: base-accel {
+ compatible = "cros-ec,bmi160-accel";
+ status = "okay";
+
+ label = "Base Accel";
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&mutex_bmi160>;
+ port = <&i2c_sensor>;
+ rot-standard-ref = <&base_rot_ref>;
+ drv-data = <&bmi160_data>;
+ configs {
+ compatible =
+ "cros-ec,motionsense-sensor-config";
+ ec-s0 {
+ label = "SENSOR_CONFIG_EC_S0";
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ ec-s3 {
+ label = "SENSOR_CONFIG_EC_S3";
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ };
+ };
+
+ base-gyro {
+ compatible = "cros-ec,bmi160-gyro";
+ status = "okay";
+
+ label = "Base Gyro";
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&mutex_bmi160>;
+ port = <&i2c_sensor>;
+ rot-standard-ref = <&base_rot_ref>;
+ drv-data = <&bmi160_data>;
+ };
+ };
+
+ motionsense-sensor-info {
+ compatible = "cros-ec,motionsense-sensor-info";
+
+ /*
+ * list of GPIO interrupts that have to
+ * be enabled at initial stage
+ */
+ sensor-irqs = <&gpio_accel_gyro_int_l>;
+ /* list of sensors in force mode */
+ accel-force-mode-sensors = <&lid_accel>;
+ };
+};
diff --git a/zephyr/projects/asurada/hayato/prj.conf b/zephyr/projects/asurada/hayato/prj.conf
index de1c961a9d..54d5db8d59 100644
--- a/zephyr/projects/asurada/hayato/prj.conf
+++ b/zephyr/projects/asurada/hayato/prj.conf
@@ -8,6 +8,25 @@ CONFIG_SHIMMED_TASKS=y
CONFIG_KERNEL_SHELL=y
+# Sensors
+CONFIG_PLATFORM_EC_MOTIONSENSE=y
+CONFIG_PLATFORM_EC_ACCEL_FIFO=y
+CONFIG_PLATFORM_EC_ACCEL_INTERRUPTS=y
+CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCELS=y
+CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCEL_INFO=y
+CONFIG_PLATFORM_EC_GMR_TABLET_MODE=y
+CONFIG_PLATFORM_EC_LID_ANGLE=y
+CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y
+CONFIG_PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS=y
+CONFIG_PLATFORM_EC_TABLET_MODE=y
+CONFIG_PLATFORM_EC_TABLET_MODE_SWITCH=y
+
+# Sensor Drivers
+CONFIG_PLATFORM_EC_ACCEL_LIS2DW12=y
+CONFIG_PLATFORM_EC_ACCEL_LIS2DW12_AS_BASE=y
+CONFIG_PLATFORM_EC_ACCELGYRO_BMI160=y
+CONFIG_PLATFORM_EC_ACCELGYRO_BMI_COMM_I2C=y
+
# TODO(b/180980668): bring these features up
CONFIG_LTO=n
CONFIG_PLATFORM_EC_BACKLIGHT_LID=n
diff --git a/zephyr/projects/asurada/hayato/src/sensors.c b/zephyr/projects/asurada/hayato/src/sensors.c
new file mode 100644
index 0000000000..6207461976
--- /dev/null
+++ b/zephyr/projects/asurada/hayato/src/sensors.c
@@ -0,0 +1,29 @@
+/* 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 "chipset.h"
+#include "common.h"
+#include "keyboard_scan.h"
+
+/* Hayato board specific sensor implementation */
+
+#ifdef CONFIG_LID_ANGLE_UPDATE
+void lid_angle_peripheral_enable(int enable)
+{
+ int chipset_in_s0 = chipset_in_state(CHIPSET_STATE_ON);
+
+ if (enable) {
+ keyboard_scan_enable(1, KB_SCAN_DISABLE_LID_ANGLE);
+ } else {
+ /*
+ * Ensure that the chipset is off before disabling the keyboard.
+ * When the chipset is on, the EC keeps the keyboard enabled and
+ * the AP decides whether to ignore input devices or not.
+ */
+ if (!chipset_in_s0)
+ keyboard_scan_enable(0, KB_SCAN_DISABLE_LID_ANGLE);
+ }
+}
+#endif
diff --git a/zephyr/projects/asurada/hayato/zmake.yaml b/zephyr/projects/asurada/hayato/zmake.yaml
index cda916c4ea..8501d63dc3 100644
--- a/zephyr/projects/asurada/hayato/zmake.yaml
+++ b/zephyr/projects/asurada/hayato/zmake.yaml
@@ -5,6 +5,7 @@
board: asurada
dts-overlays:
- gpio.dts
+ - motionsense.dts
supported-zephyr-versions:
- v2.5
toolchain: coreboot-sdk