[PATCH 18/22] OF: base: import property iterators from Linux OF API

Sebastian Hesselbarth sebastian.hesselbarth at gmail.com
Tue Jun 18 13:30:03 EDT 2013


This imports of_prop_next_u32, of_prop_next_string, and the corresponding
for_property_for_each_ helpers from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   41 +++++++++++++++++++++++++++++++++++++++++
 include/of.h      |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4c6f2f4..489fa89 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -797,6 +797,47 @@ int of_property_count_strings(struct device_node *np, const char *propname)
 }
 EXPORT_SYMBOL_GPL(of_property_count_strings);
 
+const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
+			u32 *pu)
+{
+	const void *curv = cur;
+
+	if (!prop)
+		return NULL;
+
+	if (!cur) {
+		curv = prop->value;
+		goto out_val;
+	}
+
+	curv += sizeof(*cur);
+	if (curv >= prop->value + prop->length)
+		return NULL;
+
+out_val:
+	*pu = be32_to_cpup(curv);
+	return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_u32);
+
+const char *of_prop_next_string(struct property *prop, const char *cur)
+{
+	const void *curv = cur;
+
+	if (!prop)
+		return NULL;
+
+	if (!cur)
+		return prop->value;
+
+	curv += strlen(cur) + 1;
+	if (curv >= prop->value + prop->length)
+		return NULL;
+
+	return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_string);
+
 /**
  * of_property_write_bool - Create/Delete empty (bool) property.
  *
diff --git a/include/of.h b/include/of.h
index 53a135a..0306742 100644
--- a/include/of.h
+++ b/include/of.h
@@ -205,6 +205,10 @@ extern int of_property_match_string(struct device_node *np,
 extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 
+extern const __be32 *of_prop_next_u32(struct property *prop,
+				const __be32 *cur, u32 *pu);
+extern const char *of_prop_next_string(struct property *prop, const char *cur);
+
 extern int of_property_write_bool(struct device_node *np,
 				const char *propname, const bool value);
 extern int of_property_write_u8_array(struct device_node *np,
@@ -357,6 +361,18 @@ static inline int of_property_count_strings(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline const __be32 *of_prop_next_u32(struct property *prop,
+					const __be32 *cur, u32 *pu)
+{
+	return 0;
+}
+
+static inline const char *of_prop_next_string(struct property *prop,
+					const char *cur)
+{
+	return NULL;
+}
+
 static inline int of_property_write_bool(struct device_node *np,
 				const char *propname, const bool value)
 {
@@ -536,6 +552,33 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+/*
+ * struct property *prop;
+ * const __be32 *p;
+ * u32 u;
+ *
+ * of_property_for_each_u32(np, "propname", prop, p, u)
+ *         printk("U32 value: %x\n", u);
+ */
+#define of_property_for_each_u32(np, propname, prop, p, u)	\
+	for (prop = of_find_property(np, propname, NULL),	\
+		p = of_prop_next_u32(prop, NULL, &u);		\
+		p;						\
+		p = of_prop_next_u32(prop, p, &u))
+
+/*
+ * struct property *prop;
+ * const char *s;
+ *
+ * of_property_for_each_string(np, "propname", prop, s)
+ *         printk("String value: %s\n", s);
+ */
+#define of_property_for_each_string(np, propname, prop, s)	\
+	for (prop = of_find_property(np, propname, NULL),	\
+		s = of_prop_next_string(prop, NULL);		\
+		s;						\
+		s = of_prop_next_string(prop, s))
+
 static inline int of_property_write_u8(struct device_node *np,
 				       const char *propname, u8 value)
 {
-- 
1.7.2.5




More information about the barebox mailing list