Commit 3ddecfc74086aa185a2f671cc07cb826b72d35f0

Authored by Simon Glass
Committed by Albert ARIBAUD
1 parent 96875e7d3b

fdt: Add function to return next compatible subnode

We need to iterate through subnodes of a parent, looking only at
compatible nodes. Add a utility function to do this for us.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Warren <twarren@nvidia.com>

Showing 2 changed files with 32 additions and 0 deletions Side-by-side Diff

... ... @@ -117,6 +117,23 @@
117 117 enum fdt_compat_id id);
118 118  
119 119 /**
  120 + * Find the next compatible subnode for a peripheral.
  121 + *
  122 + * Do the first call with node set to the parent and depth = 0. This
  123 + * function will return the offset of the next compatible node. Next time
  124 + * you call this function, pass the node value returned last time, with
  125 + * depth unchanged, and the next node will be provided.
  126 + *
  127 + * @param blob FDT blob to use
  128 + * @param node Start node for search
  129 + * @param id Compatible ID to look for (enum fdt_compat_id)
  130 + * @param depthp Current depth (set to 0 before first call)
  131 + * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
  132 + */
  133 +int fdtdec_next_compatible_subnode(const void *blob, int node,
  134 + enum fdt_compat_id id, int *depthp);
  135 +
  136 +/**
120 137 * Look up an address property in a node and return it as an address.
121 138 * The property must hold either one address with no trailing data or
122 139 * one address with a length. This is only tested on 32-bit machines.
... ... @@ -133,6 +133,21 @@
133 133 return fdt_node_offset_by_compatible(blob, node, compat_names[id]);
134 134 }
135 135  
  136 +int fdtdec_next_compatible_subnode(const void *blob, int node,
  137 + enum fdt_compat_id id, int *depthp)
  138 +{
  139 + do {
  140 + node = fdt_next_node(blob, node, depthp);
  141 + } while (*depthp > 1);
  142 +
  143 + /* If this is a direct subnode, and compatible, return it */
  144 + if (*depthp == 1 && 0 == fdt_node_check_compatible(
  145 + blob, node, compat_names[id]))
  146 + return node;
  147 +
  148 + return -FDT_ERR_NOTFOUND;
  149 +}
  150 +
136 151 int fdtdec_next_alias(const void *blob, const char *name,
137 152 enum fdt_compat_id id, int *upto)
138 153 {