summaryrefslogtreecommitdiff
path: root/zephyr/projects
diff options
context:
space:
mode:
authorHyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com>2021-04-19 16:51:10 -0700
committerCommit Bot <commit-bot@chromium.org>2021-04-26 18:40:35 +0000
commit0755def82f3bc526c9e56ec725d85f3f55adc05d (patch)
treea7e15544ead870bc5675a6730cc1d2bc2123b970 /zephyr/projects
parent4641d7655be01b5585b47b537d50647b5f1876ea (diff)
downloadchrome-ec-0755def82f3bc526c9e56ec725d85f3f55adc05d.tar.gz
zephyr: enable motionsense for delbin
This change enables motionsense for delbin BUG=none BRANCH=none TEST=build delbin zephyr Signed-off-by: Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com> Change-Id: Ic11615fdf71fa14d8e77ebac45b38704e3f6cba0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2841143 Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr/projects')
-rw-r--r--zephyr/projects/volteer/delbin/CMakeLists.txt4
-rw-r--r--zephyr/projects/volteer/delbin/gpio.dts4
-rw-r--r--zephyr/projects/volteer/delbin/include/gpio_map.h16
-rw-r--r--zephyr/projects/volteer/delbin/motionsense.dts162
-rw-r--r--zephyr/projects/volteer/delbin/prj.conf17
-rw-r--r--zephyr/projects/volteer/delbin/src/sensors.c28
-rw-r--r--zephyr/projects/volteer/delbin/zmake.yaml1
7 files changed, 231 insertions, 1 deletions
diff --git a/zephyr/projects/volteer/delbin/CMakeLists.txt b/zephyr/projects/volteer/delbin/CMakeLists.txt
index f08356ecf2..66d556723e 100644
--- a/zephyr/projects/volteer/delbin/CMakeLists.txt
+++ b/zephyr/projects/volteer/delbin/CMakeLists.txt
@@ -23,3 +23,7 @@ zephyr_library_include_directories(
# Include selected EC source for the baseboard
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_POWERSEQ
"${PLATFORM_EC_BASEBOARD}/power.c")
+
+# Board specific sensor implementation
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_MOTIONSENSE
+ "src/sensors.c")
diff --git a/zephyr/projects/volteer/delbin/gpio.dts b/zephyr/projects/volteer/delbin/gpio.dts
index 776cc293f9..7d7a89d4f2 100644
--- a/zephyr/projects/volteer/delbin/gpio.dts
+++ b/zephyr/projects/volteer/delbin/gpio.dts
@@ -62,12 +62,14 @@
enum-name = "GPIO_PG_EC_ALL_SYS_PWRGD";
label = "PG_EC_ALL_SYS_PWRGD";
};
- ec_imu_int_l {
+ gpio_ec_imu_int_l: ec_imu_int_l {
gpios = <&gpio5 6 GPIO_INPUT>;
+ enum-name = "GPIO_EC_IMU_INT_L";
label = "EC_IMU_INT_L";
};
tablet_mode_l {
gpios = <&gpio9 5 GPIO_INPUT>;
+ enum-name = "GPIO_TABLET_MODE_L";
label = "TABLET_MODE_L";
};
ec_accel_int {
diff --git a/zephyr/projects/volteer/delbin/include/gpio_map.h b/zephyr/projects/volteer/delbin/include/gpio_map.h
index 0dce0d3be8..3afdfba213 100644
--- a/zephyr/projects/volteer/delbin/include/gpio_map.h
+++ b/zephyr/projects/volteer/delbin/include/gpio_map.h
@@ -21,6 +21,20 @@
#define AP_PROCHOT_INT(gpio, edge)
#endif
+#ifdef CONFIG_PLATFORM_EC_ACCELGYRO_BMI260
+#define BMI260_INT(gpio, edge) GPIO_INT(gpio, edge, bmi260_interrupt)
+#else
+#define BMI260_INT(gpio, edge)
+#endif
+
+#ifdef CONFIG_PLATFORM_EC_GMR_TABLET_MODE
+#define GMR_TABLET_MODE_INT(gpio, edge) GPIO_INT(gpio, edge, \
+ gmr_tablet_switch_isr)
+#define GMR_TABLET_MODE_GPIO_L GPIO_TABLET_MODE_L
+#else
+#define GMR_TABLET_MODE_INT(gpio, edge)
+#endif
+
/*
* Set EC_CROS_GPIO_INTERRUPTS to a space-separated list of GPIO_INT items.
*
@@ -37,6 +51,8 @@
* GPIO_INT(NAMED_GPIO(h1_ec_pwr_btn_odl), GPIO_INT_EDGE_BOTH, button_print)
*/
#define EC_CROS_GPIO_INTERRUPTS \
+ BMI260_INT(GPIO_EC_IMU_INT_L, GPIO_INT_EDGE_FALLING) \
+ GMR_TABLET_MODE_INT(GPIO_TABLET_MODE_L, GPIO_INT_EDGE_BOTH) \
GPIO_INT(GPIO_AC_PRESENT, GPIO_INT_EDGE_BOTH, extpower_interrupt) \
GPIO_INT(GPIO_LID_OPEN, GPIO_INT_EDGE_BOTH, lid_interrupt) \
GPIO_INT(GPIO_POWER_BUTTON_L, GPIO_INT_EDGE_BOTH, \
diff --git a/zephyr/projects/volteer/delbin/motionsense.dts b/zephyr/projects/volteer/delbin/motionsense.dts
new file mode 100644
index 0000000000..badc21a5e7
--- /dev/null
+++ b/zephyr/projects/volteer/delbin/motionsense.dts
@@ -0,0 +1,162 @@
+/* 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 <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.
+ */
+ bmi260-int = &base_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";
+ mutex_bma255: bma255-mutex {
+ label = "BMA255_MUTEX";
+ };
+
+ mutex_bmi260: bmi260-mutex {
+ label = "BMI260_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 {
+ bma255_data: bma255-drv-data {
+ compatible = "cros-ec,drvdata-bma255";
+ status = "okay";
+ };
+
+ bmi260_data: bmi260-drv-data {
+ compatible = "cros-ec,drvdata-bmi260";
+ 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,bma255";
+ status = "okay";
+
+ label = "Lid Accel";
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_LID";
+ mutex = <&mutex_bma255>;
+ port = <&i2c_sensor>;
+ rot-standard-ref = <&lid_rot_ref>;
+ default-range = <2>;
+ drv-data = <&bma255_data>;
+ i2c-spi-addr-flags = "BMA2x2_I2C_ADDR1_FLAGS";
+ 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,bmi260-accel";
+ status = "okay";
+
+ label = "Base Accel";
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&mutex_bmi260>;
+ port = <&i2c_sensor>;
+ rot-standard-ref = <&base_rot_ref>;
+ default-range = <4>;
+ drv-data = <&bmi260_data>;
+ i2c-spi-addr-flags = "BMI260_ADDR0_FLAGS";
+ configs {
+ compatible =
+ "cros-ec,motionsense-sensor-config";
+ ec-s0 {
+ label = "SENSOR_CONFIG_EC_S0";
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ ec-rate = <(100 * USEC_PER_MSEC)>;
+ };
+ ec-s3 {
+ label = "SENSOR_CONFIG_EC_S3";
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ ec-rate = <(100 * USEC_PER_MSEC)>;
+ };
+ };
+ };
+
+ base-gyro {
+ compatible = "cros-ec,bmi260-gyro";
+ status = "okay";
+
+ label = "Base Gyro";
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&mutex_bmi260>;
+ port = <&i2c_sensor>;
+ rot-standard-ref = <&base_rot_ref>;
+ default-range = <1000>; /* dps */
+ drv-data = <&bmi260_data>;
+ i2c-spi-addr-flags = "BMI260_ADDR0_FLAGS";
+ };
+ };
+
+ motionsense-sensor-info {
+ compatible = "cros-ec,motionsense-sensor-info";
+
+ /*
+ * list of GPIO interrupts that have to
+ * be enabled at initial stage
+ */
+ sensor-irqs = <&gpio_ec_imu_int_l>;
+ /* list of sensors in force mode */
+ accel-force-mode-sensors = <&lid_accel>;
+ };
+};
diff --git a/zephyr/projects/volteer/delbin/prj.conf b/zephyr/projects/volteer/delbin/prj.conf
index c7e847f538..cb246f3196 100644
--- a/zephyr/projects/volteer/delbin/prj.conf
+++ b/zephyr/projects/volteer/delbin/prj.conf
@@ -5,6 +5,7 @@
CONFIG_CROS_EC=y
CONFIG_PLATFORM_EC=y
CONFIG_SHIMMED_TASKS=y
+CONFIG_I2C=y
CONFIG_PLATFORM_EC_BRINGUP=y
CONFIG_PLATFORM_EC_VBOOT=n
@@ -26,3 +27,19 @@ CONFIG_PLATFORM_EC_POWERSEQ_RTC_RESET=y
CONFIG_PLATFORM_EC_BOARD_VERSION=n
CONFIG_PLATFORM_EC_VBOOT_HASH=n
CONFIG_PLATFORM_EC_VSTORE=n
+
+# Sensors
+CONFIG_PLATFORM_EC_MOTIONSENSE=y
+CONFIG_PLATFORM_EC_ACCEL_FIFO=y
+CONFIG_PLATFORM_EC_ACCEL_INTERRUPTS=y
+CONFIG_PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT=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
+
+# Sensor Drivers
+CONFIG_PLATFORM_EC_ACCEL_BMA255=y
+CONFIG_PLATFORM_EC_ACCELGYRO_BMI260=y
+CONFIG_PLATFORM_EC_ACCELGYRO_BMI_COMM_I2C=y
diff --git a/zephyr/projects/volteer/delbin/src/sensors.c b/zephyr/projects/volteer/delbin/src/sensors.c
new file mode 100644
index 0000000000..8a052837f8
--- /dev/null
+++ b/zephyr/projects/volteer/delbin/src/sensors.c
@@ -0,0 +1,28 @@
+/* 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"
+#include "lid_angle.h"
+
+/* Delbin board specific sensor implementation */
+
+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);
+ }
+}
diff --git a/zephyr/projects/volteer/delbin/zmake.yaml b/zephyr/projects/volteer/delbin/zmake.yaml
index c72b16c1fb..1f1cf49de4 100644
--- a/zephyr/projects/volteer/delbin/zmake.yaml
+++ b/zephyr/projects/volteer/delbin/zmake.yaml
@@ -5,6 +5,7 @@
board: volteer
dts-overlays:
- gpio.dts
+ - motionsense.dts
supported-zephyr-versions:
- v2.5
toolchain: coreboot-sdk