diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2021-11-18 11:37:46 +0100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-06 23:45:59 +0000 |
commit | ee9053226b1118f797d16fbb3490c26178ee5a6e (patch) | |
tree | 7bd505b709c1622f1aa508fd1ccb0d06444da12d /zephyr/shim/include/motionsense_sensors.h | |
parent | ee5fe104f5378a17de5a24438500f9e3eccfa08d (diff) | |
download | chrome-ec-ee9053226b1118f797d16fbb3490c26178ee5a6e.tar.gz |
zephyr: move probing of alt sensors to a function
Remove a function to probe all alternate motion sensors, but prepare a
function to probe a specific sensor. It introduces more flexibility.
Also, create a separated header file motionsense_sensors_defs.h with
definitions needed in board.h.
BUG=b:202451919
TEST=zmake testall & test if an alternate sensors are used as it is done
in CL:3310639
BRANCH=main
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: Ibfab10cbff39e17c8a86aad0c6d7c5897285a0a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3289415
Commit-Queue: Keith Short <keithshort@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr/shim/include/motionsense_sensors.h')
-rw-r--r-- | zephyr/shim/include/motionsense_sensors.h | 117 |
1 files changed, 28 insertions, 89 deletions
diff --git a/zephyr/shim/include/motionsense_sensors.h b/zephyr/shim/include/motionsense_sensors.h index f4ca97840e..cbc672e34a 100644 --- a/zephyr/shim/include/motionsense_sensors.h +++ b/zephyr/shim/include/motionsense_sensors.h @@ -7,104 +7,43 @@ #define __CROS_EC_MOTIONSENSE_SENSORS_H #include <devicetree.h> +#include "motion_sense.h" -#define SENSOR_NODE DT_PATH(motionsense_sensor) -#define SENSOR_INFO_NODE DT_PATH(motionsense_sensor_info) -#define SENSOR_ALT_NODE DT_PATH(motionsense_sensor_alt) - -#define SENSOR_ID(id) DT_CAT(SENSOR_, 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) - DT_FOREACH_CHILD(SENSOR_NODE, SENSOR_ID_WITH_COMMA) -#endif - 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, -}; +extern struct motion_sensor_t motion_sensors_alt[]; /* - * Find the accelerometers for lid angle calculation. - * - * The angle calculation requires two accelerometers. One is on the lid - * and the other one is on the base. So we need to specify which sensor is - * on the lid and which one is on the base. We use two labels "lid_accel" - * and "base_accel". - * - * base_accel - label for the accelerometer sensor on the base. - * lid_accel - label for the accelerometer sensor on the lid. - * - * e.g) below shows BMA255 is the accelerometer on the lid and bmi260 is - * the accelerometer on the base. - * - * motionsense-sensor { - * lid_accel: lid-accel { - * compatible = "cros-ec,bma255"; - * status = "okay"; - * : - * : - * }; - * - * base_accel: base-accel { - * compatible = "cros-ec,bmi260"; - * status = "okay"; - * : - * : - * }; - * }; + * Performs probing of an alternate sensor. + * @param alt_idx Index in motion_sensors_alt of the sensor to be probed. + * It should be gained with SENSOR_ID, + * e.g. with SENSOR_ID(DT_NODELABEL(label)). + * @return EC_SUCCESS if the probe was successful, non-zero otherwise. */ -#ifdef CONFIG_LID_ANGLE -#define CONFIG_LID_ANGLE_SENSOR_LID SENSOR_ID(DT_NODELABEL(lid_accel)) -#define CONFIG_LID_ANGLE_SENSOR_BASE SENSOR_ID(DT_NODELABEL(base_accel)) -#endif +int motion_sense_probe(enum sensor_alt_id alt_idx); + +#define ENABLE_ALT_MOTION_SENSOR(alt_id) \ + motion_sensors[SENSOR_ID(DT_PHANDLE(alt_id, alternate_for))] = \ + motion_sensors_alt[SENSOR_ID(alt_id)]; /* - * Get the sensors running in force mode from DT and create a bit mask for it. - * - * e.g) lid accel and als_clear are in accel_force_mode. The macro below finds - * the corresponding bit for each sensor in bit mask and set it. - * motionsense-sensor-info { - * compatible = "cros-ec,motionsense-sensor-info"; - * - * // list of sensors in force mode - * accel-force-mode-sensors = <&lid_accel &als_clear>; - * }; + * Replaces a default motion sensor with an alternate one pointed by nodelabel. */ -#if DT_NODE_HAS_PROP(SENSOR_INFO_NODE, accel_force_mode_sensors) -#define SENSOR_IN_FORCE_MODE(i, id) \ - | BIT(SENSOR_ID(DT_PHANDLE_BY_IDX(id, accel_force_mode_sensors, i))) -#define CONFIG_ACCEL_FORCE_MODE_MASK \ - (0 UTIL_LISTIFY(DT_PROP_LEN(SENSOR_INFO_NODE, \ - accel_force_mode_sensors), SENSOR_IN_FORCE_MODE, \ - SENSOR_INFO_NODE)) -#endif +#define MOTIONSENSE_ENABLE_ALTERNATE(nodelabel) \ + do { \ + BUILD_ASSERT(DT_NODE_EXISTS(DT_NODELABEL(nodelabel)), \ + "Motionsense alternate node does not exist"); \ + ENABLE_ALT_MOTION_SENSOR(DT_NODELABEL(nodelabel)); \ + } while (0) /* - * Performs probing of alternative sensors marked with "runtime-probe" property - * in device tree. If an alternative sensor is detected, the function replaces - * a default one in the motion_sensors array. + * Probes and replaces a default motion sensor with an alternate one pointed by + * nodelabel, if the probe was successful. */ -void motion_sense_probe_sensors(void); +#define MOTIONSENSE_PROBE_AND_ENABLE_ALTERNATE(nodelabel) \ + do { \ + BUILD_ASSERT(DT_NODE_EXISTS(DT_NODELABEL(nodelabel)), \ + "Motionsense alternate node does not exist"); \ + if (!motion_sense_probe(SENSOR_ID(DT_NODELABEL(nodelabel)))) \ + ENABLE_ALT_MOTION_SENSOR(DT_NODELABEL(nodelabel)); \ + } while (0) #endif /* __CROS_EC_MOTIONSENSE_SENSORS_H */ |