Zephyr API Documentation  3.6.99
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 <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
636#define DT_PROP(node_id, prop) DT_CAT3(node_id, _P_, prop)
637
670#define DT_PROP_LEN(node_id, prop) DT_CAT4(node_id, _P_, prop, _LEN)
671
686#define DT_PROP_LEN_OR(node_id, prop, default_value) \
687 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
688 (DT_PROP_LEN(node_id, prop)), (default_value))
689
710#define DT_PROP_HAS_IDX(node_id, prop, idx) \
711 IS_ENABLED(DT_CAT6(node_id, _P_, prop, _IDX_, idx, _EXISTS))
712
745#define DT_PROP_HAS_NAME(node_id, prop, name) \
746 IS_ENABLED(DT_CAT6(node_id, _P_, prop, _NAME_, name, _EXISTS))
747
782#define DT_PROP_BY_IDX(node_id, prop, idx) \
783 DT_CAT5(node_id, _P_, prop, _IDX_, idx)
784
798#define DT_PROP_OR(node_id, prop, default_value) \
799 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
800 (DT_PROP(node_id, prop)), (default_value))
801
842#define DT_ENUM_IDX(node_id, prop) DT_CAT4(node_id, _P_, prop, _ENUM_IDX)
843
858#define DT_ENUM_IDX_OR(node_id, prop, default_idx_value) \
859 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
860 (DT_ENUM_IDX(node_id, prop)), (default_idx_value))
861
870#define DT_ENUM_HAS_VALUE(node_id, prop, value) \
871 IS_ENABLED(DT_CAT6(node_id, _P_, prop, _ENUM_VAL_, value, _EXISTS))
872
932#define DT_STRING_TOKEN(node_id, prop) \
933 DT_CAT4(node_id, _P_, prop, _STRING_TOKEN)
934
948#define DT_STRING_TOKEN_OR(node_id, prop, default_value) \
949 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
950 (DT_STRING_TOKEN(node_id, prop)), (default_value))
951
1009#define DT_STRING_UPPER_TOKEN(node_id, prop) \
1010 DT_CAT4(node_id, _P_, prop, _STRING_UPPER_TOKEN)
1011
1026#define DT_STRING_UPPER_TOKEN_OR(node_id, prop, default_value) \
1027 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
1028 (DT_STRING_UPPER_TOKEN(node_id, prop)), (default_value))
1029
1070#define DT_STRING_UNQUOTED(node_id, prop) \
1071 DT_CAT4(node_id, _P_, prop, _STRING_UNQUOTED)
1072
1087#define DT_STRING_UNQUOTED_OR(node_id, prop, default_value) \
1088 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
1089 (DT_STRING_UNQUOTED(node_id, prop)), (default_value))
1090
1138#define DT_STRING_TOKEN_BY_IDX(node_id, prop, idx) \
1139 DT_CAT6(node_id, _P_, prop, _IDX_, idx, _STRING_TOKEN)
1140
1188#define DT_STRING_UPPER_TOKEN_BY_IDX(node_id, prop, idx) \
1189 DT_CAT6(node_id, _P_, prop, _IDX_, idx, _STRING_UPPER_TOKEN)
1190
1231#define DT_STRING_UNQUOTED_BY_IDX(node_id, prop, idx) \
1232 DT_CAT6(node_id, _P_, prop, _IDX_, idx, _STRING_UNQUOTED)
1233
1234/*
1235 * phandle properties
1236 *
1237 * These are special-cased to manage the impedance mismatch between
1238 * phandles, which are just uint32_t node properties that only make sense
1239 * within the tree itself, and C values.
1240 */
1241
1287#define DT_PROP_BY_PHANDLE_IDX(node_id, phs, idx, prop) \
1288 DT_PROP(DT_PHANDLE_BY_IDX(node_id, phs, idx), prop)
1289
1309#define DT_PROP_BY_PHANDLE_IDX_OR(node_id, phs, idx, prop, default_value) \
1310 DT_PROP_OR(DT_PHANDLE_BY_IDX(node_id, phs, idx), prop, default_value)
1311
1323#define DT_PROP_BY_PHANDLE(node_id, ph, prop) \
1324 DT_PROP_BY_PHANDLE_IDX(node_id, ph, 0, prop)
1325
1380#define DT_PHA_BY_IDX(node_id, pha, idx, cell) \
1381 DT_CAT7(node_id, _P_, pha, _IDX_, idx, _VAL_, cell)
1382
1406#define DT_PHA_BY_IDX_OR(node_id, pha, idx, cell, default_value) \
1407 DT_PROP_OR(node_id, DT_CAT5(pha, _IDX_, idx, _VAL_, cell), default_value)
1408
1416#define DT_PHA(node_id, pha, cell) DT_PHA_BY_IDX(node_id, pha, 0, cell)
1417
1432#define DT_PHA_OR(node_id, pha, cell, default_value) \
1433 DT_PHA_BY_IDX_OR(node_id, pha, 0, cell, default_value)
1434
1475#define DT_PHA_BY_NAME(node_id, pha, name, cell) \
1476 DT_CAT7(node_id, _P_, pha, _NAME_, name, _VAL_, cell)
1477
1499#define DT_PHA_BY_NAME_OR(node_id, pha, name, cell, default_value) \
1500 DT_PROP_OR(node_id, DT_CAT5(pha, _NAME_, name, _VAL_, cell), default_value)
1501
1549#define DT_PHANDLE_BY_NAME(node_id, pha, name) \
1550 DT_CAT6(node_id, _P_, pha, _NAME_, name, _PH)
1551
1601#define DT_PHANDLE_BY_IDX(node_id, prop, idx) \
1602 DT_CAT6(node_id, _P_, prop, _IDX_, idx, _PH)
1603
1615#define DT_PHANDLE(node_id, prop) DT_PHANDLE_BY_IDX(node_id, prop, 0)
1616
1663#define DT_NUM_RANGES(node_id) DT_CAT(node_id, _RANGES_NUM)
1664
1717#define DT_RANGES_HAS_IDX(node_id, idx) \
1718 IS_ENABLED(DT_CAT4(node_id, _RANGES_IDX_, idx, _EXISTS))
1719
1772#define DT_RANGES_HAS_CHILD_BUS_FLAGS_AT_IDX(node_id, idx) \
1773 IS_ENABLED(DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_CHILD_BUS_FLAGS_EXISTS))
1774
1812#define DT_RANGES_CHILD_BUS_FLAGS_BY_IDX(node_id, idx) \
1813 DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_CHILD_BUS_FLAGS)
1814
1861#define DT_RANGES_CHILD_BUS_ADDRESS_BY_IDX(node_id, idx) \
1862 DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_CHILD_BUS_ADDRESS)
1863
1910#define DT_RANGES_PARENT_BUS_ADDRESS_BY_IDX(node_id, idx) \
1911 DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_PARENT_BUS_ADDRESS)
1912
1959#define DT_RANGES_LENGTH_BY_IDX(node_id, idx) \
1960 DT_CAT4(node_id, _RANGES_IDX_, idx, _VAL_LENGTH)
1961
2001#define DT_FOREACH_RANGE(node_id, fn) \
2002 DT_CAT(node_id, _FOREACH_RANGE)(fn)
2003
2049#define DT_NODE_VENDOR_BY_IDX(node_id, idx) \
2050 DT_CAT3(node_id, _COMPAT_VENDOR_IDX_, idx)
2051
2064#define DT_NODE_VENDOR_HAS_IDX(node_id, idx) \
2065 IS_ENABLED(DT_CAT4(node_id, _COMPAT_VENDOR_IDX_, idx, _EXISTS))
2066
2081#define DT_NODE_VENDOR_BY_IDX_OR(node_id, idx, default_value) \
2082 COND_CODE_1(DT_NODE_VENDOR_HAS_IDX(node_id, idx), \
2083 (DT_NODE_VENDOR_BY_IDX(node_id, idx)), (default_value))
2084
2093#define DT_NODE_VENDOR_OR(node_id, default_value) \
2094 DT_NODE_VENDOR_BY_IDX_OR(node_id, 0, default_value)
2095
2125#define DT_NODE_MODEL_BY_IDX(node_id, idx) \
2126 DT_CAT3(node_id, _COMPAT_MODEL_IDX_, idx)
2127
2140#define DT_NODE_MODEL_HAS_IDX(node_id, idx) \
2141 IS_ENABLED(DT_CAT4(node_id, _COMPAT_MODEL_IDX_, idx, _EXISTS))
2142
2157#define DT_NODE_MODEL_BY_IDX_OR(node_id, idx, default_value) \
2158 COND_CODE_1(DT_NODE_MODEL_HAS_IDX(node_id, idx), \
2159 (DT_NODE_MODEL_BY_IDX(node_id, idx)), (default_value))
2160
2169#define DT_NODE_MODEL_OR(node_id, default_value) \
2170 DT_NODE_MODEL_BY_IDX_OR(node_id, 0, default_value)
2171
2189#define DT_NUM_REGS(node_id) DT_CAT(node_id, _REG_NUM)
2190
2202#define DT_REG_HAS_IDX(node_id, idx) \
2203 IS_ENABLED(DT_CAT4(node_id, _REG_IDX_, idx, _EXISTS))
2204
2211#define DT_REG_ADDR_BY_IDX(node_id, idx) \
2212 DT_CAT4(node_id, _REG_IDX_, idx, _VAL_ADDRESS)
2213
2225#define DT_REG_SIZE_BY_IDX(node_id, idx) \
2226 DT_CAT4(node_id, _REG_IDX_, idx, _VAL_SIZE)
2227
2235#define DT_REG_ADDR(node_id) DT_REG_ADDR_BY_IDX(node_id, 0)
2236
2247#define DT_REG_ADDR_U64(node_id) DT_U64_C(DT_REG_ADDR(node_id))
2248
2256#define DT_REG_SIZE(node_id) DT_REG_SIZE_BY_IDX(node_id, 0)
2257
2264#define DT_REG_ADDR_BY_NAME(node_id, name) \
2265 DT_CAT4(node_id, _REG_NAME_, name, _VAL_ADDRESS)
2266
2279#define DT_REG_ADDR_BY_NAME_U64(node_id, name) \
2280 DT_U64_C(DT_REG_ADDR_BY_NAME(node_id, name))
2281
2288#define DT_REG_SIZE_BY_NAME(node_id, name) \
2289 DT_CAT4(node_id, _REG_NAME_, name, _VAL_SIZE)
2290
2309#define DT_NUM_IRQS(node_id) DT_CAT(node_id, _IRQ_NUM)
2310
2317#define DT_IRQ_LEVEL(node_id) DT_CAT(node_id, _IRQ_LEVEL)
2318
2329#define DT_IRQ_HAS_IDX(node_id, idx) \
2330 IS_ENABLED(DT_CAT4(node_id, _IRQ_IDX_, idx, _EXISTS))
2331
2342#define DT_IRQ_HAS_CELL_AT_IDX(node_id, idx, cell) \
2343 IS_ENABLED(DT_CAT6(node_id, _IRQ_IDX_, idx, _VAL_, cell, _EXISTS))
2344
2352#define DT_IRQ_HAS_CELL(node_id, cell) DT_IRQ_HAS_CELL_AT_IDX(node_id, 0, cell)
2353
2363#define DT_IRQ_HAS_NAME(node_id, name) \
2364 IS_ENABLED(DT_CAT4(node_id, _IRQ_NAME_, name, _VAL_irq_EXISTS))
2365
2401#define DT_IRQ_BY_IDX(node_id, idx, cell) \
2402 DT_CAT5(node_id, _IRQ_IDX_, idx, _VAL_, cell)
2403
2419#define DT_IRQ_BY_NAME(node_id, name, cell) \
2420 DT_CAT5(node_id, _IRQ_NAME_, name, _VAL_, cell)
2421
2429#define DT_IRQ(node_id, cell) DT_IRQ_BY_IDX(node_id, 0, cell)
2430
2473#define DT_IRQ_INTC_BY_IDX(node_id, idx) \
2474 DT_CAT4(node_id, _IRQ_IDX_, idx, _CONTROLLER)
2475
2520#define DT_IRQ_INTC_BY_NAME(node_id, name) \
2521 DT_CAT4(node_id, _IRQ_NAME_, name, _CONTROLLER)
2522
2562#define DT_IRQ_INTC(node_id) \
2563 DT_IRQ_INTC_BY_IDX(node_id, 0)
2564
2569/* DT helper macro to encode a node's IRQN to level 1 according to the multi-level scheme */
2570#define DT_IRQN_L1_INTERNAL(node_id, idx) DT_IRQ_BY_IDX(node_id, idx, irq)
2571/* DT helper macro to encode a node's IRQN to level 2 according to the multi-level scheme */
2572#define DT_IRQN_L2_INTERNAL(node_id, idx) \
2573 (IRQ_TO_L2(DT_IRQN_L1_INTERNAL(node_id, idx)) | \
2574 DT_IRQ(DT_IRQ_INTC_BY_IDX(node_id, idx), irq))
2575/* DT helper macro to encode a node's IRQN to level 3 according to the multi-level scheme */
2576#define DT_IRQN_L3_INTERNAL(node_id, idx) \
2577 (IRQ_TO_L3(DT_IRQN_L1_INTERNAL(node_id, idx)) | \
2578 IRQ_TO_L2(DT_IRQ(DT_IRQ_INTC_BY_IDX(node_id, idx), irq)) | \
2579 DT_IRQ(DT_IRQ_INTC(DT_IRQ_INTC_BY_IDX(node_id, idx)), irq))
2580/* DT helper macro for the macros above */
2581#define DT_IRQN_LVL_INTERNAL(node_id, idx, level) DT_CAT3(DT_IRQN_L, level, _INTERNAL)(node_id, idx)
2582
2587#define DT_MULTI_LEVEL_IRQN_INTERNAL(node_id, idx) \
2588 DT_IRQN_LVL_INTERNAL(node_id, idx, DT_IRQ_LEVEL(node_id))
2589
2602#define DT_IRQN_BY_IDX(node_id, idx) \
2603 COND_CODE_1(IS_ENABLED(CONFIG_MULTI_LEVEL_INTERRUPTS), \
2604 (DT_MULTI_LEVEL_IRQN_INTERNAL(node_id, idx)), \
2605 (DT_IRQ_BY_IDX(node_id, idx, irq)))
2606
2617#define DT_IRQN(node_id) DT_IRQN_BY_IDX(node_id, 0)
2618
2637#define DT_CHOSEN(prop) DT_CAT(DT_CHOSEN_, prop)
2638
2645#define DT_HAS_CHOSEN(prop) IS_ENABLED(DT_CAT3(DT_CHOSEN_, prop, _EXISTS))
2646
2666#define DT_FOREACH_NODE(fn) DT_FOREACH_HELPER(fn)
2667
2680#define DT_FOREACH_NODE_VARGS(fn, ...) DT_FOREACH_VARGS_HELPER(fn, __VA_ARGS__)
2681
2693#define DT_FOREACH_STATUS_OKAY_NODE(fn) DT_FOREACH_OKAY_HELPER(fn)
2694
2709#define DT_FOREACH_STATUS_OKAY_NODE_VARGS(fn, ...) DT_FOREACH_OKAY_VARGS_HELPER(fn, __VA_ARGS__)
2710
2754#define DT_FOREACH_CHILD(node_id, fn) \
2755 DT_CAT(node_id, _FOREACH_CHILD)(fn)
2756
2797#define DT_FOREACH_CHILD_SEP(node_id, fn, sep) \
2798 DT_CAT(node_id, _FOREACH_CHILD_SEP)(fn, sep)
2799
2815#define DT_FOREACH_CHILD_VARGS(node_id, fn, ...) \
2816 DT_CAT(node_id, _FOREACH_CHILD_VARGS)(fn, __VA_ARGS__)
2817
2833#define DT_FOREACH_CHILD_SEP_VARGS(node_id, fn, sep, ...) \
2834 DT_CAT(node_id, _FOREACH_CHILD_SEP_VARGS)(fn, sep, __VA_ARGS__)
2835
2851#define DT_FOREACH_CHILD_STATUS_OKAY(node_id, fn) \
2852 DT_CAT(node_id, _FOREACH_CHILD_STATUS_OKAY)(fn)
2853
2870#define DT_FOREACH_CHILD_STATUS_OKAY_SEP(node_id, fn, sep) \
2871 DT_CAT(node_id, _FOREACH_CHILD_STATUS_OKAY_SEP)(fn, sep)
2872
2892#define DT_FOREACH_CHILD_STATUS_OKAY_VARGS(node_id, fn, ...) \
2893 DT_CAT(node_id, _FOREACH_CHILD_STATUS_OKAY_VARGS)(fn, __VA_ARGS__)
2894
2913#define DT_FOREACH_CHILD_STATUS_OKAY_SEP_VARGS(node_id, fn, sep, ...) \
2914 DT_CAT(node_id, _FOREACH_CHILD_STATUS_OKAY_SEP_VARGS)(fn, sep, __VA_ARGS__)
2915
2966#define DT_FOREACH_PROP_ELEM(node_id, prop, fn) \
2967 DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM)(fn)
2968
3011#define DT_FOREACH_PROP_ELEM_SEP(node_id, prop, fn, sep) \
3012 DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_SEP)(fn, sep)
3013
3034#define DT_FOREACH_PROP_ELEM_VARGS(node_id, prop, fn, ...) \
3035 DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_VARGS)(fn, __VA_ARGS__)
3036
3053#define DT_FOREACH_PROP_ELEM_SEP_VARGS(node_id, prop, fn, sep, ...) \
3054 DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_SEP_VARGS)( \
3055 fn, sep, __VA_ARGS__)
3056
3110#define DT_FOREACH_STATUS_OKAY(compat, fn) \
3111 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
3112 (DT_CAT(DT_FOREACH_OKAY_, compat)(fn)), \
3113 ())
3114
3159#define DT_FOREACH_STATUS_OKAY_VARGS(compat, fn, ...) \
3160 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
3161 (DT_CAT(DT_FOREACH_OKAY_VARGS_, \
3162 compat)(fn, __VA_ARGS__)), \
3163 ())
3164
3189#define DT_NODE_EXISTS(node_id) IS_ENABLED(DT_CAT(node_id, _EXISTS))
3190
3212#define DT_NODE_HAS_STATUS(node_id, status) \
3213 DT_NODE_HAS_STATUS_INTERNAL(node_id, status)
3214
3234#define DT_HAS_COMPAT_STATUS_OKAY(compat) \
3235 IS_ENABLED(DT_CAT(DT_COMPAT_HAS_OKAY_, compat))
3236
3243#define DT_NUM_INST_STATUS_OKAY(compat) \
3244 UTIL_AND(DT_HAS_COMPAT_STATUS_OKAY(compat), \
3245 UTIL_CAT(DT_N_INST, DT_DASH(compat, NUM_OKAY)))
3246
3274#define DT_NODE_HAS_COMPAT(node_id, compat) \
3275 IS_ENABLED(DT_CAT3(node_id, _COMPAT_MATCHES_, compat))
3276
3291#define DT_NODE_HAS_COMPAT_STATUS(node_id, compat, status) \
3292 DT_NODE_HAS_COMPAT(node_id, compat) && DT_NODE_HAS_STATUS(node_id, status)
3293
3307#define DT_NODE_HAS_PROP(node_id, prop) \
3308 IS_ENABLED(DT_CAT4(node_id, _P_, prop, _EXISTS))
3309
3310
3327#define DT_PHA_HAS_CELL_AT_IDX(node_id, pha, idx, cell) \
3328 IS_ENABLED(DT_CAT8(node_id, _P_, pha, \
3329 _IDX_, idx, _VAL_, cell, _EXISTS))
3330
3340#define DT_PHA_HAS_CELL(node_id, pha, cell) \
3341 DT_PHA_HAS_CELL_AT_IDX(node_id, pha, 0, cell)
3342
3384#define DT_BUS(node_id) DT_CAT(node_id, _BUS)
3385
3414#define DT_ON_BUS(node_id, bus) IS_ENABLED(DT_CAT3(node_id, _BUS_, bus))
3415
3432#define DT_DRV_INST(inst) DT_INST(inst, DT_DRV_COMPAT)
3433
3441#define DT_INST_PARENT(inst) DT_PARENT(DT_DRV_INST(inst))
3442
3450#define DT_INST_GPARENT(inst) DT_GPARENT(DT_DRV_INST(inst))
3451
3461#define DT_INST_CHILD(inst, child) \
3462 DT_CHILD(DT_DRV_INST(inst), child)
3463
3473#define DT_INST_CHILD_NUM(inst) DT_CHILD_NUM(DT_DRV_INST(inst))
3474
3484#define DT_INST_CHILD_NUM_STATUS_OKAY(inst) \
3485 DT_CHILD_NUM_STATUS_OKAY(DT_DRV_INST(inst))
3486
3501#define DT_INST_FOREACH_CHILD(inst, fn) \
3502 DT_FOREACH_CHILD(DT_DRV_INST(inst), fn)
3503
3517#define DT_INST_FOREACH_CHILD_SEP(inst, fn, sep) \
3518 DT_FOREACH_CHILD_SEP(DT_DRV_INST(inst), fn, sep)
3519
3535#define DT_INST_FOREACH_CHILD_VARGS(inst, fn, ...) \
3536 DT_FOREACH_CHILD_VARGS(DT_DRV_INST(inst), fn, __VA_ARGS__)
3537
3552#define DT_INST_FOREACH_CHILD_SEP_VARGS(inst, fn, sep, ...) \
3553 DT_FOREACH_CHILD_SEP_VARGS(DT_DRV_INST(inst), fn, sep, __VA_ARGS__)
3554
3566#define DT_INST_FOREACH_CHILD_STATUS_OKAY(inst, fn) \
3567 DT_FOREACH_CHILD_STATUS_OKAY(DT_DRV_INST(inst), fn)
3568
3583#define DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(inst, fn, sep) \
3584 DT_FOREACH_CHILD_STATUS_OKAY_SEP(DT_DRV_INST(inst), fn, sep)
3585
3599#define DT_INST_FOREACH_CHILD_STATUS_OKAY_VARGS(inst, fn, ...) \
3600 DT_FOREACH_CHILD_STATUS_OKAY_VARGS(DT_DRV_INST(inst), fn, __VA_ARGS__)
3601
3617#define DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP_VARGS(inst, fn, sep, ...) \
3618 DT_FOREACH_CHILD_STATUS_OKAY_SEP_VARGS(DT_DRV_INST(inst), fn, sep, __VA_ARGS__)
3619
3626#define DT_INST_ENUM_IDX(inst, prop) \
3627 DT_ENUM_IDX(DT_DRV_INST(inst), prop)
3628
3637#define DT_INST_ENUM_IDX_OR(inst, prop, default_idx_value) \
3638 DT_ENUM_IDX_OR(DT_DRV_INST(inst), prop, default_idx_value)
3639
3648#define DT_INST_ENUM_HAS_VALUE(inst, prop, value) \
3649 DT_ENUM_HAS_VALUE(DT_DRV_INST(inst), prop, value)
3650
3657#define DT_INST_PROP(inst, prop) DT_PROP(DT_DRV_INST(inst), prop)
3658
3665#define DT_INST_PROP_LEN(inst, prop) DT_PROP_LEN(DT_DRV_INST(inst), prop)
3666
3676#define DT_INST_PROP_HAS_IDX(inst, prop, idx) \
3677 DT_PROP_HAS_IDX(DT_DRV_INST(inst), prop, idx)
3678
3687#define DT_INST_PROP_HAS_NAME(inst, prop, name) \
3688 DT_PROP_HAS_NAME(DT_DRV_INST(inst), prop, name)
3689
3697#define DT_INST_PROP_BY_IDX(inst, prop, idx) \
3698 DT_PROP_BY_IDX(DT_DRV_INST(inst), prop, idx)
3699
3707#define DT_INST_PROP_OR(inst, prop, default_value) \
3708 DT_PROP_OR(DT_DRV_INST(inst), prop, default_value)
3709
3717#define DT_INST_PROP_LEN_OR(inst, prop, default_value) \
3718 DT_PROP_LEN_OR(DT_DRV_INST(inst), prop, default_value)
3719
3729#define DT_INST_STRING_TOKEN(inst, prop) \
3730 DT_STRING_TOKEN(DT_DRV_INST(inst), prop)
3731
3739#define DT_INST_STRING_UPPER_TOKEN(inst, prop) \
3740 DT_STRING_UPPER_TOKEN(DT_DRV_INST(inst), prop)
3741
3750#define DT_INST_STRING_UNQUOTED(inst, prop) \
3751 DT_STRING_UNQUOTED(DT_DRV_INST(inst), prop)
3752
3760#define DT_INST_STRING_TOKEN_BY_IDX(inst, prop, idx) \
3761 DT_STRING_TOKEN_BY_IDX(DT_DRV_INST(inst), prop, idx)
3762
3770#define DT_INST_STRING_UPPER_TOKEN_BY_IDX(inst, prop, idx) \
3771 DT_STRING_UPPER_TOKEN_BY_IDX(DT_DRV_INST(inst), prop, idx)
3772
3780#define DT_INST_STRING_UNQUOTED_BY_IDX(inst, prop, idx) \
3781 DT_STRING_UNQUOTED_BY_IDX(DT_DRV_INST(inst), prop, idx)
3782
3791#define DT_INST_PROP_BY_PHANDLE(inst, ph, prop) \
3792 DT_INST_PROP_BY_PHANDLE_IDX(inst, ph, 0, prop)
3793
3805#define DT_INST_PROP_BY_PHANDLE_IDX(inst, phs, idx, prop) \
3806 DT_PROP_BY_PHANDLE_IDX(DT_DRV_INST(inst), phs, idx, prop)
3807
3816#define DT_INST_PHA_BY_IDX(inst, pha, idx, cell) \
3817 DT_PHA_BY_IDX(DT_DRV_INST(inst), pha, idx, cell)
3818
3828#define DT_INST_PHA_BY_IDX_OR(inst, pha, idx, cell, default_value) \
3829 DT_PHA_BY_IDX_OR(DT_DRV_INST(inst), pha, idx, cell, default_value)
3830
3839#define DT_INST_PHA(inst, pha, cell) DT_INST_PHA_BY_IDX(inst, pha, 0, cell)
3840
3849#define DT_INST_PHA_OR(inst, pha, cell, default_value) \
3850 DT_INST_PHA_BY_IDX_OR(inst, pha, 0, cell, default_value)
3851
3861#define DT_INST_PHA_BY_NAME(inst, pha, name, cell) \
3862 DT_PHA_BY_NAME(DT_DRV_INST(inst), pha, name, cell)
3863
3873#define DT_INST_PHA_BY_NAME_OR(inst, pha, name, cell, default_value) \
3874 DT_PHA_BY_NAME_OR(DT_DRV_INST(inst), pha, name, cell, default_value)
3875
3884#define DT_INST_PHANDLE_BY_NAME(inst, pha, name) \
3885 DT_PHANDLE_BY_NAME(DT_DRV_INST(inst), pha, name) \
3886
3896#define DT_INST_PHANDLE_BY_IDX(inst, prop, idx) \
3897 DT_PHANDLE_BY_IDX(DT_DRV_INST(inst), prop, idx)
3898
3907#define DT_INST_PHANDLE(inst, prop) DT_INST_PHANDLE_BY_IDX(inst, prop, 0)
3908
3916#define DT_INST_REG_HAS_IDX(inst, idx) DT_REG_HAS_IDX(DT_DRV_INST(inst), idx)
3917
3924#define DT_INST_REG_ADDR_BY_IDX(inst, idx) DT_REG_ADDR_BY_IDX(DT_DRV_INST(inst), idx)
3925
3932#define DT_INST_REG_SIZE_BY_IDX(inst, idx) \
3933 DT_REG_SIZE_BY_IDX(DT_DRV_INST(inst), idx)
3934
3941#define DT_INST_REG_ADDR_BY_NAME(inst, name) \
3942 DT_REG_ADDR_BY_NAME(DT_DRV_INST(inst), name)
3943
3956#define DT_INST_REG_ADDR_BY_NAME_U64(inst, name) \
3957 DT_U64_C(DT_INST_REG_ADDR_BY_NAME(inst, name))
3958
3965#define DT_INST_REG_SIZE_BY_NAME(inst, name) \
3966 DT_REG_SIZE_BY_NAME(DT_DRV_INST(inst), name)
3967
3973#define DT_INST_REG_ADDR(inst) DT_INST_REG_ADDR_BY_IDX(inst, 0)
3974
3986#define DT_INST_REG_ADDR_U64(inst) DT_U64_C(DT_INST_REG_ADDR(inst))
3987
3993#define DT_INST_REG_SIZE(inst) DT_INST_REG_SIZE_BY_IDX(inst, 0)
3994
4001#define DT_INST_IRQ_LEVEL(inst) DT_IRQ_LEVEL(DT_DRV_INST(inst))
4002
4010#define DT_INST_IRQ_BY_IDX(inst, idx, cell) \
4011 DT_IRQ_BY_IDX(DT_DRV_INST(inst), idx, cell)
4012
4019#define DT_INST_IRQ_INTC_BY_IDX(inst, idx) \
4020 DT_IRQ_INTC_BY_IDX(DT_DRV_INST(inst), idx)
4021
4028#define DT_INST_IRQ_INTC_BY_NAME(inst, name) \
4029 DT_IRQ_INTC_BY_NAME(DT_DRV_INST(inst), name)
4030
4038#define DT_INST_IRQ_INTC(inst) \
4039 DT_INST_IRQ_INTC_BY_IDX(inst, 0)
4040
4048#define DT_INST_IRQ_BY_NAME(inst, name, cell) \
4049 DT_IRQ_BY_NAME(DT_DRV_INST(inst), name, cell)
4050
4057#define DT_INST_IRQ(inst, cell) DT_INST_IRQ_BY_IDX(inst, 0, cell)
4058
4064#define DT_INST_IRQN(inst) DT_IRQN(DT_DRV_INST(inst))
4065
4072#define DT_INST_IRQN_BY_IDX(inst, idx) DT_IRQN_BY_IDX(DT_DRV_INST(inst), idx)
4073
4079#define DT_INST_BUS(inst) DT_BUS(DT_DRV_INST(inst))
4080
4088#define DT_INST_ON_BUS(inst, bus) DT_ON_BUS(DT_DRV_INST(inst), bus)
4089
4099#define DT_INST_STRING_TOKEN_OR(inst, name, default_value) \
4100 DT_STRING_TOKEN_OR(DT_DRV_INST(inst), name, default_value)
4101
4110#define DT_INST_STRING_UPPER_TOKEN_OR(inst, name, default_value) \
4111 DT_STRING_UPPER_TOKEN_OR(DT_DRV_INST(inst), name, default_value)
4112
4121#define DT_INST_STRING_UNQUOTED_OR(inst, name, default_value) \
4122 DT_STRING_UNQUOTED_OR(DT_DRV_INST(inst), name, default_value)
4123
4124/*
4125 * @brief Test if any enabled node with the given compatible is on
4126 * the given bus type
4127 *
4128 * This is like DT_ANY_INST_ON_BUS_STATUS_OKAY(), except it can also
4129 * be useful for handling multiple compatibles in single source file.
4130 *
4131 * Example devicetree overlay:
4132 *
4133 * @code{.dts}
4134 * &i2c0 {
4135 * temp: temperature-sensor@76 {
4136 * compatible = "vnd,some-sensor";
4137 * reg = <0x76>;
4138 * };
4139 * };
4140 * @endcode
4141 *
4142 * Example usage, assuming `i2c0` is an I2C bus controller node, and
4143 * therefore `temp` is on an I2C bus:
4144 *
4145 * @code{.c}
4146 * DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(vnd_some_sensor, i2c) // 1
4147 * @endcode
4148 *
4149 * @param compat lowercase-and-underscores compatible, without quotes
4150 * @param bus a binding's bus type as a C token, lowercased and without quotes
4151 * @return 1 if any enabled node with that compatible is on that bus type,
4152 * 0 otherwise
4153 */
4154#define DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(compat, bus) \
4155 IS_ENABLED(DT_CAT4(DT_COMPAT_, compat, _BUS_, bus))
4156
4189#define DT_ANY_INST_ON_BUS_STATUS_OKAY(bus) \
4190 DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(DT_DRV_COMPAT, bus)
4191
4236#define DT_ANY_INST_HAS_PROP_STATUS_OKAY(prop) \
4237 COND_CODE_1(IS_EMPTY(DT_ANY_INST_HAS_PROP_STATUS_OKAY_(prop)), (0), (1))
4238
4304#define DT_INST_FOREACH_STATUS_OKAY(fn) \
4305 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \
4306 (UTIL_CAT(DT_FOREACH_OKAY_INST_, \
4307 DT_DRV_COMPAT)(fn)), \
4308 ())
4309
4321#define DT_INST_FOREACH_STATUS_OKAY_VARGS(fn, ...) \
4322 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \
4323 (UTIL_CAT(DT_FOREACH_OKAY_INST_VARGS_, \
4324 DT_DRV_COMPAT)(fn, __VA_ARGS__)), \
4325 ())
4326
4337#define DT_INST_FOREACH_PROP_ELEM(inst, prop, fn) \
4338 DT_FOREACH_PROP_ELEM(DT_DRV_INST(inst), prop, fn)
4339
4352#define DT_INST_FOREACH_PROP_ELEM_SEP(inst, prop, fn, sep) \
4353 DT_FOREACH_PROP_ELEM_SEP(DT_DRV_INST(inst), prop, fn, sep)
4354
4369#define DT_INST_FOREACH_PROP_ELEM_VARGS(inst, prop, fn, ...) \
4370 DT_FOREACH_PROP_ELEM_VARGS(DT_DRV_INST(inst), prop, fn, __VA_ARGS__)
4371
4389#define DT_INST_FOREACH_PROP_ELEM_SEP_VARGS(inst, prop, fn, sep, ...) \
4390 DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_DRV_INST(inst), prop, fn, sep, \
4391 __VA_ARGS__)
4392
4399#define DT_INST_NODE_HAS_PROP(inst, prop) \
4400 DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop)
4401
4408#define DT_INST_NODE_HAS_COMPAT(inst, compat) \
4409 DT_NODE_HAS_COMPAT(DT_DRV_INST(inst), compat)
4410
4421#define DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, idx, cell) \
4422 DT_PHA_HAS_CELL_AT_IDX(DT_DRV_INST(inst), pha, idx, cell)
4423
4433#define DT_INST_PHA_HAS_CELL(inst, pha, cell) \
4434 DT_INST_PHA_HAS_CELL_AT_IDX(inst, pha, 0, cell)
4435
4443#define DT_INST_IRQ_HAS_IDX(inst, idx) DT_IRQ_HAS_IDX(DT_DRV_INST(inst), idx)
4444
4453#define DT_INST_IRQ_HAS_CELL_AT_IDX(inst, idx, cell) \
4454 DT_IRQ_HAS_CELL_AT_IDX(DT_DRV_INST(inst), idx, cell)
4455
4463#define DT_INST_IRQ_HAS_CELL(inst, cell) \
4464 DT_INST_IRQ_HAS_CELL_AT_IDX(inst, 0, cell)
4465
4472#define DT_INST_IRQ_HAS_NAME(inst, name) \
4473 DT_IRQ_HAS_NAME(DT_DRV_INST(inst), name)
4474
4492#define DT_ANY_INST_HAS_PROP_STATUS_OKAY__(idx, prop) \
4493 COND_CODE_1(DT_INST_NODE_HAS_PROP(idx, prop), (1,), ())
4506#define DT_ANY_INST_HAS_PROP_STATUS_OKAY_(prop) \
4507 DT_INST_FOREACH_STATUS_OKAY_VARGS(DT_ANY_INST_HAS_PROP_STATUS_OKAY__, prop)
4508
4509#define DT_PATH_INTERNAL(...) \
4510 UTIL_CAT(DT_ROOT, MACRO_MAP_CAT(DT_S_PREFIX, __VA_ARGS__))
4516#define DT_S_PREFIX(name) _S_##name
4517
4532#define DT_CAT(a1, a2) a1 ## a2
4534#define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
4536#define DT_CAT4(a1, a2, a3, a4) a1 ## a2 ## a3 ## a4
4538#define DT_CAT5(a1, a2, a3, a4, a5) a1 ## a2 ## a3 ## a4 ## a5
4540#define DT_CAT6(a1, a2, a3, a4, a5, a6) a1 ## a2 ## a3 ## a4 ## a5 ## a6
4542#define DT_CAT7(a1, a2, a3, a4, a5, a6, a7) \
4543 a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7
4545#define DT_CAT8(a1, a2, a3, a4, a5, a6, a7, a8) \
4546 a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7 ## a8
4547/*
4548 * If you need to define a bigger DT_CATN(), do so here. Don't leave
4549 * any "holes" of undefined macros, please.
4550 */
4551
4553#define DT_DASH(...) MACRO_MAP_CAT(DT_DASH_PREFIX, __VA_ARGS__)
4555#define DT_DASH_PREFIX(name) _##name
4557#define DT_NODE_HAS_STATUS_INTERNAL(node_id, status) \
4558 IS_ENABLED(DT_CAT3(node_id, _STATUS_, status))
4559
4561#define DT_INST_NODE_HAS_PROP_AND_OR(inst, prop) \
4562 DT_INST_NODE_HAS_PROP(inst, prop) ||
4563
4568#if defined(_LINKER) || defined(_ASMLANGUAGE)
4569#define DT_U64_C(_v) (_v)
4570#else
4571#define DT_U64_C(_v) UINT64_C(_v)
4572#endif
4573
4576/* have these last so they have access to all previously defined macros */
4579#include <zephyr/devicetree/gpio.h>
4580#include <zephyr/devicetree/spi.h>
4581#include <zephyr/devicetree/dma.h>
4582#include <zephyr/devicetree/pwms.h>
4586#include <zephyr/devicetree/can.h>
4588#include <zephyr/devicetree/mbox.h>
4589
4590#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.