summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com>2021-03-19 22:13:44 -0700
committerCommit Bot <commit-bot@chromium.org>2021-03-24 02:10:38 +0000
commit6307a8c932d667a40d5955084a28b4ef15391de5 (patch)
tree4f83a66ce884ee21540238bec9f1366690f929d5
parent3c5dd8f4b8d96d73545668b327bb2706b67ffb9d (diff)
downloadchrome-ec-6307a8c932d667a40d5955084a28b4ef15391de5.tar.gz
zephyr: DT: support creating motion_als_sensors
This change allows to create motion_als_sensors array by using the information from DT. BUG=b:173507858 BRANCH=none TEST=make buildall -j8 build volteer on zephyr Signed-off-by: Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com> Change-Id: Ic1c169d8f98de9f6b09f68d99844cb709f57e33d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2778817 Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--zephyr/dts/bindings/motionsense/cros-ec,motionsense-sensor-info.yaml32
-rw-r--r--zephyr/shim/include/motionsense_sensors.h1
-rw-r--r--zephyr/shim/src/motionsense_sensors.c35
3 files changed, 68 insertions, 0 deletions
diff --git a/zephyr/dts/bindings/motionsense/cros-ec,motionsense-sensor-info.yaml b/zephyr/dts/bindings/motionsense/cros-ec,motionsense-sensor-info.yaml
new file mode 100644
index 0000000000..9afa040da8
--- /dev/null
+++ b/zephyr/dts/bindings/motionsense/cros-ec,motionsense-sensor-info.yaml
@@ -0,0 +1,32 @@
+# 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.
+
+description: The node has the information required by motion sense running
+
+compatible: "cros-ec,motionsense-sensor-info"
+
+properties:
+ als-sensors:
+ type: phandles
+ required: false
+ description: |
+ List of ALS sensors to create motion_als_sensors array.
+ The ALS sensors listed in the motion_als_sensors array
+ are managed by motion sense task. The task reads the sensor
+ data from the sensors and put them into the designated part
+ in the ec mmap. For example, als_clear and als_rgb are aliases
+ of ALS sensor noded defined in motionsense-sensor node.
+ als-sensors = <&als_clear, &als_rgb>;
+ This will automatically generate motion_als_sensors array from it.
+
+#
+# examples:
+#
+# motionsense-sensor-info {
+# compatible = "cros-ec,motionsense-sensor-info";
+#
+# /* list of entries for motion_als_sensors */
+# als-sensors = <&als_clear>;
+# };
+#
diff --git a/zephyr/shim/include/motionsense_sensors.h b/zephyr/shim/include/motionsense_sensors.h
index f0c51c1f7b..fe9b294d45 100644
--- a/zephyr/shim/include/motionsense_sensors.h
+++ b/zephyr/shim/include/motionsense_sensors.h
@@ -9,6 +9,7 @@
#include <devicetree.h>
#define SENSOR_NODE DT_PATH(motionsense_sensor)
+#define SENSOR_INFO_NODE DT_PATH(motionsense_sensor_info)
#define SENSOR_ID(id) DT_CAT(SENSOR_, id)
#define SENSOR_ID_WITH_COMMA(id) \
diff --git a/zephyr/shim/src/motionsense_sensors.c b/zephyr/shim/src/motionsense_sensors.c
index f01f782dd8..d2567cb8fe 100644
--- a/zephyr/shim/src/motionsense_sensors.c
+++ b/zephyr/shim/src/motionsense_sensors.c
@@ -285,3 +285,38 @@ unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
#else
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
#endif
+
+/*
+ * Create a list of ALS sensors needed by motion sense
+ *
+ * The following example adds tcs3400 als sensor to motion_als_sensors array
+ *
+ * motionsense-sensors {
+ * lid_accel: bma255 {
+ * :
+ * };
+ * :
+ * :
+ * als_clear: tcs3400 {
+ * :
+ * };
+ * };
+ *
+ * motionsense-sensor-info {
+ * compatible = "cros-ec,motionsense-sensor-info";
+ *
+ * // list of entries for motion_als_sensors
+ * als-sensors = <&als_clear>;
+ * :
+ * :
+ * };
+ */
+#if DT_NODE_HAS_PROP(SENSOR_INFO_NODE, als_sensors)
+#define ALS_SENSOR_ENTRY_WITH_COMMA(i, id) \
+ &motion_sensors[SENSOR_ID(DT_PHANDLE_BY_IDX(id, als_sensors, i))],
+const struct motion_sensor_t *motion_als_sensors[] = {
+ UTIL_LISTIFY(DT_PROP_LEN(SENSOR_INFO_NODE, als_sensors),
+ ALS_SENSOR_ENTRY_WITH_COMMA, SENSOR_INFO_NODE)
+};
+BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT);
+#endif