summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-04-21 01:23:24 -0600
committerCommit Bot <commit-bot@chromium.org>2021-04-22 16:56:06 +0000
commit20b5af2676fa9d2b1123970c1119a9a9080f3271 (patch)
tree702ffb8e2166b40be963156bc6d06c808caba933
parenta5e79ff79000ac7c4c996b942c8b1907f1b60ed2 (diff)
downloadchrome-ec-20b5af2676fa9d2b1123970c1119a9a9080f3271.tar.gz
zephyr: motionsense: add bmi160 to the sensor driver list
Adds the code to create the motion sensor structs for the bmi160. BRANCH=none BUG=b:185966444 TEST=zmake testall Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I8b9c31b4006b404beeff33e9edcddb13c7dbf848 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2842713 Commit-Queue: Keith Short <keithshort@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/shim/src/motionsense_driver/bmi160-drvinfo.inc57
-rw-r--r--zephyr/shim/src/motionsense_driver/sensor_drv_list.inc3
2 files changed, 60 insertions, 0 deletions
diff --git a/zephyr/shim/src/motionsense_driver/bmi160-drvinfo.inc b/zephyr/shim/src/motionsense_driver/bmi160-drvinfo.inc
new file mode 100644
index 0000000000..cb762c841a
--- /dev/null
+++ b/zephyr/shim/src/motionsense_driver/bmi160-drvinfo.inc
@@ -0,0 +1,57 @@
+/* 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 "driver/accelgyro_bmi_common_public.h"
+#include "driver/accelgyro_bmi160_public.h"
+
+/*
+ * CREATE_SENSOR_DATA which is defined in motionsense_sensros.c is
+ * the helper to create sensor driver specific data.
+ *
+ * CREATE_SENSOR_DATA gets two arguments. One is the compatible
+ * property value specified in device tree and the other one is the macro
+ * that actually creates sensor driver specific data. The macro gets
+ * node id and the name to be used for the sensor driver data.
+ */
+
+/*
+ * Create driver data. It can be shared among the entries in
+ * motion_sensors array which are using the same bmi160 driver.
+ */
+#define CREATE_SENSOR_DATA_BMI160(id, drvdata_name) \
+ static struct bmi_drv_data_t drvdata_name;
+
+/*
+ * Create driver data for each BMI160 drvinfo instance in device tree.
+ * (compatible = "cros-ec,drvdata-bmi160")
+ */
+CREATE_SENSOR_DATA(cros_ec_drvdata_bmi160, CREATE_SENSOR_DATA_BMI160)
+/*
+ * CREATE_MOTION_SENSOR which is defined in motionsense_sensros.c is
+ * the macro to create an entry in motion_sensors array.
+ * The macro gets value of compatible property of
+ * the sensor in device tree and sensor specific values like chip ID,
+ * type of sensor, name of driver, default min/max frequency.
+ * Then using the values, it creates the corresponding motion_sense_t entry
+ * in motion_sensors array.
+ */
+
+/*
+ * Here, we call CREATE_MOTION_SENSOR to create a motion_sensor_t entry
+ * for each BMI160_accel instance(compatible = "cros-ec,bmi160-accel")
+ * in device tree.
+ */
+CREATE_MOTION_SENSOR(cros_ec_bmi160_accel, MOTIONSENSE_CHIP_BMI160, \
+ MOTIONSENSE_TYPE_ACCEL, bmi160_drv, \
+ BMI_ACCEL_MIN_FREQ, BMI_ACCEL_MAX_FREQ)
+
+/*
+ * Here, we call CREATE_MOTION_SENSOR to create a motion_sensor_t entry
+ * for each BMI260_gyro instance (compatible = "cros-ec,bmi160-gyro")
+ * in device tree.
+ */
+CREATE_MOTION_SENSOR(cros_ec_bmi160_gyro, MOTIONSENSE_CHIP_BMI160, \
+ MOTIONSENSE_TYPE_GYRO, bmi160_drv, \
+ BMI_GYRO_MIN_FREQ, BMI_GYRO_MAX_FREQ)
diff --git a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc
index a46471c52a..67fb660dbe 100644
--- a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc
+++ b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc
@@ -22,6 +22,9 @@
#ifdef CONFIG_PLATFORM_EC_ACCEL_BMA255
#include "bma255-drvinfo.inc"
#endif
+#ifdef CONFIG_PLATFORM_EC_ACCELGYRO_BMI160
+#include "bmi160-drvinfo.inc"
+#endif
#ifdef CONFIG_PLATFORM_EC_ACCELGYRO_BMI260
#include "bmi260-drvinfo.inc"
#endif