Line data Source code
1 1 : /**
2 : * @file
3 : * @brief PWMs 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_PWMS_H_
13 : #define ZEPHYR_INCLUDE_DEVICETREE_PWMS_H_
14 :
15 : #ifdef __cplusplus
16 : extern "C" {
17 : #endif
18 :
19 : /**
20 : * @defgroup devicetree-pwms Devicetree PWMs API
21 : * @ingroup devicetree
22 : * @ingroup pwm_interface
23 : * @{
24 : */
25 :
26 : /**
27 : * @brief Get the node identifier for the PWM controller from a
28 : * pwms property at an index
29 : *
30 : * Example devicetree fragment:
31 : *
32 : * pwm1: pwm-controller@... { ... };
33 : *
34 : * pwm2: pwm-controller@... { ... };
35 : *
36 : * n: node {
37 : * pwms = <&pwm1 1 PWM_POLARITY_NORMAL>,
38 : * <&pwm2 3 PWM_POLARITY_INVERTED>;
39 : * };
40 : *
41 : * Example usage:
42 : *
43 : * DT_PWMS_CTLR_BY_IDX(DT_NODELABEL(n), 0) // DT_NODELABEL(pwm1)
44 : * DT_PWMS_CTLR_BY_IDX(DT_NODELABEL(n), 1) // DT_NODELABEL(pwm2)
45 : *
46 : * @param node_id node identifier for a node with a pwms property
47 : * @param idx logical index into pwms property
48 : * @return the node identifier for the PWM controller referenced at
49 : * index "idx"
50 : * @see DT_PROP_BY_PHANDLE_IDX()
51 : */
52 1 : #define DT_PWMS_CTLR_BY_IDX(node_id, idx) \
53 : DT_PHANDLE_BY_IDX(node_id, pwms, idx)
54 :
55 : /**
56 : * @brief Get the node identifier for the PWM controller from a
57 : * pwms property by name
58 : *
59 : * Example devicetree fragment:
60 : *
61 : * pwm1: pwm-controller@... { ... };
62 : *
63 : * pwm2: pwm-controller@... { ... };
64 : *
65 : * n: node {
66 : * pwms = <&pwm1 1 PWM_POLARITY_NORMAL>,
67 : * <&pwm2 3 PWM_POLARITY_INVERTED>;
68 : * pwm-names = "alpha", "beta";
69 : * };
70 : *
71 : * Example usage:
72 : *
73 : * DT_PWMS_CTLR_BY_NAME(DT_NODELABEL(n), alpha) // DT_NODELABEL(pwm1)
74 : * DT_PWMS_CTLR_BY_NAME(DT_NODELABEL(n), beta) // DT_NODELABEL(pwm2)
75 : *
76 : * @param node_id node identifier for a node with a pwms property
77 : * @param name lowercase-and-underscores name of a pwms element
78 : * as defined by the node's pwm-names property
79 : * @return the node identifier for the PWM controller in the named element
80 : * @see DT_PHANDLE_BY_NAME()
81 : */
82 1 : #define DT_PWMS_CTLR_BY_NAME(node_id, name) \
83 : DT_PHANDLE_BY_NAME(node_id, pwms, name)
84 :
85 : /**
86 : * @brief Equivalent to DT_PWMS_CTLR_BY_IDX(node_id, 0)
87 : * @param node_id node identifier for a node with a pwms property
88 : * @return the node identifier for the PWM controller at index 0
89 : * in the node's "pwms" property
90 : * @see DT_PWMS_CTLR_BY_IDX()
91 : */
92 1 : #define DT_PWMS_CTLR(node_id) DT_PWMS_CTLR_BY_IDX(node_id, 0)
93 :
94 : /**
95 : * @brief Get PWM specifier's cell value at an index
96 : *
97 : * Example devicetree fragment:
98 : *
99 : * pwm1: pwm-controller@... {
100 : * compatible = "vnd,pwm";
101 : * #pwm-cells = <2>;
102 : * };
103 : *
104 : * pwm2: pwm-controller@... {
105 : * compatible = "vnd,pwm";
106 : * #pwm-cells = <2>;
107 : * };
108 : *
109 : * n: node {
110 : * pwms = <&pwm1 1 200000 PWM_POLARITY_NORMAL>,
111 : * <&pwm2 3 100000 PWM_POLARITY_INVERTED>;
112 : * };
113 : *
114 : * Bindings fragment for the "vnd,pwm" compatible:
115 : *
116 : * pwm-cells:
117 : * - channel
118 : * - period
119 : * - flags
120 : *
121 : * Example usage:
122 : *
123 : * DT_PWMS_CELL_BY_IDX(DT_NODELABEL(n), 0, channel) // 1
124 : * DT_PWMS_CELL_BY_IDX(DT_NODELABEL(n), 1, channel) // 3
125 : * DT_PWMS_CELL_BY_IDX(DT_NODELABEL(n), 0, period) // 200000
126 : * DT_PWMS_CELL_BY_IDX(DT_NODELABEL(n), 1, period) // 100000
127 : * DT_PWMS_CELL_BY_IDX(DT_NODELABEL(n), 0, flags) // PWM_POLARITY_NORMAL
128 : * DT_PWMS_CELL_BY_IDX(DT_NODELABEL(n), 1, flags) // PWM_POLARITY_INVERTED
129 : *
130 : * @param node_id node identifier for a node with a pwms property
131 : * @param idx logical index into pwms property
132 : * @param cell lowercase-and-underscores cell name
133 : * @return the cell value at index "idx"
134 : * @see DT_PHA_BY_IDX()
135 : */
136 1 : #define DT_PWMS_CELL_BY_IDX(node_id, idx, cell) \
137 : DT_PHA_BY_IDX(node_id, pwms, idx, cell)
138 :
139 : /**
140 : * @brief Get a PWM specifier's cell value by name
141 : *
142 : * Example devicetree fragment:
143 : *
144 : * pwm1: pwm-controller@... {
145 : * compatible = "vnd,pwm";
146 : * #pwm-cells = <2>;
147 : * };
148 : *
149 : * pwm2: pwm-controller@... {
150 : * compatible = "vnd,pwm";
151 : * #pwm-cells = <2>;
152 : * };
153 : *
154 : * n: node {
155 : * pwms = <&pwm1 1 200000 PWM_POLARITY_NORMAL>,
156 : * <&pwm2 3 100000 PWM_POLARITY_INVERTED>;
157 : * pwm-names = "alpha", "beta";
158 : * };
159 : *
160 : * Bindings fragment for the "vnd,pwm" compatible:
161 : *
162 : * pwm-cells:
163 : * - channel
164 : * - period
165 : * - flags
166 : *
167 : * Example usage:
168 : *
169 : * DT_PWMS_CELL_BY_NAME(DT_NODELABEL(n), alpha, channel) // 1
170 : * DT_PWMS_CELL_BY_NAME(DT_NODELABEL(n), beta, channel) // 3
171 : * DT_PWMS_CELL_BY_NAME(DT_NODELABEL(n), alpha, period) // 200000
172 : * DT_PWMS_CELL_BY_NAME(DT_NODELABEL(n), beta, period) // 100000
173 : * DT_PWMS_CELL_BY_NAME(DT_NODELABEL(n), alpha, flags) // PWM_POLARITY_NORMAL
174 : * DT_PWMS_CELL_BY_NAME(DT_NODELABEL(n), beta, flags) // PWM_POLARITY_INVERTED
175 : *
176 : * @param node_id node identifier for a node with a pwms property
177 : * @param name lowercase-and-underscores name of a pwms element
178 : * as defined by the node's pwm-names property
179 : * @param cell lowercase-and-underscores cell name
180 : * @return the cell value in the specifier at the named element
181 : * @see DT_PHA_BY_NAME()
182 : */
183 1 : #define DT_PWMS_CELL_BY_NAME(node_id, name, cell) \
184 : DT_PHA_BY_NAME(node_id, pwms, name, cell)
185 :
186 : /**
187 : * @brief Equivalent to DT_PWMS_CELL_BY_IDX(node_id, 0, cell)
188 : * @param node_id node identifier for a node with a pwms property
189 : * @param cell lowercase-and-underscores cell name
190 : * @return the cell value at index 0
191 : * @see DT_PWMS_CELL_BY_IDX()
192 : */
193 1 : #define DT_PWMS_CELL(node_id, cell) DT_PWMS_CELL_BY_IDX(node_id, 0, cell)
194 :
195 : /**
196 : * @brief Get a PWM specifier's channel cell value at an index
197 : *
198 : * This macro only works for PWM specifiers with cells named "channel".
199 : * Refer to the node's binding to check if necessary.
200 : *
201 : * This is equivalent to DT_PWMS_CELL_BY_IDX(node_id, idx, channel).
202 : *
203 : * @param node_id node identifier for a node with a pwms property
204 : * @param idx logical index into pwms property
205 : * @return the channel cell value at index "idx"
206 : * @see DT_PWMS_CELL_BY_IDX()
207 : */
208 1 : #define DT_PWMS_CHANNEL_BY_IDX(node_id, idx) \
209 : DT_PWMS_CELL_BY_IDX(node_id, idx, channel)
210 :
211 : /**
212 : * @brief Get a PWM specifier's channel cell value by name
213 : *
214 : * This macro only works for PWM specifiers with cells named "channel".
215 : * Refer to the node's binding to check if necessary.
216 : *
217 : * This is equivalent to DT_PWMS_CELL_BY_NAME(node_id, name, channel).
218 : *
219 : * @param node_id node identifier for a node with a pwms property
220 : * @param name lowercase-and-underscores name of a pwms element
221 : * as defined by the node's pwm-names property
222 : * @return the channel cell value in the specifier at the named element
223 : * @see DT_PWMS_CELL_BY_NAME()
224 : */
225 1 : #define DT_PWMS_CHANNEL_BY_NAME(node_id, name) \
226 : DT_PWMS_CELL_BY_NAME(node_id, name, channel)
227 :
228 : /**
229 : * @brief Equivalent to DT_PWMS_CHANNEL_BY_IDX(node_id, 0)
230 : * @param node_id node identifier for a node with a pwms property
231 : * @return the channel cell value at index 0
232 : * @see DT_PWMS_CHANNEL_BY_IDX()
233 : */
234 1 : #define DT_PWMS_CHANNEL(node_id) DT_PWMS_CHANNEL_BY_IDX(node_id, 0)
235 :
236 : /**
237 : * @brief Get PWM specifier's period cell value at an index
238 : *
239 : * This macro only works for PWM specifiers with cells named "period".
240 : * Refer to the node's binding to check if necessary.
241 : *
242 : * This is equivalent to DT_PWMS_CELL_BY_IDX(node_id, idx, period).
243 : *
244 : * @param node_id node identifier for a node with a pwms property
245 : * @param idx logical index into pwms property
246 : * @return the period cell value at index "idx"
247 : * @see DT_PWMS_CELL_BY_IDX()
248 : */
249 1 : #define DT_PWMS_PERIOD_BY_IDX(node_id, idx) \
250 : DT_PWMS_CELL_BY_IDX(node_id, idx, period)
251 :
252 : /**
253 : * @brief Get a PWM specifier's period cell value by name
254 : *
255 : * This macro only works for PWM specifiers with cells named "period".
256 : * Refer to the node's binding to check if necessary.
257 : *
258 : * This is equivalent to DT_PWMS_CELL_BY_NAME(node_id, name, period).
259 : *
260 : * @param node_id node identifier for a node with a pwms property
261 : * @param name lowercase-and-underscores name of a pwms element
262 : * as defined by the node's pwm-names property
263 : * @return the period cell value in the specifier at the named element
264 : * @see DT_PWMS_CELL_BY_NAME()
265 : */
266 1 : #define DT_PWMS_PERIOD_BY_NAME(node_id, name) \
267 : DT_PWMS_CELL_BY_NAME(node_id, name, period)
268 :
269 : /**
270 : * @brief Equivalent to DT_PWMS_PERIOD_BY_IDX(node_id, 0)
271 : * @param node_id node identifier for a node with a pwms property
272 : * @return the period cell value at index 0
273 : * @see DT_PWMS_PERIOD_BY_IDX()
274 : */
275 1 : #define DT_PWMS_PERIOD(node_id) DT_PWMS_PERIOD_BY_IDX(node_id, 0)
276 :
277 : /**
278 : * @brief Get a PWM specifier's flags cell value at an index
279 : *
280 : * This macro expects PWM specifiers with cells named "flags".
281 : * If there is no "flags" cell in the PWM specifier, zero is returned.
282 : * Refer to the node's binding to check specifier cell names if necessary.
283 : *
284 : * This is equivalent to DT_PWMS_CELL_BY_IDX(node_id, idx, flags).
285 : *
286 : * @param node_id node identifier for a node with a pwms property
287 : * @param idx logical index into pwms property
288 : * @return the flags cell value at index "idx", or zero if there is none
289 : * @see DT_PWMS_CELL_BY_IDX()
290 : */
291 1 : #define DT_PWMS_FLAGS_BY_IDX(node_id, idx) \
292 : DT_PHA_BY_IDX_OR(node_id, pwms, idx, flags, 0)
293 :
294 : /**
295 : * @brief Get a PWM specifier's flags cell value by name
296 : *
297 : * This macro expects PWM specifiers with cells named "flags".
298 : * If there is no "flags" cell in the PWM specifier, zero is returned.
299 : * Refer to the node's binding to check specifier cell names if necessary.
300 : *
301 : * This is equivalent to DT_PWMS_CELL_BY_NAME(node_id, name, flags) if
302 : * there is a flags cell, but expands to zero if there is none.
303 : *
304 : * @param node_id node identifier for a node with a pwms property
305 : * @param name lowercase-and-underscores name of a pwms element
306 : * as defined by the node's pwm-names property
307 : * @return the flags cell value in the specifier at the named element,
308 : * or zero if there is none
309 : * @see DT_PWMS_CELL_BY_NAME()
310 : */
311 1 : #define DT_PWMS_FLAGS_BY_NAME(node_id, name) \
312 : DT_PHA_BY_NAME_OR(node_id, pwms, name, flags, 0)
313 :
314 : /**
315 : * @brief Equivalent to DT_PWMS_FLAGS_BY_IDX(node_id, 0)
316 : * @param node_id node identifier for a node with a pwms property
317 : * @return the flags cell value at index 0, or zero if there is none
318 : * @see DT_PWMS_FLAGS_BY_IDX()
319 : */
320 1 : #define DT_PWMS_FLAGS(node_id) DT_PWMS_FLAGS_BY_IDX(node_id, 0)
321 :
322 : /**
323 : * @brief Get the node identifier for the PWM controller from a
324 : * DT_DRV_COMPAT instance's pwms property at an index
325 : *
326 : * @param inst DT_DRV_COMPAT instance number
327 : * @param idx logical index into pwms property
328 : * @return the node identifier for the PWM controller referenced at
329 : * index "idx"
330 : * @see DT_PWMS_CTLR_BY_IDX()
331 : */
332 1 : #define DT_INST_PWMS_CTLR_BY_IDX(inst, idx) \
333 : DT_PWMS_CTLR_BY_IDX(DT_DRV_INST(inst), idx)
334 :
335 : /**
336 : * @brief Get the node identifier for the PWM controller from a
337 : * DT_DRV_COMPAT instance's pwms property by name
338 : * @param inst DT_DRV_COMPAT instance number
339 : * @param name lowercase-and-underscores name of a pwms element
340 : * as defined by the node's pwm-names property
341 : * @return the node identifier for the PWM controller in the named element
342 : * @see DT_PWMS_CTLR_BY_NAME()
343 : */
344 1 : #define DT_INST_PWMS_CTLR_BY_NAME(inst, name) \
345 : DT_PWMS_CTLR_BY_NAME(DT_DRV_INST(inst), name)
346 :
347 : /**
348 : * @brief Equivalent to DT_INST_PWMS_CTLR_BY_IDX(inst, 0)
349 : * @param inst DT_DRV_COMPAT instance number
350 : * @return the node identifier for the PWM controller at index 0
351 : * in the instance's "pwms" property
352 : * @see DT_PWMS_CTLR_BY_IDX()
353 : */
354 1 : #define DT_INST_PWMS_CTLR(inst) DT_INST_PWMS_CTLR_BY_IDX(inst, 0)
355 :
356 : /**
357 : * @brief Get a DT_DRV_COMPAT instance's PWM specifier's cell value
358 : * at an index
359 : * @param inst DT_DRV_COMPAT instance number
360 : * @param idx logical index into pwms property
361 : * @param cell lowercase-and-underscores cell name
362 : * @return the cell value at index "idx"
363 : */
364 1 : #define DT_INST_PWMS_CELL_BY_IDX(inst, idx, cell) \
365 : DT_PWMS_CELL_BY_IDX(DT_DRV_INST(inst), idx, cell)
366 :
367 : /**
368 : * @brief Get a DT_DRV_COMPAT instance's PWM specifier's cell value by name
369 : * @param inst DT_DRV_COMPAT instance number
370 : * @param name lowercase-and-underscores name of a pwms element
371 : * as defined by the node's pwm-names property
372 : * @param cell lowercase-and-underscores cell name
373 : * @return the cell value in the specifier at the named element
374 : * @see DT_PWMS_CELL_BY_NAME()
375 : */
376 1 : #define DT_INST_PWMS_CELL_BY_NAME(inst, name, cell) \
377 : DT_PWMS_CELL_BY_NAME(DT_DRV_INST(inst), name, cell)
378 :
379 : /**
380 : * @brief Equivalent to DT_INST_PWMS_CELL_BY_IDX(inst, 0, cell)
381 : * @param inst DT_DRV_COMPAT instance number
382 : * @param cell lowercase-and-underscores cell name
383 : * @return the cell value at index 0
384 : */
385 1 : #define DT_INST_PWMS_CELL(inst, cell) \
386 : DT_INST_PWMS_CELL_BY_IDX(inst, 0, cell)
387 :
388 : /**
389 : * @brief Equivalent to DT_INST_PWMS_CELL_BY_IDX(inst, idx, channel)
390 : * @param inst DT_DRV_COMPAT instance number
391 : * @param idx logical index into pwms property
392 : * @return the channel cell value at index "idx"
393 : * @see DT_INST_PWMS_CELL_BY_IDX()
394 : */
395 1 : #define DT_INST_PWMS_CHANNEL_BY_IDX(inst, idx) \
396 : DT_INST_PWMS_CELL_BY_IDX(inst, idx, channel)
397 :
398 : /**
399 : * @brief Equivalent to DT_INST_PWMS_CELL_BY_NAME(inst, name, channel)
400 : * @param inst DT_DRV_COMPAT instance number
401 : * @param name lowercase-and-underscores name of a pwms element
402 : * as defined by the node's pwm-names property
403 : * @return the channel cell value in the specifier at the named element
404 : * @see DT_INST_PWMS_CELL_BY_NAME()
405 : */
406 1 : #define DT_INST_PWMS_CHANNEL_BY_NAME(inst, name) \
407 : DT_INST_PWMS_CELL_BY_NAME(inst, name, channel)
408 :
409 : /**
410 : * @brief Equivalent to DT_INST_PWMS_CHANNEL_BY_IDX(inst, 0)
411 : * @param inst DT_DRV_COMPAT instance number
412 : * @return the channel cell value at index 0
413 : * @see DT_INST_PWMS_CHANNEL_BY_IDX()
414 : */
415 1 : #define DT_INST_PWMS_CHANNEL(inst) DT_INST_PWMS_CHANNEL_BY_IDX(inst, 0)
416 :
417 : /**
418 : * @brief Equivalent to DT_INST_PWMS_CELL_BY_IDX(inst, idx, period)
419 : * @param inst DT_DRV_COMPAT instance number
420 : * @param idx logical index into pwms property
421 : * @return the period cell value at index "idx"
422 : * @see DT_INST_PWMS_CELL_BY_IDX()
423 : */
424 1 : #define DT_INST_PWMS_PERIOD_BY_IDX(inst, idx) \
425 : DT_INST_PWMS_CELL_BY_IDX(inst, idx, period)
426 :
427 : /**
428 : * @brief Equivalent to DT_INST_PWMS_CELL_BY_NAME(inst, name, period)
429 : * @param inst DT_DRV_COMPAT instance number
430 : * @param name lowercase-and-underscores name of a pwms element
431 : * as defined by the node's pwm-names property
432 : * @return the period cell value in the specifier at the named element
433 : * @see DT_INST_PWMS_CELL_BY_NAME()
434 : */
435 1 : #define DT_INST_PWMS_PERIOD_BY_NAME(inst, name) \
436 : DT_INST_PWMS_CELL_BY_NAME(inst, name, period)
437 :
438 : /**
439 : * @brief Equivalent to DT_INST_PWMS_PERIOD_BY_IDX(inst, 0)
440 : * @param inst DT_DRV_COMPAT instance number
441 : * @return the period cell value at index 0
442 : * @see DT_INST_PWMS_PERIOD_BY_IDX()
443 : */
444 1 : #define DT_INST_PWMS_PERIOD(inst) DT_INST_PWMS_PERIOD_BY_IDX(inst, 0)
445 :
446 : /**
447 : * @brief Equivalent to DT_INST_PWMS_CELL_BY_IDX(inst, idx, flags)
448 : * @param inst DT_DRV_COMPAT instance number
449 : * @param idx logical index into pwms property
450 : * @return the flags cell value at index "idx", or zero if there is none
451 : * @see DT_INST_PWMS_CELL_BY_IDX()
452 : */
453 1 : #define DT_INST_PWMS_FLAGS_BY_IDX(inst, idx) \
454 : DT_INST_PWMS_CELL_BY_IDX(inst, idx, flags)
455 :
456 : /**
457 : * @brief Equivalent to DT_INST_PWMS_CELL_BY_NAME(inst, name, flags)
458 : * @param inst DT_DRV_COMPAT instance number
459 : * @param name lowercase-and-underscores name of a pwms element
460 : * as defined by the node's pwm-names property
461 : * @return the flags cell value in the specifier at the named element,
462 : * or zero if there is none
463 : * @see DT_INST_PWMS_CELL_BY_NAME()
464 : */
465 1 : #define DT_INST_PWMS_FLAGS_BY_NAME(inst, name) \
466 : DT_INST_PWMS_CELL_BY_NAME(inst, name, flags)
467 :
468 : /**
469 : * @brief Equivalent to DT_INST_PWMS_FLAGS_BY_IDX(inst, 0)
470 : * @param inst DT_DRV_COMPAT instance number
471 : * @return the flags cell value at index 0, or zero if there is none
472 : * @see DT_INST_PWMS_FLAGS_BY_IDX()
473 : */
474 1 : #define DT_INST_PWMS_FLAGS(inst) DT_INST_PWMS_FLAGS_BY_IDX(inst, 0)
475 :
476 : /**
477 : * @}
478 : */
479 :
480 : #ifdef __cplusplus
481 : }
482 : #endif
483 :
484 : #endif /* ZEPHYR_INCLUDE_DEVICETREE_PWMS_H_ */
|