blob: 61c42311f8e51e35ef274f65d48a33030ed782db [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass4984de22017-05-17 17:18:10 -06002/*
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass4984de22017-05-17 17:18:10 -06005 */
6
7#ifndef _DM_OFNODE_H
8#define _DM_OFNODE_H
9
Simon Glass9e512042017-05-18 20:08:58 -060010/* TODO(sjg@chromium.org): Drop fdtdec.h include */
11#include <fdtdec.h>
12#include <dm/of.h>
13
14/* Enable checks to protect against invalid calls */
15#undef OF_CHECKS
16
Simon Glassdcf98852017-07-25 08:29:55 -060017struct resource;
18
Simon Glass4984de22017-05-17 17:18:10 -060019/**
20 * ofnode - reference to a device tree node
21 *
22 * This union can hold either a straightforward pointer to a struct device_node
23 * in the live device tree, or an offset within the flat device tree. In the
24 * latter case, the pointer value is just the integer offset within the flat DT.
25 *
26 * Thus we can reference nodes in both the live tree (once available) and the
27 * flat tree (until then). Functions are available to translate between an
28 * ofnode and either an offset or a struct device_node *.
29 *
30 * The reference can also hold a null offset, in which case the pointer value
Simon Glass9e512042017-05-18 20:08:58 -060031 * here is NULL. This corresponds to a struct device_node * value of
Simon Glass4984de22017-05-17 17:18:10 -060032 * NULL, or an offset of -1.
33 *
34 * There is no ambiguity as to whether ofnode holds an offset or a node
35 * pointer: when the live tree is active it holds a node pointer, otherwise it
36 * holds an offset. The value itself does not need to be unique and in theory
37 * the same value could point to a valid device node or a valid offset. We
38 * could arrange for a unique value to be used (e.g. by making the pointer
39 * point to an offset within the flat device tree in the case of an offset) but
40 * this increases code size slightly due to the subtraction. Since it offers no
41 * real benefit, the approach described here seems best.
42 *
43 * For now these points use constant types, since we don't allow writing
44 * the DT.
45 *
46 * @np: Pointer to device node, used for live tree
Baruch Siachafc1a782017-11-09 13:44:28 +020047 * @of_offset: Pointer into flat device tree, used for flat tree. Note that this
Simon Glass4984de22017-05-17 17:18:10 -060048 * is not a really a pointer to a node: it is an offset value. See above.
49 */
50typedef union ofnode_union {
51 const struct device_node *np; /* will be used for future live tree */
52 long of_offset;
53} ofnode;
54
Simon Glass9e512042017-05-18 20:08:58 -060055struct ofnode_phandle_args {
56 ofnode node;
57 int args_count;
58 uint32_t args[OF_MAX_PHANDLE_ARGS];
59};
60
61/**
62 * _ofnode_to_np() - convert an ofnode to a live DT node pointer
63 *
64 * This cannot be called if the reference contains an offset.
65 *
66 * @node: Reference containing struct device_node * (possibly invalid)
67 * @return pointer to device node (can be NULL)
68 */
69static inline const struct device_node *ofnode_to_np(ofnode node)
70{
71#ifdef OF_CHECKS
72 if (!of_live_active())
73 return NULL;
74#endif
75 return node.np;
76}
77
Simon Glass4984de22017-05-17 17:18:10 -060078/**
79 * ofnode_to_offset() - convert an ofnode to a flat DT offset
80 *
81 * This cannot be called if the reference contains a node pointer.
82 *
83 * @node: Reference containing offset (possibly invalid)
84 * @return DT offset (can be -1)
85 */
86static inline int ofnode_to_offset(ofnode node)
87{
Simon Glass9e512042017-05-18 20:08:58 -060088#ifdef OF_CHECKS
89 if (of_live_active())
90 return -1;
91#endif
Simon Glass4984de22017-05-17 17:18:10 -060092 return node.of_offset;
93}
94
95/**
96 * ofnode_valid() - check if an ofnode is valid
97 *
98 * @return true if the reference contains a valid ofnode, false if it is NULL
99 */
100static inline bool ofnode_valid(ofnode node)
101{
Simon Glass9e512042017-05-18 20:08:58 -0600102 if (of_live_active())
103 return node.np != NULL;
104 else
105 return node.of_offset != -1;
Simon Glass4984de22017-05-17 17:18:10 -0600106}
107
108/**
109 * offset_to_ofnode() - convert a DT offset to an ofnode
110 *
111 * @of_offset: DT offset (either valid, or -1)
112 * @return reference to the associated DT offset
113 */
114static inline ofnode offset_to_ofnode(int of_offset)
115{
116 ofnode node;
117
Simon Glass9e512042017-05-18 20:08:58 -0600118 if (of_live_active())
119 node.np = NULL;
120 else
121 node.of_offset = of_offset;
Simon Glass4984de22017-05-17 17:18:10 -0600122
123 return node;
124}
125
126/**
Simon Glass9e512042017-05-18 20:08:58 -0600127 * np_to_ofnode() - convert a node pointer to an ofnode
128 *
129 * @np: Live node pointer (can be NULL)
130 * @return reference to the associated node pointer
131 */
132static inline ofnode np_to_ofnode(const struct device_node *np)
133{
134 ofnode node;
135
136 node.np = np;
137
138 return node;
139}
140
141/**
142 * ofnode_is_np() - check if a reference is a node pointer
143 *
144 * This function associated that if there is a valid live tree then all
145 * references will use it. This is because using the flat DT when the live tree
146 * is valid is not permitted.
147 *
148 * @node: reference to check (possibly invalid)
149 * @return true if the reference is a live node pointer, false if it is a DT
150 * offset
151 */
152static inline bool ofnode_is_np(ofnode node)
153{
154#ifdef OF_CHECKS
155 /*
156 * Check our assumption that flat tree offsets are not used when a
157 * live tree is in use.
158 */
159 assert(!ofnode_valid(node) ||
160 (of_live_active() ? _ofnode_to_np(node)
161 : _ofnode_to_np(node)));
162#endif
163 return of_live_active() && ofnode_valid(node);
164}
165
166/**
Simon Glass4984de22017-05-17 17:18:10 -0600167 * ofnode_equal() - check if two references are equal
168 *
169 * @return true if equal, else false
170 */
171static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
172{
173 /* We only need to compare the contents */
174 return ref1.of_offset == ref2.of_offset;
175}
176
Simon Glass9e512042017-05-18 20:08:58 -0600177/**
178 * ofnode_null() - Obtain a null ofnode
179 *
180 * This returns an ofnode which points to no node. It works both with the flat
181 * tree and livetree.
182 */
183static inline ofnode ofnode_null(void)
184{
185 ofnode node;
186
187 if (of_live_active())
188 node.np = NULL;
189 else
190 node.of_offset = -1;
191
192 return node;
193}
194
195/**
196 * ofnode_read_u32() - Read a 32-bit integer from a property
197 *
198 * @ref: valid node reference to read property from
199 * @propname: name of the property to read from
200 * @outp: place to put value (if found)
201 * @return 0 if OK, -ve on error
202 */
203int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
204
205/**
206 * ofnode_read_s32() - Read a 32-bit integer from a property
207 *
208 * @ref: valid node reference to read property from
209 * @propname: name of the property to read from
210 * @outp: place to put value (if found)
211 * @return 0 if OK, -ve on error
212 */
213static inline int ofnode_read_s32(ofnode node, const char *propname,
214 s32 *out_value)
215{
216 return ofnode_read_u32(node, propname, (u32 *)out_value);
217}
218
219/**
220 * ofnode_read_u32_default() - Read a 32-bit integer from a property
221 *
222 * @ref: valid node reference to read property from
223 * @propname: name of the property to read from
224 * @def: default value to return if the property has no value
225 * @return property value, or @def if not found
226 */
227int ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
228
229/**
230 * ofnode_read_s32_default() - Read a 32-bit integer from a property
231 *
232 * @ref: valid node reference to read property from
233 * @propname: name of the property to read from
234 * @def: default value to return if the property has no value
235 * @return property value, or @def if not found
236 */
237int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
238
239/**
Simon Glass7e5196c2018-06-11 13:07:10 -0600240 * ofnode_read_u64_default() - Read a 64-bit integer from a property
241 *
242 * @ref: valid node reference to read property from
243 * @propname: name of the property to read from
244 * @def: default value to return if the property has no value
245 * @return property value, or @def if not found
246 */
247int ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
248
249/**
Simon Glass9e512042017-05-18 20:08:58 -0600250 * ofnode_read_string() - Read a string from a property
251 *
252 * @ref: valid node reference to read property from
253 * @propname: name of the property to read
254 * @return string from property value, or NULL if there is no such property
255 */
256const char *ofnode_read_string(ofnode node, const char *propname);
257
258/**
Simon Glassbed77492017-05-18 20:09:01 -0600259 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
Simon Glass9e512042017-05-18 20:08:58 -0600260 *
261 * @node: valid node reference to read property from
262 * @propname: name of the property to read
263 * @out_values: pointer to return value, modified only if return value is 0
264 * @sz: number of array elements to read
Simon Glassfbe8d032018-06-11 13:07:11 -0600265 * @return 0 if OK, -ve on error
Simon Glass9e512042017-05-18 20:08:58 -0600266 *
267 * Search for a property in a device node and read 32-bit value(s) from
268 * it. Returns 0 on success, -EINVAL if the property does not exist,
269 * -ENODATA if property does not have a value, and -EOVERFLOW if the
270 * property data isn't large enough.
271 *
272 * The out_values is modified only if a valid u32 value can be decoded.
273 */
274int ofnode_read_u32_array(ofnode node, const char *propname,
275 u32 *out_values, size_t sz);
276
277/**
278 * ofnode_read_bool() - read a boolean value from a property
279 *
280 * @node: valid node reference to read property from
281 * @propname: name of property to read
282 * @return true if property is present (meaning true), false if not present
283 */
284bool ofnode_read_bool(ofnode node, const char *propname);
285
286/**
287 * ofnode_find_subnode() - find a named subnode of a parent node
288 *
289 * @node: valid reference to parent node
290 * @subnode_name: name of subnode to find
291 * @return reference to subnode (which can be invalid if there is no such
292 * subnode)
293 */
294ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
295
296/**
297 * ofnode_first_subnode() - find the first subnode of a parent node
298 *
299 * @node: valid reference to a valid parent node
300 * @return reference to the first subnode (which can be invalid if the parent
301 * node has no subnodes)
302 */
303ofnode ofnode_first_subnode(ofnode node);
304
305/**
306 * ofnode_next_subnode() - find the next sibling of a subnode
307 *
308 * @node: valid reference to previous node (sibling)
309 * @return reference to the next subnode (which can be invalid if the node
310 * has no more siblings)
311 */
312ofnode ofnode_next_subnode(ofnode node);
313
314/**
Philipp Tomsiche2d59972018-02-23 17:38:49 +0100315 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
316 *
317 * @node: valid node to look up
318 * @return ofnode reference of the parent node
319 */
320ofnode ofnode_get_parent(ofnode node);
321
322/**
Simon Glass9e512042017-05-18 20:08:58 -0600323 * ofnode_get_name() - get the name of a node
324 *
325 * @node: valid node to look up
326 * @return name or node
327 */
328const char *ofnode_get_name(ofnode node);
329
330/**
Kever Yangb4f20762018-02-23 17:38:50 +0100331 * ofnode_get_by_phandle() - get ofnode from phandle
332 *
333 * @phandle: phandle to look up
334 * @return ofnode reference to the phandle
335 */
336ofnode ofnode_get_by_phandle(uint phandle);
337
338/**
Simon Glass9e512042017-05-18 20:08:58 -0600339 * ofnode_read_size() - read the size of a property
340 *
341 * @node: node to check
342 * @propname: property to check
343 * @return size of property if present, or -EINVAL if not
344 */
345int ofnode_read_size(ofnode node, const char *propname);
346
347/**
Simon Glassbed77492017-05-18 20:09:01 -0600348 * ofnode_get_addr_index() - get an address from a node
349 *
350 * This reads the register address from a node
351 *
352 * @node: node to read from
353 * @index: Index of address to read (0 for first)
354 * @return address, or FDT_ADDR_T_NONE if not present or invalid
355 */
356phys_addr_t ofnode_get_addr_index(ofnode node, int index);
357
358/**
359 * ofnode_get_addr() - get an address from a node
360 *
361 * This reads the register address from a node
362 *
363 * @node: node to read from
364 * @return address, or FDT_ADDR_T_NONE if not present or invalid
365 */
366phys_addr_t ofnode_get_addr(ofnode node);
367
368/**
Simon Glass9e512042017-05-18 20:08:58 -0600369 * ofnode_stringlist_search() - find a string in a string list and return index
370 *
371 * Note that it is possible for this function to succeed on property values
372 * that are not NUL-terminated. That's because the function will stop after
373 * finding the first occurrence of @string. This can for example happen with
374 * small-valued cell properties, such as #address-cells, when searching for
375 * the empty string.
376 *
377 * @node: node to check
378 * @propname: name of the property containing the string list
379 * @string: string to look up in the string list
380 *
381 * @return:
382 * the index of the string in the list of strings
383 * -ENODATA if the property is not found
384 * -EINVAL on some other error
385 */
386int ofnode_stringlist_search(ofnode node, const char *propname,
387 const char *string);
388
389/**
Simon Glass8c293d62017-06-12 06:21:28 -0600390 * ofnode_read_string_index() - obtain an indexed string from a string list
Simon Glass9e512042017-05-18 20:08:58 -0600391 *
392 * Note that this will successfully extract strings from properties with
393 * non-NUL-terminated values. For example on small-valued cell properties
394 * this function will return the empty string.
395 *
396 * If non-NULL, the length of the string (on success) or a negative error-code
397 * (on failure) will be stored in the integer pointer to by lenp.
398 *
399 * @node: node to check
400 * @propname: name of the property containing the string list
401 * @index: index of the string to return
402 * @lenp: return location for the string length or an error code on failure
403 *
404 * @return:
405 * length of string, if found or -ve error value if not found
406 */
407int ofnode_read_string_index(ofnode node, const char *propname, int index,
408 const char **outp);
409
410/**
Simon Glass8c293d62017-06-12 06:21:28 -0600411 * ofnode_read_string_count() - find the number of strings in a string list
412 *
413 * @node: node to check
414 * @propname: name of the property containing the string list
415 * @return:
416 * number of strings in the list, or -ve error value if not found
417 */
418int ofnode_read_string_count(ofnode node, const char *property);
419
420/**
Simon Glass9e512042017-05-18 20:08:58 -0600421 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
422 *
423 * This function is useful to parse lists of phandles and their arguments.
424 * Returns 0 on success and fills out_args, on error returns appropriate
425 * errno value.
426 *
427 * Caller is responsible to call of_node_put() on the returned out_args->np
428 * pointer.
429 *
430 * Example:
431 *
432 * phandle1: node1 {
433 * #list-cells = <2>;
434 * }
435 *
436 * phandle2: node2 {
437 * #list-cells = <1>;
438 * }
439 *
440 * node3 {
441 * list = <&phandle1 1 2 &phandle2 3>;
442 * }
443 *
444 * To get a device_node of the `node2' node you may call this:
445 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
446 *
447 * @node: device tree node containing a list
448 * @list_name: property name that contains a list
449 * @cells_name: property name that specifies phandles' arguments count
450 * @cells_count: Cell count to use if @cells_name is NULL
451 * @index: index of a phandle to parse out
452 * @out_args: optional pointer to output arguments structure (will be filled)
453 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
454 * @list_name does not exist, -EINVAL if a phandle was not found,
455 * @cells_name could not be found, the arguments were truncated or there
456 * were too many arguments.
457 */
458int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
459 const char *cells_name, int cell_count,
460 int index,
461 struct ofnode_phandle_args *out_args);
462
463/**
Patrice Chotard642346a2017-07-18 11:57:08 +0200464 * ofnode_count_phandle_with_args() - Count number of phandle in a list
465 *
466 * This function is useful to count phandles into a list.
467 * Returns number of phandle on success, on error returns appropriate
468 * errno value.
469 *
470 * @node: device tree node containing a list
471 * @list_name: property name that contains a list
472 * @cells_name: property name that specifies phandles' arguments count
473 * @return number of phandle on success, -ENOENT if @list_name does not
474 * exist, -EINVAL if a phandle was not found, @cells_name could not
475 * be found.
476 */
477int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
478 const char *cells_name);
479
480/**
Simon Glass9e512042017-05-18 20:08:58 -0600481 * ofnode_path() - find a node by full path
482 *
483 * @path: Full path to node, e.g. "/bus/spi@1"
484 * @return reference to the node found. Use ofnode_valid() to check if it exists
485 */
486ofnode ofnode_path(const char *path);
487
488/**
489 * ofnode_get_chosen_prop() - get the value of a chosen property
490 *
491 * This looks for a property within the /chosen node and returns its value
492 *
493 * @propname: Property name to look for
Simon Glassfbe8d032018-06-11 13:07:11 -0600494 * @return property value if found, else NULL
Simon Glass9e512042017-05-18 20:08:58 -0600495 */
496const char *ofnode_get_chosen_prop(const char *propname);
497
498/**
499 * ofnode_get_chosen_node() - get the chosen node
500 *
501 * @return the chosen node if present, else ofnode_null()
502 */
503ofnode ofnode_get_chosen_node(const char *name);
504
505struct display_timing;
506/**
507 * ofnode_decode_display_timing() - decode display timings
508 *
509 * Decode display timings from the supplied 'display-timings' node.
510 * See doc/device-tree-bindings/video/display-timing.txt for binding
511 * information.
512 *
513 * @node 'display-timing' node containing the timing subnodes
514 * @index Index number to read (0=first timing subnode)
515 * @config Place to put timings
516 * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
517 */
518int ofnode_decode_display_timing(ofnode node, int index,
519 struct display_timing *config);
520
521/**
Masahiro Yamada61e51ba2017-06-22 16:54:05 +0900522 * ofnode_get_property()- - get a pointer to the value of a node property
Simon Glass9e512042017-05-18 20:08:58 -0600523 *
524 * @node: node to read
525 * @propname: property to read
526 * @lenp: place to put length on success
527 * @return pointer to property, or NULL if not found
528 */
Masahiro Yamada61e51ba2017-06-22 16:54:05 +0900529const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
Simon Glass9e512042017-05-18 20:08:58 -0600530
531/**
532 * ofnode_is_available() - check if a node is marked available
533 *
534 * @node: node to check
535 * @return true if node's 'status' property is "okay" (or is missing)
536 */
537bool ofnode_is_available(ofnode node);
538
539/**
540 * ofnode_get_addr_size() - get address and size from a property
541 *
542 * This does no address translation. It simply reads an property that contains
543 * an address and a size value, one after the other.
544 *
545 * @node: node to read from
546 * @propname: property to read
547 * @sizep: place to put size value (on success)
548 * @return address value, or FDT_ADDR_T_NONE on error
549 */
550phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
551 phys_size_t *sizep);
552
553/**
554 * ofnode_read_u8_array_ptr() - find an 8-bit array
555 *
556 * Look up a property in a node and return a pointer to its contents as a
557 * byte array of given length. The property must have at least enough data
558 * for the array (count bytes). It may have more, but this will be ignored.
559 * The data is not copied.
560 *
561 * @node node to examine
562 * @propname name of property to find
563 * @sz number of array elements
564 * @return pointer to byte array if found, or NULL if the property is not
565 * found or there is not enough data
566 */
567const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
568 size_t sz);
569
570/**
571 * ofnode_read_pci_addr() - look up a PCI address
572 *
573 * Look at an address property in a node and return the PCI address which
574 * corresponds to the given type in the form of fdt_pci_addr.
575 * The property must hold one fdt_pci_addr with a lengh.
576 *
577 * @node node to examine
578 * @type pci address type (FDT_PCI_SPACE_xxx)
579 * @propname name of property to find
580 * @addr returns pci address in the form of fdt_pci_addr
581 * @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
582 * format of the property was invalid, -ENXIO if the requested
583 * address type was not found
584 */
585int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
586 const char *propname, struct fdt_pci_addr *addr);
587
588/**
589 * ofnode_read_addr_cells() - Get the number of address cells for a node
590 *
591 * This walks back up the tree to find the closest #address-cells property
592 * which controls the given node.
593 *
594 * @node: Node to check
595 * @return number of address cells this node uses
596 */
597int ofnode_read_addr_cells(ofnode node);
598
599/**
600 * ofnode_read_size_cells() - Get the number of size cells for a node
601 *
602 * This walks back up the tree to find the closest #size-cells property
603 * which controls the given node.
604 *
605 * @node: Node to check
606 * @return number of size cells this node uses
607 */
608int ofnode_read_size_cells(ofnode node);
609
610/**
Simon Glass878d68c2017-06-12 06:21:31 -0600611 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
612 *
613 * This function matches fdt_address_cells().
614 *
615 * @np: Node pointer to check
616 * @return value of #address-cells property in this node, or 2 if none
617 */
618int ofnode_read_simple_addr_cells(ofnode node);
619
620/**
621 * ofnode_read_simple_size_cells() - Get the size cells property in a node
622 *
623 * This function matches fdt_size_cells().
624 *
625 * @np: Node pointer to check
626 * @return value of #size-cells property in this node, or 2 if none
627 */
628int ofnode_read_simple_size_cells(ofnode node);
629
630/**
Simon Glass9e512042017-05-18 20:08:58 -0600631 * ofnode_pre_reloc() - check if a node should be bound before relocation
632 *
633 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
634 * via special device tree properties.
635 *
636 * Before relocation this function can be used to check if nodes are required
637 * in either SPL or TPL stages.
638 *
639 * After relocation and jumping into the real U-Boot binary it is possible to
640 * determine if a node was bound in one of SPL/TPL stages.
641 *
642 * There are 3 settings currently in use
643 * -
644 * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
645 * Existing platforms only use it to indicate nodes needed in
646 * SPL. Should probably be replaced by u-boot,dm-spl for
647 * new platforms.
648 *
649 * @node: node to check
Simon Glassfbe8d032018-06-11 13:07:11 -0600650 * @return true if node is needed in SPL/TL, false otherwise
Simon Glass9e512042017-05-18 20:08:58 -0600651 */
652bool ofnode_pre_reloc(ofnode node);
653
Simon Glassc98ad442018-06-11 13:07:12 -0600654/**
655 * ofnode_read_resource() - Read a resource from a node
656 *
657 * Read resource information from a node at the given index
658 *
659 * @node: Node to read from
660 * @index: Index of resource to read (0 = first)
661 * @res: Returns resource that was read, on success
662 * @return 0 if OK, -ve on error
663 */
Simon Glassdcf98852017-07-25 08:29:55 -0600664int ofnode_read_resource(ofnode node, uint index, struct resource *res);
Simon Glassc98ad442018-06-11 13:07:12 -0600665
666/**
667 * ofnode_read_resource_byname() - Read a resource from a node by name
668 *
669 * Read resource information from a node matching the given name. This uses a
670 * 'reg-names' string list property with the names matching the associated
671 * 'reg' property list.
672 *
673 * @node: Node to read from
674 * @name: Name of resource to read
675 * @res: Returns resource that was read, on success
676 * @return 0 if OK, -ve on error
677 */
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900678int ofnode_read_resource_byname(ofnode node, const char *name,
679 struct resource *res);
Simon Glassdcf98852017-07-25 08:29:55 -0600680
Simon Glass3991f422017-08-05 15:45:54 -0600681/**
682 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
683 *
684 * @node: child node (ofnode, lvalue)
685 * @parent: parent node (ofnode)
686 *
687 * This is a wrapper around a for loop and is used like so:
688 *
689 * ofnode node;
690 *
691 * ofnode_for_each_subnode(node, parent) {
692 * Use node
693 * ...
694 * }
695 *
696 * Note that this is implemented as a macro and @node is used as
697 * iterator in the loop. The parent variable can be a constant or even a
698 * literal.
699 */
700#define ofnode_for_each_subnode(node, parent) \
701 for (node = ofnode_first_subnode(parent); \
702 ofnode_valid(node); \
703 node = ofnode_next_subnode(node))
704
Mario Six147c6072018-01-15 11:07:19 +0100705/**
706 * ofnode_translate_address() - Tranlate a device-tree address
707 *
708 * Translate an address from the device-tree into a CPU physical address. This
709 * function walks up the tree and applies the various bus mappings along the
710 * way.
711 *
712 * @ofnode: Device tree node giving the context in which to translate the
713 * address
714 * @in_addr: pointer to the address to translate
715 * @return the translated address; OF_BAD_ADDR on error
716 */
717u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
Masahiro Yamada5ccc2c22018-04-19 12:14:02 +0900718
719/**
720 * ofnode_device_is_compatible() - check if the node is compatible with compat
721 *
722 * This allows to check whether the node is comaptible with the compat.
723 *
724 * @node: Device tree node for which compatible needs to be verified.
725 * @compat: Compatible string which needs to verified in the given node.
726 * @return true if OK, false if the compatible is not found
727 */
728int ofnode_device_is_compatible(ofnode node, const char *compat);
Simon Glass4984de22017-05-17 17:18:10 -0600729#endif