-
Notifications
You must be signed in to change notification settings - Fork 7.8k
devicetree: allow interating devicetree nodes with identical zephyr,device-type properties #67698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
henrikbrixandersen
wants to merge
7
commits into
zephyrproject-rtos:main
from
vestas-wind-systems:dts_add_zephyr_device_type
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
30bad72
dts: bindings: base: add zephyr,device-type property
henrikbrixandersen c150003
scripts: dts: add special tooling for handling zephyr,device-type props
henrikbrixandersen 3d59bf5
dts: bindings: adc: set zephyr,device-type to adc-controller
henrikbrixandersen fe0f25d
dts: bindings: gpio: set zephyr,device-type to gpio-controller
henrikbrixandersen 39fdfcd
devicetree: allow iterating devicetree nodes with identical device-types
henrikbrixandersen 176e7b0
tests: lib: devicetree: api: add tests for zephyr,device-type props
henrikbrixandersen 466cd14
drivers: adc: shell: iterate all ADC controller devicetree nodes
henrikbrixandersen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright (c) 2024 Vestas Wind Systems A/S | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @file | ||
* @brief Devicetree device type | ||
*/ | ||
|
||
#ifndef ZEPHYR_INCLUDE_DEVICETREE_DEVICE_TYPE_H_ | ||
#define ZEPHYR_INCLUDE_DEVICETREE_DEVICE_TYPE_H_ | ||
|
||
#include <zephyr/devicetree.h> | ||
#include <zephyr/sys/util_macro.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @defgroup devicetree-device-type Devicetree device type | ||
* @ingroup devicetree | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* @brief Does a devicetree node have a zephyr,device-type property? | ||
* | ||
* Tests whether a devicetree node has a zephyr,device-type property defined. | ||
* | ||
* @param node_id node identifier | ||
* @return 1 if the node has the zephyr,device-type property, 0 otherwise. | ||
*/ | ||
#define DT_NODE_HAS_DEVICE_TYPE(node_id) DT_NODE_HAS_PROP(node_id, zephyr_device_type) | ||
|
||
/** | ||
* @brief Does a devicetree node have a matching zephyr,device-type property? | ||
* | ||
* Tests whether a devicetree node has a zephyr,device-type property matching @p device_type. | ||
* | ||
* @param node_id node identifier | ||
* @param device_type lowercase-and-underscores device type | ||
* @return 1 if the node has a matching zephyr,device-type property, 0 otherwise. | ||
*/ | ||
#define DT_NODE_IS_DEVICE_TYPE(node_id, device_type) \ | ||
IS_ENABLED(DT_CAT3(node_id, _ZEPHYR_DEVICE_TYPE_, device_type)) | ||
|
||
/** | ||
* @brief Does a devicetree node have a matching zephyr,device-type property and status `okay`? | ||
* | ||
* Tests whether a devicetree node has a zephyr,device-type property matching @p device_type and | ||
* status `okay` (as usual, a missing status property is treated as status `okay`). | ||
* | ||
* @param node_id node identifier | ||
* @param device_type lowercase-and-underscores device type | ||
* @return 1 if the node has a matching zephyr,device-type property and status `okay`, 0 otherwise. | ||
*/ | ||
#define DT_NODE_IS_DEVICE_TYPE_STATUS_OKAY(node_id, device_type) \ | ||
UTIL_AND(DT_NODE_IS_DEVICE_TYPE(node_id, device_type), DT_NODE_HAS_STATUS(node_id, okay)) | ||
|
||
/** | ||
* @cond INTERNAL_HIDDEN | ||
*/ | ||
|
||
#define DT_FOREACH_DEVICE_TYPE_NODE_INTERNAL(node_id, device_type, fn) \ | ||
COND_CODE_1(DT_NODE_IS_DEVICE_TYPE(node_id, device_type), (fn(node_id)), ()) | ||
|
||
#define DT_FOREACH_DEVICE_TYPE_NODE_VARGS_INTERNAL(node_id, device_type, fn, ...) \ | ||
COND_CODE_1(DT_NODE_IS_DEVICE_TYPE(node_id, device_type), (fn(node_id, __VA_ARGS__)), ()) | ||
|
||
/** | ||
* INTERNAL_HIDDEN @endcond | ||
*/ | ||
|
||
/** | ||
* @brief Invokes @p fn for every node in the tree with a ``zephyr,device-type`` property matching | ||
* @p device_type. | ||
* | ||
* The macro @p fn must take one parameter, which will be a node identifier. The macro is expanded | ||
* once for each node in the tree with a ``zephyr,device-type`` property matching @p | ||
* device_type. The order that nodes are visited in is not specified. | ||
* | ||
* @param device_type lowercase-and-underscores device type | ||
* @param fn macro to invoke | ||
*/ | ||
#define DT_FOREACH_DEVICE_TYPE_NODE(device_type, fn) \ | ||
DT_FOREACH_NODE_VARGS(DT_FOREACH_DEVICE_TYPE_NODE_INTERNAL, device_type, fn) | ||
|
||
/** | ||
* @brief Invokes @p fn for every node in the tree with a ``zephyr,device-type`` property matching | ||
* @p device_type with multiple arguments. | ||
* | ||
* The macro @p fn takes multiple arguments. The first should be the node identifier for the | ||
* node. The macro is expanded once for each node in the tree with a ``zephyr,device-type`` property | ||
* matching @p device_type. The order that nodes are visited in is not specified. | ||
* | ||
* @param device_type lowercase-and-underscores device type | ||
* @param fn macro to invoke | ||
*/ | ||
#define DT_FOREACH_DEVICE_TYPE_NODE_VARGS(device_type, fn, ...) \ | ||
DT_FOREACH_NODE_VARGS(DT_FOREACH_DEVICE_TYPE_NODE_VARGS_INTERNAL, device_type, fn, \ | ||
__VA_ARGS__) | ||
|
||
/** | ||
* @brief Invokes @p fn for every node in the tree with a ``zephyr,device-type`` property matching | ||
* @p device_type. | ||
* | ||
* The macro @p fn must take one parameter, which will be a node identifier. The macro is expanded | ||
* once for each node in the tree with a ``zephyr,device-type`` property matching @p device_type and | ||
* with status `okay` (as usual, a missing status property is treated as status `okay`). The order | ||
* that nodes are visited in is not specified. | ||
* | ||
* @param device_type lowercase-and-underscores device type | ||
* @param fn macro to invoke | ||
*/ | ||
#define DT_FOREACH_DEVICE_TYPE_STATUS_OKAY_NODE(device_type, fn) \ | ||
DT_FOREACH_STATUS_OKAY_NODE_VARGS(DT_FOREACH_DEVICE_TYPE_NODE_INTERNAL, device_type, fn) | ||
|
||
/** | ||
* @brief Invokes @p fn for every node in the tree with a ``zephyr,device-type`` property matching | ||
* @p device_type with multiple arguments. | ||
* | ||
* The macro @p fn takes multiple arguments. The first should be the node identifier for the | ||
* node. The macro is expanded once for each node in the tree with a ``zephyr,device-type`` property | ||
* matching @p device_type and with status `okay` (as usual, a missing status property is treated as | ||
* status `okay`). The order that nodes are visited in is not specified. | ||
* | ||
* @param device_type lowercase-and-underscores device type | ||
* @param fn macro to invoke | ||
*/ | ||
#define DT_FOREACH_DEVICE_TYPE_STATUS_OKAY_NODE_VARGS(device_type, fn, ...) \ | ||
DT_FOREACH_STATUS_OKAY_NODE_VARGS(DT_FOREACH_DEVICE_TYPE_NODE_VARGS_INTERNAL, device_type, \ | ||
fn, __VA_ARGS__) | ||
|
||
/** | ||
* @} | ||
*/ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ZEPHYR_INCLUDE_DEVICETREE_DEVICE_TYPE_H_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/lib/devicetree/api/dts/bindings/test-unique-device-type.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2024 Vestas Wind Systems A/S | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: Test node with unique zephyr,device-type | ||
|
||
compatible: "test-unique-device-type" | ||
|
||
include: base.yaml | ||
|
||
properties: | ||
zephyr,device-type: | ||
default: test-unique-device-type-string | ||
const: test-unique-device-type-string |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, but to me, using devicetree to add yet more software properties is a -1. Usage of
zephyr,
has become a mess to a point where we should likely renamedevicetree
to something else, maybeztree
or something. This solution also doesn't account for device nodes that can have >1 device type, which even if not supported now, they should if we ever pretend to fully align with Linux.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding that my suggestion just above would theoretically be able to handle multiple types