Line data Source code
1 1 : /**
2 : * @file
3 : * @brief DMA Devicetree macro public API header file.
4 : */
5 :
6 : /*
7 : * Copyright (c) 2020, Linaro Ltd.
8 : *
9 : * SPDX-License-Identifier: Apache-2.0
10 : */
11 :
12 : #ifndef ZEPHYR_INCLUDE_DEVICETREE_DMAS_H_
13 : #define ZEPHYR_INCLUDE_DEVICETREE_DMAS_H_
14 :
15 : #ifdef __cplusplus
16 : extern "C" {
17 : #endif
18 :
19 : /**
20 : * @defgroup devicetree-dmas Devicetree DMA API
21 : * @ingroup devicetree
22 : * @{
23 : */
24 :
25 : /**
26 : * @brief Get the node identifier for the DMA controller from a
27 : * dmas property at an index
28 : *
29 : * Example devicetree fragment:
30 : *
31 : * dma1: dma@... { ... };
32 : *
33 : * dma2: dma@... { ... };
34 : *
35 : * n: node {
36 : * dmas = <&dma1 1 2 0x400 0x3>,
37 : * <&dma2 6 3 0x404 0x5>;
38 : * };
39 : *
40 : * Example usage:
41 : *
42 : * DT_DMAS_CTLR_BY_IDX(DT_NODELABEL(n), 0) // DT_NODELABEL(dma1)
43 : * DT_DMAS_CTLR_BY_IDX(DT_NODELABEL(n), 1) // DT_NODELABEL(dma2)
44 : *
45 : * @param node_id node identifier for a node with a dmas property
46 : * @param idx logical index into dmas property
47 : * @return the node identifier for the DMA controller referenced at
48 : * index "idx"
49 : * @see DT_PROP_BY_PHANDLE_IDX()
50 : */
51 1 : #define DT_DMAS_CTLR_BY_IDX(node_id, idx) DT_PHANDLE_BY_IDX(node_id, dmas, idx)
52 :
53 : /**
54 : * @brief Get the node identifier for the DMA controller from a
55 : * dmas property by name
56 : *
57 : * Example devicetree fragment:
58 : *
59 : * dma1: dma@... { ... };
60 : *
61 : * dma2: dma@... { ... };
62 : *
63 : * n: node {
64 : * dmas = <&dma1 1 2 0x400 0x3>,
65 : * <&dma2 6 3 0x404 0x5>;
66 : * dma-names = "tx", "rx";
67 : * };
68 : *
69 : * Example usage:
70 : *
71 : * DT_DMAS_CTLR_BY_NAME(DT_NODELABEL(n), tx) // DT_NODELABEL(dma1)
72 : * DT_DMAS_CTLR_BY_NAME(DT_NODELABEL(n), rx) // DT_NODELABEL(dma2)
73 : *
74 : * @param node_id node identifier for a node with a dmas property
75 : * @param name lowercase-and-underscores name of a dmas element
76 : * as defined by the node's dma-names property
77 : * @return the node identifier for the DMA controller in the named element
78 : * @see DT_PHANDLE_BY_NAME()
79 : */
80 1 : #define DT_DMAS_CTLR_BY_NAME(node_id, name) \
81 : DT_PHANDLE_BY_NAME(node_id, dmas, name)
82 :
83 : /**
84 : * @brief Equivalent to DT_DMAS_CTLR_BY_IDX(node_id, 0)
85 : * @param node_id node identifier for a node with a dmas property
86 : * @return the node identifier for the DMA controller at index 0
87 : * in the node's "dmas" property
88 : * @see DT_DMAS_CTLR_BY_IDX()
89 : */
90 1 : #define DT_DMAS_CTLR(node_id) DT_DMAS_CTLR_BY_IDX(node_id, 0)
91 :
92 : /**
93 : * @brief Get the node identifier for the DMA controller from a
94 : * DT_DRV_COMPAT instance's dmas property at an index
95 : *
96 : * @param inst DT_DRV_COMPAT instance number
97 : * @param idx logical index into dmas property
98 : * @return the node identifier for the DMA controller referenced at
99 : * index "idx"
100 : * @see DT_DMAS_CTLR_BY_IDX()
101 : */
102 1 : #define DT_INST_DMAS_CTLR_BY_IDX(inst, idx) \
103 : DT_DMAS_CTLR_BY_IDX(DT_DRV_INST(inst), idx)
104 :
105 : /**
106 : * @brief Get the node identifier for the DMA controller from a
107 : * DT_DRV_COMPAT instance's dmas property by name
108 : * @param inst DT_DRV_COMPAT instance number
109 : * @param name lowercase-and-underscores name of a dmas element
110 : * as defined by the node's dma-names property
111 : * @return the node identifier for the DMA controller in the named element
112 : * @see DT_DMAS_CTLR_BY_NAME()
113 : */
114 1 : #define DT_INST_DMAS_CTLR_BY_NAME(inst, name) \
115 : DT_DMAS_CTLR_BY_NAME(DT_DRV_INST(inst), name)
116 :
117 : /**
118 : * @brief Equivalent to DT_INST_DMAS_CTLR_BY_IDX(inst, 0)
119 : * @param inst DT_DRV_COMPAT instance number
120 : * @return the node identifier for the DMA controller at index 0
121 : * in the instance's "dmas" property
122 : * @see DT_DMAS_CTLR_BY_IDX()
123 : */
124 1 : #define DT_INST_DMAS_CTLR(inst) DT_INST_DMAS_CTLR_BY_IDX(inst, 0)
125 :
126 : /**
127 : * @brief Get a DMA specifier's cell value at an index
128 : *
129 : * Example devicetree fragment:
130 : *
131 : * dma1: dma@... {
132 : * compatible = "vnd,dma";
133 : * #dma-cells = <2>;
134 : * };
135 : *
136 : * dma2: dma@... {
137 : * compatible = "vnd,dma";
138 : * #dma-cells = <2>;
139 : * };
140 : *
141 : * n: node {
142 : * dmas = <&dma1 1 0x400>,
143 : * <&dma2 6 0x404>;
144 : * };
145 : *
146 : * Bindings fragment for the vnd,dma compatible:
147 : *
148 : * dma-cells:
149 : * - channel
150 : * - config
151 : *
152 : * Example usage:
153 : *
154 : * DT_DMAS_CELL_BY_IDX(DT_NODELABEL(n), 0, channel) // 1
155 : * DT_DMAS_CELL_BY_IDX(DT_NODELABEL(n), 1, channel) // 6
156 : * DT_DMAS_CELL_BY_IDX(DT_NODELABEL(n), 0, config) // 0x400
157 : * DT_DMAS_CELL_BY_IDX(DT_NODELABEL(n), 1, config) // 0x404
158 : *
159 : * @param node_id node identifier for a node with a dmas property
160 : * @param idx logical index into dmas property
161 : * @param cell lowercase-and-underscores cell name
162 : * @return the cell value at index "idx"
163 : * @see DT_PHA_BY_IDX()
164 : */
165 1 : #define DT_DMAS_CELL_BY_IDX(node_id, idx, cell) \
166 : DT_PHA_BY_IDX(node_id, dmas, idx, cell)
167 :
168 : /**
169 : * @brief Get a DT_DRV_COMPAT instance's DMA specifier's cell value at an index
170 : * @param inst DT_DRV_COMPAT instance number
171 : * @param idx logical index into dmas property
172 : * @param cell lowercase-and-underscores cell name
173 : * @return the cell value at index "idx"
174 : * @see DT_DMAS_CELL_BY_IDX()
175 : */
176 1 : #define DT_INST_DMAS_CELL_BY_IDX(inst, idx, cell) \
177 : DT_PHA_BY_IDX(DT_DRV_INST(inst), dmas, idx, cell)
178 :
179 : /**
180 : * @brief Get a DMA specifier's cell value by name
181 : *
182 : * Example devicetree fragment:
183 : *
184 : * dma1: dma@... {
185 : * compatible = "vnd,dma";
186 : * #dma-cells = <2>;
187 : * };
188 : *
189 : * dma2: dma@... {
190 : * compatible = "vnd,dma";
191 : * #dma-cells = <2>;
192 : * };
193 : *
194 : * n: node {
195 : * dmas = <&dma1 1 0x400>,
196 : * <&dma2 6 0x404>;
197 : * dma-names = "tx", "rx";
198 : * };
199 : *
200 : * Bindings fragment for the vnd,dma compatible:
201 : *
202 : * dma-cells:
203 : * - channel
204 : * - config
205 : *
206 : * Example usage:
207 : *
208 : * DT_DMAS_CELL_BY_NAME(DT_NODELABEL(n), tx, channel) // 1
209 : * DT_DMAS_CELL_BY_NAME(DT_NODELABEL(n), rx, channel) // 6
210 : * DT_DMAS_CELL_BY_NAME(DT_NODELABEL(n), tx, config) // 0x400
211 : * DT_DMAS_CELL_BY_NAME(DT_NODELABEL(n), rx, config) // 0x404
212 : *
213 : * @param node_id node identifier for a node with a dmas property
214 : * @param name lowercase-and-underscores name of a dmas element
215 : * as defined by the node's dma-names property
216 : * @param cell lowercase-and-underscores cell name
217 : * @return the cell value in the specifier at the named element
218 : * @see DT_PHA_BY_NAME()
219 : */
220 1 : #define DT_DMAS_CELL_BY_NAME(node_id, name, cell) \
221 : DT_PHA_BY_NAME(node_id, dmas, name, cell)
222 :
223 : /**
224 : * @brief Like DT_DMAS_CELL_BY_NAME(), but with a fallback to @p default_value
225 : *
226 : * If the value exists, this expands to DT_DMAS_CELL_BY_NAME(node_id,
227 : * name, cell). The @p default_value parameter is not expanded in this case.
228 : *
229 : * Otherwise, this expands to @p default_value.
230 : *
231 : * @param node_id node identifier for a node with a dmas property
232 : * @param name lowercase-and-underscores name of a dmas element
233 : * as defined by the node's dma-names property
234 : * @param cell lowercase-and-underscores cell name
235 : * @param default_value a fallback value to expand to
236 : * @return the cell's value or @p default_value
237 : * @see DT_PHA_BY_NAME_OR()
238 : */
239 1 : #define DT_DMAS_CELL_BY_NAME_OR(node_id, name, cell, default_value) \
240 : DT_PHA_BY_NAME_OR(node_id, dmas, name, cell, default_value)
241 :
242 : /**
243 : * @brief Get a DT_DRV_COMPAT instance's DMA specifier's cell value by name
244 : * @param inst DT_DRV_COMPAT instance number
245 : * @param name lowercase-and-underscores name of a dmas element
246 : * as defined by the node's dma-names property
247 : * @param cell lowercase-and-underscores cell name
248 : * @return the cell value in the specifier at the named element
249 : * @see DT_DMAS_CELL_BY_NAME()
250 : */
251 1 : #define DT_INST_DMAS_CELL_BY_NAME(inst, name, cell) \
252 : DT_DMAS_CELL_BY_NAME(DT_DRV_INST(inst), name, cell)
253 :
254 : /**
255 : * @brief Is index "idx" valid for a dmas property?
256 : * @param node_id node identifier for a node with a dmas property
257 : * @param idx logical index into dmas property
258 : * @return 1 if the "dmas" property has index "idx", 0 otherwise
259 : */
260 1 : #define DT_DMAS_HAS_IDX(node_id, idx) \
261 : IS_ENABLED(DT_CAT4(node_id, _P_dmas_IDX_, idx, _EXISTS))
262 :
263 : /**
264 : * @brief Is index "idx" valid for a DT_DRV_COMPAT instance's dmas property?
265 : * @param inst DT_DRV_COMPAT instance number
266 : * @param idx logical index into dmas property
267 : * @return 1 if the "dmas" property has a specifier at index "idx", 0 otherwise
268 : */
269 1 : #define DT_INST_DMAS_HAS_IDX(inst, idx) \
270 : DT_DMAS_HAS_IDX(DT_DRV_INST(inst), idx)
271 :
272 : /**
273 : * @brief Does a dmas property have a named element?
274 : * @param node_id node identifier for a node with a dmas property
275 : * @param name lowercase-and-underscores name of a dmas element
276 : * as defined by the node's dma-names property
277 : * @return 1 if the dmas property has the named element, 0 otherwise
278 : */
279 1 : #define DT_DMAS_HAS_NAME(node_id, name) \
280 : DT_PROP_HAS_NAME(node_id, dmas, name)
281 :
282 : /**
283 : * @brief Does a DT_DRV_COMPAT instance's dmas property have a named element?
284 : * @param inst DT_DRV_COMPAT instance number
285 : * @param name lowercase-and-underscores name of a dmas element
286 : * as defined by the node's dma-names property
287 : * @return 1 if the dmas property has the named element, 0 otherwise
288 : */
289 1 : #define DT_INST_DMAS_HAS_NAME(inst, name) \
290 : DT_DMAS_HAS_NAME(DT_DRV_INST(inst), name)
291 :
292 : /**
293 : * @}
294 : */
295 :
296 : #ifdef __cplusplus
297 : }
298 : #endif
299 :
300 : #endif /* ZEPHYR_INCLUDE_DEVICETREE_DMAS_H_ */
|