diff options
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/dts/bindings/motionsense/cros-ec,motionsense-sensor-info.yaml | 32 | ||||
-rw-r--r-- | zephyr/shim/include/motionsense_sensors.h | 1 | ||||
-rw-r--r-- | zephyr/shim/src/motionsense_sensors.c | 35 |
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 |