Skip to content
Snippets Groups Projects
Commit 3ddecfc7 authored by Simon Glass's avatar Simon Glass Committed by Albert ARIBAUD
Browse files

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: default avatarSimon Glass <sjg@chromium.org>
Signed-off-by: default avatarTom Warren <twarren@nvidia.com>
parent 96875e7d
No related branches found
No related tags found
No related merge requests found
...@@ -116,6 +116,23 @@ int fdtdec_next_alias(const void *blob, const char *name, ...@@ -116,6 +116,23 @@ int fdtdec_next_alias(const void *blob, const char *name,
int fdtdec_next_compatible(const void *blob, int node, int fdtdec_next_compatible(const void *blob, int node,
enum fdt_compat_id id); enum fdt_compat_id id);
/**
* Find the next compatible subnode for a peripheral.
*
* Do the first call with node set to the parent and depth = 0. This
* function will return the offset of the next compatible node. Next time
* you call this function, pass the node value returned last time, with
* depth unchanged, and the next node will be provided.
*
* @param blob FDT blob to use
* @param node Start node for search
* @param id Compatible ID to look for (enum fdt_compat_id)
* @param depthp Current depth (set to 0 before first call)
* @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
*/
int fdtdec_next_compatible_subnode(const void *blob, int node,
enum fdt_compat_id id, int *depthp);
/** /**
* Look up an address property in a node and return it as an address. * Look up an address property in a node and return it as an address.
* The property must hold either one address with no trailing data or * The property must hold either one address with no trailing data or
......
...@@ -133,6 +133,21 @@ int fdtdec_next_compatible(const void *blob, int node, ...@@ -133,6 +133,21 @@ int fdtdec_next_compatible(const void *blob, int node,
return fdt_node_offset_by_compatible(blob, node, compat_names[id]); return fdt_node_offset_by_compatible(blob, node, compat_names[id]);
} }
int fdtdec_next_compatible_subnode(const void *blob, int node,
enum fdt_compat_id id, int *depthp)
{
do {
node = fdt_next_node(blob, node, depthp);
} while (*depthp > 1);
/* If this is a direct subnode, and compatible, return it */
if (*depthp == 1 && 0 == fdt_node_check_compatible(
blob, node, compat_names[id]))
return node;
return -FDT_ERR_NOTFOUND;
}
int fdtdec_next_alias(const void *blob, const char *name, int fdtdec_next_alias(const void *blob, const char *name,
enum fdt_compat_id id, int *upto) enum fdt_compat_id id, int *upto)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment