diff options
author | Simon Glass <sjg@chromium.org> | 2017-05-18 20:09:01 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2017-06-01 07:03:07 -0600 |
commit | bed774969c0ba2ac6999b82953c0a0a708f3ad43 (patch) | |
tree | e9afe3fa2de5531daf25f020046c8131cb88a44e /drivers/core | |
parent | ec002119cf30a7e7ef721071d890a0d8248232da (diff) |
dm: core: Add address operations on device tree references
Add functions to add addresses in the device tree using ofnode references.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/ofnode.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index e6c9a28baef..ac312d65465 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -11,6 +11,7 @@ #include <fdt_support.h> #include <libfdt.h> #include <dm/of_access.h> +#include <dm/of_addr.h> #include <dm/ofnode.h> #include <linux/err.h> @@ -195,6 +196,32 @@ int ofnode_read_size(ofnode node, const char *propname) return -EINVAL; } +fdt_addr_t ofnode_get_addr_index(ofnode node, int index) +{ + if (ofnode_is_np(node)) { + const __be32 *prop_val; + uint flags; + u64 size; + + prop_val = of_get_address( + (struct device_node *)ofnode_to_np(node), index, + &size, &flags); + if (!prop_val) + return FDT_ADDR_T_NONE; + return be32_to_cpup(prop_val); + } else { + return fdt_get_base_address(gd->fdt_blob, + ofnode_to_offset(node)); + } + + return FDT_ADDR_T_NONE; +} + +fdt_addr_t ofnode_get_addr(ofnode node) +{ + return ofnode_get_addr_index(node, 0); +} + int ofnode_stringlist_search(ofnode node, const char *property, const char *string) { |