Line data Source code
1 1 : /**
2 : * @file
3 : * @brief Reset Controller Devicetree macro public API header file.
4 : */
5 :
6 : /*
7 : * Copyright (c) 2022, Andrei-Edward Popa
8 : *
9 : * SPDX-License-Identifier: Apache-2.0
10 : */
11 :
12 : #ifndef ZEPHYR_INCLUDE_DEVICETREE_RESET_H_
13 : #define ZEPHYR_INCLUDE_DEVICETREE_RESET_H_
14 :
15 : #ifdef __cplusplus
16 : extern "C" {
17 : #endif
18 :
19 : /**
20 : * @defgroup devicetree-reset-controller Devicetree Reset Controller API
21 : * @ingroup devicetree
22 : * @ingroup reset_controller_interface
23 : * @{
24 : */
25 :
26 : /**
27 : * @brief Get the node identifier for the controller phandle from a
28 : * "resets" phandle-array property at an index
29 : *
30 : * Example devicetree fragment:
31 : *
32 : * reset1: reset-controller@... { ... };
33 : *
34 : * reset2: reset-controller@... { ... };
35 : *
36 : * n: node {
37 : * resets = <&reset1 10>, <&reset2 20>;
38 : * };
39 : *
40 : * Example usage:
41 : *
42 : * DT_RESET_CTLR_BY_IDX(DT_NODELABEL(n), 0)) // DT_NODELABEL(reset1)
43 : * DT_RESET_CTLR_BY_IDX(DT_NODELABEL(n), 1)) // DT_NODELABEL(reset2)
44 : *
45 : * @param node_id node identifier
46 : * @param idx logical index into "resets"
47 : * @return the node identifier for the reset controller referenced at
48 : * index "idx"
49 : * @see DT_PHANDLE_BY_IDX()
50 : */
51 1 : #define DT_RESET_CTLR_BY_IDX(node_id, idx) \
52 : DT_PHANDLE_BY_IDX(node_id, resets, idx)
53 :
54 : /**
55 : * @brief Equivalent to DT_RESET_CTLR_BY_IDX(node_id, 0)
56 : * @param node_id node identifier
57 : * @return a node identifier for the reset controller at index 0
58 : * in "resets"
59 : * @see DT_RESET_CTLR_BY_IDX()
60 : */
61 1 : #define DT_RESET_CTLR(node_id) \
62 : DT_RESET_CTLR_BY_IDX(node_id, 0)
63 :
64 : /**
65 : * @brief Get the node identifier for the controller phandle from a
66 : * resets phandle-array property by name
67 : *
68 : * Example devicetree fragment:
69 : *
70 : * reset1: reset-controller@... { ... };
71 : *
72 : * reset2: reset-controller@... { ... };
73 : *
74 : * n: node {
75 : * resets = <&reset1 10>, <&reset2 20>;
76 : * reset-names = "alpha", "beta";
77 : * };
78 : *
79 : * Example usage:
80 : *
81 : * DT_RESET_CTLR_BY_NAME(DT_NODELABEL(n), alpha) // DT_NODELABEL(reset1)
82 : * DT_RESET_CTLR_BY_NAME(DT_NODELABEL(n), beta) // DT_NODELABEL(reset2)
83 : *
84 : * @param node_id node identifier
85 : * @param name lowercase-and-underscores name of a resets element
86 : * as defined by the node's reset-names property
87 : * @return the node identifier for the reset controller referenced by name
88 : * @see DT_PHANDLE_BY_NAME()
89 : */
90 1 : #define DT_RESET_CTLR_BY_NAME(node_id, name) \
91 : DT_PHANDLE_BY_NAME(node_id, resets, name)
92 :
93 : /**
94 : * @brief Get a reset specifier's cell value at an index
95 : *
96 : * Example devicetree fragment:
97 : *
98 : * reset: reset-controller@... {
99 : * compatible = "vnd,reset";
100 : * #reset-cells = <1>;
101 : * };
102 : *
103 : * n: node {
104 : * resets = <&reset 10>;
105 : * };
106 : *
107 : * Bindings fragment for the vnd,reset compatible:
108 : *
109 : * reset-cells:
110 : * - id
111 : *
112 : * Example usage:
113 : *
114 : * DT_RESET_CELL_BY_IDX(DT_NODELABEL(n), 0, id) // 10
115 : *
116 : * @param node_id node identifier for a node with a resets property
117 : * @param idx logical index into resets property
118 : * @param cell lowercase-and-underscores cell name
119 : * @return the cell value at index "idx"
120 : * @see DT_PHA_BY_IDX()
121 : */
122 1 : #define DT_RESET_CELL_BY_IDX(node_id, idx, cell) \
123 : DT_PHA_BY_IDX(node_id, resets, idx, cell)
124 :
125 : /**
126 : * @brief Get a reset specifier's cell value by name
127 : *
128 : * Example devicetree fragment:
129 : *
130 : * reset: reset-controller@... {
131 : * compatible = "vnd,reset";
132 : * #reset-cells = <1>;
133 : * };
134 : *
135 : * n: node {
136 : * resets = <&reset 10>;
137 : * reset-names = "alpha";
138 : * };
139 : *
140 : * Bindings fragment for the vnd,reset compatible:
141 : *
142 : * reset-cells:
143 : * - id
144 : *
145 : * Example usage:
146 : *
147 : * DT_RESET_CELL_BY_NAME(DT_NODELABEL(n), alpha, id) // 10
148 : *
149 : * @param node_id node identifier for a node with a resets property
150 : * @param name lowercase-and-underscores name of a resets element
151 : * as defined by the node's reset-names property
152 : * @param cell lowercase-and-underscores cell name
153 : * @return the cell value in the specifier at the named element
154 : * @see DT_PHA_BY_NAME()
155 : */
156 1 : #define DT_RESET_CELL_BY_NAME(node_id, name, cell) \
157 : DT_PHA_BY_NAME(node_id, resets, name, cell)
158 :
159 : /**
160 : * @brief Equivalent to DT_RESET_CELL_BY_IDX(node_id, 0, cell)
161 : * @param node_id node identifier for a node with a resets property
162 : * @param cell lowercase-and-underscores cell name
163 : * @return the cell value at index 0
164 : * @see DT_RESET_CELL_BY_IDX()
165 : */
166 1 : #define DT_RESET_CELL(node_id, cell) \
167 : DT_RESET_CELL_BY_IDX(node_id, 0, cell)
168 :
169 : /**
170 : * @brief Get the node identifier for the controller phandle from a
171 : * "resets" phandle-array property at an index
172 : *
173 : * @param inst instance number
174 : * @param idx logical index into "resets"
175 : * @return the node identifier for the reset controller referenced at
176 : * index "idx"
177 : * @see DT_RESET_CTLR_BY_IDX()
178 : */
179 1 : #define DT_INST_RESET_CTLR_BY_IDX(inst, idx) \
180 : DT_RESET_CTLR_BY_IDX(DT_DRV_INST(inst), idx)
181 :
182 : /**
183 : * @brief Equivalent to DT_INST_RESET_CTLR_BY_IDX(inst, 0)
184 : * @param inst instance number
185 : * @return a node identifier for the reset controller at index 0
186 : * in "resets"
187 : * @see DT_RESET_CTLR()
188 : */
189 1 : #define DT_INST_RESET_CTLR(inst) \
190 : DT_INST_RESET_CTLR_BY_IDX(inst, 0)
191 :
192 : /**
193 : * @brief Get the node identifier for the controller phandle from a
194 : * resets phandle-array property by name
195 : *
196 : * @param inst instance number
197 : * @param name lowercase-and-underscores name of a resets element
198 : * as defined by the node's reset-names property
199 : * @return the node identifier for the reset controller referenced by
200 : * the named element
201 : * @see DT_RESET_CTLR_BY_NAME()
202 : */
203 1 : #define DT_INST_RESET_CTLR_BY_NAME(inst, name) \
204 : DT_RESET_CTLR_BY_NAME(DT_DRV_INST(inst), name)
205 :
206 : /**
207 : * @brief Get a DT_DRV_COMPAT instance's reset specifier's cell value
208 : * at an index
209 : * @param inst DT_DRV_COMPAT instance number
210 : * @param idx logical index into resets property
211 : * @param cell lowercase-and-underscores cell name
212 : * @return the cell value at index "idx"
213 : * @see DT_RESET_CELL_BY_IDX()
214 : */
215 1 : #define DT_INST_RESET_CELL_BY_IDX(inst, idx, cell) \
216 : DT_RESET_CELL_BY_IDX(DT_DRV_INST(inst), idx, cell)
217 :
218 : /**
219 : * @brief Get a DT_DRV_COMPAT instance's reset specifier's cell value by name
220 : * @param inst DT_DRV_COMPAT instance number
221 : * @param name lowercase-and-underscores name of a resets element
222 : * as defined by the node's reset-names property
223 : * @param cell lowercase-and-underscores cell name
224 : * @return the cell value in the specifier at the named element
225 : * @see DT_RESET_CELL_BY_NAME()
226 : */
227 1 : #define DT_INST_RESET_CELL_BY_NAME(inst, name, cell) \
228 : DT_RESET_CELL_BY_NAME(DT_DRV_INST(inst), name, cell)
229 :
230 : /**
231 : * @brief Equivalent to DT_INST_RESET_CELL_BY_IDX(inst, 0, cell)
232 : * @param inst DT_DRV_COMPAT instance number
233 : * @param cell lowercase-and-underscores cell name
234 : * @return the value of the cell inside the specifier at index 0
235 : */
236 1 : #define DT_INST_RESET_CELL(inst, cell) \
237 : DT_INST_RESET_CELL_BY_IDX(inst, 0, cell)
238 :
239 : /**
240 : * @brief Get a Reset Controller specifier's id cell at an index
241 : *
242 : * This macro only works for Reset Controller specifiers with cells named "id".
243 : * Refer to the node's binding to check if necessary.
244 : *
245 : * Example devicetree fragment:
246 : *
247 : * reset: reset-controller@... {
248 : * compatible = "vnd,reset";
249 : * #reset-cells = <1>;
250 : * };
251 : *
252 : * n: node {
253 : * resets = <&reset 10>;
254 : * };
255 : *
256 : * Bindings fragment for the vnd,reset compatible:
257 : *
258 : * reset-cells:
259 : * - id
260 : *
261 : * Example usage:
262 : *
263 : * DT_RESET_ID_BY_IDX(DT_NODELABEL(n), 0) // 10
264 : *
265 : * @param node_id node identifier
266 : * @param idx logical index into "resets"
267 : * @return the id cell value at index "idx"
268 : * @see DT_PHA_BY_IDX()
269 : */
270 1 : #define DT_RESET_ID_BY_IDX(node_id, idx) \
271 : DT_PHA_BY_IDX(node_id, resets, idx, id)
272 :
273 : /**
274 : * @brief Equivalent to DT_RESET_ID_BY_IDX(node_id, 0)
275 : * @param node_id node identifier
276 : * @return the id cell value at index 0
277 : * @see DT_RESET_ID_BY_IDX()
278 : */
279 1 : #define DT_RESET_ID(node_id) \
280 : DT_RESET_ID_BY_IDX(node_id, 0)
281 :
282 : /**
283 : * @brief Get a DT_DRV_COMPAT instance's Reset Controller specifier's id cell value
284 : * at an index
285 : * @param inst DT_DRV_COMPAT instance number
286 : * @param idx logical index into "resets"
287 : * @return the id cell value at index "idx"
288 : * @see DT_RESET_ID_BY_IDX()
289 : */
290 1 : #define DT_INST_RESET_ID_BY_IDX(inst, idx) \
291 : DT_RESET_ID_BY_IDX(DT_DRV_INST(inst), idx)
292 :
293 : /**
294 : * @brief Equivalent to DT_INST_RESET_ID_BY_IDX(inst, 0)
295 : * @param inst DT_DRV_COMPAT instance number
296 : * @return the id cell value at index 0
297 : * @see DT_INST_RESET_ID_BY_IDX()
298 : */
299 1 : #define DT_INST_RESET_ID(inst) \
300 : DT_INST_RESET_ID_BY_IDX(inst, 0)
301 :
302 : /**
303 : * @}
304 : */
305 :
306 : #ifdef __cplusplus
307 : }
308 : #endif
309 :
310 : #endif /* ZEPHYR_INCLUDE_DEVICETREE_RESET_H_ */
|