1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
10 /* TODO(sjg@chromium.org): Drop fdtdec.h include */
13 #include <dm/of_access.h>
16 /* Enable checks to protect against invalid calls */
22 * ofnode - reference to a device tree node
24 * This union can hold either a straightforward pointer to a struct device_node
25 * in the live device tree, or an offset within the flat device tree. In the
26 * latter case, the pointer value is just the integer offset within the flat DT.
28 * Thus we can reference nodes in both the live tree (once available) and the
29 * flat tree (until then). Functions are available to translate between an
30 * ofnode and either an offset or a struct device_node *.
32 * The reference can also hold a null offset, in which case the pointer value
33 * here is NULL. This corresponds to a struct device_node * value of
34 * NULL, or an offset of -1.
36 * There is no ambiguity as to whether ofnode holds an offset or a node
37 * pointer: when the live tree is active it holds a node pointer, otherwise it
38 * holds an offset. The value itself does not need to be unique and in theory
39 * the same value could point to a valid device node or a valid offset. We
40 * could arrange for a unique value to be used (e.g. by making the pointer
41 * point to an offset within the flat device tree in the case of an offset) but
42 * this increases code size slightly due to the subtraction. Since it offers no
43 * real benefit, the approach described here seems best.
45 * For now these points use constant types, since we don't allow writing
48 * @np: Pointer to device node, used for live tree
49 * @of_offset: Pointer into flat device tree, used for flat tree. Note that this
50 * is not a really a pointer to a node: it is an offset value. See above.
52 typedef union ofnode_union {
53 const struct device_node *np;
57 struct ofnode_phandle_args {
60 uint32_t args[OF_MAX_PHANDLE_ARGS];
64 * ofprop - reference to a property of a device tree node
66 * This struct hold the reference on one property of one node,
67 * using struct ofnode and an offset within the flat device tree or either
68 * a pointer to a struct property in the live device tree.
70 * Thus we can reference arguments in both the live tree and the flat tree.
72 * The property reference can also hold a null reference. This corresponds to
73 * a struct property NULL pointer or an offset of -1.
75 * @node: Pointer to device node
76 * @offset: Pointer into flat device tree, used for flat tree.
77 * @prop: Pointer to property, used for live treee.
84 const struct property *prop;
89 * ofnode_to_np() - convert an ofnode to a live DT node pointer
91 * This cannot be called if the reference contains an offset.
93 * @node: Reference containing struct device_node * (possibly invalid)
94 * @return pointer to device node (can be NULL)
96 static inline const struct device_node *ofnode_to_np(ofnode node)
99 if (!of_live_active())
106 * ofnode_to_offset() - convert an ofnode to a flat DT offset
108 * This cannot be called if the reference contains a node pointer.
110 * @node: Reference containing offset (possibly invalid)
111 * @return DT offset (can be -1)
113 static inline int ofnode_to_offset(ofnode node)
116 if (of_live_active())
119 return node.of_offset;
123 * ofnode_valid() - check if an ofnode is valid
125 * @return true if the reference contains a valid ofnode, false if it is NULL
127 static inline bool ofnode_valid(ofnode node)
129 if (of_live_active())
130 return node.np != NULL;
132 return node.of_offset >= 0;
136 * offset_to_ofnode() - convert a DT offset to an ofnode
138 * @of_offset: DT offset (either valid, or -1)
139 * @return reference to the associated DT offset
141 static inline ofnode offset_to_ofnode(int of_offset)
145 if (of_live_active())
148 node.of_offset = of_offset >= 0 ? of_offset : -1;
154 * np_to_ofnode() - convert a node pointer to an ofnode
156 * @np: Live node pointer (can be NULL)
157 * @return reference to the associated node pointer
159 static inline ofnode np_to_ofnode(const struct device_node *np)
169 * ofnode_is_np() - check if a reference is a node pointer
171 * This function associated that if there is a valid live tree then all
172 * references will use it. This is because using the flat DT when the live tree
173 * is valid is not permitted.
175 * @node: reference to check (possibly invalid)
176 * @return true if the reference is a live node pointer, false if it is a DT
179 static inline bool ofnode_is_np(ofnode node)
183 * Check our assumption that flat tree offsets are not used when a
184 * live tree is in use.
186 assert(!ofnode_valid(node) ||
187 (of_live_active() ? ofnode_to_np(node)
188 : ofnode_to_np(node)));
190 return of_live_active() && ofnode_valid(node);
194 * ofnode_equal() - check if two references are equal
196 * @return true if equal, else false
198 static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
200 /* We only need to compare the contents */
201 return ref1.of_offset == ref2.of_offset;
205 * ofnode_null() - Obtain a null ofnode
207 * This returns an ofnode which points to no node. It works both with the flat
210 static inline ofnode ofnode_null(void)
214 if (of_live_active())
222 static inline ofnode ofnode_root(void)
226 if (of_live_active())
227 node.np = gd_of_root();
235 * ofnode_read_u32() - Read a 32-bit integer from a property
237 * @ref: valid node reference to read property from
238 * @propname: name of the property to read from
239 * @outp: place to put value (if found)
240 * @return 0 if OK, -ve on error
242 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
245 * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
247 * @ref: valid node reference to read property from
248 * @propname: name of the property to read from
249 * @index: index of the integer to return
250 * @outp: place to put value (if found)
251 * @return 0 if OK, -ve on error
253 int ofnode_read_u32_index(ofnode node, const char *propname, int index,
257 * ofnode_read_s32() - Read a 32-bit integer from a property
259 * @ref: valid node reference to read property from
260 * @propname: name of the property to read from
261 * @outp: place to put value (if found)
262 * @return 0 if OK, -ve on error
264 static inline int ofnode_read_s32(ofnode node, const char *propname,
267 return ofnode_read_u32(node, propname, (u32 *)out_value);
271 * ofnode_read_u32_default() - Read a 32-bit integer from a property
273 * @ref: valid node reference to read property from
274 * @propname: name of the property to read from
275 * @def: default value to return if the property has no value
276 * @return property value, or @def if not found
278 u32 ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
281 * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
284 * @ref: valid node reference to read property from
285 * @propname: name of the property to read from
286 * @index: index of the integer to return
287 * @def: default value to return if the property has no value
288 * @return property value, or @def if not found
290 u32 ofnode_read_u32_index_default(ofnode ref, const char *propname, int index,
294 * ofnode_read_s32_default() - Read a 32-bit integer from a property
296 * @ref: valid node reference to read property from
297 * @propname: name of the property to read from
298 * @def: default value to return if the property has no value
299 * @return property value, or @def if not found
301 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
304 * ofnode_read_u64() - Read a 64-bit integer from a property
306 * @node: valid node reference to read property from
307 * @propname: name of the property to read from
308 * @outp: place to put value (if found)
309 * @return 0 if OK, -ve on error
311 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
314 * ofnode_read_u64_default() - Read a 64-bit integer from a property
316 * @ref: valid node reference to read property from
317 * @propname: name of the property to read from
318 * @def: default value to return if the property has no value
319 * @return property value, or @def if not found
321 u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
324 * ofnode_read_prop() - Read a property from a node
326 * @node: valid node reference to read property from
327 * @propname: name of the property to read
328 * @sizep: if non-NULL, returns the size of the property, or an error code
330 * @return property value, or NULL if there is no such property
332 const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
335 * ofnode_read_string() - Read a string from a property
337 * @node: valid node reference to read property from
338 * @propname: name of the property to read
339 * @return string from property value, or NULL if there is no such property
341 const char *ofnode_read_string(ofnode node, const char *propname);
344 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
346 * @node: valid node reference to read property from
347 * @propname: name of the property to read
348 * @out_values: pointer to return value, modified only if return value is 0
349 * @sz: number of array elements to read
350 * @return 0 if OK, -ve on error
352 * Search for a property in a device node and read 32-bit value(s) from
353 * it. Returns 0 on success, -EINVAL if the property does not exist,
354 * -ENODATA if property does not have a value, and -EOVERFLOW if the
355 * property data isn't large enough.
357 * The out_values is modified only if a valid u32 value can be decoded.
359 int ofnode_read_u32_array(ofnode node, const char *propname,
360 u32 *out_values, size_t sz);
363 * ofnode_read_bool() - read a boolean value from a property
365 * @node: valid node reference to read property from
366 * @propname: name of property to read
367 * @return true if property is present (meaning true), false if not present
369 bool ofnode_read_bool(ofnode node, const char *propname);
372 * ofnode_find_subnode() - find a named subnode of a parent node
374 * @node: valid reference to parent node
375 * @subnode_name: name of subnode to find
376 * @return reference to subnode (which can be invalid if there is no such
379 ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
381 #if CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
382 #include <asm/global_data.h>
384 static inline bool ofnode_is_enabled(ofnode node)
386 if (ofnode_is_np(node)) {
387 return of_device_is_available(ofnode_to_np(node));
389 return fdtdec_get_is_enabled(gd->fdt_blob,
390 ofnode_to_offset(node));
394 static inline ofnode ofnode_first_subnode(ofnode node)
396 assert(ofnode_valid(node));
397 if (ofnode_is_np(node))
398 return np_to_ofnode(node.np->child);
400 return offset_to_ofnode(
401 fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
404 static inline ofnode ofnode_next_subnode(ofnode node)
406 assert(ofnode_valid(node));
407 if (ofnode_is_np(node))
408 return np_to_ofnode(node.np->sibling);
410 return offset_to_ofnode(
411 fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
415 * ofnode_is_enabled() - Checks whether a node is enabled.
416 * This looks for a 'status' property. If this exists, then returns true if
417 * the status is 'okay' and false otherwise. If there is no status property,
418 * it returns true on the assumption that anything mentioned should be enabled
421 * @node: node to examine
422 * @return false (not enabled) or true (enabled)
424 bool ofnode_is_enabled(ofnode node);
427 * ofnode_first_subnode() - find the first subnode of a parent node
429 * @node: valid reference to a valid parent node
430 * @return reference to the first subnode (which can be invalid if the parent
431 * node has no subnodes)
433 ofnode ofnode_first_subnode(ofnode node);
436 * ofnode_next_subnode() - find the next sibling of a subnode
438 * @node: valid reference to previous node (sibling)
439 * @return reference to the next subnode (which can be invalid if the node
440 * has no more siblings)
442 ofnode ofnode_next_subnode(ofnode node);
443 #endif /* DM_INLINE_OFNODE */
446 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
448 * @node: valid node to look up
449 * @return ofnode reference of the parent node
451 ofnode ofnode_get_parent(ofnode node);
454 * ofnode_get_name() - get the name of a node
456 * @node: valid node to look up
457 * @return name of node
459 const char *ofnode_get_name(ofnode node);
462 * ofnode_get_by_phandle() - get ofnode from phandle
464 * @phandle: phandle to look up
465 * @return ofnode reference to the phandle
467 ofnode ofnode_get_by_phandle(uint phandle);
470 * ofnode_read_size() - read the size of a property
472 * @node: node to check
473 * @propname: property to check
474 * @return size of property if present, or -EINVAL if not
476 int ofnode_read_size(ofnode node, const char *propname);
479 * ofnode_get_addr_size_index() - get an address/size from a node
482 * This reads the register address/size from a node based on index
484 * @node: node to read from
485 * @index: Index of address to read (0 for first)
486 * @size: Pointer to size of the address
487 * @return address, or FDT_ADDR_T_NONE if not present or invalid
489 phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
493 * ofnode_get_addr_index() - get an address from a node
495 * This reads the register address from a node
497 * @node: node to read from
498 * @index: Index of address to read (0 for first)
499 * @return address, or FDT_ADDR_T_NONE if not present or invalid
501 phys_addr_t ofnode_get_addr_index(ofnode node, int index);
504 * ofnode_get_addr() - get an address from a node
506 * This reads the register address from a node
508 * @node: node to read from
509 * @return address, or FDT_ADDR_T_NONE if not present or invalid
511 phys_addr_t ofnode_get_addr(ofnode node);
514 * ofnode_get_size() - get size from a node
516 * This reads the register size from a node
518 * @node: node to read from
519 * @return size of the address, or FDT_SIZE_T_NONE if not present or invalid
521 fdt_size_t ofnode_get_size(ofnode node);
524 * ofnode_stringlist_search() - find a string in a string list and return index
526 * Note that it is possible for this function to succeed on property values
527 * that are not NUL-terminated. That's because the function will stop after
528 * finding the first occurrence of @string. This can for example happen with
529 * small-valued cell properties, such as #address-cells, when searching for
532 * @node: node to check
533 * @propname: name of the property containing the string list
534 * @string: string to look up in the string list
537 * the index of the string in the list of strings
538 * -ENODATA if the property is not found
539 * -EINVAL on some other error
541 int ofnode_stringlist_search(ofnode node, const char *propname,
545 * ofnode_read_string_index() - obtain an indexed string from a string list
547 * Note that this will successfully extract strings from properties with
548 * non-NUL-terminated values. For example on small-valued cell properties
549 * this function will return the empty string.
551 * If non-NULL, the length of the string (on success) or a negative error-code
552 * (on failure) will be stored in the integer pointer to by lenp.
554 * @node: node to check
555 * @propname: name of the property containing the string list
556 * @index: index of the string to return
557 * @lenp: return location for the string length or an error code on failure
560 * length of string, if found or -ve error value if not found
562 int ofnode_read_string_index(ofnode node, const char *propname, int index,
566 * ofnode_read_string_count() - find the number of strings in a string list
568 * @node: node to check
569 * @propname: name of the property containing the string list
571 * number of strings in the list, or -ve error value if not found
573 int ofnode_read_string_count(ofnode node, const char *property);
576 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
578 * This function is useful to parse lists of phandles and their arguments.
579 * Returns 0 on success and fills out_args, on error returns appropriate
582 * Caller is responsible to call of_node_put() on the returned out_args->np
596 * list = <&phandle1 1 2 &phandle2 3>;
599 * To get a device_node of the `node2' node you may call this:
600 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
602 * @node: device tree node containing a list
603 * @list_name: property name that contains a list
604 * @cells_name: property name that specifies phandles' arguments count
605 * @cells_count: Cell count to use if @cells_name is NULL
606 * @index: index of a phandle to parse out
607 * @out_args: optional pointer to output arguments structure (will be filled)
608 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
609 * @list_name does not exist, -EINVAL if a phandle was not found,
610 * @cells_name could not be found, the arguments were truncated or there
611 * were too many arguments.
613 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
614 const char *cells_name, int cell_count,
616 struct ofnode_phandle_args *out_args);
619 * ofnode_count_phandle_with_args() - Count number of phandle in a list
621 * This function is useful to count phandles into a list.
622 * Returns number of phandle on success, on error returns appropriate
625 * @node: device tree node containing a list
626 * @list_name: property name that contains a list
627 * @cells_name: property name that specifies phandles' arguments count
628 * @cells_count: Cell count to use if @cells_name is NULL
629 * @return number of phandle on success, -ENOENT if @list_name does not
630 * exist, -EINVAL if a phandle was not found, @cells_name could not
633 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
634 const char *cells_name, int cell_count);
637 * ofnode_path() - find a node by full path
639 * @path: Full path to node, e.g. "/bus/spi@1"
640 * @return reference to the node found. Use ofnode_valid() to check if it exists
642 ofnode ofnode_path(const char *path);
645 * ofnode_read_chosen_prop() - get the value of a chosen property
647 * This looks for a property within the /chosen node and returns its value
649 * @propname: Property name to look for
650 * @sizep: Returns size of property, or FDT_ERR_... error code if function
652 * @return property value if found, else NULL
654 const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
657 * ofnode_read_chosen_string() - get the string value of a chosen property
659 * This looks for a property within the /chosen node and returns its value,
660 * checking that it is a valid nul-terminated string
662 * @propname: Property name to look for
663 * @return string value if found, else NULL
665 const char *ofnode_read_chosen_string(const char *propname);
668 * ofnode_get_chosen_node() - get a referenced node from the chosen node
670 * This looks up a named property in the chosen node and uses that as a path to
673 * @return the referenced node if present, else ofnode_null()
675 ofnode ofnode_get_chosen_node(const char *propname);
678 * ofnode_read_aliases_prop() - get the value of a aliases property
680 * This looks for a property within the /aliases node and returns its value
682 * @propname: Property name to look for
683 * @sizep: Returns size of property, or FDT_ERR_... error code if function
685 * @return property value if found, else NULL
687 const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
690 * ofnode_get_aliases_node() - get a referenced node from the aliases node
692 * This looks up a named property in the aliases node and uses that as a path to
695 * @return the referenced node if present, else ofnode_null()
697 ofnode ofnode_get_aliases_node(const char *propname);
699 struct display_timing;
701 * ofnode_decode_display_timing() - decode display timings
703 * Decode display timings from the supplied 'display-timings' node.
704 * See doc/device-tree-bindings/video/display-timing.txt for binding
707 * @node 'display-timing' node containing the timing subnodes
708 * @index Index number to read (0=first timing subnode)
709 * @config Place to put timings
710 * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
712 int ofnode_decode_display_timing(ofnode node, int index,
713 struct display_timing *config);
716 * ofnode_get_property() - get a pointer to the value of a node property
718 * @node: node to read
719 * @propname: property to read
720 * @lenp: place to put length on success
721 * @return pointer to property, or NULL if not found
723 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
726 * ofnode_get_first_property()- get the reference of the first property
728 * Get reference to the first property of the node, it is used to iterate
729 * and read all the property with ofnode_get_property_by_prop().
731 * @node: node to read
732 * @prop: place to put argument reference
733 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
735 int ofnode_get_first_property(ofnode node, struct ofprop *prop);
738 * ofnode_get_next_property() - get the reference of the next property
740 * Get reference to the next property of the node, it is used to iterate
741 * and read all the property with ofnode_get_property_by_prop().
743 * @prop: reference of current argument and place to put reference of next one
744 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
746 int ofnode_get_next_property(struct ofprop *prop);
749 * ofnode_get_property_by_prop() - get a pointer to the value of a property
751 * Get value for the property identified by the provided reference.
753 * @prop: reference on property
754 * @propname: If non-NULL, place to property name on success,
755 * @lenp: If non-NULL, place to put length on success
756 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
758 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
759 const char **propname, int *lenp);
762 * ofnode_is_available() - check if a node is marked available
764 * @node: node to check
765 * @return true if node's 'status' property is "okay" (or is missing)
767 bool ofnode_is_available(ofnode node);
770 * ofnode_get_addr_size() - get address and size from a property
772 * This does no address translation. It simply reads an property that contains
773 * an address and a size value, one after the other.
775 * @node: node to read from
776 * @propname: property to read
777 * @sizep: place to put size value (on success)
778 * @return address value, or FDT_ADDR_T_NONE on error
780 phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
784 * ofnode_read_u8_array_ptr() - find an 8-bit array
786 * Look up a property in a node and return a pointer to its contents as a
787 * byte array of given length. The property must have at least enough data
788 * for the array (count bytes). It may have more, but this will be ignored.
789 * The data is not copied.
791 * @node node to examine
792 * @propname name of property to find
793 * @sz number of array elements
794 * @return pointer to byte array if found, or NULL if the property is not
795 * found or there is not enough data
797 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
801 * ofnode_read_pci_addr() - look up a PCI address
803 * Look at an address property in a node and return the PCI address which
804 * corresponds to the given type in the form of fdt_pci_addr.
805 * The property must hold one fdt_pci_addr with a lengh.
807 * @node node to examine
808 * @type pci address type (FDT_PCI_SPACE_xxx)
809 * @propname name of property to find
810 * @addr returns pci address in the form of fdt_pci_addr
811 * @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
812 * format of the property was invalid, -ENXIO if the requested
813 * address type was not found
815 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
816 const char *propname, struct fdt_pci_addr *addr);
819 * ofnode_read_pci_vendev() - look up PCI vendor and device id
821 * Look at the compatible property of a device node that represents a PCI
822 * device and extract pci vendor id and device id from it.
824 * @param node node to examine
825 * @param vendor vendor id of the pci device
826 * @param device device id of the pci device
827 * @return 0 if ok, negative on error
829 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
832 * ofnode_read_addr_cells() - Get the number of address cells for a node
834 * This walks back up the tree to find the closest #address-cells property
835 * which controls the given node.
837 * @node: Node to check
838 * @return number of address cells this node uses
840 int ofnode_read_addr_cells(ofnode node);
843 * ofnode_read_size_cells() - Get the number of size cells for a node
845 * This walks back up the tree to find the closest #size-cells property
846 * which controls the given node.
848 * @node: Node to check
849 * @return number of size cells this node uses
851 int ofnode_read_size_cells(ofnode node);
854 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
856 * This function matches fdt_address_cells().
858 * @np: Node pointer to check
859 * @return value of #address-cells property in this node, or 2 if none
861 int ofnode_read_simple_addr_cells(ofnode node);
864 * ofnode_read_simple_size_cells() - Get the size cells property in a node
866 * This function matches fdt_size_cells().
868 * @np: Node pointer to check
869 * @return value of #size-cells property in this node, or 2 if none
871 int ofnode_read_simple_size_cells(ofnode node);
874 * ofnode_pre_reloc() - check if a node should be bound before relocation
876 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
877 * via special device tree properties.
879 * Before relocation this function can be used to check if nodes are required
880 * in either SPL or TPL stages.
882 * After relocation and jumping into the real U-Boot binary it is possible to
883 * determine if a node was bound in one of SPL/TPL stages.
885 * There are 4 settings currently in use
886 * - u-boot,dm-pre-proper: U-Boot proper pre-relocation only
887 * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
888 * Existing platforms only use it to indicate nodes needed in
889 * SPL. Should probably be replaced by u-boot,dm-spl for
891 * - u-boot,dm-spl: SPL and U-Boot pre-relocation
892 * - u-boot,dm-tpl: TPL and U-Boot pre-relocation
894 * @node: node to check
895 * @return true if node is needed in SPL/TL, false otherwise
897 bool ofnode_pre_reloc(ofnode node);
900 * ofnode_read_resource() - Read a resource from a node
902 * Read resource information from a node at the given index
904 * @node: Node to read from
905 * @index: Index of resource to read (0 = first)
906 * @res: Returns resource that was read, on success
907 * @return 0 if OK, -ve on error
909 int ofnode_read_resource(ofnode node, uint index, struct resource *res);
912 * ofnode_read_resource_byname() - Read a resource from a node by name
914 * Read resource information from a node matching the given name. This uses a
915 * 'reg-names' string list property with the names matching the associated
916 * 'reg' property list.
918 * @node: Node to read from
919 * @name: Name of resource to read
920 * @res: Returns resource that was read, on success
921 * @return 0 if OK, -ve on error
923 int ofnode_read_resource_byname(ofnode node, const char *name,
924 struct resource *res);
927 * ofnode_by_compatible() - Find the next compatible node
929 * Find the next node after @from that is compatible with @compat
931 * @from: ofnode to start from (use ofnode_null() to start at the beginning)
932 * @compat: Compatible string to match
933 * @return ofnode found, or ofnode_null() if none
935 ofnode ofnode_by_compatible(ofnode from, const char *compat);
938 * ofnode_by_prop_value() - Find the next node with given property value
940 * Find the next node after @from that has a @propname with a value
941 * @propval and a length @proplen.
943 * @from: ofnode to start from (use ofnode_null() to start at the
944 * beginning) @propname: property name to check @propval: property value to
945 * search for @proplen: length of the value in propval @return ofnode
946 * found, or ofnode_null() if none
948 ofnode ofnode_by_prop_value(ofnode from, const char *propname,
949 const void *propval, int proplen);
952 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
954 * @node: child node (ofnode, lvalue)
955 * @parent: parent node (ofnode)
957 * This is a wrapper around a for loop and is used like so:
961 * ofnode_for_each_subnode(node, parent) {
966 * Note that this is implemented as a macro and @node is used as
967 * iterator in the loop. The parent variable can be a constant or even a
970 #define ofnode_for_each_subnode(node, parent) \
971 for (node = ofnode_first_subnode(parent); \
972 ofnode_valid(node); \
973 node = ofnode_next_subnode(node))
976 * ofnode_get_child_count() - get the child count of a ofnode
978 * @node: valid node to get its child count
979 * @return the number of subnodes
981 int ofnode_get_child_count(ofnode parent);
984 * ofnode_translate_address() - Translate a device-tree address
986 * Translate an address from the device-tree into a CPU physical address. This
987 * function walks up the tree and applies the various bus mappings along the
990 * @ofnode: Device tree node giving the context in which to translate the
992 * @in_addr: pointer to the address to translate
993 * @return the translated address; OF_BAD_ADDR on error
995 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
998 * ofnode_translate_dma_address() - Translate a device-tree DMA address
1000 * Translate a DMA address from the device-tree into a CPU physical address.
1001 * This function walks up the tree and applies the various bus mappings along
1004 * @ofnode: Device tree node giving the context in which to translate the
1006 * @in_addr: pointer to the DMA address to translate
1007 * @return the translated DMA address; OF_BAD_ADDR on error
1009 u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
1012 * ofnode_get_dma_range() - get dma-ranges for a specific DT node
1014 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
1015 * cpu->bus address translations
1017 * @param blob Pointer to device tree blob
1018 * @param node_offset Node DT offset
1019 * @param cpu Pointer to variable storing the range's cpu address
1020 * @param bus Pointer to variable storing the range's bus address
1021 * @param size Pointer to variable storing the range's size
1022 * @return translated DMA address or OF_BAD_ADDR on error
1024 int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus,
1028 * ofnode_device_is_compatible() - check if the node is compatible with compat
1030 * This allows to check whether the node is comaptible with the compat.
1032 * @node: Device tree node for which compatible needs to be verified.
1033 * @compat: Compatible string which needs to verified in the given node.
1034 * @return true if OK, false if the compatible is not found
1036 int ofnode_device_is_compatible(ofnode node, const char *compat);
1039 * ofnode_write_prop() - Set a property of a ofnode
1041 * Note that the value passed to the function is *not* allocated by the
1042 * function itself, but must be allocated by the caller if necessary.
1044 * @node: The node for whose property should be set
1045 * @propname: The name of the property to set
1046 * @len: The length of the new value of the property
1047 * @value: The new value of the property (must be valid prior to calling
1049 * @return 0 if successful, -ve on error
1051 int ofnode_write_prop(ofnode node, const char *propname, int len,
1055 * ofnode_write_string() - Set a string property of a ofnode
1057 * Note that the value passed to the function is *not* allocated by the
1058 * function itself, but must be allocated by the caller if necessary.
1060 * @node: The node for whose string property should be set
1061 * @propname: The name of the string property to set
1062 * @value: The new value of the string property (must be valid prior to
1063 * calling the function)
1064 * @return 0 if successful, -ve on error
1066 int ofnode_write_string(ofnode node, const char *propname, const char *value);
1069 * ofnode_set_enabled() - Enable or disable a device tree node given by its
1072 * This function effectively sets the node's "status" property to either "okay"
1073 * or "disable", hence making it available for driver model initialization or
1076 * @node: The node to enable
1077 * @value: Flag that tells the function to either disable or enable the
1079 * @return 0 if successful, -ve on error
1081 int ofnode_set_enabled(ofnode node, bool value);