1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2017 Google, Inc
15 /* Enable checks to protect against invalid calls */
21 * ofnode - reference to a device tree node
23 * This union can hold either a straightforward pointer to a struct device_node
24 * in the live device tree, or an offset within the flat device tree. In the
25 * latter case, the pointer value is just the integer offset within the flat DT.
27 * Thus we can reference nodes in both the live tree (once available) and the
28 * flat tree (until then). Functions are available to translate between an
29 * ofnode and either an offset or a struct device_node *.
31 * The reference can also hold a null offset, in which case the pointer value
32 * here is NULL. This corresponds to a struct device_node * value of
33 * NULL, or an offset of -1.
35 * There is no ambiguity as to whether ofnode holds an offset or a node
36 * pointer: when the live tree is active it holds a node pointer, otherwise it
37 * holds an offset. The value itself does not need to be unique and in theory
38 * the same value could point to a valid device node or a valid offset. We
39 * could arrange for a unique value to be used (e.g. by making the pointer
40 * point to an offset within the flat device tree in the case of an offset) but
41 * this increases code size slightly due to the subtraction. Since it offers no
42 * real benefit, the approach described here seems best.
44 * For now these points use constant types, since we don't allow writing
47 * @np: Pointer to device node, used for live tree
48 * @of_offset: Pointer into flat device tree, used for flat tree. Note that this
49 * is not a really a pointer to a node: it is an offset value. See above.
51 typedef union ofnode_union {
52 const struct device_node *np;
56 struct ofnode_phandle_args {
59 uint32_t args[OF_MAX_PHANDLE_ARGS];
63 * ofprop - reference to a property of a device tree node
65 * This struct hold the reference on one property of one node,
66 * using struct ofnode and an offset within the flat device tree or either
67 * a pointer to a struct property in the live device tree.
69 * Thus we can reference arguments in both the live tree and the flat tree.
71 * The property reference can also hold a null reference. This corresponds to
72 * a struct property NULL pointer or an offset of -1.
74 * @node: Pointer to device node
75 * @offset: Pointer into flat device tree, used for flat tree.
76 * @prop: Pointer to property, used for live treee.
83 const struct property *prop;
88 * ofnode_to_np() - convert an ofnode to a live DT node pointer
90 * This cannot be called if the reference contains an offset.
92 * @node: Reference containing struct device_node * (possibly invalid)
93 * @return pointer to device node (can be NULL)
95 static inline const struct device_node *ofnode_to_np(ofnode node)
98 if (!of_live_active())
105 * ofnode_to_offset() - convert an ofnode to a flat DT offset
107 * This cannot be called if the reference contains a node pointer.
109 * @node: Reference containing offset (possibly invalid)
110 * @return DT offset (can be -1)
112 static inline int ofnode_to_offset(ofnode node)
115 if (of_live_active())
118 return node.of_offset;
122 * ofnode_valid() - check if an ofnode is valid
124 * @return true if the reference contains a valid ofnode, false if it is NULL
126 static inline bool ofnode_valid(ofnode node)
128 if (of_live_active())
129 return node.np != NULL;
131 return node.of_offset >= 0;
135 * offset_to_ofnode() - convert a DT offset to an ofnode
137 * @of_offset: DT offset (either valid, or -1)
138 * @return reference to the associated DT offset
140 static inline ofnode offset_to_ofnode(int of_offset)
144 if (of_live_active())
147 node.of_offset = of_offset >= 0 ? of_offset : -1;
153 * np_to_ofnode() - convert a node pointer to an ofnode
155 * @np: Live node pointer (can be NULL)
156 * @return reference to the associated node pointer
158 static inline ofnode np_to_ofnode(const struct device_node *np)
168 * ofnode_is_np() - check if a reference is a node pointer
170 * This function associated that if there is a valid live tree then all
171 * references will use it. This is because using the flat DT when the live tree
172 * is valid is not permitted.
174 * @node: reference to check (possibly invalid)
175 * @return true if the reference is a live node pointer, false if it is a DT
178 static inline bool ofnode_is_np(ofnode node)
182 * Check our assumption that flat tree offsets are not used when a
183 * live tree is in use.
185 assert(!ofnode_valid(node) ||
186 (of_live_active() ? ofnode_to_np(node)
187 : ofnode_to_np(node)));
189 return of_live_active() && ofnode_valid(node);
193 * ofnode_equal() - check if two references are equal
195 * @return true if equal, else false
197 static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
199 /* We only need to compare the contents */
200 return ref1.of_offset == ref2.of_offset;
204 * ofnode_null() - Obtain a null ofnode
206 * This returns an ofnode which points to no node. It works both with the flat
209 static inline ofnode ofnode_null(void)
213 if (of_live_active())
222 * ofnode_read_u32() - Read a 32-bit integer from a property
224 * @ref: valid node reference to read property from
225 * @propname: name of the property to read from
226 * @outp: place to put value (if found)
227 * @return 0 if OK, -ve on error
229 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
232 * ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
234 * @ref: valid node reference to read property from
235 * @propname: name of the property to read from
236 * @index: index of the integer to return
237 * @outp: place to put value (if found)
238 * @return 0 if OK, -ve on error
240 int ofnode_read_u32_index(ofnode node, const char *propname, int index,
244 * ofnode_read_s32() - Read a 32-bit integer from a property
246 * @ref: valid node reference to read property from
247 * @propname: name of the property to read from
248 * @outp: place to put value (if found)
249 * @return 0 if OK, -ve on error
251 static inline int ofnode_read_s32(ofnode node, const char *propname,
254 return ofnode_read_u32(node, propname, (u32 *)out_value);
258 * ofnode_read_u32_default() - Read a 32-bit integer from a property
260 * @ref: valid node reference to read property from
261 * @propname: name of the property to read from
262 * @def: default value to return if the property has no value
263 * @return property value, or @def if not found
265 u32 ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
268 * ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
271 * @ref: valid node reference to read property from
272 * @propname: name of the property to read from
273 * @index: index of the integer to return
274 * @def: default value to return if the property has no value
275 * @return property value, or @def if not found
277 u32 ofnode_read_u32_index_default(ofnode ref, const char *propname, int index,
281 * ofnode_read_s32_default() - Read a 32-bit integer from a property
283 * @ref: valid node reference to read property from
284 * @propname: name of the property to read from
285 * @def: default value to return if the property has no value
286 * @return property value, or @def if not found
288 int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
291 * ofnode_read_u64() - Read a 64-bit integer from a property
293 * @node: valid node reference to read property from
294 * @propname: name of the property to read from
295 * @outp: place to put value (if found)
296 * @return 0 if OK, -ve on error
298 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
301 * ofnode_read_u64_default() - Read a 64-bit integer from a property
303 * @ref: valid node reference to read property from
304 * @propname: name of the property to read from
305 * @def: default value to return if the property has no value
306 * @return property value, or @def if not found
308 u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
311 * ofnode_read_prop() - Read a property from a node
313 * @node: valid node reference to read property from
314 * @propname: name of the property to read
315 * @sizep: if non-NULL, returns the size of the property, or an error code
317 * @return property value, or NULL if there is no such property
319 const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
322 * ofnode_read_string() - Read a string from a property
324 * @node: valid node reference to read property from
325 * @propname: name of the property to read
326 * @return string from property value, or NULL if there is no such property
328 const char *ofnode_read_string(ofnode node, const char *propname);
331 * ofnode_read_u32_array() - Find and read an array of 32 bit integers
333 * @node: valid node reference to read property from
334 * @propname: name of the property to read
335 * @out_values: pointer to return value, modified only if return value is 0
336 * @sz: number of array elements to read
337 * @return 0 if OK, -ve on error
339 * Search for a property in a device node and read 32-bit value(s) from
340 * it. Returns 0 on success, -EINVAL if the property does not exist,
341 * -ENODATA if property does not have a value, and -EOVERFLOW if the
342 * property data isn't large enough.
344 * The out_values is modified only if a valid u32 value can be decoded.
346 int ofnode_read_u32_array(ofnode node, const char *propname,
347 u32 *out_values, size_t sz);
350 * ofnode_read_bool() - read a boolean value from a property
352 * @node: valid node reference to read property from
353 * @propname: name of property to read
354 * @return true if property is present (meaning true), false if not present
356 bool ofnode_read_bool(ofnode node, const char *propname);
359 * ofnode_find_subnode() - find a named subnode of a parent node
361 * @node: valid reference to parent node
362 * @subnode_name: name of subnode to find
363 * @return reference to subnode (which can be invalid if there is no such
366 ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
369 * ofnode_first_subnode() - find the first subnode of a parent node
371 * @node: valid reference to a valid parent node
372 * @return reference to the first subnode (which can be invalid if the parent
373 * node has no subnodes)
375 ofnode ofnode_first_subnode(ofnode node);
378 * ofnode_next_subnode() - find the next sibling of a subnode
380 * @node: valid reference to previous node (sibling)
381 * @return reference to the next subnode (which can be invalid if the node
382 * has no more siblings)
384 ofnode ofnode_next_subnode(ofnode node);
387 * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
389 * @node: valid node to look up
390 * @return ofnode reference of the parent node
392 ofnode ofnode_get_parent(ofnode node);
395 * ofnode_get_name() - get the name of a node
397 * @node: valid node to look up
398 * @return name of node
400 const char *ofnode_get_name(ofnode node);
403 * ofnode_get_by_phandle() - get ofnode from phandle
405 * @phandle: phandle to look up
406 * @return ofnode reference to the phandle
408 ofnode ofnode_get_by_phandle(uint phandle);
411 * ofnode_read_size() - read the size of a property
413 * @node: node to check
414 * @propname: property to check
415 * @return size of property if present, or -EINVAL if not
417 int ofnode_read_size(ofnode node, const char *propname);
420 * ofnode_get_addr_size_index() - get an address/size from a node
423 * This reads the register address/size from a node based on index
425 * @node: node to read from
426 * @index: Index of address to read (0 for first)
427 * @size: Pointer to size of the address
428 * @return address, or FDT_ADDR_T_NONE if not present or invalid
430 phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
434 * ofnode_get_addr_index() - get an address from a node
436 * This reads the register address from a node
438 * @node: node to read from
439 * @index: Index of address to read (0 for first)
440 * @return address, or FDT_ADDR_T_NONE if not present or invalid
442 phys_addr_t ofnode_get_addr_index(ofnode node, int index);
445 * ofnode_get_addr() - get an address from a node
447 * This reads the register address from a node
449 * @node: node to read from
450 * @return address, or FDT_ADDR_T_NONE if not present or invalid
452 phys_addr_t ofnode_get_addr(ofnode node);
455 * ofnode_stringlist_search() - find a string in a string list and return index
457 * Note that it is possible for this function to succeed on property values
458 * that are not NUL-terminated. That's because the function will stop after
459 * finding the first occurrence of @string. This can for example happen with
460 * small-valued cell properties, such as #address-cells, when searching for
463 * @node: node to check
464 * @propname: name of the property containing the string list
465 * @string: string to look up in the string list
468 * the index of the string in the list of strings
469 * -ENODATA if the property is not found
470 * -EINVAL on some other error
472 int ofnode_stringlist_search(ofnode node, const char *propname,
476 * ofnode_read_string_index() - obtain an indexed string from a string list
478 * Note that this will successfully extract strings from properties with
479 * non-NUL-terminated values. For example on small-valued cell properties
480 * this function will return the empty string.
482 * If non-NULL, the length of the string (on success) or a negative error-code
483 * (on failure) will be stored in the integer pointer to by lenp.
485 * @node: node to check
486 * @propname: name of the property containing the string list
487 * @index: index of the string to return
488 * @lenp: return location for the string length or an error code on failure
491 * length of string, if found or -ve error value if not found
493 int ofnode_read_string_index(ofnode node, const char *propname, int index,
497 * ofnode_read_string_count() - find the number of strings in a string list
499 * @node: node to check
500 * @propname: name of the property containing the string list
502 * number of strings in the list, or -ve error value if not found
504 int ofnode_read_string_count(ofnode node, const char *property);
507 * ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
509 * This function is useful to parse lists of phandles and their arguments.
510 * Returns 0 on success and fills out_args, on error returns appropriate
513 * Caller is responsible to call of_node_put() on the returned out_args->np
527 * list = <&phandle1 1 2 &phandle2 3>;
530 * To get a device_node of the `node2' node you may call this:
531 * ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
533 * @node: device tree node containing a list
534 * @list_name: property name that contains a list
535 * @cells_name: property name that specifies phandles' arguments count
536 * @cells_count: Cell count to use if @cells_name is NULL
537 * @index: index of a phandle to parse out
538 * @out_args: optional pointer to output arguments structure (will be filled)
539 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
540 * @list_name does not exist, -EINVAL if a phandle was not found,
541 * @cells_name could not be found, the arguments were truncated or there
542 * were too many arguments.
544 int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
545 const char *cells_name, int cell_count,
547 struct ofnode_phandle_args *out_args);
550 * ofnode_count_phandle_with_args() - Count number of phandle in a list
552 * This function is useful to count phandles into a list.
553 * Returns number of phandle on success, on error returns appropriate
556 * @node: device tree node containing a list
557 * @list_name: property name that contains a list
558 * @cells_name: property name that specifies phandles' arguments count
559 * @cells_count: Cell count to use if @cells_name is NULL
560 * @return number of phandle on success, -ENOENT if @list_name does not
561 * exist, -EINVAL if a phandle was not found, @cells_name could not
564 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
565 const char *cells_name, int cell_count);
568 * ofnode_path() - find a node by full path
570 * @path: Full path to node, e.g. "/bus/spi@1"
571 * @return reference to the node found. Use ofnode_valid() to check if it exists
573 ofnode ofnode_path(const char *path);
576 * ofnode_read_chosen_prop() - get the value of a chosen property
578 * This looks for a property within the /chosen node and returns its value
580 * @propname: Property name to look for
581 * @sizep: Returns size of property, or FDT_ERR_... error code if function
583 * @return property value if found, else NULL
585 const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
588 * ofnode_read_chosen_string() - get the string value of a chosen property
590 * This looks for a property within the /chosen node and returns its value,
591 * checking that it is a valid nul-terminated string
593 * @propname: Property name to look for
594 * @return string value if found, else NULL
596 const char *ofnode_read_chosen_string(const char *propname);
599 * ofnode_get_chosen_node() - get a referenced node from the chosen node
601 * This looks up a named property in the chosen node and uses that as a path to
604 * @return the referenced node if present, else ofnode_null()
606 ofnode ofnode_get_chosen_node(const char *propname);
609 * ofnode_read_aliases_prop() - get the value of a aliases property
611 * This looks for a property within the /aliases node and returns its value
613 * @propname: Property name to look for
614 * @sizep: Returns size of property, or FDT_ERR_... error code if function
616 * @return property value if found, else NULL
618 const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
621 * ofnode_get_aliases_node() - get a referenced node from the aliases node
623 * This looks up a named property in the aliases node and uses that as a path to
626 * @return the referenced node if present, else ofnode_null()
628 ofnode ofnode_get_aliases_node(const char *propname);
630 struct display_timing;
632 * ofnode_decode_display_timing() - decode display timings
634 * Decode display timings from the supplied 'display-timings' node.
635 * See doc/device-tree-bindings/video/display-timing.txt for binding
638 * @node 'display-timing' node containing the timing subnodes
639 * @index Index number to read (0=first timing subnode)
640 * @config Place to put timings
641 * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
643 int ofnode_decode_display_timing(ofnode node, int index,
644 struct display_timing *config);
647 * ofnode_get_property() - get a pointer to the value of a node property
649 * @node: node to read
650 * @propname: property to read
651 * @lenp: place to put length on success
652 * @return pointer to property, or NULL if not found
654 const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
657 * ofnode_get_first_property()- get the reference of the first property
659 * Get reference to the first property of the node, it is used to iterate
660 * and read all the property with ofnode_get_property_by_prop().
662 * @node: node to read
663 * @prop: place to put argument reference
664 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
666 int ofnode_get_first_property(ofnode node, struct ofprop *prop);
669 * ofnode_get_next_property() - get the reference of the next property
671 * Get reference to the next property of the node, it is used to iterate
672 * and read all the property with ofnode_get_property_by_prop().
674 * @prop: reference of current argument and place to put reference of next one
675 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
677 int ofnode_get_next_property(struct ofprop *prop);
680 * ofnode_get_property_by_prop() - get a pointer to the value of a property
682 * Get value for the property identified by the provided reference.
684 * @prop: reference on property
685 * @propname: If non-NULL, place to property name on success,
686 * @lenp: If non-NULL, place to put length on success
687 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
689 const void *ofnode_get_property_by_prop(const struct ofprop *prop,
690 const char **propname, int *lenp);
693 * ofnode_is_available() - check if a node is marked available
695 * @node: node to check
696 * @return true if node's 'status' property is "okay" (or is missing)
698 bool ofnode_is_available(ofnode node);
701 * ofnode_get_addr_size() - get address and size from a property
703 * This does no address translation. It simply reads an property that contains
704 * an address and a size value, one after the other.
706 * @node: node to read from
707 * @propname: property to read
708 * @sizep: place to put size value (on success)
709 * @return address value, or FDT_ADDR_T_NONE on error
711 phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
715 * ofnode_read_u8_array_ptr() - find an 8-bit array
717 * Look up a property in a node and return a pointer to its contents as a
718 * byte array of given length. The property must have at least enough data
719 * for the array (count bytes). It may have more, but this will be ignored.
720 * The data is not copied.
722 * @node node to examine
723 * @propname name of property to find
724 * @sz number of array elements
725 * @return pointer to byte array if found, or NULL if the property is not
726 * found or there is not enough data
728 const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
732 * ofnode_read_pci_addr() - look up a PCI address
734 * Look at an address property in a node and return the PCI address which
735 * corresponds to the given type in the form of fdt_pci_addr.
736 * The property must hold one fdt_pci_addr with a lengh.
738 * @node node to examine
739 * @type pci address type (FDT_PCI_SPACE_xxx)
740 * @propname name of property to find
741 * @addr returns pci address in the form of fdt_pci_addr
742 * @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
743 * format of the property was invalid, -ENXIO if the requested
744 * address type was not found
746 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
747 const char *propname, struct fdt_pci_addr *addr);
750 * ofnode_read_pci_vendev() - look up PCI vendor and device id
752 * Look at the compatible property of a device node that represents a PCI
753 * device and extract pci vendor id and device id from it.
755 * @param node node to examine
756 * @param vendor vendor id of the pci device
757 * @param device device id of the pci device
758 * @return 0 if ok, negative on error
760 int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
763 * ofnode_read_addr_cells() - Get the number of address cells for a node
765 * This walks back up the tree to find the closest #address-cells property
766 * which controls the given node.
768 * @node: Node to check
769 * @return number of address cells this node uses
771 int ofnode_read_addr_cells(ofnode node);
774 * ofnode_read_size_cells() - Get the number of size cells for a node
776 * This walks back up the tree to find the closest #size-cells property
777 * which controls the given node.
779 * @node: Node to check
780 * @return number of size cells this node uses
782 int ofnode_read_size_cells(ofnode node);
785 * ofnode_read_simple_addr_cells() - Get the address cells property in a node
787 * This function matches fdt_address_cells().
789 * @np: Node pointer to check
790 * @return value of #address-cells property in this node, or 2 if none
792 int ofnode_read_simple_addr_cells(ofnode node);
795 * ofnode_read_simple_size_cells() - Get the size cells property in a node
797 * This function matches fdt_size_cells().
799 * @np: Node pointer to check
800 * @return value of #size-cells property in this node, or 2 if none
802 int ofnode_read_simple_size_cells(ofnode node);
805 * ofnode_pre_reloc() - check if a node should be bound before relocation
807 * Device tree nodes can be marked as needing-to-be-bound in the loader stages
808 * via special device tree properties.
810 * Before relocation this function can be used to check if nodes are required
811 * in either SPL or TPL stages.
813 * After relocation and jumping into the real U-Boot binary it is possible to
814 * determine if a node was bound in one of SPL/TPL stages.
816 * There are 4 settings currently in use
817 * - u-boot,dm-pre-proper: U-Boot proper pre-relocation only
818 * - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
819 * Existing platforms only use it to indicate nodes needed in
820 * SPL. Should probably be replaced by u-boot,dm-spl for
822 * - u-boot,dm-spl: SPL and U-Boot pre-relocation
823 * - u-boot,dm-tpl: TPL and U-Boot pre-relocation
825 * @node: node to check
826 * @return true if node is needed in SPL/TL, false otherwise
828 bool ofnode_pre_reloc(ofnode node);
831 * ofnode_read_resource() - Read a resource from a node
833 * Read resource information from a node at the given index
835 * @node: Node to read from
836 * @index: Index of resource to read (0 = first)
837 * @res: Returns resource that was read, on success
838 * @return 0 if OK, -ve on error
840 int ofnode_read_resource(ofnode node, uint index, struct resource *res);
843 * ofnode_read_resource_byname() - Read a resource from a node by name
845 * Read resource information from a node matching the given name. This uses a
846 * 'reg-names' string list property with the names matching the associated
847 * 'reg' property list.
849 * @node: Node to read from
850 * @name: Name of resource to read
851 * @res: Returns resource that was read, on success
852 * @return 0 if OK, -ve on error
854 int ofnode_read_resource_byname(ofnode node, const char *name,
855 struct resource *res);
858 * ofnode_by_compatible() - Find the next compatible node
860 * Find the next node after @from that is compatible with @compat
862 * @from: ofnode to start from (use ofnode_null() to start at the beginning)
863 * @compat: Compatible string to match
864 * @return ofnode found, or ofnode_null() if none
866 ofnode ofnode_by_compatible(ofnode from, const char *compat);
869 * ofnode_by_prop_value() - Find the next node with given property value
871 * Find the next node after @from that has a @propname with a value
872 * @propval and a length @proplen.
874 * @from: ofnode to start from (use ofnode_null() to start at the
875 * beginning) @propname: property name to check @propval: property value to
876 * search for @proplen: length of the value in propval @return ofnode
877 * found, or ofnode_null() if none
879 ofnode ofnode_by_prop_value(ofnode from, const char *propname,
880 const void *propval, int proplen);
883 * ofnode_for_each_subnode() - iterate over all subnodes of a parent
885 * @node: child node (ofnode, lvalue)
886 * @parent: parent node (ofnode)
888 * This is a wrapper around a for loop and is used like so:
892 * ofnode_for_each_subnode(node, parent) {
897 * Note that this is implemented as a macro and @node is used as
898 * iterator in the loop. The parent variable can be a constant or even a
901 #define ofnode_for_each_subnode(node, parent) \
902 for (node = ofnode_first_subnode(parent); \
903 ofnode_valid(node); \
904 node = ofnode_next_subnode(node))
907 * ofnode_get_child_count() - get the child count of a ofnode
909 * @node: valid node to get its child count
910 * @return the number of subnodes
912 int ofnode_get_child_count(ofnode parent);
915 * ofnode_translate_address() - Translate a device-tree address
917 * Translate an address from the device-tree into a CPU physical address. This
918 * function walks up the tree and applies the various bus mappings along the
921 * @ofnode: Device tree node giving the context in which to translate the
923 * @in_addr: pointer to the address to translate
924 * @return the translated address; OF_BAD_ADDR on error
926 u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
929 * ofnode_translate_dma_address() - Translate a device-tree DMA address
931 * Translate a DMA address from the device-tree into a CPU physical address.
932 * This function walks up the tree and applies the various bus mappings along
935 * @ofnode: Device tree node giving the context in which to translate the
937 * @in_addr: pointer to the DMA address to translate
938 * @return the translated DMA address; OF_BAD_ADDR on error
940 u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
943 * ofnode_device_is_compatible() - check if the node is compatible with compat
945 * This allows to check whether the node is comaptible with the compat.
947 * @node: Device tree node for which compatible needs to be verified.
948 * @compat: Compatible string which needs to verified in the given node.
949 * @return true if OK, false if the compatible is not found
951 int ofnode_device_is_compatible(ofnode node, const char *compat);
954 * ofnode_write_prop() - Set a property of a ofnode
956 * Note that the value passed to the function is *not* allocated by the
957 * function itself, but must be allocated by the caller if necessary.
959 * @node: The node for whose property should be set
960 * @propname: The name of the property to set
961 * @len: The length of the new value of the property
962 * @value: The new value of the property (must be valid prior to calling
964 * @return 0 if successful, -ve on error
966 int ofnode_write_prop(ofnode node, const char *propname, int len,
970 * ofnode_write_string() - Set a string property of a ofnode
972 * Note that the value passed to the function is *not* allocated by the
973 * function itself, but must be allocated by the caller if necessary.
975 * @node: The node for whose string property should be set
976 * @propname: The name of the string property to set
977 * @value: The new value of the string property (must be valid prior to
978 * calling the function)
979 * @return 0 if successful, -ve on error
981 int ofnode_write_string(ofnode node, const char *propname, const char *value);
984 * ofnode_set_enabled() - Enable or disable a device tree node given by its
987 * This function effectively sets the node's "status" property to either "okay"
988 * or "disable", hence making it available for driver model initialization or
991 * @node: The node to enable
992 * @value: Flag that tells the function to either disable or enable the
994 * @return 0 if successful, -ve on error
996 int ofnode_set_enabled(ofnode node, bool value);