Zephyr API Documentation  3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
devicetree.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: Apache-2.0
3 * Copyright (c) 2020 Nordic Semiconductor
4 * Copyright (c) 2020, Linaro Ltd.
5 *
6 * Not a generated file. Feel free to modify.
7 */
8
16#ifndef DEVICETREE_H
17#define DEVICETREE_H
18
19#include <zephyr/devicetree_generated.h>
21
22#if !defined(_LINKER) && !defined(_ASMLANGUAGE)
23#include <stdint.h>
24#endif
25
26#include <zephyr/sys/util.h>
27
37/*
38 * Property suffixes
39 * -----------------
40 *
41 * These are the optional parts that come after the _P_<property>
42 * part in DT_N_<path-id>_P_<property-id> macros, or the "prop-suf"
43 * nonterminal in the DT guide's macros.bnf file.
44 *
45 * Before adding new ones, check this list to avoid conflicts. If any
46 * are missing from this list, please add them. It should be complete.
47 *
48 * _ENUM_IDX: property's value as an index into bindings enum
49 * _ENUM_VAL_<val>_EXISTS property's value as a token exists
50 * _ENUM_TOKEN: property's value as a token into bindings enum (string
51 * enum values are identifiers) [deprecated, use _STRING_TOKEN]
52 * _ENUM_UPPER_TOKEN: like _ENUM_TOKEN, but uppercased [deprecated, use
53 * _STRING_UPPER_TOKEN]
54 * _EXISTS: property is defined
55 * _FOREACH_PROP_ELEM: helper for "iterating" over values in the property
56 * _FOREACH_PROP_ELEM_VARGS: foreach functions with variable number of arguments
57 * _IDX_<i>: logical index into property
58 * _IDX_<i>_EXISTS: logical index into property is defined
59 * _IDX_<i>_PH: phandle array's phandle by index (or phandle, phandles)
60 * _IDX_<i>_STRING_TOKEN: string array element value as a token
61 * _IDX_<i>_STRING_UPPER_TOKEN: string array element value as a uppercased token
62 * _IDX <i>_STRING_UNQUOTED: string array element value as a sequence of tokens, with no quotes
63 * _IDX_<i>_VAL_<val>: phandle array's specifier value by index
64 * _IDX_<i>_VAL_<val>_EXISTS: cell value exists, by index
65 * _LEN: property logical length
66 * _NAME_<name>_PH: phandle array's phandle by name
67 * _NAME_<name>_VAL_<val>: phandle array's property specifier by name
68 * _NAME_<name>_VAL_<val>_EXISTS: cell value exists, by name
69 * _STRING_TOKEN: string property's value as a token
70 * _STRING_UPPER_TOKEN: like _STRING_TOKEN, but uppercased
71 * _STRING_UNQUOTED: string property's value as a sequence of tokens, with no quotes
72 */
73
87#define DT_INVALID_NODE _
88
92#define DT_ROOT DT_N
93
144#define DT_PATH(...) DT_PATH_INTERNAL(__VA_ARGS__)
145
200#define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
201
240#define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
241
336#define DT_INST(inst, compat) UTIL_CAT(DT_N_INST, DT_DASH(inst, compat))
337
361#define DT_PARENT(node_id) DT_CAT(node_id, _PARENT)
362
386#define DT_GPARENT(node_id) DT_PARENT(DT_PARENT(node_id))
387
423#define DT_CHILD(node_id, child) UTIL_CAT(node_id, DT_S_PREFIX(child))
424
466#define DT_COMPAT_GET_ANY_STATUS_OKAY(compat) \
467 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
468 (DT_INST(0, compat)), \
469 (DT_INVALID_NODE))
470
498#define DT_NODE_PATH(node_id) DT_CAT(node_id, _PATH)
499
524#define DT_NODE_FULL_NAME(node_id) DT_CAT(node_id, _FULL_NAME)
525
552#define DT_NODE_CHILD_IDX(node_id) DT_CAT(node_id, _CHILD_IDX)
553
560#define DT_CHILD_NUM(node_id) DT_CAT(node_id, _CHILD_NUM)
561
562
570#define DT_CHILD_NUM_STATUS_OKAY(node_id) \
571 DT_CAT(node_id, _CHILD_NUM_STATUS_OKAY)
572
593#define DT_SAME_NODE(node_id1, node_id2) \
594 (DT_DEP_ORD(node_id1) == (DT_DEP_ORD(node_id2)))
595
620#define DT_NODELABEL_STRING_ARRAY(node_id) \
621 { DT_FOREACH_NODELABEL(node_id, DT_NODELABEL_STRING_ARRAY_ENTRY_INTERNAL) }
622
663#define DT_PROP(node_id, prop) DT_CAT3(node_id, _P_, prop)
664
697#define DT_PROP_LEN(node_id, prop) DT_CAT4(node_id, _P_, prop, _LEN)
698
713#define DT_PROP_LEN_OR(node_id, prop, default_value) \
714 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
715 (DT_PROP_LEN(node_id, prop)), (default_value))
716
737#define DT_PROP_HAS_IDX(node_id, prop, idx) \
738 IS_ENABLED(DT_CAT6(node_id, _P_, prop, _IDX_, idx, _EXISTS))
739
772#define DT_PROP_HAS_NAME(node_id, prop, name) \
773 IS_ENABLED(DT_CAT6(node_id, _P_, prop, _NAME_, name, _EXISTS))
774
809#define DT_PROP_BY_IDX(node_id, prop, idx) \
810 DT_CAT5(node_id, _P_, prop, _IDX_, idx)
811
825#define DT_PROP_OR(node_id, prop, default_value) \
826 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
827 (DT_PROP(node_id, prop)), (default_value))
828
869#define DT_ENUM_IDX(node_id, prop) DT_CAT4(node_id, _P_, prop, _ENUM_IDX)
870
885#define DT_ENUM_IDX_OR(node_id, prop, default_idx_value) \
886 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
887 (DT_ENUM_IDX(node_id, prop)), (default_idx_value))
888
897#define DT_ENUM_HAS_VALUE(node_id, prop, value) \
898 IS_ENABLED(DT_CAT6(node_id, _P_, prop, _ENUM_VAL_, value, _EXISTS))
899
959#define DT_STRING_TOKEN(node_id, prop) \
960 DT_CAT4(node_id, _P_, prop, _STRING_TOKEN)
961
975#define DT_STRING_TOKEN_OR(node_id, prop, default_value) \
976 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
977 (DT_STRING_TOKEN(node_id, prop)), (default_value))
978
1036#define DT_STRING_UPPER_TOKEN(node_id, prop) \
1037 DT_CAT4(node_id, _P_, prop, _STRING_UPPER_TOKEN)
1038
1053#define DT_STRING_UPPER_TOKEN_OR(node_id, prop, default_value) \
1054 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
1055 (DT_STRING_UPPER_TOKEN(node_id, prop)), (default_value))
1056
1097#define DT_STRING_UNQUOTED(node_id, prop) \
1098 DT_CAT4(node_id, _P_, prop, _STRING_UNQUOTED)
1099
1114#define DT_STRING_UNQUOTED_OR(node_id, prop, default_value) \
1115 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
1116 (DT_STRING_UNQUOTED(node_id, prop)), (default_value))
1117
1165#define DT_STRING_TOKEN_BY_IDX(node_id, prop, idx) \
1166 DT_CAT6(node_id, _P_, prop, _IDX_, idx, _STRING_TOKEN)
1167
1215#define DT_STRING_UPPER_TOKEN_BY_IDX(node_id, prop, idx) \
1216 DT_CAT6(node_id, _P_, prop, _IDX_, idx, _STRING_UPPER_TOKEN)
1217
1258#define DT_STRING_UNQUOTED_BY_IDX(node_id, prop, idx) \
1259 DT_CAT6(node_id, _P_, prop, _IDX_, idx, _STRING_UNQUOTED)
1260
1261/*
1262 * phandle properties
1263 *
1264 * These are special-cased to manage the impedance mismatch between
1265 * phandles, which are just uint32_t node properties that only make sense
1266 * within the tree itself, and C values.
1267 */
1268
1314#define DT_PROP_BY_PHANDLE_IDX(node_id, phs, idx, prop) \
1315 DT_PROP(DT_PHANDLE_BY_IDX(node_id, phs, idx), prop)
1316
1336#define DT_PROP_BY_PHANDLE_IDX_OR(node_id, phs, idx, prop, default_value) \
1337 DT_PROP_OR(DT_PHANDLE_BY_IDX(node_id, phs, idx), prop, default_value)
1338
1350#define DT_PROP_BY_PHANDLE(node_id, ph, prop) \
1351 DT_PROP_BY_PHANDLE_IDX(node_id, ph, 0, prop)
1352
1407#define DT_PHA_BY_IDX(node_id, pha, idx, cell) \
1408 DT_CAT7(node_id, _P_, pha, _IDX_, idx, _VAL_, cell)
1409
1433#define DT_PHA_BY_IDX_OR(node_id, pha, idx, cell, default_value) \
1434 DT_PROP_OR(node_id, DT_CAT5(pha, _IDX_, idx, _VAL_, cell), default_value)
1435
1443#define DT_PHA(node_id, pha, cell) DT_PHA_BY_IDX(node_id, pha, 0, cell)
1444
1459#define DT_PHA_OR(node_id, pha, cell, default_value) \
1460 DT_PHA_BY_IDX_OR(node_id, pha, 0, cell, default_value)
1461
1502#define DT_PHA_BY_NAME(node_id, pha, name, cell) \
1503 DT_CAT7(node_id, _P_, pha, _NAME_, name, _VAL_, cell)
1504
1526#define DT_PHA_BY_NAME_OR(node_id, pha, name, cell, default_value) \
1527 DT_PROP_OR(node_id, DT_CAT5(pha, _NAME_, name, _VAL_, cell), default_value)
1528
1576#define DT_PHANDLE_BY_NAME(node_id, pha, name) \
1577 DT_CAT6(node_id, _P_, pha, _NAME_, name, _PH)
1578
1628#define DT_PHANDLE_BY_IDX(node_id, prop, idx) \
1629 DT_CAT6(node_id, _P_, prop, _IDX_, idx, _PH)
1630
1642#define DT_PHANDLE(node_id, prop) DT_PHANDLE_BY_IDX(node_id, prop, 0)
1643
1690#define DT_NUM_RANGES(node_id) DT_CAT(node_id, _RANGES_NUM)
1691
1744#define DT_RANGES_HAS_IDX(node_id, idx) \
1745 IS_ENABLED(DT_CAT4(node_id, _RANGES_IDX_, idx, _EXISTS))
1746
1799#define DT_RANGES_HAS_CHILD_BUS_FLAGS_AT_IDX(node_id, idx) \
1800 IS_ENABLED(DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_CHILD_BUS_FLAGS_EXISTS))
1801
1839#define DT_RANGES_CHILD_BUS_FLAGS_BY_IDX(node_id, idx) \
1840 DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_CHILD_BUS_FLAGS)
1841
1888#define DT_RANGES_CHILD_BUS_ADDRESS_BY_IDX(node_id, idx) \
1889 DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_CHILD_BUS_ADDRESS)
1890
1937#define DT_RANGES_PARENT_BUS_ADDRESS_BY_IDX(node_id, idx) \
1938 DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_PARENT_BUS_ADDRESS)
1939
1986#define DT_RANGES_LENGTH_BY_IDX(node_id, idx) \
1987 DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_LENGTH)
1988
2028#define DT_FOREACH_RANGE(node_id, fn) \
2029 DT_CAT(node_id, _FOREACH_RANGE)(fn)
2030
2076#define DT_NODE_VENDOR_BY_IDX(node_id, idx) \
2077 DT_CAT3(node_id, _COMPAT_VENDOR_IDX_, idx)
2078
2091#define DT_NODE_VENDOR_HAS_IDX(node_id, idx) \
2092 IS_ENABLED(DT_CAT4(node_id, _COMPAT_VENDOR_IDX_, idx, _EXISTS))
2093
2108#define DT_NODE_VENDOR_BY_IDX_OR(node_id, idx, default_value) \
2109 COND_CODE_1(DT_NODE_VENDOR_HAS_IDX(node_id, idx), \
2110 (DT_NODE_VENDOR_BY_IDX(node_id, idx)), (default_value))
2111
2120#define DT_NODE_VENDOR_OR(node_id, default_value) \
2121 DT_NODE_VENDOR_BY_IDX_OR(node_id, 0, default_value)
2122
2152#define DT_NODE_MODEL_BY_IDX(node_id, idx) \
2153 DT_CAT3(node_id, _COMPAT_MODEL_IDX_, idx)
2154
2167#define DT_NODE_MODEL_HAS_IDX(node_id, idx) \
2168 IS_ENABLED(DT_CAT4(node_id, _COMPAT_MODEL_IDX_, idx, _EXISTS))
2169
2184#define DT_NODE_MODEL_BY_IDX_OR(node_id, idx, default_value) \
2185 COND_CODE_1(DT_NODE_MODEL_HAS_IDX(node_id, idx), \
2186 (DT_NODE_MODEL_BY_IDX(node_id, idx)), (default_value))
2187
2196#define DT_NODE_MODEL_OR(node_id, default_value) \
2197 DT_NODE_MODEL_BY_IDX_OR(node_id, 0, default_value)
2198
2216#define DT_NUM_REGS(node_id) DT_CAT(node_id, _REG_NUM)
2217
2229#define DT_REG_HAS_IDX(node_id, idx) \
2230 IS_ENABLED(DT_CAT4(node_id, _REG_IDX_, idx, _EXISTS))
2231
2243#define DT_REG_HAS_NAME(node_id, name) \
2244 IS_ENABLED(DT_CAT4(node_id, _REG_NAME_, name, _EXISTS))
2245
2252#define DT_REG_ADDR_BY_IDX(node_id, idx) \
2253 DT_CAT4(node_id, _REG_IDX_, idx, _VAL_ADDRESS)
2254
2266#define DT_REG_SIZE_BY_IDX(node_id, idx) \
2267 DT_CAT4(node_id, _REG_IDX_, idx, _VAL_SIZE)
2268
2276#define DT_REG_ADDR(node_id) DT_REG_ADDR_BY_IDX(node_id, 0)
2277
2288#define DT_REG_ADDR_U64(node_id) DT_U64_C(DT_REG_ADDR(node_id))
2289
2297#define DT_REG_SIZE(node_id) DT_REG_SIZE_BY_IDX(node_id, 0)
2298
2305#define DT_REG_ADDR_BY_NAME(node_id, name) \
2306 DT_CAT4(node_id, _REG_NAME_, name, _VAL_ADDRESS)
2307
2316#define DT_REG_ADDR_BY_NAME_OR(node_id, name, default_value) \
2317 COND_CODE_1(DT_REG_HAS_NAME(node_id, name), \
2318 (DT_REG_ADDR_BY_NAME(node_id, name)), (default_value))
2319
2332#define DT_REG_ADDR_BY_NAME_U64(node_id, name) \
2333 DT_U64_C(DT_REG_ADDR_BY_NAME(node_id, name))
2334
2341#define DT_REG_SIZE_BY_NAME(node_id, name) \
2342 DT_CAT4(node_id, _REG_NAME_, name, _VAL_SIZE)
2343
2352#define DT_REG_SIZE_BY_NAME_OR(node_id, name, default_value) \
2353 COND_CODE_1(DT_REG_HAS_NAME(node_id, name), \
2354 (DT_REG_SIZE_BY_NAME(node_id, name)), (default_value))
2355
2356
2375#define DT_NUM_IRQS(node_id) DT_CAT(node_id, _IRQ_NUM)
2376
2401#define DT_NUM_NODELABELS(node_id) DT_CAT(node_id, _NODELABEL_NUM)
2402
2409#define DT_IRQ_LEVEL(node_id) DT_CAT(node_id, _IRQ_LEVEL)
2410
2421#define DT_IRQ_HAS_IDX(node_id, idx) \
2422 IS_ENABLED(DT_CAT4(node_id, _IRQ_IDX_, idx, _EXISTS))
2423
2434#define DT_IRQ_HAS_CELL_AT_IDX(node_id, idx, cell) \
2435 IS_ENABLED(DT_CAT6(node_id, _IRQ_IDX_, idx, _VAL_, cell, _EXISTS))
2436
2444#define DT_IRQ_HAS_CELL(node_id, cell) DT_IRQ_HAS_CELL_AT_IDX(node_id, 0, cell)
2445
2455#define DT_IRQ_HAS_NAME(node_id, name) \
2456 IS_ENABLED(DT_CAT4(node_id, _IRQ_NAME_, name, _VAL_irq_EXISTS))
2457
2493#define DT_IRQ_BY_IDX(node_id, idx, cell) \
2494 DT_CAT5(node_id, _IRQ_IDX_, idx, _VAL_, cell)
2495
2511#define DT_IRQ_BY_NAME(node_id, name, cell) \
2512 DT_CAT5(node_id, _IRQ_NAME_, name, _VAL_, cell)
2513
2521#define DT_IRQ(node_id, cell) DT_IRQ_BY_IDX(node_id, 0, cell)
2522
2565#define DT_IRQ_INTC_BY_IDX(node_id, idx) \
2566 DT_CAT4(node_id, _IRQ_IDX_, idx, _CONTROLLER)
2567
2612#define DT_IRQ_INTC_BY_NAME(node_id, name) \
2613 DT_CAT4(node_id, _IRQ_NAME_, name, _CONTROLLER)
2614
2654#define DT_IRQ_INTC(node_id) \
2655 DT_IRQ_INTC_BY_IDX(node_id, 0)
2656
2661/* DT helper macro to encode a node's IRQN to level 1 according to the multi-level scheme */
2662#define DT_IRQN_L1_INTERNAL(node_id, idx) DT_IRQ_BY_IDX(node_id, idx, irq)
2663/* DT helper macro to encode a node's IRQN to level 2 according to the multi-level scheme */
2664#define DT_IRQN_L2_INTERNAL(node_id, idx) \
2665 (IRQ_TO_L2(DT_IRQN_L1_INTERNAL(node_id, idx)) | \
2666 DT_IRQ(DT_IRQ_INTC_BY_IDX(node_id, idx), irq))
2667/* DT helper macro to encode a node's IRQN to level 3 according to the multi-level scheme */
2668#define DT_IRQN_L3_INTERNAL(node_id, idx) \
2669 (IRQ_TO_L3(DT_IRQN_L1_INTERNAL(node_id, idx)) | \
2670 IRQ_TO_L2(DT_IRQ(DT_IRQ_INTC_BY_IDX(node_id, idx), irq)) | \
2671 DT_IRQ(DT_IRQ_INTC(DT_IRQ_INTC_BY_IDX(node_id, idx)), irq))
2672/* DT helper macro for the macros above */
2673#define DT_IRQN_LVL_INTERNAL(node_id, idx, level) DT_CAT3(DT_IRQN_L, level, _INTERNAL)(node_id, idx)
2674
2679#define DT_MULTI_LEVEL_IRQN_INTERNAL(node_id, idx) \
2680 DT_IRQN_LVL_INTERNAL(node_id, idx, DT_IRQ_LEVEL(node_id))
2681
2694#define DT_IRQN_BY_IDX(node_id, idx) \
2695 COND_CODE_1(IS_ENABLED(CONFIG_MULTI_LEVEL_INTERRUPTS), \
2696 (DT_MULTI_LEVEL_IRQN_INTERNAL(node_id, idx)), \
2697 (DT_IRQ_BY_IDX(node_id, idx, irq)))
2698
2709#define DT_IRQN(node_id) DT_IRQN_BY_IDX(node_id, 0)
2710
2729#define DT_CHOSEN(prop) DT_CAT(DT_CHOSEN_, prop)
2730
2737#define DT_HAS_CHOSEN(prop) IS_ENABLED(DT_CAT3(DT_CHOSEN_, prop, _EXISTS))
2738
2758#define DT_FOREACH_NODE(fn) DT_FOREACH_HELPER(fn)
2759
2772#define DT_FOREACH_NODE_VARGS(fn, ...) DT_FOREACH_VARGS_HELPER(fn, __VA_ARGS__)
2773
2785#define DT_FOREACH_STATUS_OKAY_NODE(fn) DT_FOREACH_OKAY_HELPER(fn)
2786
2801#define DT_FOREACH_STATUS_OKAY_NODE_VARGS(fn, ...) DT_FOREACH_OKAY_VARGS_HELPER(fn, __VA_ARGS__)
2802
2846#define DT_FOREACH_CHILD(node_id, fn) \
2847 DT_CAT(node_id, _FOREACH_CHILD)(fn)
2848
2889#define DT_FOREACH_CHILD_SEP(node_id, fn, sep) \
2890 DT_CAT(node_id, _FOREACH_CHILD_SEP)(fn, sep)
2891
2907#define DT_FOREACH_CHILD_VARGS(node_id, fn, ...) \
2908 DT_CAT(node_id, _FOREACH_CHILD_VARGS)(fn, __VA_ARGS__)
2909
2925#define DT_FOREACH_CHILD_SEP_VARGS(node_id, fn, sep, ...) \
2926 DT_CAT(node_id, _FOREACH_CHILD_SEP_VARGS)(fn, sep, __VA_ARGS__)
2927
2943#define DT_FOREACH_CHILD_STATUS_OKAY(node_id, fn) \
2944 DT_CAT(node_id, _FOREACH_CHILD_STATUS_OKAY)(fn)
2945
2962#define DT_FOREACH_CHILD_STATUS_OKAY_SEP(node_id, fn, sep) \
2963 DT_CAT(node_id, _FOREACH_CHILD_STATUS_OKAY_SEP)(fn, sep)
2964
2984#define DT_FOREACH_CHILD_STATUS_OKAY_VARGS(node_id, fn, ...) \
2985 DT_CAT(node_id, _FOREACH_CHILD_STATUS_OKAY_VARGS)(fn, __VA_ARGS__)
2986
3005#define DT_FOREACH_CHILD_STATUS_OKAY_SEP_VARGS(node_id, fn, sep, ...) \
3006 DT_CAT(node_id, _FOREACH_CHILD_STATUS_OKAY_SEP_VARGS)(fn, sep, __VA_ARGS__)
3007
3058#define DT_FOREACH_PROP_ELEM(node_id, prop, fn) \
3059 DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM)(fn)
3060
3103#define DT_FOREACH_PROP_ELEM_SEP(node_id, prop, fn, sep) \
3104 DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_SEP)(fn, sep)
3105
3126#define DT_FOREACH_PROP_ELEM_VARGS(node_id, prop, fn, ...) \
3127 DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_VARGS)(fn, __VA_ARGS__)
3128
3145#define DT_FOREACH_PROP_ELEM_SEP_VARGS(node_id, prop, fn, sep, ...) \
3146 DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_SEP_VARGS)( \
3147 fn, sep, __VA_ARGS__)
3148
3202#define DT_FOREACH_STATUS_OKAY(compat, fn) \
3203 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
3204 (DT_CAT(DT_FOREACH_OKAY_, compat)(fn)), \
3205 ())
3206
3251#define DT_FOREACH_STATUS_OKAY_VARGS(compat, fn, ...) \
3252 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
3253 (DT_CAT(DT_FOREACH_OKAY_VARGS_, \
3254 compat)(fn, __VA_ARGS__)), \
3255 ())
3256
3295#define DT_FOREACH_NODELABEL(node_id, fn) DT_CAT(node_id, _FOREACH_NODELABEL)(fn)
3296
3334#define DT_FOREACH_NODELABEL_VARGS(node_id, fn, ...) \
3335 DT_CAT(node_id, _FOREACH_NODELABEL_VARGS)(fn, __VA_ARGS__)
3336
3361#define DT_NODE_EXISTS(node_id) IS_ENABLED(DT_CAT(node_id, _EXISTS))
3362
3384#define DT_NODE_HAS_STATUS(node_id, status) \
3385 DT_NODE_HAS_STATUS_INTERNAL(node_id, status)
3386
3406#define DT_HAS_COMPAT_STATUS_OKAY(compat) \
3407 IS_ENABLED(DT_CAT(DT_COMPAT_HAS_OKAY_, compat))
3408
3415#define DT_NUM_INST_STATUS_OKAY(compat) \
3416 UTIL_AND(DT_HAS_COMPAT_STATUS_OKAY(compat), \
3417 UTIL_CAT(DT_N_INST, DT_DASH(compat, NUM_OKAY)))
3418
3446#define DT_NODE_HAS_COMPAT(node_id, compat) \
3447 IS_ENABLED(DT_CAT3(node_id, _COMPAT_MATCHES_, compat))
3448
3463#define DT_NODE_HAS_COMPAT_STATUS(node_id, compat, status) \
3464 UTIL_AND(DT_NODE_HAS_COMPAT(node_id, compat), DT_NODE_HAS_STATUS(node_id, status))
3465
3479#define DT_NODE_HAS_PROP(node_id, prop) \
3480 IS_ENABLED(DT_CAT4(node_id, _P_, prop, _EXISTS))
3481
3482
3499#define DT_PHA_HAS_CELL_AT_IDX(node_id, pha, idx, cell) \
3500 IS_ENABLED(DT_CAT8(node_id, _P_, pha, \
3501 _IDX_, idx, _VAL_, cell, _EXISTS))
3502
3512#define DT_PHA_HAS_CELL(node_id, pha, cell) \
3513 DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell)
3514
3556#define DT_BUS(node_id) DT_CAT(node_id, _BUS)
3557
3586#define DT_ON_BUS(node_id, bus) IS_ENABLED(DT_CAT3(node_id, _BUS_, bus))
3587
3604#define DT_DRV_INST(inst) DT_INST(inst, DT_DRV_COMPAT)
3605
3613#define DT_INST_PARENT(inst) DT_PARENT(DT_DRV_INST(inst))
3614
3622#define DT_INST_GPARENT(inst) DT_GPARENT(DT_DRV_INST(inst))
3623
3633#define DT_INST_CHILD(inst, child) \
3634 DT_CHILD(DT_DRV_INST(inst), child)
3635
3645#define DT_INST_CHILD_NUM(inst) DT_CHILD_NUM(DT_DRV_INST(inst))
3646
3656#define DT_INST_CHILD_NUM_STATUS_OKAY(inst) \
3657 DT_CHILD_NUM_STATUS_OKAY(DT_DRV_INST(inst))
3658
3667#define DT_INST_NODELABEL_STRING_ARRAY(inst) DT_NODELABEL_STRING_ARRAY(DT_DRV_INST(inst))
3668
3677#define DT_INST_NUM_NODELABELS(inst) DT_NUM_NODELABELS(DT_DRV_INST(inst))
3678
3693#define DT_INST_FOREACH_CHILD(inst, fn) \
3694 DT_FOREACH_CHILD(DT_DRV_INST(inst), fn)
3695
3709#define DT_INST_FOREACH_CHILD_SEP(inst, fn, sep) \
3710 DT_FOREACH_CHILD_SEP(DT_DRV_INST(inst), fn, sep)
3711
3727#define DT_INST_FOREACH_CHILD_VARGS(inst, fn, ...) \
3728 DT_FOREACH_CHILD_VARGS(DT_DRV_INST(inst), fn, __VA_ARGS__)
3729
3744#define DT_INST_FOREACH_CHILD_SEP_VARGS(inst, fn, sep, ...) \
3745 DT_FOREACH_CHILD_SEP_VARGS(DT_DRV_INST(inst), fn, sep, __VA_ARGS__)
3746
3758#define DT_INST_FOREACH_CHILD_STATUS_OKAY(inst, fn) \
3759 DT_FOREACH_CHILD_STATUS_OKAY(DT_DRV_INST(inst), fn)
3760
3775#define DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(inst, fn, sep) \
3776 DT_FOREACH_CHILD_STATUS_OKAY_SEP(DT_DRV_INST(inst), fn, sep)
3777
3791#define DT_INST_FOREACH_CHILD_STATUS_OKAY_VARGS(inst, fn, ...) \
3792 DT_FOREACH_CHILD_STATUS_OKAY_VARGS(DT_DRV_INST(inst), fn, __VA_ARGS__)
3793
3809#define DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP_VARGS(inst, fn, sep, ...) \
3810 DT_FOREACH_CHILD_STATUS_OKAY_SEP_VARGS(DT_DRV_INST(inst), fn, sep, __VA_ARGS__)
3811
3818#define DT_INST_ENUM_IDX(inst, prop) \
3819 DT_ENUM_IDX(DT_DRV_INST(inst), prop)
3820
3829#define DT_INST_ENUM_IDX_OR(inst, prop, default_idx_value) \
3830 DT_ENUM_IDX_OR(DT_DRV_INST(inst), prop, default_idx_value)
3831
3840#define DT_INST_ENUM_HAS_VALUE(inst, prop, value) \
3841 DT_ENUM_HAS_VALUE(DT_DRV_INST(inst), prop, value)
3842
3849#define DT_INST_PROP(inst, prop) DT_PROP(DT_DRV_INST(inst), prop)
3850
3857#define DT_INST_PROP_LEN(inst, prop) DT_PROP_LEN(DT_DRV_INST(inst), prop)
3858
3868#define DT_INST_PROP_HAS_IDX(inst, prop, idx) \
3869 DT_PROP_HAS_IDX(DT_DRV_INST(inst), prop, idx)
3870
3879#define DT_INST_PROP_HAS_NAME(inst, prop, name) \
3880 DT_PROP_HAS_NAME(DT_DRV_INST(inst), prop, name)
3881
3889#define DT_INST_PROP_BY_IDX(inst, prop, idx) \
3890 DT_PROP_BY_IDX(DT_DRV_INST(inst), prop, idx)
3891
3899#define DT_INST_PROP_OR(inst, prop, default_value) \
3900 DT_PROP_OR(DT_DRV_INST(inst), prop, default_value)
3901
3909#define DT_INST_PROP_LEN_OR(inst, prop, default_value) \
3910 DT_PROP_LEN_OR(DT_DRV_INST(inst), prop, default_value)
3911
3921#define DT_INST_STRING_TOKEN(inst, prop) \
3922 DT_STRING_TOKEN(DT_DRV_INST(inst), prop)
3923
3931#define DT_INST_STRING_UPPER_TOKEN(inst, prop) \
3932 DT_STRING_UPPER_TOKEN(DT_DRV_INST(inst), prop)
3933
3942#define DT_INST_STRING_UNQUOTED(inst, prop) \
3943 DT_STRING_UNQUOTED(DT_DRV_INST(inst), prop)
3944
3952#define DT_INST_STRING_TOKEN_BY_IDX(inst, prop, idx) \
3953 DT_STRING_TOKEN_BY_IDX(DT_DRV_INST(inst), prop, idx)
3954
3962#define DT_INST_STRING_UPPER_TOKEN_BY_IDX(inst, prop, idx) \
3963 DT_STRING_UPPER_TOKEN_BY_IDX(DT_DRV_INST(inst), prop, idx)
3964
3972#define DT_INST_STRING_UNQUOTED_BY_IDX(inst, prop, idx) \
3973 DT_STRING_UNQUOTED_BY_IDX(DT_DRV_INST(inst), prop, idx)
3974
3983#define DT_INST_PROP_BY_PHANDLE(inst, ph, prop) \
3984 DT_INST_PROP_BY_PHANDLE_IDX(inst, ph, 0, prop)
3985
3997#define DT_INST_PROP_BY_PHANDLE_IDX(inst, phs, idx, prop) \
3998 DT_PROP_BY_PHANDLE_IDX(DT_DRV_INST(inst), phs, idx, prop)
3999
4008#define DT_INST_PHA_BY_IDX(inst, pha, idx, cell) \
4009 DT_PHA_BY_IDX(DT_DRV_INST(inst), pha, idx, cell)
4010
4020#define DT_INST_PHA_BY_IDX_OR(inst, pha, idx, cell, default_value) \
4021 DT_PHA_BY_IDX_OR(DT_DRV_INST(inst), pha, idx, cell, default_value)
4022
4031#define DT_INST_PHA(inst, pha, cell) DT_INST_PHA_BY_IDX(inst, pha, 0, cell)
4032
4041#define DT_INST_PHA_OR(inst, pha, cell, default_value) \
4042 DT_INST_PHA_BY_IDX_OR(inst, pha, 0, cell, default_value)
4043
4053#define DT_INST_PHA_BY_NAME(inst, pha, name, cell) \
4054 DT_PHA_BY_NAME(DT_DRV_INST(inst), pha, name, cell)
4055
4065#define DT_INST_PHA_BY_NAME_OR(inst, pha, name, cell, default_value) \
4066 DT_PHA_BY_NAME_OR(DT_DRV_INST(inst), pha, name, cell, default_value)
4067
4076#define DT_INST_PHANDLE_BY_NAME(inst, pha, name) \
4077 DT_PHANDLE_BY_NAME(DT_DRV_INST(inst), pha, name) \
4078
4088#define DT_INST_PHANDLE_BY_IDX(inst, prop, idx) \
4089 DT_PHANDLE_BY_IDX(DT_DRV_INST(inst), prop, idx)
4090
4099#define DT_INST_PHANDLE(inst, prop) DT_INST_PHANDLE_BY_IDX(inst, prop, 0)
4100
4108#define DT_INST_REG_HAS_IDX(inst, idx) DT_REG_HAS_IDX(DT_DRV_INST(inst), idx)
4109
4117#define DT_INST_REG_HAS_NAME(inst, name) DT_REG_HAS_NAME(DT_DRV_INST(inst), name)
4118
4125#define DT_INST_REG_ADDR_BY_IDX(inst, idx) DT_REG_ADDR_BY_IDX(DT_DRV_INST(inst), idx)
4126
4133#define DT_INST_REG_SIZE_BY_IDX(inst, idx) \
4134 DT_REG_SIZE_BY_IDX(DT_DRV_INST(inst), idx)
4135
4142#define DT_INST_REG_ADDR_BY_NAME(inst, name) \
4143 DT_REG_ADDR_BY_NAME(DT_DRV_INST(inst), name)
4144
4153#define DT_INST_REG_ADDR_BY_NAME_OR(inst, name, default_value) \
4154 DT_REG_ADDR_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
4155
4168#define DT_INST_REG_ADDR_BY_NAME_U64(inst, name) \
4169 DT_U64_C(DT_INST_REG_ADDR_BY_NAME(inst, name))
4170
4177#define DT_INST_REG_SIZE_BY_NAME(inst, name) \
4178 DT_REG_SIZE_BY_NAME(DT_DRV_INST(inst), name)
4179
4188#define DT_INST_REG_SIZE_BY_NAME_OR(inst, name, default_value) \
4189 DT_REG_SIZE_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
4190
4196#define DT_INST_REG_ADDR(inst) DT_INST_REG_ADDR_BY_IDX(inst, 0)
4197
4209#define DT_INST_REG_ADDR_U64(inst) DT_U64_C(DT_INST_REG_ADDR(inst))
4210
4216#define DT_INST_REG_SIZE(inst) DT_INST_REG_SIZE_BY_IDX(inst, 0)
4217
4224#define DT_INST_IRQ_LEVEL(inst) DT_IRQ_LEVEL(DT_DRV_INST(inst))
4225
4233#define DT_INST_IRQ_BY_IDX(inst, idx, cell) \
4234 DT_IRQ_BY_IDX(DT_DRV_INST(inst), idx, cell)
4235
4242#define DT_INST_IRQ_INTC_BY_IDX(inst, idx) \
4243 DT_IRQ_INTC_BY_IDX(DT_DRV_INST(inst), idx)
4244
4251#define DT_INST_IRQ_INTC_BY_NAME(inst, name) \
4252 DT_IRQ_INTC_BY_NAME(DT_DRV_INST(inst), name)
4253
4261#define DT_INST_IRQ_INTC(inst) \
4262 DT_INST_IRQ_INTC_BY_IDX(inst, 0)
4263
4271#define DT_INST_IRQ_BY_NAME(inst, name, cell) \
4272 DT_IRQ_BY_NAME(DT_DRV_INST(inst), name, cell)
4273
4280#define DT_INST_IRQ(inst, cell) DT_INST_IRQ_BY_IDX(inst, 0, cell)
4281
4287#define DT_INST_IRQN(inst) DT_IRQN(DT_DRV_INST(inst))
4288
4295#define DT_INST_IRQN_BY_IDX(inst, idx) DT_IRQN_BY_IDX(DT_DRV_INST(inst), idx)
4296
4302#define DT_INST_BUS(inst) DT_BUS(DT_DRV_INST(inst))
4303
4311#define DT_INST_ON_BUS(inst, bus) DT_ON_BUS(DT_DRV_INST(inst), bus)
4312
4322#define DT_INST_STRING_TOKEN_OR(inst, name, default_value) \
4323 DT_STRING_TOKEN_OR(DT_DRV_INST(inst), name, default_value)
4324
4333#define DT_INST_STRING_UPPER_TOKEN_OR(inst, name, default_value) \
4334 DT_STRING_UPPER_TOKEN_OR(DT_DRV_INST(inst), name, default_value)
4335
4344#define DT_INST_STRING_UNQUOTED_OR(inst, name, default_value) \
4345 DT_STRING_UNQUOTED_OR(DT_DRV_INST(inst), name, default_value)
4346
4347/*
4348 * @brief Test if any enabled node with the given compatible is on
4349 * the given bus type
4350 *
4351 * This is like DT_ANY_INST_ON_BUS_STATUS_OKAY(), except it can also
4352 * be useful for handling multiple compatibles in single source file.
4353 *
4354 * Example devicetree overlay:
4355 *
4356 * @code{.dts}
4357 * &i2c0 {
4358 * temp: temperature-sensor@76 {
4359 * compatible = "vnd,some-sensor";
4360 * reg = <0x76>;
4361 * };
4362 * };
4363 * @endcode
4364 *
4365 * Example usage, assuming `i2c0` is an I2C bus controller node, and
4366 * therefore `temp` is on an I2C bus:
4367 *
4368 * @code{.c}
4369 * DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(vnd_some_sensor, i2c) // 1
4370 * @endcode
4371 *
4372 * @param compat lowercase-and-underscores compatible, without quotes
4373 * @param bus a binding's bus type as a C token, lowercased and without quotes
4374 * @return 1 if any enabled node with that compatible is on that bus type,
4375 * 0 otherwise
4376 */
4377#define DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(compat, bus) \
4378 IS_ENABLED(DT_CAT4(DT_COMPAT_, compat, _BUS_, bus))
4379
4412#define DT_ANY_INST_ON_BUS_STATUS_OKAY(bus) \
4413 DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(DT_DRV_COMPAT, bus)
4414
4459#define DT_ANY_INST_HAS_PROP_STATUS_OKAY(prop) \
4460 COND_CODE_1(IS_EMPTY(DT_ANY_INST_HAS_PROP_STATUS_OKAY_(prop)), (0), (1))
4461
4527#define DT_INST_FOREACH_STATUS_OKAY(fn) \
4528 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \
4529 (UTIL_CAT(DT_FOREACH_OKAY_INST_, \
4530 DT_DRV_COMPAT)(fn)), \
4531 ())
4532
4544#define DT_INST_FOREACH_STATUS_OKAY_VARGS(fn, ...) \
4545 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \
4546 (UTIL_CAT(DT_FOREACH_OKAY_INST_VARGS_, \
4547 DT_DRV_COMPAT)(fn, __VA_ARGS__)), \
4548 ())
4549
4559#define DT_INST_FOREACH_NODELABEL(inst, fn) \
4560 DT_FOREACH_NODELABEL(DT_DRV_INST(inst), fn)
4561
4573#define DT_INST_FOREACH_NODELABEL_VARGS(inst, fn, ...) \
4574 DT_FOREACH_NODELABEL_VARGS(DT_DRV_INST(inst), fn, __VA_ARGS__)
4575
4586#define DT_INST_FOREACH_PROP_ELEM(inst, prop, fn) \
4587 DT_FOREACH_PROP_ELEM(DT_DRV_INST(inst), prop, fn)
4588
4601#define DT_INST_FOREACH_PROP_ELEM_SEP(inst, prop, fn, sep) \
4602 DT_FOREACH_PROP_ELEM_SEP(DT_DRV_INST(inst), prop, fn, sep)
4603
4618#define DT_INST_FOREACH_PROP_ELEM_VARGS(inst, prop, fn, ...) \
4619 DT_FOREACH_PROP_ELEM_VARGS(DT_DRV_INST(inst), prop, fn, __VA_ARGS__)
4620
4638#define DT_INST_FOREACH_PROP_ELEM_SEP_VARGS(inst, prop, fn, sep, ...) \
4639 DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_DRV_INST(inst), prop, fn, sep, \
4640 __VA_ARGS__)
4641
4648#define DT_INST_NODE_HAS_PROP(inst, prop) \
4649 DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop)
4650
4657#define DT_INST_NODE_HAS_COMPAT(inst, compat) \
4658 DT_NODE_HAS_COMPAT(DT_DRV_INST(inst), compat)
4659
4670#define DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, idx, cell) \
4671 DT_PHA_HAS_CELL_AT_IDX(DT_DRV_INST(inst), pha, idx, cell)
4672
4682#define DT_INST_PHA_HAS_CELL(inst, pha, cell) \
4683 DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, 0, cell)
4684
4692#define DT_INST_IRQ_HAS_IDX(inst, idx) DT_IRQ_HAS_IDX(DT_DRV_INST(inst), idx)
4693
4702#define DT_INST_IRQ_HAS_CELL_AT_IDX(inst, idx, cell) \
4703 DT_IRQ_HAS_CELL_AT_IDX(DT_DRV_INST(inst), idx, cell)
4704
4712#define DT_INST_IRQ_HAS_CELL(inst, cell) \
4713 DT_INST_IRQ_HAS_CELL_AT_IDX(inst, 0, cell)
4714
4721#define DT_INST_IRQ_HAS_NAME(inst, name) \
4722 DT_IRQ_HAS_NAME(DT_DRV_INST(inst), name)
4723
4741#define DT_ANY_INST_HAS_PROP_STATUS_OKAY__(idx, prop) \
4742 COND_CODE_1(DT_INST_NODE_HAS_PROP(idx, prop), (1,), ())
4755#define DT_ANY_INST_HAS_PROP_STATUS_OKAY_(prop) \
4756 DT_INST_FOREACH_STATUS_OKAY_VARGS(DT_ANY_INST_HAS_PROP_STATUS_OKAY__, prop)
4757
4758#define DT_PATH_INTERNAL(...) \
4759 UTIL_CAT(DT_ROOT, MACRO_MAP_CAT(DT_S_PREFIX, __VA_ARGS__))
4765#define DT_S_PREFIX(name) _S_##name
4766
4781#define DT_CAT(a1, a2) a1 ## a2
4783#define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
4785#define DT_CAT4(a1, a2, a3, a4) a1 ## a2 ## a3 ## a4
4787#define DT_CAT5(a1, a2, a3, a4, a5) a1 ## a2 ## a3 ## a4 ## a5
4789#define DT_CAT6(a1, a2, a3, a4, a5, a6) a1 ## a2 ## a3 ## a4 ## a5 ## a6
4791#define DT_CAT7(a1, a2, a3, a4, a5, a6, a7) \
4792 a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7
4794#define DT_CAT8(a1, a2, a3, a4, a5, a6, a7, a8) \
4795 a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7 ## a8
4796/*
4797 * If you need to define a bigger DT_CATN(), do so here. Don't leave
4798 * any "holes" of undefined macros, please.
4799 */
4800
4802#define DT_DASH(...) MACRO_MAP_CAT(DT_DASH_PREFIX, __VA_ARGS__)
4804#define DT_DASH_PREFIX(name) _##name
4806#define DT_NODE_HAS_STATUS_INTERNAL(node_id, status) \
4807 IS_ENABLED(DT_CAT3(node_id, _STATUS_, status))
4808
4813#if defined(_LINKER) || defined(_ASMLANGUAGE)
4814#define DT_U64_C(_v) (_v)
4815#else
4816#define DT_U64_C(_v) UINT64_C(_v)
4817#endif
4818
4819/* Helpers for DT_NODELABEL_STRING_ARRAY. We define our own stringify
4820 * in order to avoid adding a dependency on toolchain.h..
4821 */
4822#define DT_NODELABEL_STRING_ARRAY_ENTRY_INTERNAL(nodelabel) DT_STRINGIFY_INTERNAL(nodelabel),
4823#define DT_STRINGIFY_INTERNAL(arg) DT_STRINGIFY_INTERNAL_HELPER(arg)
4824#define DT_STRINGIFY_INTERNAL_HELPER(arg) #arg
4825
4828/* have these last so they have access to all previously defined macros */
4831#include <zephyr/devicetree/gpio.h>
4832#include <zephyr/devicetree/spi.h>
4833#include <zephyr/devicetree/dma.h>
4834#include <zephyr/devicetree/pwms.h>
4838#include <zephyr/devicetree/can.h>
4840#include <zephyr/devicetree/mbox.h>
4841
4842#endif /* DEVICETREE_H */
Clocks Devicetree macro public API header file.
CAN devicetree macro public API header file.
DMA Devicetree macro public API header file.
GPIO Devicetree macro public API header file.
MBOX Devicetree macro public API header file.
Devicetree pin control helpers.
Reset Controller Devicetree macro public API header file.
SPI Devicetree macro public API header file.
Flash Devicetree macro public API header file.
IO channels devicetree macro public API header file.
Public interface for multi-level interrupts.
Devicetree node dependency ordinals.
PWMs Devicetree macro public API header file.
Misc utilities.