diff mbox

[U-Boot,v3,11/72] dm: core: Add address operations on device tree references

Message ID 20170519021002.1098-12-sjg@chromium.org
State Accepted
Commit bed774969c0ba2ac6999b82953c0a0a708f3ad43
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass May 19, 2017, 2:09 a.m. UTC
Add functions to add addresses in the device tree using ofnode references.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/core/ofnode.c | 27 +++++++++++++++++++++++++++
 include/dm/ofnode.h   | 23 ++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

Comments

Simon Glass May 25, 2017, 12:07 a.m. UTC | #1
Add functions to add addresses in the device tree using ofnode references.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/core/ofnode.c | 27 +++++++++++++++++++++++++++
 include/dm/ofnode.h   | 23 ++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

Applied to u-boot-dm
diff mbox

Patch

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index e6c9a28bae..ac312d6546 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)
 {
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index e8b33c158d..149622a0b2 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -245,7 +245,7 @@  int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
 const char *ofnode_read_string(ofnode node, const char *propname);
 
 /**
- * ofnode_read_u32_array - Find and read an array of 32 bit integers
+ * ofnode_read_u32_array() - Find and read an array of 32 bit integers
  *
  * @node:	valid node reference to read property from
  * @propname:	name of the property to read
@@ -317,6 +317,27 @@  const char *ofnode_get_name(ofnode node);
 int ofnode_read_size(ofnode node, const char *propname);
 
 /**
+ * ofnode_get_addr_index() - get an address from a node
+ *
+ * This reads the register address from a node
+ *
+ * @node: node to read from
+ * @index: Index of address to read (0 for first)
+ * @return address, or FDT_ADDR_T_NONE if not present or invalid
+ */
+phys_addr_t ofnode_get_addr_index(ofnode node, int index);
+
+/**
+ * ofnode_get_addr() - get an address from a node
+ *
+ * This reads the register address from a node
+ *
+ * @node: node to read from
+ * @return address, or FDT_ADDR_T_NONE if not present or invalid
+ */
+phys_addr_t ofnode_get_addr(ofnode node);
+
+/**
  * ofnode_stringlist_search() - find a string in a string list and return index
  *
  * Note that it is possible for this function to succeed on property values