diff options
author | Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com> | 2021-03-10 14:32:02 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-22 18:52:23 +0000 |
commit | 8f6efc52ecc3b9089b714231f12316a49be002b8 (patch) | |
tree | ff0611a300867844097bad6a58479129841e281f | |
parent | a8e5da56d1c3117d55768e3cd378c1088f975f51 (diff) | |
download | chrome-ec-8f6efc52ecc3b9089b714231f12316a49be002b8.tar.gz |
zephyr: DT: support sensor driver mutex
This change creates mutex instances based
on information from device tree.
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: I785e58efe1db9c5fad633bbfb87be3909f253162
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2749427
Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | zephyr/dts/bindings/motionsense/cros-ec,motionsense-mutex.yaml | 34 | ||||
-rw-r--r-- | zephyr/shim/src/motionsense_sensors.c | 33 |
2 files changed, 67 insertions, 0 deletions
diff --git a/zephyr/dts/bindings/motionsense/cros-ec,motionsense-mutex.yaml b/zephyr/dts/bindings/motionsense/cros-ec,motionsense-mutex.yaml new file mode 100644 index 0000000000..c988af258d --- /dev/null +++ b/zephyr/dts/bindings/motionsense/cros-ec,motionsense-mutex.yaml @@ -0,0 +1,34 @@ +# Copyright (c) 2021 The Chromium OS Authors +# SPDX-License-Identifier: Apache-2.0 + +description: Motion sense mutex parent node + +compatible: "cros-ec,motionsense-mutex" + +child-binding: + description: A mutex node is used to create an instance of mutex_t. + A mutex node is referenced by one or more sensor nodes in + "/motionsense-sensors" node. + properties: + label: + required: true + type: string + description: Human readable string describing the mutex. + This is a brief explanation about the mutex. + The property is not actually used in code. + + +# +# examples: +# +# motionsense-mutex { +# compatible = "cros-ec,motionsense-mutex"; +# mutex_bma255: bma255-mutex { +# label = "BMA255_MUTEX"; +# }; +# +# mutex_bmi260: bmi260-mutex { +# label = "BMI260_MUTEX"; +# }; +# }; +# diff --git a/zephyr/shim/src/motionsense_sensors.c b/zephyr/shim/src/motionsense_sensors.c new file mode 100644 index 0000000000..681ebcce6b --- /dev/null +++ b/zephyr/shim/src/motionsense_sensors.c @@ -0,0 +1,33 @@ +/* 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 "common.h" + +#define SENSOR_MUTEX_NODE DT_PATH(motionsense_mutex) +#define SENSOR_MUTEX_NAME(id) DT_CAT(MUTEX_, id) + +#if DT_NODE_EXISTS(SENSOR_MUTEX_NODE) +#define DECLARE_SENSOR_MUTEX(id) static mutex_t SENSOR_MUTEX_NAME(id); +#define INIT_SENSOR_MUTEX(id) k_mutex_init(&SENSOR_MUTEX_NAME(id)); + +/* + * Declare mutex for + * each child node of "/motionsense-mutex" node in DT. + * + * A mutex can be shared among the motion sensors. + */ +DT_FOREACH_CHILD(SENSOR_MUTEX_NODE, DECLARE_SENSOR_MUTEX) + +/* Initialize mutexes */ +static int init_sensor_mutex(const struct device *dev) +{ + ARG_UNUSED(dev); + + DT_FOREACH_CHILD(SENSOR_MUTEX_NODE, INIT_SENSOR_MUTEX) + + return 0; +} +SYS_INIT(init_sensor_mutex, POST_KERNEL, 50); +#endif /* DT_NODE_EXISTS(SENSOR_MUTEX_NODE) */ |