lib/device_tree: Add method to get phandle

Add a method to retrieve a node's phandle.
Useful for board specific devicetree manipulations.

Change-Id: I966151ad7e82fc678ab4f56cf9b5868ef39398e0
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/26191
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Patrick Rudolph 2018-05-08 11:18:54 +02:00 committed by Patrick Georgi
parent 79d26c7a83
commit c38960d7f3
2 changed files with 24 additions and 0 deletions

View File

@ -147,6 +147,8 @@ struct device_tree_node *dt_find_next_compat_child(struct device_tree_node *pare
// Look up a node relative to a parent node, through its property value. // Look up a node relative to a parent node, through its property value.
struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent, const char *name, struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent, const char *name,
void *data, size_t size); void *data, size_t size);
// Return the phandle
uint32_t dt_get_phandle(struct device_tree_node *node);
// Write src into *dest as a 'length'-byte big-endian integer. // Write src into *dest as a 'length'-byte big-endian integer.
void dt_write_int(u8 *dest, u64 src, size_t length); void dt_write_int(u8 *dest, u64 src, size_t length);
// Add different kinds of properties to a node, or update existing ones. // Add different kinds of properties to a node, or update existing ones.

View File

@ -725,6 +725,28 @@ struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent,
return NULL; return NULL;
} }
/**
* Find the phandle of a node.
*
* @param node Pointer to node containing the phandle
* @return Zero on error, the phandle on success
*/
uint32_t dt_get_phandle(struct device_tree_node *node)
{
uint32_t *phandle;
size_t len;
dt_find_bin_prop(node, "phandle", (void **)&phandle, &len);
if (phandle != NULL && len == sizeof(*phandle))
return be32_to_cpu(*phandle);
dt_find_bin_prop(node, "linux,phandle", (void **)&phandle, &len);
if (phandle != NULL && len == sizeof(*phandle))
return be32_to_cpu(*phandle);
return 0;
}
/* /*
* Write an arbitrary sized big-endian integer into a pointer. * Write an arbitrary sized big-endian integer into a pointer.
* *