From 4aaa85760faeec02f94b86b99d40768362d8c158 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Thu, 22 Apr 2021 10:56:19 -0600 Subject: zephyr: sensors: Add alternate sensors support In some boards there's a runtime decision for which sensor to use. In order to support this we'll need an instance of the alternate sensors as well as a mapping for them. Add an optional phandle `alternate-for` to the base sensors bindings. When used, the sensor will be excluded from the primary motion_sensors array and added instead to the motion_sensors_alt array. BRANCH=none BUG=b:183990188, b:185966444 TEST=zmake testall Signed-off-by: Yuval Peress Change-Id: I6f6e3a9659a381c45fd97fbce9fecb2a807f7fa2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2846415 Reviewed-by: Keith Short Commit-Queue: Keith Short --- zephyr/shim/include/motionsense_sensors.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'zephyr/shim/include/motionsense_sensors.h') diff --git a/zephyr/shim/include/motionsense_sensors.h b/zephyr/shim/include/motionsense_sensors.h index 013a03d8dc..bf7ff95f85 100644 --- a/zephyr/shim/include/motionsense_sensors.h +++ b/zephyr/shim/include/motionsense_sensors.h @@ -10,10 +10,17 @@ #define SENSOR_NODE DT_PATH(motionsense_sensor) #define SENSOR_INFO_NODE DT_PATH(motionsense_sensor_info) +#define SENSOR_ALT_NODE DT_PATH(motionsesne_sensor_alt) #define SENSOR_ID(id) DT_CAT(SENSOR_, id) -#define SENSOR_ID_WITH_COMMA(id) \ - IF_ENABLED(DT_NODE_HAS_STATUS(id, okay), (SENSOR_ID(id),)) + +/* Define the SENSOR_ID if: + * DT_NODE_HAS_STATUS(id, okay) && !DT_NODE_HAS_PROP(id, alternate_for) + */ +#define SENSOR_ID_WITH_COMMA(id) \ + IF_ENABLED(DT_NODE_HAS_STATUS(id, okay), \ + (COND_CODE_0(DT_NODE_HAS_PROP(id, alternate_for), \ + (SENSOR_ID(id), ), ()))) enum sensor_id { #if DT_NODE_EXISTS(SENSOR_NODE) @@ -22,6 +29,21 @@ enum sensor_id { SENSOR_COUNT, }; +#undef SENSOR_ID_WITH_COMMA +/* Define the SENSOR_ID if: + * DT_NODE_HAS_STATUS(id, okay) && DT_NODE_HAS_PROP(id, alternate_for) + */ +#define SENSOR_ID_WITH_COMMA(id) \ + IF_ENABLED(DT_NODE_HAS_STATUS(id, okay), \ + (COND_CODE_1(DT_NODE_HAS_PROP(id, alternate_for), \ + (SENSOR_ID(id), ), ()))) +enum sensor_alt_id { +#if DT_NODE_EXISTS(SENSOR_ALT_NODE) + DT_FOREACH_CHILD(SENSOR_ALT_NODE, SENSOR_ID_WITH_COMMA) +#endif + SENSOR_ALT_COUNT, +}; + /* * Find the accelerometers for lid angle calculation. * -- cgit v1.2.1