* [PATCH 01/22] lib: string: import case-insensitive string compare
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 02/22] OF: base: bail out early on missing matches for of_match_node Sebastian Hesselbarth
` (43 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports strnicmp, strcasecmp, and strncasecmp from Linux to barebox.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
include/linux/string.h | 9 +++++++
lib/string.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index afd0aa6..658264c 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -53,6 +53,15 @@ extern int strcmp(const char *,const char *);
#ifndef __HAVE_ARCH_STRNCMP
extern int strncmp(const char *,const char *,__kernel_size_t);
#endif
+#ifndef __HAVE_ARCH_STRNICMP
+extern int strnicmp(const char *, const char *, __kernel_size_t);
+#endif
+#ifndef __HAVE_ARCH_STRCASECMP
+extern int strcasecmp(const char *s1, const char *s2);
+#endif
+#ifndef __HAVE_ARCH_STRNCASECMP
+extern int strncasecmp(const char *s1, const char *s2, size_t n);
+#endif
#ifndef __HAVE_ARCH_STRCHR
extern char * _strchr(const char *,int);
#endif
diff --git a/lib/string.c b/lib/string.c
index db4f2ae..f544b23 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -22,6 +22,66 @@
char * ___strtok;
+#ifndef __HAVE_ARCH_STRNICMP
+/**
+ * strnicmp - Case insensitive, length-limited string comparison
+ * @s1: One string
+ * @s2: The other string
+ * @len: the maximum number of characters to compare
+ */
+int strnicmp(const char *s1, const char *s2, size_t len)
+{
+ /* Yes, Virginia, it had better be unsigned */
+ unsigned char c1, c2;
+
+ if (!len)
+ return 0;
+
+ do {
+ c1 = *s1++;
+ c2 = *s2++;
+ if (!c1 || !c2)
+ break;
+ if (c1 == c2)
+ continue;
+ c1 = tolower(c1);
+ c2 = tolower(c2);
+ if (c1 != c2)
+ break;
+ } while (--len);
+ return (int)c1 - (int)c2;
+}
+EXPORT_SYMBOL(strnicmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRCASECMP
+int strcasecmp(const char *s1, const char *s2)
+{
+ int c1, c2;
+
+ do {
+ c1 = tolower(*s1++);
+ c2 = tolower(*s2++);
+ } while (c1 == c2 && c1 != 0);
+ return c1 - c2;
+}
+EXPORT_SYMBOL(strcasecmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRNCASECMP
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ int c1, c2;
+
+ do {
+ c1 = tolower(*s1++);
+ c2 = tolower(*s2++);
+ } while ((--n > 0) && c1 == c2 && c1 != 0);
+ return c1 - c2;
+}
+EXPORT_SYMBOL(strncasecmp);
+#endif
+
#ifndef __HAVE_ARCH_STRCPY
/**
* strcpy - Copy a %NUL terminated string
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 02/22] OF: base: bail out early on missing matches for of_match_node
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 01/22] lib: string: import case-insensitive string compare Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 03/22] OF: base: also update property length on of_property_write_u32 Sebastian Hesselbarth
` (42 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
of_match_node checks for compatiblity between a set of matches and a
node. Neither the matches nor node pointer are checked for validity.
This adds the required checks to of_match_node.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4241e65..ab0f4cd 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -321,6 +321,9 @@ EXPORT_SYMBOL(of_device_is_compatible);
const struct of_device_id *of_match_node(const struct of_device_id *matches,
const struct device_node *node)
{
+ if (!matches || !node)
+ return NULL;
+
while (matches->compatible) {
if (of_device_is_compatible(node, matches->compatible) == 1)
return matches;
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 03/22] OF: base: also update property length on of_property_write_u32
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 01/22] lib: string: import case-insensitive string compare Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 02/22] OF: base: bail out early on missing matches for of_match_node Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 04/22] OF: base: export of_alias_scan Sebastian Hesselbarth
` (41 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Current implementation of of_property_write_u32 does free old property
values and allocates new values depending on the size passed. While
copying the new values to the property, corresponding length is not
set. This makes of_property_write_u32 set the length of the new property
values and also adds a API header describing the function.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ab0f4cd..616b93d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -383,6 +383,21 @@ int of_property_read_u32_array(const struct device_node *np,
}
EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+/**
+ * of_property_write_u32_array - Write an array of u32 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write 32-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
int of_property_write_u32_array(struct device_node *np,
const char *propname, const u32 *values,
size_t sz)
@@ -397,14 +412,15 @@ int of_property_write_u32_array(struct device_node *np,
free(prop->value);
- prop->value = malloc(sizeof(__be32) * sz);
+ prop->length = sizeof(*val) * sz;
+ prop->value = malloc(prop->length);
if (!prop->value)
return -ENOMEM;
val = prop->value;
-
while (sz--)
*val++ = cpu_to_be32(*values++);
+
return 0;
}
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 04/22] OF: base: export of_alias_scan
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (2 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 03/22] OF: base: also update property length on of_property_write_u32 Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 05/22] OF: base: convert strcmp to default string compare functions Sebastian Hesselbarth
` (40 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
To prepare clean-up of OF API, we need to export of_alias_scan.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 3 ++-
include/of.h | 31 ++++++++++++++++++-------------
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 616b93d..f3ed836 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -135,7 +135,7 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
* the global lookup table with the properties. It returns the
* number of alias_prop found, or error code in error case.
*/
-static void of_alias_scan(void)
+void of_alias_scan(void)
{
struct property *pp;
struct alias_prop *app, *tmp;
@@ -187,6 +187,7 @@ static void of_alias_scan(void)
of_alias_add(ap, np, id, start, len);
}
}
+EXPORT_SYMBOL(of_alias_scan);
/**
* of_alias_get_id - Get alias id for the given device_node
diff --git a/include/of.h b/include/of.h
index 300b706..8a69793 100644
--- a/include/of.h
+++ b/include/of.h
@@ -178,10 +178,11 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
struct cdev;
#ifdef CONFIG_OFTREE
-int of_parse_partitions(struct cdev *cdev, struct device_node *node);
+extern void of_alias_scan(void);
+extern int of_alias_get_id(struct device_node *np, const char *stem);
+extern const char *of_alias_get(struct device_node *np);
-int of_alias_get_id(struct device_node *np, const char *stem);
-const char *of_alias_get(struct device_node *np);
+int of_parse_partitions(struct cdev *cdev, struct device_node *node);
int of_device_is_stdout_path(struct device_d *dev);
const char *of_get_model(void);
void *of_flatten_dtb(struct device_node *node);
@@ -196,16 +197,6 @@ static inline int of_parse_partitions(struct cdev *cdev,
return -EINVAL;
}
-static inline int of_alias_get_id(struct device_node *np, const char *stem)
-{
- return -ENOENT;
-}
-
-static inline const char *of_alias_get(struct device_node *np)
-{
- return NULL;
-}
-
static inline int of_device_is_stdout_path(struct device_d *dev)
{
return 0;
@@ -230,6 +221,20 @@ static inline struct device_node *of_get_root_node(void)
{
return NULL;
}
+
+static inline void of_alias_scan(void)
+{
+}
+
+static inline int of_alias_get_id(struct device_node *np, const char *stem)
+{
+ return -ENOSYS;
+}
+
+static inline const char *of_alias_get(struct device_node *np)
+{
+ return NULL;
+}
#endif
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 05/22] OF: base: convert strcmp to default string compare functions
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (3 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 04/22] OF: base: export of_alias_scan Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 06/22] OF: base: sync of_find_property with linux OF API Sebastian Hesselbarth
` (39 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Barebox compares compatible, node names, and property names with strcmp.
Linux by default compares compatible and node names with strcasecmp. To
avoid inconsitencies between Barebox and Linux dts files, we convert to
these default string compare functions.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 25 +++++++++++++------------
include/of.h | 5 +++++
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index f3ed836..1c9ef58 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -104,14 +104,15 @@ static void of_bus_count_cells(struct device_node *dev,
struct property *of_find_property(const struct device_node *node, const char *name)
{
- struct property *p;
+ struct property *pp;
if (!node)
return NULL;
- list_for_each_entry(p, &node->properties, list)
- if (!strcmp(p->name, name))
- return p;
+ list_for_each_entry(pp, &node->properties, list)
+ if (of_prop_cmp(pp->name, name) == 0)
+ return pp;
+
return NULL;
}
EXPORT_SYMBOL(of_find_property);
@@ -160,9 +161,9 @@ void of_alias_scan(void)
int id, len;
/* Skip those we do not want to proceed */
- if (!strcmp(pp->name, "name") ||
- !strcmp(pp->name, "phandle") ||
- !strcmp(pp->name, "linux,phandle"))
+ if (!of_prop_cmp(pp->name, "name") ||
+ !of_prop_cmp(pp->name, "phandle") ||
+ !of_prop_cmp(pp->name, "linux,phandle"))
continue;
np = of_find_node_by_path(root_node, pp->value);
@@ -203,7 +204,7 @@ int of_alias_get_id(struct device_node *np, const char *stem)
int id = -ENODEV;
list_for_each_entry(app, &aliases_lookup, link) {
- if (strcmp(app->stem, stem) != 0)
+ if (of_node_cmp(app->stem, stem) != 0)
continue;
if (np == app->np) {
@@ -221,7 +222,7 @@ const char *of_alias_get(struct device_node *np)
struct property *pp;
list_for_each_entry(pp, &of_aliases->properties, list) {
- if (!strcmp(np->full_name, pp->value))
+ if (!of_node_cmp(np->full_name, pp->value))
return pp->name;
}
@@ -301,7 +302,7 @@ int of_device_is_compatible(const struct device_node *device,
if (cp == NULL)
return 0;
while (cplen > 0) {
- if (strcmp(cp, compat) == 0)
+ if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
return 1;
l = strlen(cp) + 1;
cp += l;
@@ -958,7 +959,7 @@ int of_add_memory(struct device_node *node, bool dump)
if (ret)
return -ENXIO;
- if (strcmp(device_type, "memory"))
+ if (of_node_cmp(device_type, "memory"))
return -ENXIO;
of_bus_count_cells(node, &na, &nc);
@@ -1177,7 +1178,7 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
struct device_node *_n;
device_node_for_nach_child(node, _n)
- if (!strcmp(_n->name, name))
+ if (!of_node_cmp(_n->name, name))
return _n;
return NULL;
diff --git a/include/of.h b/include/of.h
index 8a69793..a91a4c9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -5,6 +5,11 @@
#include <errno.h>
#include <asm/byteorder.h>
+/* Default string compare functions */
+#define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
+#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
+#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
+
#define OF_BAD_ADDR ((u64)-1)
typedef u32 phandle;
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 06/22] OF: base: sync of_find_property with linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (4 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 05/22] OF: base: convert strcmp to default string compare functions Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 07/22] OF: base: sync of_find_node_by_path " Sebastian Hesselbarth
` (38 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
To start synchronizing OF API of barebox with linux OF API, this adds
a length pointer to of_find_property. Also all current users of that
function are updated to reflect the API change.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
commands/of_property.c | 2 +-
drivers/of/base.c | 38 ++++++++++++++++++--------------------
drivers/of/fdt.c | 5 ++++-
drivers/of/of_net.c | 6 +++---
drivers/pinctrl/pinctrl.c | 4 ++--
drivers/spi/spi.c | 10 +++++-----
drivers/usb/imx/chipidea-imx.c | 3 ++-
include/of.h | 12 ++++++++++--
8 files changed, 45 insertions(+), 35 deletions(-)
diff --git a/commands/of_property.c b/commands/of_property.c
index 44bb388..d1a9a17 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -212,7 +212,7 @@ static int do_of_property(int argc, char *argv[])
if (optind + 1 < argc) {
propname = argv[optind + 1];
- pp = of_find_property(node, propname);
+ pp = of_find_property(node, propname, NULL);
if (!set && !pp) {
printf("Cannot find property %s\n", propname);
return -ENOENT;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1c9ef58..85199b6 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -102,16 +102,20 @@ static void of_bus_count_cells(struct device_node *dev,
of_bus_default_count_cells(dev, addrc, sizec);
}
-struct property *of_find_property(const struct device_node *node, const char *name)
+struct property *of_find_property(const struct device_node *np,
+ const char *name, int *lenp)
{
struct property *pp;
- if (!node)
+ if (!np)
return NULL;
- list_for_each_entry(pp, &node->properties, list)
- if (of_prop_cmp(pp->name, name) == 0)
+ list_for_each_entry(pp, &np->properties, list)
+ if (of_prop_cmp(pp->name, name) == 0) {
+ if (lenp)
+ *lenp = pp->length;
return pp;
+ }
return NULL;
}
@@ -242,7 +246,7 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
return addr;
node = node->parent;
- p = of_find_property(node, "ranges");
+ p = of_find_property(node, "ranges", NULL);
if (!p && node->parent)
return OF_BAD_ADDR;
of_bus_count_cells(node, &na, &nc);
@@ -277,13 +281,7 @@ EXPORT_SYMBOL(of_find_node_by_phandle);
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp)
{
- struct property *pp = of_find_property(np, name);
-
- if (!pp)
- return NULL;
-
- if (lenp)
- *lenp = pp->length;
+ struct property *pp = of_find_property(np, name, lenp);
return pp ? pp->value : NULL;
}
@@ -368,7 +366,7 @@ int of_property_read_u32_array(const struct device_node *np,
const char *propname, u32 *out_values,
size_t sz)
{
- struct property *prop = of_find_property(np, propname);
+ struct property *prop = of_find_property(np, propname, NULL);
const __be32 *val;
if (!prop)
@@ -404,7 +402,7 @@ int of_property_write_u32_array(struct device_node *np,
const char *propname, const u32 *values,
size_t sz)
{
- struct property *prop = of_find_property(np, propname);
+ struct property *prop = of_find_property(np, propname, NULL);
__be32 *val;
if (!prop)
@@ -619,7 +617,7 @@ EXPORT_SYMBOL(of_find_node_by_path);
int of_property_read_string(struct device_node *np, const char *propname,
const char **out_string)
{
- struct property *prop = of_find_property(np, propname);
+ struct property *prop = of_find_property(np, propname, NULL);
if (!prop)
return -EINVAL;
if (!prop->value)
@@ -652,7 +650,7 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
int of_property_read_string_index(struct device_node *np, const char *propname,
int index, const char **output)
{
- struct property *prop = of_find_property(np, propname);
+ struct property *prop = of_find_property(np, propname, NULL);
int i = 0;
size_t l = 0, total = 0;
const char *p;
@@ -725,7 +723,7 @@ static int of_node_disabled(struct device_node *node)
{
struct property *p;
- p = of_find_property(node, "status");
+ p = of_find_property(node, "status", NULL);
if (p) {
if (!strcmp("disabled", p->value))
return 1;
@@ -833,7 +831,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
if (!np)
return -ENOENT;
- pp = of_find_property(np, name);
+ pp = of_find_property(np, name, NULL);
if (pp) {
void *data;
@@ -1278,11 +1276,11 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
} else {
struct property *pp;
- pp = of_find_property(chosen, "linux,initrd-start");
+ pp = of_find_property(chosen, "linux,initrd-start", NULL);
if (pp)
of_delete_property(pp);
- pp = of_find_property(chosen, "linux,initrd-end");
+ pp = of_find_property(chosen, "linux,initrd-end", NULL);
if (pp)
of_delete_property(pp);
}
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a3ec576..a76396e 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -178,7 +178,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
goto err;
}
- if (merge && (p = of_find_property(node, name))) {
+ p = NULL;
+ if (merge)
+ p = of_find_property(node, name, NULL);
+ if (merge && p) {
free(p->value);
p->value = xzalloc(len);
memcpy(p->value, nodep, len);
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index de93fbc..2bf05e2 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -76,15 +76,15 @@ const void *of_get_mac_address(struct device_node *np)
{
struct property *pp;
- pp = of_find_property(np, "mac-address");
+ pp = of_find_property(np, "mac-address", NULL);
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
return pp->value;
- pp = of_find_property(np, "local-mac-address");
+ pp = of_find_property(np, "local-mac-address", NULL);
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
return pp->value;
- pp = of_find_property(np, "address");
+ pp = of_find_property(np, "address", NULL);
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
return pp->value;
diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index fa979a1..7c797d3 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -64,14 +64,14 @@ int pinctrl_select_state(struct device_d *dev, const char *name)
if (!np)
return 0;
- if (!of_find_property(np, "pinctrl-0"))
+ if (!of_find_property(np, "pinctrl-0", NULL))
return 0;
/* For each defined state ID */
for (state = 0; ; state++) {
/* Retrieve the pinctrl-* property */
propname = asprintf("pinctrl-%d", state);
- prop = of_find_property(np, propname);
+ prop = of_find_property(np, propname, NULL);
free(propname);
if (!prop) {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index f460a7a..eebf64c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -112,17 +112,17 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
chip.name = xstrdup(n->name);
chip.bus_num = master->bus_num;
/* Mode (clock phase/polarity/etc.) */
- if (of_find_property(n, "spi-cpha"))
+ if (of_find_property(n, "spi-cpha", NULL))
chip.mode |= SPI_CPHA;
- if (of_find_property(n, "spi-cpol"))
+ if (of_find_property(n, "spi-cpol", NULL))
chip.mode |= SPI_CPOL;
- if (of_find_property(n, "spi-cs-high"))
+ if (of_find_property(n, "spi-cs-high", NULL))
chip.mode |= SPI_CS_HIGH;
- if (of_find_property(n, "spi-3wire"))
+ if (of_find_property(n, "spi-3wire", NULL))
chip.mode |= SPI_3WIRE;
of_property_read_u32(n, "spi-max-frequency",
&chip.max_speed_hz);
- reg = of_find_property(n, "reg");
+ reg = of_find_property(n, "reg", NULL);
if (!reg)
continue;
chip.chip_select = of_read_number(reg->value, 1);
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 4ee7610..32b05aa 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -108,7 +108,8 @@ static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
return -EINVAL;
}
- if (of_find_property(ci->dev->device_node, "disable-over-current"))
+ if (of_find_property(ci->dev->device_node,
+ "disable-over-current"), NULL)
ci->flags |= MXC_EHCI_DISABLE_OVERCURRENT;
return 0;
diff --git a/include/of.h b/include/of.h
index a91a4c9..7ebde62 100644
--- a/include/of.h
+++ b/include/of.h
@@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
int of_n_addr_cells(struct device_node *np);
int of_n_size_cells(struct device_node *np);
-struct property *of_find_property(const struct device_node *node, const char *name);
-
struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
@@ -183,6 +181,9 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
struct cdev;
#ifdef CONFIG_OFTREE
+extern struct property *of_find_property(const struct device_node *np,
+ const char *name, int *lenp);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -227,6 +228,13 @@ static inline struct device_node *of_get_root_node(void)
return NULL;
}
+static inline struct property *of_find_property(const struct device_node *np,
+ const char *name,
+ int *lenp)
+{
+ return NULL;
+}
+
static inline void of_alias_scan(void)
{
}
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 07/22] OF: base: sync of_find_node_by_path with linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (5 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 06/22] OF: base: sync of_find_property with linux OF API Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 20:13 ` Sascha Hauer
2013-06-18 17:29 ` [PATCH 08/22] OF: base: rename of_node_disabled to of_device_is_available Sebastian Hesselbarth
` (37 subsequent siblings)
44 siblings, 1 reply; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Barebox of_find_node_by_path requires a node to be passed as start node
to start searching. Linux OF API does not pass this node and no current
user of it in barebox is passing anything else than the root node.
Therefore, the device_node argument is removed and all current users of
that function are updated to reflect the API change.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
arch/arm/boards/highbank/init.c | 4 ++--
arch/ppc/mach-mpc5xxx/cpu.c | 4 ++--
commands/of_node.c | 2 +-
commands/of_property.c | 10 ++--------
commands/oftree.c | 11 +----------
common/oftree.c | 2 +-
drivers/of/base.c | 22 ++++++++++------------
include/of.h | 9 +++++++--
net/eth.c | 2 +-
9 files changed, 27 insertions(+), 39 deletions(-)
diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index d4a5c5a..1aa713b 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -53,7 +53,7 @@ static int hb_fixup(struct device_node *root)
if ((opp_table[0] >> 16) != HB_OPP_VERSION)
return 0;
- node = of_find_node_by_path(root, "/cpus/cpu@0");
+ node = of_find_node_by_path("/cpus/cpu@0");
if (!node)
return 0;
@@ -89,7 +89,7 @@ static int highbank_mem_init(void)
of_set_root_node(root);
- np = of_find_node_by_path(root, "/memory");
+ np = of_find_node_by_path("/memory");
if (!np) {
pr_warn("no memory node use default configuration\n");
goto not_found;
diff --git a/arch/ppc/mach-mpc5xxx/cpu.c b/arch/ppc/mach-mpc5xxx/cpu.c
index 99f16eb..0ece4a9 100644
--- a/arch/ppc/mach-mpc5xxx/cpu.c
+++ b/arch/ppc/mach-mpc5xxx/cpu.c
@@ -83,7 +83,7 @@ static int of_mpc5200_fixup(struct device_node *root)
int div = in_8((void*)CFG_MBAR + 0x204) & 0x0020 ? 8 : 4;
- node = of_find_node_by_path(root, "/cpus/PowerPC,5200@0");
+ node = of_find_node_by_path("/cpus/PowerPC,5200@0");
if (!node)
return -EINVAL;
@@ -91,7 +91,7 @@ static int of_mpc5200_fixup(struct device_node *root)
of_property_write_u32(node, "bus-frequency", get_bus_clock());
of_property_write_u32(node, "clock-frequency", get_cpu_clock());
- node = of_find_node_by_path(root, "/soc5200@f0000000");
+ node = of_find_node_by_path("/soc5200@f0000000");
if (!node)
return -EINVAL;
diff --git a/commands/of_node.c b/commands/of_node.c
index 0249d97..e60ef66 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -81,7 +81,7 @@ static int do_of_node(int argc, char *argv[])
if (!path)
return COMMAND_ERROR_USAGE;
- node = of_find_node_by_path(root, path);
+ node = of_find_node_by_path(path);
if (!node) {
printf("Cannot find nodepath %s\n", path);
return -ENOENT;
diff --git a/commands/of_property.c b/commands/of_property.c
index d1a9a17..8ffe30b 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -175,7 +175,7 @@ static int do_of_property(int argc, char *argv[])
int set = 0;
int ret;
char *path = NULL, *propname = NULL;
- struct device_node *root, *node = NULL;
+ struct device_node *node = NULL;
struct property *pp = NULL;
while ((opt = getopt(argc, argv, "ds")) > 0) {
@@ -194,15 +194,9 @@ static int do_of_property(int argc, char *argv[])
if (optind == argc)
return COMMAND_ERROR_USAGE;
- root = of_get_root_node();
- if (!root) {
- printf("root node not set\n");
- return -ENOENT;
- }
-
if (optind < argc) {
path = argv[optind];
- node = of_find_node_by_path(root, path);
+ node = of_find_node_by_path(path);
if (!node) {
printf("Cannot find nodepath %s\n", path);
return -ENOENT;
diff --git a/commands/oftree.c b/commands/oftree.c
index 468235a..9149517 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -164,16 +164,7 @@ static int do_oftree(int argc, char *argv[])
of_print_nodes(root, 0);
of_free(root);
} else {
- struct device_node *root, *n;
-
- root = of_get_root_node();
- if (!root) {
- ret = -ENOENT;
- goto out;
- }
-
- n = of_find_node_by_path(root, node);
-
+ struct device_node *n = of_find_node_by_path(node);
if (!n) {
ret = -ENOENT;
goto out;
diff --git a/common/oftree.c b/common/oftree.c
index 475d418..aff4c28 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -100,7 +100,7 @@ void of_print_property(const void *data, int len)
void of_print_cmdline(struct device_node *root)
{
- struct device_node *node = of_find_node_by_path(root, "/chosen");
+ struct device_node *node = of_find_node_by_path("/chosen");
const char *cmdline;
if (!node) {
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 85199b6..34793b3 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -153,7 +153,7 @@ void of_alias_scan(void)
if (!root_node)
return;
- of_aliases = of_find_node_by_path(root_node, "/aliases");
+ of_aliases = of_find_node_by_path("/aliases");
if (!of_aliases)
return;
@@ -170,7 +170,7 @@ void of_alias_scan(void)
!of_prop_cmp(pp->name, "linux,phandle"))
continue;
- np = of_find_node_by_path(root_node, pp->value);
+ np = of_find_node_by_path(pp->value);
if (!np)
continue;
@@ -557,18 +557,16 @@ EXPORT_SYMBOL(of_machine_is_compatible);
/**
* of_find_node_by_path - Find a node matching a full OF path
- * @root: The root node of this tree
* @path: The full path to match
*
- * Returns a node pointer with refcount incremented, use
- * of_node_put() on it when done.
+ * Returns a pointer to the node found or NULL.
*/
-struct device_node *of_find_node_by_path(struct device_node *root, const char *path)
+struct device_node *of_find_node_by_path(const char *path)
{
char *slash, *p, *freep;
- struct device_node *dn = root;
+ struct device_node *dn = root_node;
- if (*path != '/')
+ if (!dn || !path || *path != '/')
return NULL;
path++;
@@ -1156,12 +1154,12 @@ int of_probe(void)
if(!root_node)
return -ENODEV;
- of_chosen = of_find_node_by_path(root_node, "/chosen");
+ of_chosen = of_find_node_by_path("/chosen");
of_property_read_string(root_node, "model", &of_model);
__of_parse_phandles(root_node);
- memory = of_find_node_by_path(root_node, "/memory");
+ memory = of_find_node_by_path("/memory");
if (memory)
of_add_memory(memory, false);
@@ -1234,8 +1232,8 @@ int of_device_is_stdout_path(struct device_d *dev)
name = of_get_property(of_chosen, "linux,stdout-path", NULL);
if (name == NULL)
return 0;
- dn = of_find_node_by_path(root_node, name);
+ dn = of_find_node_by_path(name);
if (!dn)
return 0;
@@ -1264,7 +1262,7 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
struct device_node *chosen;
__be32 buf[2];
- chosen = of_find_node_by_path(root, "/chosen");
+ chosen = of_find_node_by_path("/chosen");
if (!chosen)
return -EINVAL;
diff --git a/include/of.h b/include/of.h
index 7ebde62..871f5e9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
int of_n_addr_cells(struct device_node *np);
int of_n_size_cells(struct device_node *np);
-struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
-
struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
struct fdt_header *fdt_get_tree(void);
@@ -184,6 +182,8 @@ struct cdev;
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
+extern struct device_node *of_find_node_by_path(const char *path);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -235,6 +235,11 @@ static inline struct property *of_find_property(const struct device_node *np,
return NULL;
}
+static inline struct device_node *of_find_node_by_path(const char *path)
+{
+ return NULL;
+}
+
static inline void of_alias_scan(void)
{
}
diff --git a/net/eth.c b/net/eth.c
index 7240b4d..09b3bd5 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -296,7 +296,7 @@ static int eth_of_fixup(struct device_node *root)
continue;
}
- node = of_find_node_by_path(root, edev->nodepath);
+ node = of_find_node_by_path(edev->nodepath);
if (!node) {
dev_dbg(&edev->dev, "%s: fixup node %s not found\n",
__func__, edev->nodepath);
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH 07/22] OF: base: sync of_find_node_by_path with linux OF API
2013-06-18 17:29 ` [PATCH 07/22] OF: base: sync of_find_node_by_path " Sebastian Hesselbarth
@ 2013-06-18 20:13 ` Sascha Hauer
2013-06-18 20:19 ` Sebastian Hesselbarth
0 siblings, 1 reply; 55+ messages in thread
From: Sascha Hauer @ 2013-06-18 20:13 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
On Tue, Jun 18, 2013 at 07:29:52PM +0200, Sebastian Hesselbarth wrote:
> Barebox of_find_node_by_path requires a node to be passed as start node
> to start searching. Linux OF API does not pass this node and no current
> user of it in barebox is passing anything else than the root node.
> Therefore, the device_node argument is removed and all current users of
> that function are updated to reflect the API change.
This is a patch I'm not quite happy with. devicetree is such a nice data
structure that it can be useful for other purposes than just a
singular tree for describing the hardware layout.
Maybe we should rename the current implementatiion to
of_find_node_by_path_from() and add a of_find_node_by_path() which calls
this with root_node as first argument?
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH 07/22] OF: base: sync of_find_node_by_path with linux OF API
2013-06-18 20:13 ` Sascha Hauer
@ 2013-06-18 20:19 ` Sebastian Hesselbarth
0 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 20:19 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 06/18/2013 10:13 PM, Sascha Hauer wrote:
> On Tue, Jun 18, 2013 at 07:29:52PM +0200, Sebastian Hesselbarth wrote:
>> Barebox of_find_node_by_path requires a node to be passed as start node
>> to start searching. Linux OF API does not pass this node and no current
>> user of it in barebox is passing anything else than the root node.
>> Therefore, the device_node argument is removed and all current users of
>> that function are updated to reflect the API change.
>
> This is a patch I'm not quite happy with. devicetree is such a nice data
> structure that it can be useful for other purposes than just a
> singular tree for describing the hardware layout.
>
> Maybe we should rename the current implementatiion to
> of_find_node_by_path_from() and add a of_find_node_by_path() which calls
> this with root_node as first argument?
Agree, I droped a similar patch removing root node passing from
of_print_cmdline() because I realized that root_node is only for the
installed device tree.
Will have in mind for a v2.
Sebastian
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 08/22] OF: base: rename of_node_disabled to of_device_is_available
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (6 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 07/22] OF: base: sync of_find_node_by_path " Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 09/22] OF: base: import of_find_node_by_name from Linux OF API Sebastian Hesselbarth
` (36 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
According to ePAPR 1.1 spec, device tree nodes status can be either
"okay", "disabled", "fail", or "fail-sss". Barebox already has a function
to check for "disabled" nodes, while Linux checks for "okay" or "ok".
To synchronize Barebox and Linux OF APIs, rename of_node_disabled to
of_device_is_available and check for "okay" instead of "disabled" as it
also makes "fail"ed devices unavailable.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 26 ++++++++++++++++++++------
include/of.h | 6 ++++++
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 34793b3..827a1db 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -717,17 +717,31 @@ int of_set_root_node(struct device_node *node)
return 0;
}
-static int of_node_disabled(struct device_node *node)
+/**
+ * of_device_is_available - check if a device is available for use
+ *
+ * @device: Node to check for availability
+ *
+ * Returns 1 if the status property is absent or set to "okay" or "ok",
+ * 0 otherwise
+ */
+int of_device_is_available(const struct device_node *device)
{
- struct property *p;
+ const char *status;
+ int statlen;
+
+ status = of_get_property(device, "status", &statlen);
+ if (status == NULL)
+ return 1;
- p = of_find_property(node, "status", NULL);
- if (p) {
- if (!strcmp("disabled", p->value))
+ if (statlen > 0) {
+ if (!strcmp(status, "okay") || !strcmp(status, "ok"))
return 1;
}
+
return 0;
}
+EXPORT_SYMBOL(of_device_is_available);
void of_print_nodes(struct device_node *node, int indent)
{
@@ -921,7 +935,7 @@ static struct device_d *add_of_device(struct device_node *node,
{
const struct property *cp;
- if (of_node_disabled(node))
+ if (!of_device_is_available(node))
return NULL;
cp = of_get_property(node, "compatible", NULL);
diff --git a/include/of.h b/include/of.h
index 871f5e9..340fb83 100644
--- a/include/of.h
+++ b/include/of.h
@@ -183,6 +183,7 @@ extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
extern struct device_node *of_find_node_by_path(const char *path);
+extern int of_device_is_available(const struct device_node *device);
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -240,6 +241,11 @@ static inline struct device_node *of_find_node_by_path(const char *path)
return NULL;
}
+static inline int of_device_is_available(const struct device_node *device)
+{
+ return 0;
+}
+
static inline void of_alias_scan(void)
{
}
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 09/22] OF: base: import of_find_node_by_name from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (7 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 08/22] OF: base: rename of_node_disabled to of_device_is_available Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 10/22] OF: base: import of_find_compatible_node " Sebastian Hesselbarth
` (35 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_find_node_by_name and corresponding for_each_node_by_name
helper from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 26 ++++++++++++++++++++++++++
include/of.h | 12 ++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 827a1db..85358d9 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -312,6 +312,32 @@ int of_device_is_compatible(const struct device_node *device,
EXPORT_SYMBOL(of_device_is_compatible);
/**
+ * of_find_node_by_name - Find a node by its "name" property
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @name: The name string to match against
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name)
+{
+ struct device_node *np;
+
+ if (!from)
+ from = root_node;
+
+ of_tree_for_each_node(np, from)
+ if (np->name && !of_node_cmp(np->name, name))
+ return np;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_node_by_name);
+
+/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @matches: array of of device match structures to search in
* @node: the of device structure to match against
diff --git a/include/of.h b/include/of.h
index 340fb83..d1503de 100644
--- a/include/of.h
+++ b/include/of.h
@@ -182,6 +182,8 @@ struct cdev;
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
+extern struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name);
extern struct device_node *of_find_node_by_path(const char *path);
extern int of_device_is_available(const struct device_node *device);
@@ -241,6 +243,12 @@ static inline struct device_node *of_find_node_by_path(const char *path)
return NULL;
}
+static inline struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name)
+{
+ return NULL;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -261,4 +269,8 @@ static inline const char *of_alias_get(struct device_node *np)
}
#endif
+#define for_each_node_by_name(dn, name) \
+ for (dn = of_find_node_by_name(NULL, name); dn; \
+ dn = of_find_node_by_name(dn, name))
+
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 10/22] OF: base: import of_find_compatible_node from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (8 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 09/22] OF: base: import of_find_node_by_name from Linux OF API Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 11/22] OF: base: import of_find_matching_node_and_match " Sebastian Hesselbarth
` (34 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_find_compatible_node and corresponding for_each_compatible_node
helper from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 30 ++++++++++++++++++++++++++++++
include/of.h | 13 +++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 85358d9..50a3c22 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -338,6 +338,36 @@ struct device_node *of_find_node_by_name(struct device_node *from,
EXPORT_SYMBOL(of_find_node_by_name);
/**
+ * of_find_compatible_node - Find a node based on type and one of the
+ * tokens in its "compatible" property
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @type: The type string to match "device_type" or NULL to ignore
+ * (currently always ignored in barebox)
+ * @compatible: The string to match to one of the tokens in the device
+ * "compatible" list.
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_compatible_node(struct device_node *from,
+ const char *type, const char *compatible)
+{
+ struct device_node *np;
+
+ if (!from)
+ from = root_node;
+
+ of_tree_for_each_node(np, from)
+ if (of_device_is_compatible(np, compatible))
+ return np;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_compatible_node);
+
+/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @matches: array of of device match structures to search in
* @node: the of device structure to match against
diff --git a/include/of.h b/include/of.h
index d1503de..e170e2b 100644
--- a/include/of.h
+++ b/include/of.h
@@ -185,6 +185,8 @@ extern struct property *of_find_property(const struct device_node *np,
extern struct device_node *of_find_node_by_name(struct device_node *from,
const char *name);
extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_compatible_node(struct device_node *from,
+ const char *type, const char *compat);
extern int of_device_is_available(const struct device_node *device);
extern void of_alias_scan(void);
@@ -249,6 +251,14 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
return NULL;
}
+static inline struct device_node *of_find_compatible_node(
+ struct device_node *from,
+ const char *type,
+ const char *compat)
+{
+ return NULL;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -272,5 +282,8 @@ static inline const char *of_alias_get(struct device_node *np)
#define for_each_node_by_name(dn, name) \
for (dn = of_find_node_by_name(NULL, name); dn; \
dn = of_find_node_by_name(dn, name))
+#define for_each_compatible_node(dn, type, compatible) \
+ for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
+ dn = of_find_compatible_node(dn, type, compatible))
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 11/22] OF: base: import of_find_matching_node_and_match from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (9 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 10/22] OF: base: import of_find_compatible_node " Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 12/22] OF: base: import of_find_node_with_property " Sebastian Hesselbarth
` (33 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_find_matching_node_and_match and corresponding helpers
from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 37 +++++++++++++++++++++++++++++++++++++
include/of.h | 24 ++++++++++++++++++++++++
2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 50a3c22..218cb5a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -389,6 +389,43 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
return NULL;
}
+/**
+ * of_find_matching_node_and_match - Find a node based on an of_device_id
+ * match table.
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @matches: array of of device match structures to search in
+ * @match Updated to point at the matches entry which matched
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_matching_node_and_match(struct device_node *from,
+ const struct of_device_id *matches,
+ const struct of_device_id **match)
+{
+ struct device_node *np;
+
+ if (match)
+ *match = NULL;
+
+ if (!from)
+ from = root_node;
+
+ of_tree_for_each_node(np, from) {
+ const struct of_device_id *m = of_match_node(matches, np);
+ if (m) {
+ if (match)
+ *match = m;
+ return np;
+ }
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_matching_node_and_match);
+
int of_match(struct device_d *dev, struct driver_d *drv)
{
const struct of_device_id *id;
diff --git a/include/of.h b/include/of.h
index e170e2b..c21e73d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -187,6 +187,10 @@ extern struct device_node *of_find_node_by_name(struct device_node *from,
extern struct device_node *of_find_node_by_path(const char *path);
extern struct device_node *of_find_compatible_node(struct device_node *from,
const char *type, const char *compat);
+extern struct device_node *of_find_matching_node_and_match(
+ struct device_node *from,
+ const struct of_device_id *matches,
+ const struct of_device_id **match);
extern int of_device_is_available(const struct device_node *device);
extern void of_alias_scan(void);
@@ -259,6 +263,14 @@ static inline struct device_node *of_find_compatible_node(
return NULL;
}
+static inline struct device_node *of_find_matching_node_and_match(
+ struct device_node *from,
+ const struct of_device_id *matches,
+ const struct of_device_id **match)
+{
+ return NULL;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -285,5 +297,17 @@ static inline const char *of_alias_get(struct device_node *np)
#define for_each_compatible_node(dn, type, compatible) \
for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
dn = of_find_compatible_node(dn, type, compatible))
+static inline struct device_node *of_find_matching_node(
+ struct device_node *from,
+ const struct of_device_id *matches)
+{
+ return of_find_matching_node_and_match(from, matches, NULL);
+}
+#define for_each_matching_node(dn, matches) \
+ for (dn = of_find_matching_node(NULL, matches); dn; \
+ dn = of_find_matching_node(dn, matches))
+#define for_each_matching_node_and_match(dn, matches, match) \
+ for (dn = of_find_matching_node_and_match(NULL, matches, match); \
+ dn; dn = of_find_matching_node_and_match(dn, matches, match))
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 12/22] OF: base: import of_find_node_with_property from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (10 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 11/22] OF: base: import of_find_matching_node_and_match " Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:29 ` [PATCH 13/22] OF: base: import parent/child functions " Sebastian Hesselbarth
` (32 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_find_node_with_property and corresponding helpers
from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 26 ++++++++++++++++++++++++++
include/of.h | 11 +++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 218cb5a..148f832 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -368,6 +368,32 @@ struct device_node *of_find_compatible_node(struct device_node *from,
EXPORT_SYMBOL(of_find_compatible_node);
/**
+ * of_find_node_with_property - Find a node which has a property with
+ * the given name.
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @prop_name: The name of the property to look for.
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_with_property(struct device_node *from,
+ const char *prop_name)
+{
+ struct device_node *np;
+
+ of_tree_for_each_node(np, from) {
+ struct property *pp = of_find_property(np, prop_name, NULL);
+ if (pp)
+ return np;
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_node_with_property);
+
+/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @matches: array of of device match structures to search in
* @node: the of device structure to match against
diff --git a/include/of.h b/include/of.h
index c21e73d..208b00b 100644
--- a/include/of.h
+++ b/include/of.h
@@ -191,6 +191,8 @@ extern struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match);
+extern struct device_node *of_find_node_with_property(
+ struct device_node *from, const char *prop_name);
extern int of_device_is_available(const struct device_node *device);
extern void of_alias_scan(void);
@@ -271,6 +273,12 @@ static inline struct device_node *of_find_matching_node_and_match(
return NULL;
}
+static inline struct device_node *of_find_node_with_property(
+ struct device_node *from, const char *prop_name)
+{
+ return NULL;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -309,5 +317,8 @@ static inline struct device_node *of_find_matching_node(
#define for_each_matching_node_and_match(dn, matches, match) \
for (dn = of_find_matching_node_and_match(NULL, matches, match); \
dn; dn = of_find_matching_node_and_match(dn, matches, match))
+#define for_each_node_with_property(dn, prop_name) \
+ for (dn = of_find_node_with_property(NULL, prop_name); dn; \
+ dn = of_find_node_with_property(dn, prop_name))
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 13/22] OF: base: import parent/child functions from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (11 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 12/22] OF: base: import of_find_node_with_property " Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 20:18 ` Sascha Hauer
2013-06-18 20:29 ` Sascha Hauer
2013-06-18 17:29 ` [PATCH 14/22] OF: base: import of_property_read_* helpers " Sebastian Hesselbarth
` (31 subsequent siblings)
44 siblings, 2 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_get_parent, of_get_next_child, of_get_next_available_child,
and of_get_child_by_name and corresponding helpers from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
include/of.h | 49 +++++++++++++++++++++++++++++++++
2 files changed, 127 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 148f832..17364ea 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -862,6 +862,84 @@ int of_device_is_available(const struct device_node *device)
}
EXPORT_SYMBOL(of_device_is_available);
+/**
+ * of_get_parent - Get a node's parent if any
+ * @node: Node to get parent
+ *
+ * Returns a pointer to the parent node or NULL if already at root.
+ */
+struct device_node *of_get_parent(const struct device_node *node)
+{
+ if (!node)
+ return NULL;
+
+ return (node == root_node) ? NULL : node->parent;
+}
+EXPORT_SYMBOL(of_get_parent);
+
+/**
+ * of_get_next_child - Iterate a node childs
+ * @node: parent node
+ * @prev: previous child of the parent node, or NULL to get first
+ *
+ * Returns a pointer to the next child or NULL.
+ */
+struct device_node *of_get_next_child(const struct device_node *node,
+ struct device_node *prev)
+{
+ if (!node)
+ return NULL;
+
+ if (!prev)
+ return list_prepare_entry(prev, &node->children, parent_list);
+
+ list_for_each_entry_continue(prev, &node->children, parent_list)
+ return prev;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_get_next_child);
+
+/**
+ * of_get_next_available_child - Find the next available child node
+ * @node: parent node
+ * @prev: previous child of the parent node, or NULL to get first
+ *
+ * This function is like of_get_next_child(), except that it
+ * automatically skips any disabled nodes (i.e. status = "disabled").
+ */
+struct device_node *of_get_next_available_child(const struct device_node *node,
+ struct device_node *prev)
+{
+ for_each_child_of_node(node, prev)
+ if (of_device_is_available(prev))
+ return prev;
+ return NULL;
+}
+EXPORT_SYMBOL(of_get_next_available_child);
+
+/**
+ * of_get_child_by_name - Find the child node by name for a given parent
+ * @node: parent node
+ * @name: child name to look for.
+ *
+ * This function looks for child node for given matching name
+ *
+ * Returns a node pointer if found or NULL.
+ */
+struct device_node *of_get_child_by_name(const struct device_node *node,
+ const char *name)
+{
+ struct device_node *child;
+
+ for_each_child_of_node(node, child)
+ if (child->name && (of_node_cmp(child->name, name) == 0))
+ return child;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_get_child_by_name);
+
void of_print_nodes(struct device_node *node, int indent)
{
struct device_node *n;
diff --git a/include/of.h b/include/of.h
index 208b00b..c69b9ad 100644
--- a/include/of.h
+++ b/include/of.h
@@ -195,6 +195,14 @@ extern struct device_node *of_find_node_with_property(
struct device_node *from, const char *prop_name);
extern int of_device_is_available(const struct device_node *device);
+extern struct device_node *of_get_parent(const struct device_node *node);
+extern struct device_node *of_get_next_child(const struct device_node *node,
+ struct device_node *prev);
+extern struct device_node *of_get_next_available_child(
+ const struct device_node *node, struct device_node *prev);
+extern struct device_node *of_get_child_by_name(const struct device_node *node,
+ const char *name);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -239,6 +247,29 @@ static inline struct device_node *of_get_root_node(void)
return NULL;
}
+static inline struct device_node *of_get_parent(const struct device_node *node)
+{
+ return NULL;
+}
+
+static inline struct device_node *of_get_next_child(
+ const struct device_node *node, struct device_node *prev)
+{
+ return NULL;
+}
+
+static inline struct device_node *of_get_next_available_child(
+ const struct device_node *node, struct device_node *prev)
+{
+ return NULL;
+}
+
+static inline struct device_node *of_get_child_by_name(
+ const struct device_node *node, const char *name)
+{
+ return NULL;
+}
+
static inline struct property *of_find_property(const struct device_node *np,
const char *name,
int *lenp)
@@ -321,4 +352,22 @@ static inline struct device_node *of_find_matching_node(
for (dn = of_find_node_with_property(NULL, prop_name); dn; \
dn = of_find_node_with_property(dn, prop_name))
+#define for_each_child_of_node(parent, child) \
+ for (child = of_get_next_child(parent, NULL); child != NULL; \
+ child = of_get_next_child(parent, child))
+#define for_each_available_child_of_node(parent, child) \
+ for (child = of_get_next_available_child(parent, NULL); child != NULL; \
+ child = of_get_next_available_child(parent, child))
+
+static inline int of_get_child_count(const struct device_node *np)
+{
+ struct device_node *child;
+ int num = 0;
+
+ for_each_child_of_node(np, child)
+ num++;
+
+ return num;
+}
+
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH 13/22] OF: base: import parent/child functions from Linux OF API
2013-06-18 17:29 ` [PATCH 13/22] OF: base: import parent/child functions " Sebastian Hesselbarth
@ 2013-06-18 20:18 ` Sascha Hauer
2013-06-18 20:29 ` Sascha Hauer
1 sibling, 0 replies; 55+ messages in thread
From: Sascha Hauer @ 2013-06-18 20:18 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
On Tue, Jun 18, 2013 at 07:29:58PM +0200, Sebastian Hesselbarth wrote:
> This imports of_get_parent, of_get_next_child, of_get_next_available_child,
> and of_get_child_by_name and corresponding helpers from Linux OF API.
>
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> ---
> Cc: barebox@lists.infradead.org
> ---
> drivers/of/base.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> include/of.h | 49 +++++++++++++++++++++++++++++++++
> 2 files changed, 127 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 148f832..17364ea 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -862,6 +862,84 @@ int of_device_is_available(const struct device_node *device)
> }
> EXPORT_SYMBOL(of_device_is_available);
>
> +/**
> + * of_get_parent - Get a node's parent if any
> + * @node: Node to get parent
> + *
> + * Returns a pointer to the parent node or NULL if already at root.
> + */
> +struct device_node *of_get_parent(const struct device_node *node)
> +{
> + if (!node)
> + return NULL;
> +
> + return (node == root_node) ? NULL : node->parent;
parent should be NULL for the root_node, so it should be safe to remove
this additional check. This is also in the sense of making multiple
devicetrees possible.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH 13/22] OF: base: import parent/child functions from Linux OF API
2013-06-18 17:29 ` [PATCH 13/22] OF: base: import parent/child functions " Sebastian Hesselbarth
2013-06-18 20:18 ` Sascha Hauer
@ 2013-06-18 20:29 ` Sascha Hauer
2013-06-18 20:34 ` Sebastian Hesselbarth
1 sibling, 1 reply; 55+ messages in thread
From: Sascha Hauer @ 2013-06-18 20:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
On Tue, Jun 18, 2013 at 07:29:58PM +0200, Sebastian Hesselbarth wrote:
> This imports of_get_parent, of_get_next_child, of_get_next_available_child,
> and of_get_child_by_name and corresponding helpers from Linux OF API.
>
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> ---
> Cc: barebox@lists.infradead.org
> ---
> drivers/of/base.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> include/of.h | 49 +++++++++++++++++++++++++++++++++
> 2 files changed, 127 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 148f832..17364ea 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -862,6 +862,84 @@ int of_device_is_available(const struct device_node *device)
> }
> EXPORT_SYMBOL(of_device_is_available);
>
> +/**
> + * of_get_parent - Get a node's parent if any
> + * @node: Node to get parent
> + *
> + * Returns a pointer to the parent node or NULL if already at root.
> + */
> +struct device_node *of_get_parent(const struct device_node *node)
> +{
> + if (!node)
> + return NULL;
> +
> + return (node == root_node) ? NULL : node->parent;
> +}
> +EXPORT_SYMBOL(of_get_parent);
> +
> +/**
> + * of_get_next_child - Iterate a node childs
> + * @node: parent node
> + * @prev: previous child of the parent node, or NULL to get first
> + *
> + * Returns a pointer to the next child or NULL.
> + */
> +struct device_node *of_get_next_child(const struct device_node *node,
> + struct device_node *prev)
> +{
> + if (!node)
> + return NULL;
> +
> + if (!prev)
> + return list_prepare_entry(prev, &node->children, parent_list);
> +
> + list_for_each_entry_continue(prev, &node->children, parent_list)
> + return prev;
> +
> + return NULL;
> +}
> +EXPORT_SYMBOL(of_get_next_child);
> +
> +/**
> + * of_get_next_available_child - Find the next available child node
> + * @node: parent node
> + * @prev: previous child of the parent node, or NULL to get first
> + *
> + * This function is like of_get_next_child(), except that it
> + * automatically skips any disabled nodes (i.e. status = "disabled").
> + */
> +struct device_node *of_get_next_available_child(const struct device_node *node,
> + struct device_node *prev)
> +{
> + for_each_child_of_node(node, prev)
> + if (of_device_is_available(prev))
> + return prev;
> + return NULL;
> +}
> +EXPORT_SYMBOL(of_get_next_available_child);
> +
> +/**
> + * of_get_child_by_name - Find the child node by name for a given parent
> + * @node: parent node
> + * @name: child name to look for.
> + *
> + * This function looks for child node for given matching name
> + *
> + * Returns a node pointer if found or NULL.
> + */
> +struct device_node *of_get_child_by_name(const struct device_node *node,
> + const char *name)
> +{
> + struct device_node *child;
> +
> + for_each_child_of_node(node, child)
> + if (child->name && (of_node_cmp(child->name, name) == 0))
> + return child;
> +
> + return NULL;
> +}
> +EXPORT_SYMBOL(of_get_child_by_name);
> +
> void of_print_nodes(struct device_node *node, int indent)
> {
> struct device_node *n;
> diff --git a/include/of.h b/include/of.h
> index 208b00b..c69b9ad 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -195,6 +195,14 @@ extern struct device_node *of_find_node_with_property(
> struct device_node *from, const char *prop_name);
> extern int of_device_is_available(const struct device_node *device);
>
> +extern struct device_node *of_get_parent(const struct device_node *node);
> +extern struct device_node *of_get_next_child(const struct device_node *node,
> + struct device_node *prev);
> +extern struct device_node *of_get_next_available_child(
> + const struct device_node *node, struct device_node *prev);
> +extern struct device_node *of_get_child_by_name(const struct device_node *node,
> + const char *name);
> +
> extern void of_alias_scan(void);
> extern int of_alias_get_id(struct device_node *np, const char *stem);
> extern const char *of_alias_get(struct device_node *np);
> @@ -239,6 +247,29 @@ static inline struct device_node *of_get_root_node(void)
> return NULL;
> }
>
> +static inline struct device_node *of_get_parent(const struct device_node *node)
> +{
> + return NULL;
> +}
> +
> +static inline struct device_node *of_get_next_child(
> + const struct device_node *node, struct device_node *prev)
> +{
> + return NULL;
> +}
> +
> +static inline struct device_node *of_get_next_available_child(
> + const struct device_node *node, struct device_node *prev)
> +{
> + return NULL;
> +}
> +
> +static inline struct device_node *of_get_child_by_name(
> + const struct device_node *node, const char *name)
> +{
> + return NULL;
> +}
> +
> static inline struct property *of_find_property(const struct device_node *np,
> const char *name,
> int *lenp)
> @@ -321,4 +352,22 @@ static inline struct device_node *of_find_matching_node(
> for (dn = of_find_node_with_property(NULL, prop_name); dn; \
> dn = of_find_node_with_property(dn, prop_name))
>
> +#define for_each_child_of_node(parent, child) \
> + for (child = of_get_next_child(parent, NULL); child != NULL; \
> + child = of_get_next_child(parent, child))
Why don't we just rename the original list iteration #define?
I think we shouldn't generate worse code just for the sake of being in
sync with Linux.
I wonder why the Linux implementation doesn't use the Linux list
implementation...
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH 13/22] OF: base: import parent/child functions from Linux OF API
2013-06-18 20:29 ` Sascha Hauer
@ 2013-06-18 20:34 ` Sebastian Hesselbarth
0 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 20:34 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 06/18/2013 10:29 PM, Sascha Hauer wrote:
> On Tue, Jun 18, 2013 at 07:29:58PM +0200, Sebastian Hesselbarth wrote:
>> This imports of_get_parent, of_get_next_child, of_get_next_available_child,
>> and of_get_child_by_name and corresponding helpers from Linux OF API.
>>
>> Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth@gmail.com>
>> ---
[...]
>> +#define for_each_child_of_node(parent, child) \
>> + for (child = of_get_next_child(parent, NULL); child != NULL; \
>> + child = of_get_next_child(parent, child))
>
> Why don't we just rename the original list iteration #define?
>
> I think we shouldn't generate worse code just for the sake of being in
> sync with Linux.
Agree, reworking this will take some days as I will not be able to
get back to it soon. Rebasing that 22 patches beast is time-consuming ;)
> I wonder why the Linux implementation doesn't use the Linux list
> implementation...
Maybe you should also raise that question on devtree-discuss?
Sebastian
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 14/22] OF: base: import of_property_read_* helpers from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (12 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 13/22] OF: base: import parent/child functions " Sebastian Hesselbarth
@ 2013-06-18 17:29 ` Sebastian Hesselbarth
2013-06-18 17:30 ` [PATCH 15/22] OF: base: import of_parse_phandle " Sebastian Hesselbarth
` (30 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:29 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_property_read_* helpers from Linux OF API to allow
to read all kinds of properties.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 387 +++++++++++++++++++++++++++++++++++++++++------------
include/of.h | 132 ++++++++++++++++--
2 files changed, 420 insertions(+), 99 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 17364ea..4689f3e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -467,12 +467,137 @@ int of_match(struct device_d *dev, struct driver_d *drv)
EXPORT_SYMBOL(of_match);
/**
+ * of_find_property_value_of_size
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @len: requested length of property value
+ *
+ * Search for a property in a device node and valid the requested size.
+ * Returns the property value on success, -EINVAL if the property does not
+ * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ */
+static void *of_find_property_value_of_size(const struct device_node *np,
+ const char *propname, u32 len)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ if (!prop)
+ return ERR_PTR(-EINVAL);
+ if (!prop->value)
+ return ERR_PTR(-ENODATA);
+ if (len > prop->length)
+ return ERR_PTR(-EOVERFLOW);
+
+ return prop->value;
+}
+
+/**
+ * of_property_read_u32_index - Find and read a u32 from a multi-value property.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @index: index of the u32 in the list of values
+ * @out_value: pointer to return value, modified only if no error.
+ *
+ * Search for a property in a device node and read nth 32-bit value from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * The out_value is modified only if a valid u32 value can be decoded.
+ */
+int of_property_read_u32_index(const struct device_node *np,
+ const char *propname,
+ u32 index, u32 *out_value)
+{
+ const u32 *val = of_find_property_value_of_size(np, propname,
+ ((index + 1) * sizeof(*out_value)));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ *out_value = be32_to_cpup(((__be32 *)val) + index);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u32_index);
+
+/**
+ * of_property_read_u8_array - Find and read an array of u8 from a property.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_value: pointer to return value, modified only if return value is 0.
+ * @sz: number of array elements to read
+ *
+ * Search for a property in a device node and read 8-bit value(s) from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * dts entry of array should be like:
+ * property = /bits/ 8 <0x50 0x60 0x70>;
+ *
+ * The out_value is modified only if a valid u8 value can be decoded.
+ */
+int of_property_read_u8_array(const struct device_node *np,
+ const char *propname, u8 *out_values, size_t sz)
+{
+ const u8 *val = of_find_property_value_of_size(np, propname,
+ (sz * sizeof(*out_values)));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ while (sz--)
+ *out_values++ = *val++;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u8_array);
+
+/**
+ * of_property_read_u16_array - Find and read an array of u16 from a property.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_value: pointer to return value, modified only if return value is 0.
+ * @sz: number of array elements to read
+ *
+ * Search for a property in a device node and read 16-bit value(s) from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * dts entry of array should be like:
+ * property = /bits/ 16 <0x5000 0x6000 0x7000>;
+ *
+ * The out_value is modified only if a valid u16 value can be decoded.
+ */
+int of_property_read_u16_array(const struct device_node *np,
+ const char *propname, u16 *out_values, size_t sz)
+{
+ const __be16 *val = of_find_property_value_of_size(np, propname,
+ (sz * sizeof(*out_values)));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ while (sz--)
+ *out_values++ = be16_to_cpup(val++);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u16_array);
+
+/**
* of_property_read_u32_array - Find and read an array of 32 bit integers
* from a property.
*
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_value: pointer to return value, modified only if return value is 0.
+ * @sz: number of array elements to read
*
* Search for a property in a device node and read 32-bit value(s) from
* it. Returns 0 on success, -EINVAL if the property does not exist,
@@ -485,22 +610,192 @@ int of_property_read_u32_array(const struct device_node *np,
const char *propname, u32 *out_values,
size_t sz)
{
+ const __be32 *val = of_find_property_value_of_size(np, propname,
+ (sz * sizeof(*out_values)));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ while (sz--)
+ *out_values++ = be32_to_cpup(val++);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+
+/**
+ * of_property_read_u64 - Find and read a 64 bit integer from a property
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_value: pointer to return value, modified only if return value is 0.
+ *
+ * Search for a property in a device node and read a 64-bit value from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * The out_value is modified only if a valid u64 value can be decoded.
+ */
+int of_property_read_u64(const struct device_node *np, const char *propname,
+ u64 *out_value)
+{
+ const __be32 *val = of_find_property_value_of_size(np, propname,
+ sizeof(*out_value));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ *out_value = of_read_number(val, 2);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u64);
+
+/**
+ * of_property_read_string - Find and read a string from a property
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_string: pointer to null terminated return string, modified only if
+ * return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy). Returns 0 on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string(struct device_node *np, const char *propname,
+ const char **out_string)
+{
struct property *prop = of_find_property(np, propname, NULL);
- const __be32 *val;
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
+ *out_string = prop->value;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_string);
+
+/**
+ * of_property_read_string_index - Find and read a string from a multiple
+ * strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @index: index of the string in the list of strings
+ * @out_string: pointer to null terminated return string, modified only if
+ * return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy) in the list of strings
+ * contained in that property.
+ * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
+ * property does not have a value, and -EILSEQ if the string is not
+ * null-terminated within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string_index(struct device_node *np, const char *propname,
+ int index, const char **output)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ int i = 0;
+ size_t l = 0, total = 0;
+ const char *p;
if (!prop)
return -EINVAL;
if (!prop->value)
return -ENODATA;
- if ((sz * sizeof(*out_values)) > prop->length)
- return -EOVERFLOW;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
- val = prop->value;
- while (sz--)
- *out_values++ = be32_to_cpup(val++);
- return 0;
+ p = prop->value;
+
+ for (i = 0; total < prop->length; total += l, p += l) {
+ l = strlen(p) + 1;
+ if (i++ == index) {
+ *output = p;
+ return 0;
+ }
+ }
+ return -ENODATA;
}
-EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+EXPORT_SYMBOL_GPL(of_property_read_string_index);
+
+/**
+ * of_property_match_string() - Find string in a list and return index
+ * @np: pointer to node containing string list property
+ * @propname: string list property name
+ * @string: pointer to string to search for in string list
+ *
+ * This function searches a string list property and returns the index
+ * of a specific string value.
+ */
+int of_property_match_string(struct device_node *np, const char *propname,
+ const char *string)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ size_t l;
+ int i;
+ const char *p, *end;
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+
+ p = prop->value;
+ end = p + prop->length;
+
+ for (i = 0; p < end; i++, p += l) {
+ l = strlen(p) + 1;
+ if (p + l > end)
+ return -EILSEQ;
+ pr_debug("comparing %s with %s\n", string, p);
+ if (strcmp(string, p) == 0)
+ return i; /* Found it; return index */
+ }
+ return -ENODATA;
+}
+EXPORT_SYMBOL_GPL(of_property_match_string);
+
+/**
+ * of_property_count_strings - Find and return the number of strings from a
+ * multiple strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device tree node and retrieve the number of null
+ * terminated string contain in it. Returns the number of strings on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ */
+int of_property_count_strings(struct device_node *np, const char *propname)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ int i = 0;
+ size_t l = 0, total = 0;
+ const char *p;
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
+
+ p = prop->value;
+
+ for (i = 0; total < prop->length; total += l, p += l, i++)
+ l = strlen(p) + 1;
+
+ return i;
+}
+EXPORT_SYMBOL_GPL(of_property_count_strings);
/**
* of_property_write_u32_array - Write an array of u32 to a property. If
@@ -717,82 +1012,6 @@ out:
EXPORT_SYMBOL(of_find_node_by_path);
/**
- * of_property_read_string - Find and read a string from a property
- * @np: device node from which the property value is to be read.
- * @propname: name of the property to be searched.
- * @out_string: pointer to null terminated return string, modified only if
- * return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy). Returns 0 on
- * success, -EINVAL if the property does not exist, -ENODATA if property
- * does not have a value, and -EILSEQ if the string is not null-terminated
- * within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string(struct device_node *np, const char *propname,
- const char **out_string)
-{
- struct property *prop = of_find_property(np, propname, NULL);
- if (!prop)
- return -EINVAL;
- if (!prop->value)
- return -ENODATA;
- if (strnlen(prop->value, prop->length) >= prop->length)
- return -EILSEQ;
- *out_string = prop->value;
- return 0;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string);
-
-/**
- * of_property_read_string_index - Find and read a string from a multiple
- * strings property.
- * @np: device node from which the property value is to be read.
- * @propname: name of the property to be searched.
- * @index: index of the string in the list of strings
- * @out_string: pointer to null terminated return string, modified only if
- * return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy) in the list of strings
- * contained in that property.
- * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
- * property does not have a value, and -EILSEQ if the string is not
- * null-terminated within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string_index(struct device_node *np, const char *propname,
- int index, const char **output)
-{
- struct property *prop = of_find_property(np, propname, NULL);
- int i = 0;
- size_t l = 0, total = 0;
- const char *p;
-
- if (!prop)
- return -EINVAL;
- if (!prop->value)
- return -ENODATA;
- if (strnlen(prop->value, prop->length) >= prop->length)
- return -EILSEQ;
-
- p = prop->value;
-
- for (i = 0; total < prop->length; total += l, p += l) {
- l = strlen(p) + 1;
- if (i++ == index) {
- *output = p;
- return 0;
- }
- }
- return -ENODATA;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string_index);
-
-/**
* of_modalias_node - Lookup appropriate modalias for a device node
* @node: pointer to a device tree node
* @modalias: Pointer to buffer that modalias value will be copied into
diff --git a/include/of.h b/include/of.h
index c69b9ad..d782eaf 100644
--- a/include/of.h
+++ b/include/of.h
@@ -106,17 +106,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
}
}
-int of_property_read_u32_array(const struct device_node *np,
- const char *propname, u32 *out_values,
- size_t sz);
-
-static inline int of_property_read_u32(const struct device_node *np,
- const char *propname,
- u32 *out_value)
-{
- return of_property_read_u32_array(np, propname, out_value, 1);
-}
-
int of_property_write_u32_array(struct device_node *np,
const char *propname, const u32 *values,
size_t sz);
@@ -163,10 +152,6 @@ struct property *of_new_property(struct device_node *node, const char *name,
const void *data, int len);
void of_delete_property(struct property *pp);
-int of_property_read_string(struct device_node *np, const char *propname,
- const char **out_string);
-int of_property_read_string_index(struct device_node *np, const char *propname,
- int index, const char **output);
int of_set_property(struct device_node *node, const char *p, const void *val, int len,
int create);
struct device_node *of_create_node(struct device_node *root, const char *path);
@@ -203,6 +188,32 @@ extern struct device_node *of_get_next_available_child(
extern struct device_node *of_get_child_by_name(const struct device_node *node,
const char *name);
+extern int of_property_read_u32_index(const struct device_node *np,
+ const char *propname,
+ u32 index, u32 *out_value);
+extern int of_property_read_u8_array(const struct device_node *np,
+ const char *propname, u8 *out_values, size_t sz);
+extern int of_property_read_u16_array(const struct device_node *np,
+ const char *propname, u16 *out_values, size_t sz);
+extern int of_property_read_u32_array(const struct device_node *np,
+ const char *propname,
+ u32 *out_values,
+ size_t sz);
+extern int of_property_read_u64(const struct device_node *np,
+ const char *propname, u64 *out_value);
+
+extern int of_property_read_string(struct device_node *np,
+ const char *propname,
+ const char **out_string);
+extern int of_property_read_string_index(struct device_node *np,
+ const char *propname,
+ int index, const char **output);
+extern int of_property_match_string(struct device_node *np,
+ const char *propname,
+ const char *string);
+extern int of_property_count_strings(struct device_node *np,
+ const char *propname);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -277,6 +288,60 @@ static inline struct property *of_find_property(const struct device_node *np,
return NULL;
}
+static inline int of_property_read_u32_index(const struct device_node *np,
+ const char *propname, u32 index, u32 *out_value)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_u8_array(const struct device_node *np,
+ const char *propname, u8 *out_values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_u16_array(const struct device_node *np,
+ const char *propname, u16 *out_values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_u32_array(const struct device_node *np,
+ const char *propname, u32 *out_values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_u64(const struct device_node *np,
+ const char *propname, u64 *out_value)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_string(struct device_node *np,
+ const char *propname, const char **out_string)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_string_index(struct device_node *np,
+ const char *propname, int index, const char **output)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_match_string(struct device_node *np,
+ const char *propname, const char *string)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_count_strings(struct device_node *np,
+ const char *propname)
+{
+ return -ENOSYS;
+}
+
static inline struct device_node *of_find_node_by_path(const char *path)
{
return NULL;
@@ -370,4 +435,41 @@ static inline int of_get_child_count(const struct device_node *np)
return num;
}
+/**
+ * of_property_read_bool - Findfrom a property
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device node.
+ * Returns true if the property exist false otherwise.
+ */
+static inline bool of_property_read_bool(const struct device_node *np,
+ const char *propname)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ return prop ? true : false;
+}
+
+static inline int of_property_read_u8(const struct device_node *np,
+ const char *propname,
+ u8 *out_value)
+{
+ return of_property_read_u8_array(np, propname, out_value, 1);
+}
+
+static inline int of_property_read_u16(const struct device_node *np,
+ const char *propname,
+ u16 *out_value)
+{
+ return of_property_read_u16_array(np, propname, out_value, 1);
+}
+
+static inline int of_property_read_u32(const struct device_node *np,
+ const char *propname,
+ u32 *out_value)
+{
+ return of_property_read_u32_array(np, propname, out_value, 1);
+}
+
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 15/22] OF: base: import of_parse_phandle from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (13 preceding siblings ...)
2013-06-18 17:29 ` [PATCH 14/22] OF: base: import of_property_read_* helpers " Sebastian Hesselbarth
@ 2013-06-18 17:30 ` Sebastian Hesselbarth
2013-06-18 17:30 ` [PATCH 16/22] OF: base: import parse phandle functions " Sebastian Hesselbarth
` (29 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_parse_phandle from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 23 +++++++++++++++++++++++
include/of.h | 10 ++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4689f3e..e729a65 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -839,6 +839,29 @@ int of_property_write_u32_array(struct device_node *np,
}
/**
+ * of_parse_phandle - Resolve a phandle property to a device_node pointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ * the table
+ *
+ * Returns the device_node pointer found or NULL.
+ */
+struct device_node *of_parse_phandle(const struct device_node *np,
+ const char *phandle_name, int index)
+{
+ const __be32 *phandle;
+ int size;
+
+ phandle = of_get_property(np, phandle_name, &size);
+ if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+ return NULL;
+
+ return of_find_node_by_phandle(be32_to_cpup(phandle + index));
+}
+EXPORT_SYMBOL(of_parse_phandle);
+
+/**
* of_parse_phandles_with_args - Find a node pointed by phandle in a list
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
diff --git a/include/of.h b/include/of.h
index d782eaf..81df5a6 100644
--- a/include/of.h
+++ b/include/of.h
@@ -214,6 +214,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 struct device_node *of_parse_phandle(const struct device_node *np,
+ const char *phandle_name,
+ int index);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -342,6 +346,12 @@ static inline int of_property_count_strings(struct device_node *np,
return -ENOSYS;
}
+static inline struct device_node *of_parse_phandle(const struct device_node *np,
+ const char *phandle_name, int index)
+{
+ return NULL;
+}
+
static inline struct device_node *of_find_node_by_path(const char *path)
{
return NULL;
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 16/22] OF: base: import parse phandle functions from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (14 preceding siblings ...)
2013-06-18 17:30 ` [PATCH 15/22] OF: base: import of_parse_phandle " Sebastian Hesselbarth
@ 2013-06-18 17:30 ` Sebastian Hesselbarth
2013-06-18 17:30 ` [PATCH 17/22] OF: base: introduce property write for bool, u8, u16, and u64 Sebastian Hesselbarth
` (28 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_parse_phandle_with_args and of_count_phandle_with_args
from Linux OF API. The slightly different of_parse_phandles_with_args
is removed and all users are converted to reflect the API change.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 188 +++++++++++++++++++++++++---------------
drivers/of/gpio.c | 9 +-
drivers/usb/imx/chipidea-imx.c | 11 +--
include/of.h | 30 ++++++-
4 files changed, 151 insertions(+), 87 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index e729a65..a3a9aac 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -862,17 +862,16 @@ struct device_node *of_parse_phandle(const struct device_node *np,
EXPORT_SYMBOL(of_parse_phandle);
/**
- * of_parse_phandles_with_args - Find a node pointed by phandle in a list
+ * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
* @cells_name: property name that specifies phandles' arguments count
* @index: index of a phandle to parse out
- * @out_node: optional pointer to device_node struct pointer (will be filled)
- * @out_args: optional pointer to arguments pointer (will be filled)
+ * @out_args: optional pointer to output arguments structure (will be filled)
*
* This function is useful to parse lists of phandles and their arguments.
- * Returns 0 on success and fills out_node and out_args, on error returns
- * appropriate errno value.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
*
* Example:
*
@@ -889,92 +888,139 @@ EXPORT_SYMBOL(of_parse_phandle);
* }
*
* To get a device_node of the `node2' node you may call this:
- * of_parse_phandles_with_args(node3, "list", "#list-cells", 2, &node2, &args);
+ * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
*/
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
- const char *cells_name, int index,
- struct device_node **out_node,
- const void **out_args)
-{
- int ret = -EINVAL;
- const __be32 *list;
- const __be32 *list_end;
- int size;
- int cur_index = 0;
+static int __of_parse_phandle_with_args(const struct device_node *np,
+ const char *list_name,
+ const char *cells_name, int index,
+ struct of_phandle_args *out_args)
+{
+ const __be32 *list, *list_end;
+ int rc = 0, size, cur_index = 0;
+ uint32_t count = 0;
struct device_node *node = NULL;
- const void *args = NULL;
+ phandle phandle;
+ /* Retrieve the phandle list property */
list = of_get_property(np, list_name, &size);
- if (!list) {
- ret = -ENOENT;
- goto err0;
- }
+ if (!list)
+ return -ENOENT;
list_end = list + size / sizeof(*list);
+ /* Loop over the phandles until all the requested entry is found */
while (list < list_end) {
- const __be32 *cells;
- phandle phandle;
+ rc = -EINVAL;
+ count = 0;
+ /*
+ * If phandle is 0, then it is an empty entry with no
+ * arguments. Skip forward to the next entry.
+ */
phandle = be32_to_cpup(list++);
- args = list;
-
- /* one cell hole in the list = <>; */
- if (!phandle)
- goto next;
-
- node = of_find_node_by_phandle(phandle);
- if (!node) {
- pr_debug("%s: could not find phandle %d\n",
- np->full_name, phandle);
- goto err0;
+ if (phandle) {
+ /*
+ * Find the provider node and parse the #*-cells
+ * property to determine the argument length
+ */
+ node = of_find_node_by_phandle(phandle);
+ if (!node) {
+ pr_err("%s: could not find phandle\n",
+ np->full_name);
+ goto err;
+ }
+ if (of_property_read_u32(node, cells_name, &count)) {
+ pr_err("%s: could not get %s for %s\n",
+ np->full_name, cells_name,
+ node->full_name);
+ goto err;
+ }
+
+ /*
+ * Make sure that the arguments actually fit in the
+ * remaining property data length
+ */
+ if (list + count > list_end) {
+ pr_err("%s: arguments longer than property\n",
+ np->full_name);
+ goto err;
+ }
}
- cells = of_get_property(node, cells_name, &size);
- if (!cells || size != sizeof(*cells)) {
- pr_debug("%s: could not get %s for %s\n",
- np->full_name, cells_name, node->full_name);
- goto err1;
- }
-
- list += be32_to_cpup(cells);
- if (list > list_end) {
- pr_debug("%s: insufficient arguments length\n",
- np->full_name);
- goto err1;
+ /*
+ * All of the error cases above bail out of the loop, so at
+ * this point, the parsing is successful. If the requested
+ * index matches, then fill the out_args structure and return,
+ * or return -ENOENT for an empty entry.
+ */
+ rc = -ENOENT;
+ if (cur_index == index) {
+ if (!phandle)
+ goto err;
+
+ if (out_args) {
+ int i;
+ if (WARN_ON(count > MAX_PHANDLE_ARGS))
+ count = MAX_PHANDLE_ARGS;
+ out_args->np = node;
+ out_args->args_count = count;
+ for (i = 0; i < count; i++)
+ out_args->args[i] =
+ be32_to_cpup(list++);
+ }
+
+ /* Found it! return success */
+ return 0;
}
-next:
- if (cur_index == index)
- break;
node = NULL;
- args = NULL;
+ list += count;
cur_index++;
}
- if (!node) {
- /*
- * args w/o node indicates that the loop above has stopped at
- * the 'hole' cell. Report this differently.
- */
- if (args)
- ret = -EEXIST;
- else
- ret = -ENOENT;
- goto err0;
- }
+ /*
+ * Unlock node before returning result; will be one of:
+ * -ENOENT : index is for empty phandle
+ * -EINVAL : parsing error on data
+ * [1..n] : Number of phandle (count mode; when index = -1)
+ */
+ rc = index < 0 ? cur_index : -ENOENT;
+ err:
+ return rc;
+}
- if (out_node)
- *out_node = node;
- if (out_args)
- *out_args = args;
+int of_parse_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name, int index,
+ struct of_phandle_args *out_args)
+{
+ if (index < 0)
+ return -EINVAL;
+ return __of_parse_phandle_with_args(np, list_name, cells_name,
+ index, out_args);
+}
+EXPORT_SYMBOL(of_parse_phandle_with_args);
- return 0;
-err1:
-err0:
- pr_debug("%s failed with status %d\n", __func__, ret);
- return ret;
+/**
+ * of_count_phandle_with_args() - Find the number of phandles references in a property
+ * @np: pointer to a device tree node containing a list
+ * @list_name: property name that contains a list
+ * @cells_name: property name that specifies phandles' arguments count
+ *
+ * Returns the number of phandle + argument tuples within a property. It
+ * is a typical pattern to encode a list of phandle and variable
+ * arguments into a single property. The number of arguments is encoded
+ * by a property in the phandle-target node. For example, a gpios
+ * property would contain a list of GPIO specifies consisting of a
+ * phandle and 1 or more arguments. The number of arguments are
+ * determined by the #gpio-cells property in the node pointed to by the
+ * phandle.
+ */
+int of_count_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name)
+{
+ return __of_parse_phandle_with_args(np, list_name, cells_name,
+ -1, NULL);
}
-EXPORT_SYMBOL(of_parse_phandles_with_args);
+EXPORT_SYMBOL(of_count_phandle_with_args);
/**
* of_machine_is_compatible - Test root of device tree for a given compatible value
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 83b72c0..87b9c0c 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -9,17 +9,16 @@ int of_get_named_gpio(struct device_node *np,
const char *propname, int index)
{
int ret;
- struct device_node *gpio_np;
- const void *gpio_spec;
+ struct of_phandle_args out_args;
- ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
- &gpio_np, &gpio_spec);
+ ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
+ index, &out_args);
if (ret) {
pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
return -EINVAL;
}
- ret = gpio_get_num(gpio_np->device, be32_to_cpup(gpio_spec));
+ ret = gpio_get_num(out_args.np->device, outargs.args[0]);
if (ret < 0)
return ret;
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 32b05aa..ee7c010 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -62,16 +62,15 @@ static int imx_chipidea_port_post_init(void *drvdata)
static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
{
- const void *out_args;
- struct device_node *usbmisc_np;
+ struct of_phandle_args out_args;
enum usb_dr_mode mode;
enum usb_phy_interface phymode;
- of_parse_phandles_with_args(ci->dev->device_node, "fsl,usbmisc",
- "#index-cells", 0, &usbmisc_np, &out_args);
-
- ci->portno = be32_to_cpup(out_args);
+ if (of_parse_phandle_with_args(ci->dev->device_node, "fsl,usbmisc",
+ "#index-cells", 0, &out_args))
+ return -ENODEV;
+ ci->portno = out_args.args[0];
ci->flags = MXC_EHCI_MODE_UTMI_8BIT;
mode = of_usb_get_dr_mode(ci->dev->device_node, NULL);
diff --git a/include/of.h b/include/of.h
index 81df5a6..51ecf4d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -42,6 +42,13 @@ struct of_device_id {
unsigned long data;
};
+#define MAX_PHANDLE_ARGS 8
+struct of_phandle_args {
+ struct device_node *np;
+ int args_count;
+ uint32_t args[MAX_PHANDLE_ARGS];
+};
+
#define OF_MAX_RESERVE_MAP 16
struct of_reserve_map {
uint64_t start[OF_MAX_RESERVE_MAP];
@@ -120,11 +127,6 @@ static inline int of_property_write_u32(struct device_node *np,
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp);
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
- const char *cells_name, int index,
- struct device_node **out_node,
- const void **out_args);
-
int of_get_named_gpio(struct device_node *np,
const char *propname, int index);
@@ -217,6 +219,11 @@ extern int of_property_count_strings(struct device_node *np,
extern struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name,
int index);
+extern int of_parse_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name, int index,
+ struct of_phandle_args *out_args);
+extern int of_count_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name);
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -352,6 +359,19 @@ static inline struct device_node *of_parse_phandle(const struct device_node *np,
return NULL;
}
+static inline int of_parse_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name, int index,
+ struct of_phandle_args *out_args)
+{
+ return -ENOSYS;
+}
+
+static inline int of_count_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name)
+{
+ return -ENOSYS;
+}
+
static inline struct device_node *of_find_node_by_path(const char *path)
{
return NULL;
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 17/22] OF: base: introduce property write for bool, u8, u16, and u64
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (15 preceding siblings ...)
2013-06-18 17:30 ` [PATCH 16/22] OF: base: import parse phandle functions " Sebastian Hesselbarth
@ 2013-06-18 17:30 ` Sebastian Hesselbarth
2013-06-18 17:30 ` [PATCH 18/22] OF: base: import property iterators from Linux OF API Sebastian Hesselbarth
` (27 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This adds functions to set an array of or a single value for bool,
u8, u16, and u64 properties.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++
include/of.h | 82 ++++++++++++++++++++++++----
2 files changed, 227 insertions(+), 11 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index a3a9aac..4c6f2f4 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -798,6 +798,119 @@ int of_property_count_strings(struct device_node *np, const char *propname)
EXPORT_SYMBOL_GPL(of_property_count_strings);
/**
+ * of_property_write_bool - Create/Delete empty (bool) property.
+ *
+ * @np: device node from which the property is to be set.
+ * @propname: name of the property to be set.
+ *
+ * Search for a property in a device node and create or delete the property.
+ * If the property already exists and write value is false, the property is
+ * deleted. If write value is true and the property does not exist, it is
+ * created. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_bool(struct device_node *np, const char *propname,
+ const bool value)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ if (!value) {
+ if (prop)
+ of_delete_property(prop);
+ return 0;
+ }
+
+ if (!prop)
+ prop = of_new_property(np, propname, NULL, 0);
+ if (!prop)
+ return -ENOMEM;
+
+ return 0;
+}
+
+/**
+ * of_property_write_u8_array - Write an array of u8 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write 8-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u8_array(struct device_node *np,
+ const char *propname, const u8 *values,
+ size_t sz)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ u8 *val;
+
+ if (!prop)
+ prop = of_new_property(np, propname, NULL, 0);
+ if (!prop)
+ return -ENOMEM;
+
+ free(prop->value);
+
+ prop->length = sizeof(*val) * sz;
+ prop->value = malloc(prop->length);
+ if (!prop->value)
+ return -ENOMEM;
+
+ val = prop->value;
+ while (sz--)
+ *val++ = *values++;
+
+ return 0;
+}
+
+/**
+ * of_property_write_u16_array - Write an array of u16 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write 16-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u16_array(struct device_node *np,
+ const char *propname, const u16 *values,
+ size_t sz)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ __be16 *val;
+
+ if (!prop)
+ prop = of_new_property(np, propname, NULL, 0);
+ if (!prop)
+ return -ENOMEM;
+
+ free(prop->value);
+
+ prop->length = sizeof(*val) * sz;
+ prop->value = malloc(prop->length);
+ if (!prop->value)
+ return -ENOMEM;
+
+ val = prop->value;
+ while (sz--)
+ *val++ = cpu_to_be16(*values++);
+
+ return 0;
+}
+
+/**
* of_property_write_u32_array - Write an array of u32 to a property. If
* the property does not exist, it will be created and appended to the given
* device node.
@@ -839,6 +952,49 @@ int of_property_write_u32_array(struct device_node *np,
}
/**
+ * of_property_write_u64_array - Write an array of u64 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write 64-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u64_array(struct device_node *np,
+ const char *propname, const u64 *values,
+ size_t sz)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ __be32 *val;
+
+ if (!prop)
+ prop = of_new_property(np, propname, NULL, 0);
+ if (!prop)
+ return -ENOMEM;
+
+ free(prop->value);
+
+ prop->length = 2 * sizeof(*val) * sz;
+ prop->value = malloc(prop->length);
+ if (!prop->value)
+ return -ENOMEM;
+
+ val = prop->value;
+ while (sz--) {
+ of_write_number(val, *values++, 2);
+ val += 2;
+ }
+
+ return 0;
+}
+
+/**
* of_parse_phandle - Resolve a phandle property to a device_node pointer
* @np: Pointer to device node holding phandle property
* @phandle_name: Name of property holding a phandle value
diff --git a/include/of.h b/include/of.h
index 51ecf4d..53a135a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -113,17 +113,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
}
}
-int of_property_write_u32_array(struct device_node *np,
- const char *propname, const u32 *values,
- size_t sz);
-
-static inline int of_property_write_u32(struct device_node *np,
- const char *propname,
- u32 value)
-{
- return of_property_write_u32_array(np, propname, &value, 1);
-}
-
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp);
@@ -216,6 +205,21 @@ extern int of_property_match_string(struct device_node *np,
extern int of_property_count_strings(struct device_node *np,
const char *propname);
+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,
+ const char *propname, const u8 *values,
+ size_t sz);
+extern int of_property_write_u16_array(struct device_node *np,
+ const char *propname, const u16 *values,
+ size_t sz);
+extern int of_property_write_u32_array(struct device_node *np,
+ const char *propname, const u32 *values,
+ size_t sz);
+extern int of_property_write_u64_array(struct device_node *np,
+ const char *propname, const u64 *values,
+ size_t sz);
+
extern struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name,
int index);
@@ -353,6 +357,36 @@ static inline int of_property_count_strings(struct device_node *np,
return -ENOSYS;
}
+static inline int of_property_write_bool(struct device_node *np,
+ const char *propname, const bool value)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_write_u8_array(struct device_node *np,
+ const char *propname, const u8 *values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_write_u16_array(struct device_node *np,
+ const char *propname, const u16 *values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_write_u32_array(struct device_node *np,
+ const char *propname, const u32 *values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_write_u64_array(struct device_node *np,
+ const char *propname, const u64 *values, size_t sz)
+{
+ return -ENOSYS;
+}
+
static inline struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name, int index)
{
@@ -502,4 +536,30 @@ static inline int of_property_read_u32(const struct device_node *np,
return of_property_read_u32_array(np, propname, out_value, 1);
}
+static inline int of_property_write_u8(struct device_node *np,
+ const char *propname, u8 value)
+{
+ return of_property_write_u8_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u16(struct device_node *np,
+ const char *propname, u16 value)
+{
+ return of_property_write_u16_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u32(struct device_node *np,
+ const char *propname,
+ u32 value)
+{
+ return of_property_write_u32_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u64(struct device_node *np,
+ const char *propname,
+ u64 value)
+{
+ return of_property_write_u64_array(np, propname, &value, 1);
+}
+
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 18/22] OF: base: import property iterators from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (16 preceding siblings ...)
2013-06-18 17:30 ` [PATCH 17/22] OF: base: introduce property write for bool, u8, u16, and u64 Sebastian Hesselbarth
@ 2013-06-18 17:30 ` Sebastian Hesselbarth
2013-06-18 17:30 ` [PATCH 19/22] OF: base: remove of_tree_for_each_node from public API Sebastian Hesselbarth
` (26 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
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@gmail.com>
---
Cc: barebox@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
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 19/22] OF: base: remove of_tree_for_each_node from public API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (17 preceding siblings ...)
2013-06-18 17:30 ` [PATCH 18/22] OF: base: import property iterators from Linux OF API Sebastian Hesselbarth
@ 2013-06-18 17:30 ` Sebastian Hesselbarth
2013-06-18 17:30 ` [PATCH 20/22] OF: base: remove of_find_child_by_name Sebastian Hesselbarth
` (25 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This patch converts users of of_tree_for_each_node to recently added
for_eacg_compatible_node helper. Also of_tree_for_each_node is removed
from public OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
arch/arm/boards/at91sam9x5ek/hw_version.c | 10 +++-------
arch/arm/boards/highbank/init.c | 16 ++++++----------
drivers/of/base.c | 8 ++++++++
include/of.h | 8 --------
4 files changed, 17 insertions(+), 25 deletions(-)
diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 91af331..426bd35 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -234,13 +234,9 @@ static int cm_cogent_fixup(struct device_node *root)
int ret;
struct device_node *node;
- of_tree_for_each_node(node, root) {
- struct device_node *slotnode;
-
- if (!of_device_is_compatible(node, "atmel,hsmci"))
- continue;
-
- slotnode = of_find_child_by_name(node, "slot");
+ for_each_compatible_node(node, NULL, "atmel,hsmci") {
+ struct device_node *slotnode =
+ of_find_child_by_name(node, "slot");
if (!slotnode)
continue;
diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index 1aa713b..46ecc88 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -35,19 +35,15 @@ static int hb_fixup(struct device_node *root)
__be32 latency;
if (!(reg & HB_PWRDOM_STAT_SATA)) {
- of_tree_for_each_node(node, root) {
- if (of_device_is_compatible(node, "calxeda,hb-ahci"))
- of_set_property(node, "status", "disabled",
- sizeof("disabled"), 1);
- }
+ for_each_compatible_node(node, NULL, "calxeda,hb-ahci")
+ of_set_property(node, "status", "disabled",
+ sizeof("disabled"), 1);
}
if (!(reg & HB_PWRDOM_STAT_EMMC)) {
- of_tree_for_each_node(node, root) {
- if (of_device_is_compatible(node, "calxeda,hb-sdhci"))
- of_set_property(node, "status", "disabled",
- sizeof("disabled"), 1);
- }
+ for_each_compatible_node(node, NULL, "calxeda,hb-sdhci")
+ of_set_property(node, "status", "disabled",
+ sizeof("disabled"), 1);
}
if ((opp_table[0] >> 16) != HB_OPP_VERSION)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 489fa89..94a5c61 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -28,6 +28,14 @@
#include <linux/amba/bus.h>
#include <linux/err.h>
+/*
+ * Iterate over all nodes of a tree. As a devicetree does not
+ * have a dedicated list head, the start node (usually the root
+ * node) will not be iterated over.
+ */
+#define of_tree_for_each_node(node, root) \
+ list_for_each_entry(node, &root->list, list)
+
/**
* struct alias_prop - Alias property in 'aliases' node
* @link: List node to link the structure in aliases_lookup list
diff --git a/include/of.h b/include/of.h
index 0306742..0797dbe 100644
--- a/include/of.h
+++ b/include/of.h
@@ -85,14 +85,6 @@ int of_modalias_node(struct device_node *node, char *modalias, int len);
#define device_node_for_nach_child(node, child) \
list_for_each_entry(child, &node->children, parent_list)
-/*
- * Iterate over all nodes of a tree. As a devicetree does not
- * have a dedicated list head, the start node (usually the root
- * node) will not be iterated over.
- */
-#define of_tree_for_each_node(node, root) \
- list_for_each_entry(node, &root->list, list)
-
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 20/22] OF: base: remove of_find_child_by_name
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (18 preceding siblings ...)
2013-06-18 17:30 ` [PATCH 19/22] OF: base: remove of_tree_for_each_node from public API Sebastian Hesselbarth
@ 2013-06-18 17:30 ` Sebastian Hesselbarth
2013-06-18 17:30 ` [PATCH 21/22] OF: base: convert and remove device_node_for_nach_child Sebastian Hesselbarth
` (24 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
With of_get_child_by_name from Linux API, we can now convert and remove
of_find_child_by_name.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
arch/arm/boards/at91sam9x5ek/hw_version.c | 2 +-
drivers/of/base.c | 15 ++-------------
drivers/of/fdt.c | 9 +++++----
include/of.h | 2 --
4 files changed, 8 insertions(+), 20 deletions(-)
diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 426bd35..1207a3e 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -236,7 +236,7 @@ static int cm_cogent_fixup(struct device_node *root)
for_each_compatible_node(node, NULL, "atmel,hsmci") {
struct device_node *slotnode =
- of_find_child_by_name(node, "slot");
+ of_get_child_by_name(node, "slot");
if (!slotnode)
continue;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 94a5c61..a59a1b1 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1269,7 +1269,7 @@ struct device_node *of_find_node_by_path(const char *path)
if (slash)
*slash = 0;
- dn = of_find_child_by_name(dn, p);
+ dn = of_get_child_by_name(dn, p);
if (!dn)
goto out;
@@ -1873,17 +1873,6 @@ int of_probe(void)
return 0;
}
-struct device_node *of_find_child_by_name(struct device_node *node, const char *name)
-{
- struct device_node *_n;
-
- device_node_for_nach_child(node, _n)
- if (!of_node_cmp(_n->name, name))
- return _n;
-
- return NULL;
-}
-
/**
* of_create_node - create a new node including its parents
* @path - the nodepath to create
@@ -1908,7 +1897,7 @@ struct device_node *of_create_node(struct device_node *root, const char *path)
if (slash)
*slash = 0;
- tmp = of_find_child_by_name(dn, p);
+ tmp = of_get_child_by_name(dn, p);
if (tmp)
dn = tmp;
else
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a76396e..afaa4e0 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -61,7 +61,7 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
int len; /* length of the property */
const struct fdt_property *fdt_prop;
const char *pathp, *name;
- struct device_node *node = NULL, *n;
+ struct device_node *node = NULL;
struct property *p;
uint32_t dt_struct;
struct fdt_node_header *fnh;
@@ -135,9 +135,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
if (!node) {
node = root;
} else {
- if (merge && (n = of_find_child_by_name(node, pathp)))
- node = n;
- else
+ if (merge)
+ node = of_get_child_by_name(node,
+ pathp);
+ if (!merge || !node)
node = of_new_node(node, pathp);
}
diff --git a/include/of.h b/include/of.h
index 0797dbe..b4e18b9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -74,8 +74,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
int of_n_addr_cells(struct device_node *np);
int of_n_size_cells(struct device_node *np);
-struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
-
struct fdt_header *fdt_get_tree(void);
struct fdt_header *of_get_fixed_tree(struct device_node *node);
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 21/22] OF: base: convert and remove device_node_for_nach_child
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (19 preceding siblings ...)
2013-06-18 17:30 ` [PATCH 20/22] OF: base: remove of_find_child_by_name Sebastian Hesselbarth
@ 2013-06-18 17:30 ` Sebastian Hesselbarth
2013-06-18 17:30 ` [PATCH 22/22] OF: base: cleanup base function include Sebastian Hesselbarth
` (23 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Remove device_node_for_nach_child and convert users to corresponding
imported OF API functions.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/i2c/i2c.c | 2 +-
drivers/mfd/stmpe-i2c.c | 7 ++-----
drivers/of/partition.c | 2 +-
drivers/spi/spi.c | 2 +-
include/of.h | 3 ---
5 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index b63d946..3e09547 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -278,7 +278,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.device_node)
return;
- device_node_for_nach_child(adap->dev.device_node, n) {
+ for_each_child_of_node(adap->dev.device_node, n) {
struct i2c_board_info info = {};
struct i2c_client *result;
const __be32 *addr;
diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
index d785430..c505bc1 100644
--- a/drivers/mfd/stmpe-i2c.c
+++ b/drivers/mfd/stmpe-i2c.c
@@ -116,11 +116,8 @@ static struct stmpe_platform_data *stmpe_of_probe(struct device_d *dev)
pdata = xzalloc(sizeof(*pdata));
- device_node_for_nach_child(dev->device_node, node) {
- if (!strcmp(node->name, "stmpe_gpio")) {
- pdata->blocks |= STMPE_BLOCK_GPIO;
- }
- }
+ if (of_get_child_by_name(dev->device_node, "stmpe_gpio"))
+ pdata->blocks |= STMPE_BLOCK_GPIO;
return pdata;
}
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 2d70cf5..e4b7d1e 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -29,7 +29,7 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node)
const char *partname;
char *filename;
- device_node_for_nach_child(node, n) {
+ for_each_child_of_node(node, n) {
const __be32 *reg;
unsigned long offset, size;
const char *name;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index eebf64c..5d4dfd6 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -107,7 +107,7 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
struct spi_board_info chip;
struct property *reg;
- device_node_for_nach_child(node, n) {
+ for_each_child_of_node(node, n) {
memset(&chip, 0, sizeof(chip));
chip.name = xstrdup(n->name);
chip.bus_num = master->bus_num;
diff --git a/include/of.h b/include/of.h
index b4e18b9..4cf4313 100644
--- a/include/of.h
+++ b/include/of.h
@@ -80,9 +80,6 @@ struct fdt_header *of_get_fixed_tree(struct device_node *node);
int of_modalias_node(struct device_node *node, char *modalias, int len);
-#define device_node_for_nach_child(node, child) \
- list_for_each_entry(child, &node->children, parent_list)
-
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH 22/22] OF: base: cleanup base function include
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (20 preceding siblings ...)
2013-06-18 17:30 ` [PATCH 21/22] OF: base: convert and remove device_node_for_nach_child Sebastian Hesselbarth
@ 2013-06-18 17:30 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (22 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-18 17:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This cleans up include/of.h by moving some function prototypes below
CONFIG_OFTREE and provide bogus stubs for !CONFIG_OFTREE.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
include/of.h | 138 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 109 insertions(+), 29 deletions(-)
diff --git a/include/of.h b/include/of.h
index 4cf4313..798f17a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -71,15 +71,10 @@ int of_match(struct device_d *dev, struct driver_d *drv);
int of_add_initrd(struct device_node *root, resource_size_t start,
resource_size_t end);
-int of_n_addr_cells(struct device_node *np);
-int of_n_size_cells(struct device_node *np);
-
struct fdt_header *fdt_get_tree(void);
struct fdt_header *of_get_fixed_tree(struct device_node *node);
-int of_modalias_node(struct device_node *node, char *modalias, int len);
-
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
@@ -100,21 +95,12 @@ static inline void of_write_number(void *__cell, u64 val, int size)
}
}
-const void *of_get_property(const struct device_node *np, const char *name,
- int *lenp);
-
int of_get_named_gpio(struct device_node *np,
const char *propname, int index);
-struct device_node *of_find_node_by_phandle(phandle phandle);
void of_print_property(const void *data, int len);
void of_print_cmdline(struct device_node *root);
-int of_device_is_compatible(const struct device_node *device,
- const char *compat);
-
-int of_machine_is_compatible(const char *compat);
-
u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
@@ -123,39 +109,49 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
void of_print_nodes(struct device_node *node, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
-void of_free(struct device_node *node);
struct device_node *of_unflatten_dtb(struct device_node *root, void *fdt);
-struct device_node *of_new_node(struct device_node *parent, const char *name);
-struct property *of_new_property(struct device_node *node, const char *name,
- const void *data, int len);
-void of_delete_property(struct property *pp);
-
-int of_set_property(struct device_node *node, const char *p, const void *val, int len,
- int create);
-struct device_node *of_create_node(struct device_node *root, const char *path);
-
-int of_set_root_node(struct device_node *);
-
-const struct of_device_id *of_match_node(const struct of_device_id *matches,
- const struct device_node *node);
struct cdev;
#ifdef CONFIG_OFTREE
+extern int of_n_addr_cells(struct device_node *np);
+extern int of_n_size_cells(struct device_node *np);
+
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
+extern const void *of_get_property(const struct device_node *np,
+ const char *name, int *lenp);
+
+extern int of_set_property(struct device_node *node, const char *p,
+ const void *val, int len, int create);
+extern struct property *of_new_property(struct device_node *node,
+ const char *name, const void *data, int len);
+extern void of_delete_property(struct property *pp);
extern struct device_node *of_find_node_by_name(struct device_node *from,
const char *name);
extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_node_by_phandle(phandle phandle);
extern struct device_node *of_find_compatible_node(struct device_node *from,
const char *type, const char *compat);
+extern const struct of_device_id *of_match_node(
+ const struct of_device_id *matches, const struct device_node *node);
extern struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match);
extern struct device_node *of_find_node_with_property(
struct device_node *from, const char *prop_name);
+
+extern struct device_node *of_new_node(struct device_node *parent,
+ const char *name);
+extern struct device_node *of_create_node(struct device_node *root,
+ const char *path);
+extern void of_free(struct device_node *node);
+
+extern int of_machine_is_compatible(const char *compat);
+extern int of_device_is_compatible(const struct device_node *device,
+ const char *compat);
extern int of_device_is_available(const struct device_node *device);
extern struct device_node *of_get_parent(const struct device_node *node);
@@ -223,6 +219,10 @@ extern int of_count_phandle_with_args(const struct device_node *np,
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
+extern int of_modalias_node(struct device_node *node, char *modalias, int len);
+
+extern struct device_node *of_get_root_node(void);
+extern int of_set_root_node(struct device_node *node);
int of_parse_partitions(struct cdev *cdev, struct device_node *node);
int of_device_is_stdout_path(struct device_d *dev);
@@ -231,7 +231,6 @@ void *of_flatten_dtb(struct device_node *node);
int of_add_memory(struct device_node *node, bool dump);
void of_add_memory_bank(struct device_node *node, bool dump, int r,
u64 base, u64 size);
-struct device_node *of_get_root_node(void);
#else
static inline int of_parse_partitions(struct cdev *cdev,
struct device_node *node)
@@ -264,6 +263,21 @@ static inline struct device_node *of_get_root_node(void)
return NULL;
}
+static inline int of_set_root_node(struct device_node *node)
+{
+ return -ENOSYS;
+}
+
+static inline int of_n_addr_cells(struct device_node *np)
+{
+ return 0;
+}
+
+static inline int of_n_size_cells(struct device_node *np)
+{
+ return 0;
+}
+
static inline struct device_node *of_get_parent(const struct device_node *node)
{
return NULL;
@@ -294,6 +308,28 @@ static inline struct property *of_find_property(const struct device_node *np,
return NULL;
}
+static inline const void *of_get_property(const struct device_node *np,
+ const char *name, int *lenp)
+{
+ return NULL;
+}
+
+static inline int of_set_property(struct device_node *node, const char *p,
+ const void *val, int len, int create)
+{
+ return -ENOSYS;
+}
+
+static inline struct property *of_new_property(struct device_node *node,
+ const char *name, const void *data, int len)
+{
+ return NULL;
+}
+
+static inline void of_delete_property(struct property *pp)
+{
+}
+
static inline int of_property_read_u32_index(const struct device_node *np,
const char *propname, u32 index, u32 *out_value)
{
@@ -420,6 +456,11 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
return NULL;
}
+static inline struct device_node *of_find_node_by_phandle(phandle phandle)
+{
+ return NULL;
+}
+
static inline struct device_node *of_find_compatible_node(
struct device_node *from,
const char *type,
@@ -428,6 +469,12 @@ static inline struct device_node *of_find_compatible_node(
return NULL;
}
+static inline const struct of_device_id *of_match_node(
+ const struct of_device_id *matches, const struct device_node *node)
+{
+ return NULL;
+}
+
static inline struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
@@ -442,6 +489,33 @@ static inline struct device_node *of_find_node_with_property(
return NULL;
}
+static inline struct device_node *of_new_node(struct device_node *parent,
+ const char *name)
+{
+ return NULL;
+}
+
+static inline struct device_node *of_create_node(struct device_node *root,
+ const char *path)
+{
+ return NULL;
+}
+
+static inline void of_free(struct device_node *node)
+{
+}
+
+static inline int of_machine_is_compatible(const char *compat)
+{
+ return 0;
+}
+
+static inline int of_device_is_compatible(const struct device_node *device,
+ const char *compat)
+{
+ return 0;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -460,6 +534,12 @@ static inline const char *of_alias_get(struct device_node *np)
{
return NULL;
}
+
+static inline int of_modalias_node(struct device_node *node, char *modalias,
+ int len)
+{
+ return -ENOSYS;
+}
#endif
#define for_each_node_by_name(dn, name) \
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 00/22] Barebox OF API fixes, sync, and cleanup
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (21 preceding siblings ...)
2013-06-18 17:30 ` [PATCH 22/22] OF: base: cleanup base function include Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-20 9:18 ` Sascha Hauer
2013-06-19 9:09 ` [PATCH v2 01/22] lib: string: import case-insensitive string compare Sebastian Hesselbarth
` (21 subsequent siblings)
44 siblings, 1 reply; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This is a quite large patch set to make Barebox OF API more behave
like Linux OF API. Also, it prepares Barebox to reuse Linux OF address
handling and drivers/of/of_* helpers soon.
The patch set is roughly divided into 5 sections:
(1) Patch 1 introduces case-insensitive string compare functions that will
be used later during import of Linux OF API functions.
(2) Patches 2 and 3 fix some bugs in existing OF API functions.
(3) Patches 4-8 synchronize existing OF API functions with Linux OF API
counterparts.
(4) Patches 9-18 import API functions from Linux OF API or introduce new
functions based on existing Barebox OF API functions.
(5) Patches 19-22 convert to new API functions and remove now obsolete
functions. Further, it cleans up existing OF include, by providing
OFTREE prototypes and !OFTREE bogus stubs.
v2 of this patch set takes care of comments made by Sascha Hauer with
respect to Patches 7 and 13. A detailed changelog is given in the
respective patches. Unfortunately, I have to resend the whole patch
set, although only 2 patches really changed as the following patches
need to be rebased on to that changes.
Also, this v2 is only compile-tested for CONFIG_OFTREE set and not set.
The v2 patch set applied to barebox/next can also be found at
git://github.com/shesselba/barebox-dove.git barebox-of-sync-v2
Sebastian Hesselbarth (22):
lib: string: import case-insensitive string compare
OF: base: bail out early on missing matches for of_match_node
OF: base: also update property length on of_property_write_u32
OF: base: export of_alias_scan
OF: base: convert strcmp to default string compare functions
OF: base: sync of_find_property with linux OF API
OF: base: sync of_find_node_by_path with linux OF API
OF: base: rename of_node_disabled to of_device_is_available
OF: base: import of_find_node_by_name from Linux OF API
OF: base: import of_find_compatible_node from Linux OF API
OF: base: import of_find_matching_node_and_match from Linux OF API
OF: base: import of_find_node_with_property from Linux OF API
OF: base: import parent/child functions from Linux OF API
OF: base: import of_property_read_* helpers from Linux OF API
OF: base: import of_parse_phandle from Linux OF API
OF: base: import parse phandle functions from Linux OF API
OF: base: introduce property write for bool, u8, u16, and u64
OF: base: import property iterators from Linux OF API
OF: base: remove of_tree_for_each_node from public API
OF: base: remove of_find_child_by_name
OF: base: convert and remove device_node_for_nach_child
OF: base: cleanup base function include
arch/arm/boards/at91sam9x5ek/hw_version.c | 10 +-
arch/arm/boards/highbank/init.c | 20 +-
arch/ppc/mach-mpc5xxx/cpu.c | 4 +-
commands/of_node.c | 2 +-
commands/of_property.c | 12 +-
commands/oftree.c | 11 +-
common/oftree.c | 2 +-
drivers/i2c/i2c.c | 2 +-
drivers/mfd/stmpe-i2c.c | 7 +-
drivers/of/base.c | 1244 +++++++++++++++++++++++------
drivers/of/fdt.c | 14 +-
drivers/of/gpio.c | 9 +-
drivers/of/of_net.c | 6 +-
drivers/of/partition.c | 2 +-
drivers/pinctrl/pinctrl.c | 4 +-
drivers/spi/spi.c | 12 +-
drivers/usb/imx/chipidea-imx.c | 14 +-
include/linux/string.h | 9 +
include/of.h | 616 ++++++++++++--
lib/string.c | 60 ++
net/eth.c | 2 +-
21 files changed, 1645 insertions(+), 417 deletions(-)
---
Cc: barebox@lists.infradead.org
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH v2 00/22] Barebox OF API fixes, sync, and cleanup
2013-06-19 9:09 ` [PATCH v2 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
@ 2013-06-20 9:18 ` Sascha Hauer
0 siblings, 0 replies; 55+ messages in thread
From: Sascha Hauer @ 2013-06-20 9:18 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
On Wed, Jun 19, 2013 at 11:09:29AM +0200, Sebastian Hesselbarth wrote:
> This is a quite large patch set to make Barebox OF API more behave
> like Linux OF API. Also, it prepares Barebox to reuse Linux OF address
> handling and drivers/of/of_* helpers soon.
>
> The patch set is roughly divided into 5 sections:
>
> (1) Patch 1 introduces case-insensitive string compare functions that will
> be used later during import of Linux OF API functions.
>
> (2) Patches 2 and 3 fix some bugs in existing OF API functions.
>
> (3) Patches 4-8 synchronize existing OF API functions with Linux OF API
> counterparts.
>
> (4) Patches 9-18 import API functions from Linux OF API or introduce new
> functions based on existing Barebox OF API functions.
>
> (5) Patches 19-22 convert to new API functions and remove now obsolete
> functions. Further, it cleans up existing OF include, by providing
> OFTREE prototypes and !OFTREE bogus stubs.
>
> v2 of this patch set takes care of comments made by Sascha Hauer with
> respect to Patches 7 and 13. A detailed changelog is given in the
> respective patches. Unfortunately, I have to resend the whole patch
> set, although only 2 patches really changed as the following patches
> need to be rebased on to that changes.
>
> Also, this v2 is only compile-tested for CONFIG_OFTREE set and not set.
>
> The v2 patch set applied to barebox/next can also be found at
> git://github.com/shesselba/barebox-dove.git barebox-of-sync-v2
I gave this series a test. With the fixes I mentioned the series
compiles on all boards. I did runtime tests on a few oftree enabled
boards, everything seems to work smoothly.
I think we are good to go for this series.
Good work, thanks.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 01/22] lib: string: import case-insensitive string compare
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (22 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-20 9:04 ` Sascha Hauer
2013-06-19 9:09 ` [PATCH v2 02/22] OF: base: bail out early on missing matches for of_match_node Sebastian Hesselbarth
` (20 subsequent siblings)
44 siblings, 1 reply; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports strnicmp, strcasecmp, and strncasecmp from Linux to barebox.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
include/linux/string.h | 9 +++++++
lib/string.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index afd0aa6..658264c 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -53,6 +53,15 @@ extern int strcmp(const char *,const char *);
#ifndef __HAVE_ARCH_STRNCMP
extern int strncmp(const char *,const char *,__kernel_size_t);
#endif
+#ifndef __HAVE_ARCH_STRNICMP
+extern int strnicmp(const char *, const char *, __kernel_size_t);
+#endif
+#ifndef __HAVE_ARCH_STRCASECMP
+extern int strcasecmp(const char *s1, const char *s2);
+#endif
+#ifndef __HAVE_ARCH_STRNCASECMP
+extern int strncasecmp(const char *s1, const char *s2, size_t n);
+#endif
#ifndef __HAVE_ARCH_STRCHR
extern char * _strchr(const char *,int);
#endif
diff --git a/lib/string.c b/lib/string.c
index db4f2ae..f544b23 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -22,6 +22,66 @@
char * ___strtok;
+#ifndef __HAVE_ARCH_STRNICMP
+/**
+ * strnicmp - Case insensitive, length-limited string comparison
+ * @s1: One string
+ * @s2: The other string
+ * @len: the maximum number of characters to compare
+ */
+int strnicmp(const char *s1, const char *s2, size_t len)
+{
+ /* Yes, Virginia, it had better be unsigned */
+ unsigned char c1, c2;
+
+ if (!len)
+ return 0;
+
+ do {
+ c1 = *s1++;
+ c2 = *s2++;
+ if (!c1 || !c2)
+ break;
+ if (c1 == c2)
+ continue;
+ c1 = tolower(c1);
+ c2 = tolower(c2);
+ if (c1 != c2)
+ break;
+ } while (--len);
+ return (int)c1 - (int)c2;
+}
+EXPORT_SYMBOL(strnicmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRCASECMP
+int strcasecmp(const char *s1, const char *s2)
+{
+ int c1, c2;
+
+ do {
+ c1 = tolower(*s1++);
+ c2 = tolower(*s2++);
+ } while (c1 == c2 && c1 != 0);
+ return c1 - c2;
+}
+EXPORT_SYMBOL(strcasecmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRNCASECMP
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ int c1, c2;
+
+ do {
+ c1 = tolower(*s1++);
+ c2 = tolower(*s2++);
+ } while ((--n > 0) && c1 == c2 && c1 != 0);
+ return c1 - c2;
+}
+EXPORT_SYMBOL(strncasecmp);
+#endif
+
#ifndef __HAVE_ARCH_STRCPY
/**
* strcpy - Copy a %NUL terminated string
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH v2 01/22] lib: string: import case-insensitive string compare
2013-06-19 9:09 ` [PATCH v2 01/22] lib: string: import case-insensitive string compare Sebastian Hesselbarth
@ 2013-06-20 9:04 ` Sascha Hauer
0 siblings, 0 replies; 55+ messages in thread
From: Sascha Hauer @ 2013-06-20 9:04 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This patch needs the following before it to not break ppc compilation.
Sascha
From 1a8c27b7ad29bfa5f868db15e11da8e6bdc7d01f Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Thu, 20 Jun 2013 11:02:09 +0200
Subject: [PATCH] ppc: remove strcasecmp/strncasecmp prototypes
ppc does not implement these, so remove the prototypes and use
the ones from include/linux/string.h
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/ppc/include/asm/string.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/arch/ppc/include/asm/string.h b/arch/ppc/include/asm/string.h
index d912a6b..33d143f 100644
--- a/arch/ppc/include/asm/string.h
+++ b/arch/ppc/include/asm/string.h
@@ -13,8 +13,6 @@
#define __HAVE_ARCH_MEMCMP
#define __HAVE_ARCH_MEMCHR
-extern int strcasecmp(const char *, const char *);
-extern int strncasecmp(const char *, const char *, int);
extern char * strcpy(char *,const char *);
extern char * strncpy(char *,const char *, __kernel_size_t);
extern __kernel_size_t strlen(const char *);
--
1.8.3.1
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 02/22] OF: base: bail out early on missing matches for of_match_node
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (23 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 01/22] lib: string: import case-insensitive string compare Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 03/22] OF: base: also update property length on of_property_write_u32 Sebastian Hesselbarth
` (19 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
of_match_node checks for compatiblity between a set of matches and a
node. Neither the matches nor node pointer are checked for validity.
This adds the required checks to of_match_node.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4241e65..ab0f4cd 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -321,6 +321,9 @@ EXPORT_SYMBOL(of_device_is_compatible);
const struct of_device_id *of_match_node(const struct of_device_id *matches,
const struct device_node *node)
{
+ if (!matches || !node)
+ return NULL;
+
while (matches->compatible) {
if (of_device_is_compatible(node, matches->compatible) == 1)
return matches;
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 03/22] OF: base: also update property length on of_property_write_u32
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (24 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 02/22] OF: base: bail out early on missing matches for of_match_node Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 04/22] OF: base: export of_alias_scan Sebastian Hesselbarth
` (18 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Current implementation of of_property_write_u32 does free old property
values and allocates new values depending on the size passed. While
copying the new values to the property, corresponding length is not
set. This makes of_property_write_u32 set the length of the new property
values and also adds a API header describing the function.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ab0f4cd..616b93d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -383,6 +383,21 @@ int of_property_read_u32_array(const struct device_node *np,
}
EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+/**
+ * of_property_write_u32_array - Write an array of u32 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write 32-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
int of_property_write_u32_array(struct device_node *np,
const char *propname, const u32 *values,
size_t sz)
@@ -397,14 +412,15 @@ int of_property_write_u32_array(struct device_node *np,
free(prop->value);
- prop->value = malloc(sizeof(__be32) * sz);
+ prop->length = sizeof(*val) * sz;
+ prop->value = malloc(prop->length);
if (!prop->value)
return -ENOMEM;
val = prop->value;
-
while (sz--)
*val++ = cpu_to_be32(*values++);
+
return 0;
}
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 04/22] OF: base: export of_alias_scan
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (25 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 03/22] OF: base: also update property length on of_property_write_u32 Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 05/22] OF: base: convert strcmp to default string compare functions Sebastian Hesselbarth
` (17 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
To prepare clean-up of OF API, we need to export of_alias_scan.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 3 ++-
include/of.h | 31 ++++++++++++++++++-------------
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 616b93d..f3ed836 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -135,7 +135,7 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
* the global lookup table with the properties. It returns the
* number of alias_prop found, or error code in error case.
*/
-static void of_alias_scan(void)
+void of_alias_scan(void)
{
struct property *pp;
struct alias_prop *app, *tmp;
@@ -187,6 +187,7 @@ static void of_alias_scan(void)
of_alias_add(ap, np, id, start, len);
}
}
+EXPORT_SYMBOL(of_alias_scan);
/**
* of_alias_get_id - Get alias id for the given device_node
diff --git a/include/of.h b/include/of.h
index 300b706..8a69793 100644
--- a/include/of.h
+++ b/include/of.h
@@ -178,10 +178,11 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
struct cdev;
#ifdef CONFIG_OFTREE
-int of_parse_partitions(struct cdev *cdev, struct device_node *node);
+extern void of_alias_scan(void);
+extern int of_alias_get_id(struct device_node *np, const char *stem);
+extern const char *of_alias_get(struct device_node *np);
-int of_alias_get_id(struct device_node *np, const char *stem);
-const char *of_alias_get(struct device_node *np);
+int of_parse_partitions(struct cdev *cdev, struct device_node *node);
int of_device_is_stdout_path(struct device_d *dev);
const char *of_get_model(void);
void *of_flatten_dtb(struct device_node *node);
@@ -196,16 +197,6 @@ static inline int of_parse_partitions(struct cdev *cdev,
return -EINVAL;
}
-static inline int of_alias_get_id(struct device_node *np, const char *stem)
-{
- return -ENOENT;
-}
-
-static inline const char *of_alias_get(struct device_node *np)
-{
- return NULL;
-}
-
static inline int of_device_is_stdout_path(struct device_d *dev)
{
return 0;
@@ -230,6 +221,20 @@ static inline struct device_node *of_get_root_node(void)
{
return NULL;
}
+
+static inline void of_alias_scan(void)
+{
+}
+
+static inline int of_alias_get_id(struct device_node *np, const char *stem)
+{
+ return -ENOSYS;
+}
+
+static inline const char *of_alias_get(struct device_node *np)
+{
+ return NULL;
+}
#endif
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 05/22] OF: base: convert strcmp to default string compare functions
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (26 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 04/22] OF: base: export of_alias_scan Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 06/22] OF: base: sync of_find_property with linux OF API Sebastian Hesselbarth
` (16 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Barebox compares compatible, node names, and property names with strcmp.
Linux by default compares compatible and node names with strcasecmp. To
avoid inconsitencies between Barebox and Linux dts files, we convert to
these default string compare functions.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 25 +++++++++++++------------
include/of.h | 5 +++++
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index f3ed836..1c9ef58 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -104,14 +104,15 @@ static void of_bus_count_cells(struct device_node *dev,
struct property *of_find_property(const struct device_node *node, const char *name)
{
- struct property *p;
+ struct property *pp;
if (!node)
return NULL;
- list_for_each_entry(p, &node->properties, list)
- if (!strcmp(p->name, name))
- return p;
+ list_for_each_entry(pp, &node->properties, list)
+ if (of_prop_cmp(pp->name, name) == 0)
+ return pp;
+
return NULL;
}
EXPORT_SYMBOL(of_find_property);
@@ -160,9 +161,9 @@ void of_alias_scan(void)
int id, len;
/* Skip those we do not want to proceed */
- if (!strcmp(pp->name, "name") ||
- !strcmp(pp->name, "phandle") ||
- !strcmp(pp->name, "linux,phandle"))
+ if (!of_prop_cmp(pp->name, "name") ||
+ !of_prop_cmp(pp->name, "phandle") ||
+ !of_prop_cmp(pp->name, "linux,phandle"))
continue;
np = of_find_node_by_path(root_node, pp->value);
@@ -203,7 +204,7 @@ int of_alias_get_id(struct device_node *np, const char *stem)
int id = -ENODEV;
list_for_each_entry(app, &aliases_lookup, link) {
- if (strcmp(app->stem, stem) != 0)
+ if (of_node_cmp(app->stem, stem) != 0)
continue;
if (np == app->np) {
@@ -221,7 +222,7 @@ const char *of_alias_get(struct device_node *np)
struct property *pp;
list_for_each_entry(pp, &of_aliases->properties, list) {
- if (!strcmp(np->full_name, pp->value))
+ if (!of_node_cmp(np->full_name, pp->value))
return pp->name;
}
@@ -301,7 +302,7 @@ int of_device_is_compatible(const struct device_node *device,
if (cp == NULL)
return 0;
while (cplen > 0) {
- if (strcmp(cp, compat) == 0)
+ if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
return 1;
l = strlen(cp) + 1;
cp += l;
@@ -958,7 +959,7 @@ int of_add_memory(struct device_node *node, bool dump)
if (ret)
return -ENXIO;
- if (strcmp(device_type, "memory"))
+ if (of_node_cmp(device_type, "memory"))
return -ENXIO;
of_bus_count_cells(node, &na, &nc);
@@ -1177,7 +1178,7 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
struct device_node *_n;
device_node_for_nach_child(node, _n)
- if (!strcmp(_n->name, name))
+ if (!of_node_cmp(_n->name, name))
return _n;
return NULL;
diff --git a/include/of.h b/include/of.h
index 8a69793..a91a4c9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -5,6 +5,11 @@
#include <errno.h>
#include <asm/byteorder.h>
+/* Default string compare functions */
+#define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
+#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
+#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
+
#define OF_BAD_ADDR ((u64)-1)
typedef u32 phandle;
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 06/22] OF: base: sync of_find_property with linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (27 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 05/22] OF: base: convert strcmp to default string compare functions Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-20 8:57 ` Sascha Hauer
2013-06-19 9:09 ` [PATCH v2 07/22] OF: base: sync of_find_node_by_path " Sebastian Hesselbarth
` (15 subsequent siblings)
44 siblings, 1 reply; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
To start synchronizing OF API of barebox with linux OF API, this adds
a length pointer to of_find_property. Also all current users of that
function are updated to reflect the API change.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
commands/of_property.c | 2 +-
drivers/of/base.c | 38 ++++++++++++++++++--------------------
drivers/of/fdt.c | 5 ++++-
drivers/of/of_net.c | 6 +++---
drivers/pinctrl/pinctrl.c | 4 ++--
drivers/spi/spi.c | 10 +++++-----
drivers/usb/imx/chipidea-imx.c | 3 ++-
include/of.h | 12 ++++++++++--
8 files changed, 45 insertions(+), 35 deletions(-)
diff --git a/commands/of_property.c b/commands/of_property.c
index 44bb388..d1a9a17 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -212,7 +212,7 @@ static int do_of_property(int argc, char *argv[])
if (optind + 1 < argc) {
propname = argv[optind + 1];
- pp = of_find_property(node, propname);
+ pp = of_find_property(node, propname, NULL);
if (!set && !pp) {
printf("Cannot find property %s\n", propname);
return -ENOENT;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1c9ef58..85199b6 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -102,16 +102,20 @@ static void of_bus_count_cells(struct device_node *dev,
of_bus_default_count_cells(dev, addrc, sizec);
}
-struct property *of_find_property(const struct device_node *node, const char *name)
+struct property *of_find_property(const struct device_node *np,
+ const char *name, int *lenp)
{
struct property *pp;
- if (!node)
+ if (!np)
return NULL;
- list_for_each_entry(pp, &node->properties, list)
- if (of_prop_cmp(pp->name, name) == 0)
+ list_for_each_entry(pp, &np->properties, list)
+ if (of_prop_cmp(pp->name, name) == 0) {
+ if (lenp)
+ *lenp = pp->length;
return pp;
+ }
return NULL;
}
@@ -242,7 +246,7 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
return addr;
node = node->parent;
- p = of_find_property(node, "ranges");
+ p = of_find_property(node, "ranges", NULL);
if (!p && node->parent)
return OF_BAD_ADDR;
of_bus_count_cells(node, &na, &nc);
@@ -277,13 +281,7 @@ EXPORT_SYMBOL(of_find_node_by_phandle);
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp)
{
- struct property *pp = of_find_property(np, name);
-
- if (!pp)
- return NULL;
-
- if (lenp)
- *lenp = pp->length;
+ struct property *pp = of_find_property(np, name, lenp);
return pp ? pp->value : NULL;
}
@@ -368,7 +366,7 @@ int of_property_read_u32_array(const struct device_node *np,
const char *propname, u32 *out_values,
size_t sz)
{
- struct property *prop = of_find_property(np, propname);
+ struct property *prop = of_find_property(np, propname, NULL);
const __be32 *val;
if (!prop)
@@ -404,7 +402,7 @@ int of_property_write_u32_array(struct device_node *np,
const char *propname, const u32 *values,
size_t sz)
{
- struct property *prop = of_find_property(np, propname);
+ struct property *prop = of_find_property(np, propname, NULL);
__be32 *val;
if (!prop)
@@ -619,7 +617,7 @@ EXPORT_SYMBOL(of_find_node_by_path);
int of_property_read_string(struct device_node *np, const char *propname,
const char **out_string)
{
- struct property *prop = of_find_property(np, propname);
+ struct property *prop = of_find_property(np, propname, NULL);
if (!prop)
return -EINVAL;
if (!prop->value)
@@ -652,7 +650,7 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
int of_property_read_string_index(struct device_node *np, const char *propname,
int index, const char **output)
{
- struct property *prop = of_find_property(np, propname);
+ struct property *prop = of_find_property(np, propname, NULL);
int i = 0;
size_t l = 0, total = 0;
const char *p;
@@ -725,7 +723,7 @@ static int of_node_disabled(struct device_node *node)
{
struct property *p;
- p = of_find_property(node, "status");
+ p = of_find_property(node, "status", NULL);
if (p) {
if (!strcmp("disabled", p->value))
return 1;
@@ -833,7 +831,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
if (!np)
return -ENOENT;
- pp = of_find_property(np, name);
+ pp = of_find_property(np, name, NULL);
if (pp) {
void *data;
@@ -1278,11 +1276,11 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
} else {
struct property *pp;
- pp = of_find_property(chosen, "linux,initrd-start");
+ pp = of_find_property(chosen, "linux,initrd-start", NULL);
if (pp)
of_delete_property(pp);
- pp = of_find_property(chosen, "linux,initrd-end");
+ pp = of_find_property(chosen, "linux,initrd-end", NULL);
if (pp)
of_delete_property(pp);
}
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a3ec576..a76396e 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -178,7 +178,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
goto err;
}
- if (merge && (p = of_find_property(node, name))) {
+ p = NULL;
+ if (merge)
+ p = of_find_property(node, name, NULL);
+ if (merge && p) {
free(p->value);
p->value = xzalloc(len);
memcpy(p->value, nodep, len);
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index de93fbc..2bf05e2 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -76,15 +76,15 @@ const void *of_get_mac_address(struct device_node *np)
{
struct property *pp;
- pp = of_find_property(np, "mac-address");
+ pp = of_find_property(np, "mac-address", NULL);
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
return pp->value;
- pp = of_find_property(np, "local-mac-address");
+ pp = of_find_property(np, "local-mac-address", NULL);
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
return pp->value;
- pp = of_find_property(np, "address");
+ pp = of_find_property(np, "address", NULL);
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
return pp->value;
diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index fa979a1..7c797d3 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -64,14 +64,14 @@ int pinctrl_select_state(struct device_d *dev, const char *name)
if (!np)
return 0;
- if (!of_find_property(np, "pinctrl-0"))
+ if (!of_find_property(np, "pinctrl-0", NULL))
return 0;
/* For each defined state ID */
for (state = 0; ; state++) {
/* Retrieve the pinctrl-* property */
propname = asprintf("pinctrl-%d", state);
- prop = of_find_property(np, propname);
+ prop = of_find_property(np, propname, NULL);
free(propname);
if (!prop) {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index f460a7a..eebf64c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -112,17 +112,17 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
chip.name = xstrdup(n->name);
chip.bus_num = master->bus_num;
/* Mode (clock phase/polarity/etc.) */
- if (of_find_property(n, "spi-cpha"))
+ if (of_find_property(n, "spi-cpha", NULL))
chip.mode |= SPI_CPHA;
- if (of_find_property(n, "spi-cpol"))
+ if (of_find_property(n, "spi-cpol", NULL))
chip.mode |= SPI_CPOL;
- if (of_find_property(n, "spi-cs-high"))
+ if (of_find_property(n, "spi-cs-high", NULL))
chip.mode |= SPI_CS_HIGH;
- if (of_find_property(n, "spi-3wire"))
+ if (of_find_property(n, "spi-3wire", NULL))
chip.mode |= SPI_3WIRE;
of_property_read_u32(n, "spi-max-frequency",
&chip.max_speed_hz);
- reg = of_find_property(n, "reg");
+ reg = of_find_property(n, "reg", NULL);
if (!reg)
continue;
chip.chip_select = of_read_number(reg->value, 1);
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 4ee7610..32b05aa 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -108,7 +108,8 @@ static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
return -EINVAL;
}
- if (of_find_property(ci->dev->device_node, "disable-over-current"))
+ if (of_find_property(ci->dev->device_node,
+ "disable-over-current"), NULL)
ci->flags |= MXC_EHCI_DISABLE_OVERCURRENT;
return 0;
diff --git a/include/of.h b/include/of.h
index a91a4c9..7ebde62 100644
--- a/include/of.h
+++ b/include/of.h
@@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
int of_n_addr_cells(struct device_node *np);
int of_n_size_cells(struct device_node *np);
-struct property *of_find_property(const struct device_node *node, const char *name);
-
struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
@@ -183,6 +181,9 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
struct cdev;
#ifdef CONFIG_OFTREE
+extern struct property *of_find_property(const struct device_node *np,
+ const char *name, int *lenp);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -227,6 +228,13 @@ static inline struct device_node *of_get_root_node(void)
return NULL;
}
+static inline struct property *of_find_property(const struct device_node *np,
+ const char *name,
+ int *lenp)
+{
+ return NULL;
+}
+
static inline void of_alias_scan(void)
{
}
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH v2 06/22] OF: base: sync of_find_property with linux OF API
2013-06-19 9:09 ` [PATCH v2 06/22] OF: base: sync of_find_property with linux OF API Sebastian Hesselbarth
@ 2013-06-20 8:57 ` Sascha Hauer
0 siblings, 0 replies; 55+ messages in thread
From: Sascha Hauer @ 2013-06-20 8:57 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
On Wed, Jun 19, 2013 at 11:09:35AM +0200, Sebastian Hesselbarth wrote:
> To start synchronizing OF API of barebox with linux OF API, this adds
> a length pointer to of_find_property. Also all current users of that
> function are updated to reflect the API change.
>
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> ---
> Cc: barebox@lists.infradead.org
> ---
> commands/of_property.c | 2 +-
> drivers/of/base.c | 38 ++++++++++++++++++--------------------
> drivers/of/fdt.c | 5 ++++-
> drivers/of/of_net.c | 6 +++---
> drivers/pinctrl/pinctrl.c | 4 ++--
> drivers/spi/spi.c | 10 +++++-----
> drivers/usb/imx/chipidea-imx.c | 3 ++-
> include/of.h | 12 ++++++++++--
> 8 files changed, 45 insertions(+), 35 deletions(-)
>
> diff --git a/commands/of_property.c b/commands/of_property.c
> index 44bb388..d1a9a17 100644
> --- a/commands/of_property.c
> +++ b/commands/of_property.c
> @@ -212,7 +212,7 @@ static int do_of_property(int argc, char *argv[])
> if (optind + 1 < argc) {
> propname = argv[optind + 1];
>
> - pp = of_find_property(node, propname);
> + pp = of_find_property(node, propname, NULL);
> if (!set && !pp) {
> printf("Cannot find property %s\n", propname);
> return -ENOENT;
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 1c9ef58..85199b6 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -102,16 +102,20 @@ static void of_bus_count_cells(struct device_node *dev,
> of_bus_default_count_cells(dev, addrc, sizec);
> }
>
> -struct property *of_find_property(const struct device_node *node, const char *name)
> +struct property *of_find_property(const struct device_node *np,
> + const char *name, int *lenp)
> {
> struct property *pp;
>
> - if (!node)
> + if (!np)
> return NULL;
>
> - list_for_each_entry(pp, &node->properties, list)
> - if (of_prop_cmp(pp->name, name) == 0)
> + list_for_each_entry(pp, &np->properties, list)
> + if (of_prop_cmp(pp->name, name) == 0) {
> + if (lenp)
> + *lenp = pp->length;
> return pp;
> + }
>
> return NULL;
> }
> @@ -242,7 +246,7 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
> return addr;
>
> node = node->parent;
> - p = of_find_property(node, "ranges");
> + p = of_find_property(node, "ranges", NULL);
> if (!p && node->parent)
> return OF_BAD_ADDR;
> of_bus_count_cells(node, &na, &nc);
> @@ -277,13 +281,7 @@ EXPORT_SYMBOL(of_find_node_by_phandle);
> const void *of_get_property(const struct device_node *np, const char *name,
> int *lenp)
> {
> - struct property *pp = of_find_property(np, name);
> -
> - if (!pp)
> - return NULL;
> -
> - if (lenp)
> - *lenp = pp->length;
> + struct property *pp = of_find_property(np, name, lenp);
>
> return pp ? pp->value : NULL;
> }
> @@ -368,7 +366,7 @@ int of_property_read_u32_array(const struct device_node *np,
> const char *propname, u32 *out_values,
> size_t sz)
> {
> - struct property *prop = of_find_property(np, propname);
> + struct property *prop = of_find_property(np, propname, NULL);
> const __be32 *val;
>
> if (!prop)
> @@ -404,7 +402,7 @@ int of_property_write_u32_array(struct device_node *np,
> const char *propname, const u32 *values,
> size_t sz)
> {
> - struct property *prop = of_find_property(np, propname);
> + struct property *prop = of_find_property(np, propname, NULL);
> __be32 *val;
>
> if (!prop)
> @@ -619,7 +617,7 @@ EXPORT_SYMBOL(of_find_node_by_path);
> int of_property_read_string(struct device_node *np, const char *propname,
> const char **out_string)
> {
> - struct property *prop = of_find_property(np, propname);
> + struct property *prop = of_find_property(np, propname, NULL);
> if (!prop)
> return -EINVAL;
> if (!prop->value)
> @@ -652,7 +650,7 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
> int of_property_read_string_index(struct device_node *np, const char *propname,
> int index, const char **output)
> {
> - struct property *prop = of_find_property(np, propname);
> + struct property *prop = of_find_property(np, propname, NULL);
> int i = 0;
> size_t l = 0, total = 0;
> const char *p;
> @@ -725,7 +723,7 @@ static int of_node_disabled(struct device_node *node)
> {
> struct property *p;
>
> - p = of_find_property(node, "status");
> + p = of_find_property(node, "status", NULL);
> if (p) {
> if (!strcmp("disabled", p->value))
> return 1;
> @@ -833,7 +831,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
> if (!np)
> return -ENOENT;
>
> - pp = of_find_property(np, name);
> + pp = of_find_property(np, name, NULL);
> if (pp) {
> void *data;
>
> @@ -1278,11 +1276,11 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
> } else {
> struct property *pp;
>
> - pp = of_find_property(chosen, "linux,initrd-start");
> + pp = of_find_property(chosen, "linux,initrd-start", NULL);
> if (pp)
> of_delete_property(pp);
>
> - pp = of_find_property(chosen, "linux,initrd-end");
> + pp = of_find_property(chosen, "linux,initrd-end", NULL);
> if (pp)
> of_delete_property(pp);
> }
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index a3ec576..a76396e 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -178,7 +178,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
> goto err;
> }
>
> - if (merge && (p = of_find_property(node, name))) {
> + p = NULL;
> + if (merge)
> + p = of_find_property(node, name, NULL);
> + if (merge && p) {
> free(p->value);
> p->value = xzalloc(len);
> memcpy(p->value, nodep, len);
> diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
> index de93fbc..2bf05e2 100644
> --- a/drivers/of/of_net.c
> +++ b/drivers/of/of_net.c
> @@ -76,15 +76,15 @@ const void *of_get_mac_address(struct device_node *np)
> {
> struct property *pp;
>
> - pp = of_find_property(np, "mac-address");
> + pp = of_find_property(np, "mac-address", NULL);
> if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> return pp->value;
>
> - pp = of_find_property(np, "local-mac-address");
> + pp = of_find_property(np, "local-mac-address", NULL);
> if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> return pp->value;
>
> - pp = of_find_property(np, "address");
> + pp = of_find_property(np, "address", NULL);
> if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> return pp->value;
>
> diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
> index fa979a1..7c797d3 100644
> --- a/drivers/pinctrl/pinctrl.c
> +++ b/drivers/pinctrl/pinctrl.c
> @@ -64,14 +64,14 @@ int pinctrl_select_state(struct device_d *dev, const char *name)
> if (!np)
> return 0;
>
> - if (!of_find_property(np, "pinctrl-0"))
> + if (!of_find_property(np, "pinctrl-0", NULL))
> return 0;
>
> /* For each defined state ID */
> for (state = 0; ; state++) {
> /* Retrieve the pinctrl-* property */
> propname = asprintf("pinctrl-%d", state);
> - prop = of_find_property(np, propname);
> + prop = of_find_property(np, propname, NULL);
> free(propname);
>
> if (!prop) {
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index f460a7a..eebf64c 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -112,17 +112,17 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
> chip.name = xstrdup(n->name);
> chip.bus_num = master->bus_num;
> /* Mode (clock phase/polarity/etc.) */
> - if (of_find_property(n, "spi-cpha"))
> + if (of_find_property(n, "spi-cpha", NULL))
> chip.mode |= SPI_CPHA;
> - if (of_find_property(n, "spi-cpol"))
> + if (of_find_property(n, "spi-cpol", NULL))
> chip.mode |= SPI_CPOL;
> - if (of_find_property(n, "spi-cs-high"))
> + if (of_find_property(n, "spi-cs-high", NULL))
> chip.mode |= SPI_CS_HIGH;
> - if (of_find_property(n, "spi-3wire"))
> + if (of_find_property(n, "spi-3wire", NULL))
> chip.mode |= SPI_3WIRE;
> of_property_read_u32(n, "spi-max-frequency",
> &chip.max_speed_hz);
> - reg = of_find_property(n, "reg");
> + reg = of_find_property(n, "reg", NULL);
> if (!reg)
> continue;
> chip.chip_select = of_read_number(reg->value, 1);
> diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
> index 4ee7610..32b05aa 100644
> --- a/drivers/usb/imx/chipidea-imx.c
> +++ b/drivers/usb/imx/chipidea-imx.c
> @@ -108,7 +108,8 @@ static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
> return -EINVAL;
> }
>
> - if (of_find_property(ci->dev->device_node, "disable-over-current"))
> + if (of_find_property(ci->dev->device_node,
> + "disable-over-current"), NULL)
This needs to be:
+ if (of_find_property(ci->dev->device_node,
+ "disable-over-current", NULL))
(I'll fix this up while applying if there's no other showstopper for this
series)
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 07/22] OF: base: sync of_find_node_by_path with linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (28 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 06/22] OF: base: sync of_find_property with linux OF API Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 08/22] OF: base: rename of_node_disabled to of_device_is_available Sebastian Hesselbarth
` (14 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Barebox of_find_node_by_path requires a node to be passed as start node
to start searching. Linux OF API does not pass this node and no current
user of it in barebox is passing anything else than the root node.
Therefore, we rename current function to of_find_node_by_path_from and
introduce a Linux OF API compatible of_find_node_by_path that always
passes the current root_node. Also, all current users of that function
are updated to reflect the API change.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
Changelog:
v1->v2:
- rename current of_find_node_by_path to of_find_node_by_path_from
(Suggested by Sascha Hauer)
- implement of_find_node_by_path with root_node passed to above
(Suggested by Sascha Hauer)
---
arch/arm/boards/highbank/init.c | 4 +-
arch/ppc/mach-mpc5xxx/cpu.c | 4 +-
commands/of_node.c | 2 +-
commands/of_property.c | 10 +-------
commands/oftree.c | 11 +---------
common/oftree.c | 2 +-
drivers/of/base.c | 43 ++++++++++++++++++++++++--------------
include/of.h | 17 +++++++++++++-
net/eth.c | 2 +-
9 files changed, 52 insertions(+), 43 deletions(-)
diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index d4a5c5a..1aa713b 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -53,7 +53,7 @@ static int hb_fixup(struct device_node *root)
if ((opp_table[0] >> 16) != HB_OPP_VERSION)
return 0;
- node = of_find_node_by_path(root, "/cpus/cpu@0");
+ node = of_find_node_by_path("/cpus/cpu@0");
if (!node)
return 0;
@@ -89,7 +89,7 @@ static int highbank_mem_init(void)
of_set_root_node(root);
- np = of_find_node_by_path(root, "/memory");
+ np = of_find_node_by_path("/memory");
if (!np) {
pr_warn("no memory node use default configuration\n");
goto not_found;
diff --git a/arch/ppc/mach-mpc5xxx/cpu.c b/arch/ppc/mach-mpc5xxx/cpu.c
index 99f16eb..0ece4a9 100644
--- a/arch/ppc/mach-mpc5xxx/cpu.c
+++ b/arch/ppc/mach-mpc5xxx/cpu.c
@@ -83,7 +83,7 @@ static int of_mpc5200_fixup(struct device_node *root)
int div = in_8((void*)CFG_MBAR + 0x204) & 0x0020 ? 8 : 4;
- node = of_find_node_by_path(root, "/cpus/PowerPC,5200@0");
+ node = of_find_node_by_path("/cpus/PowerPC,5200@0");
if (!node)
return -EINVAL;
@@ -91,7 +91,7 @@ static int of_mpc5200_fixup(struct device_node *root)
of_property_write_u32(node, "bus-frequency", get_bus_clock());
of_property_write_u32(node, "clock-frequency", get_cpu_clock());
- node = of_find_node_by_path(root, "/soc5200@f0000000");
+ node = of_find_node_by_path("/soc5200@f0000000");
if (!node)
return -EINVAL;
diff --git a/commands/of_node.c b/commands/of_node.c
index 0249d97..e60ef66 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -81,7 +81,7 @@ static int do_of_node(int argc, char *argv[])
if (!path)
return COMMAND_ERROR_USAGE;
- node = of_find_node_by_path(root, path);
+ node = of_find_node_by_path(path);
if (!node) {
printf("Cannot find nodepath %s\n", path);
return -ENOENT;
diff --git a/commands/of_property.c b/commands/of_property.c
index d1a9a17..8ffe30b 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -175,7 +175,7 @@ static int do_of_property(int argc, char *argv[])
int set = 0;
int ret;
char *path = NULL, *propname = NULL;
- struct device_node *root, *node = NULL;
+ struct device_node *node = NULL;
struct property *pp = NULL;
while ((opt = getopt(argc, argv, "ds")) > 0) {
@@ -194,15 +194,9 @@ static int do_of_property(int argc, char *argv[])
if (optind == argc)
return COMMAND_ERROR_USAGE;
- root = of_get_root_node();
- if (!root) {
- printf("root node not set\n");
- return -ENOENT;
- }
-
if (optind < argc) {
path = argv[optind];
- node = of_find_node_by_path(root, path);
+ node = of_find_node_by_path(path);
if (!node) {
printf("Cannot find nodepath %s\n", path);
return -ENOENT;
diff --git a/commands/oftree.c b/commands/oftree.c
index 468235a..9149517 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -164,16 +164,7 @@ static int do_oftree(int argc, char *argv[])
of_print_nodes(root, 0);
of_free(root);
} else {
- struct device_node *root, *n;
-
- root = of_get_root_node();
- if (!root) {
- ret = -ENOENT;
- goto out;
- }
-
- n = of_find_node_by_path(root, node);
-
+ struct device_node *n = of_find_node_by_path(node);
if (!n) {
ret = -ENOENT;
goto out;
diff --git a/common/oftree.c b/common/oftree.c
index 475d418..aff4c28 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -100,7 +100,7 @@ void of_print_property(const void *data, int len)
void of_print_cmdline(struct device_node *root)
{
- struct device_node *node = of_find_node_by_path(root, "/chosen");
+ struct device_node *node = of_find_node_by_path("/chosen");
const char *cmdline;
if (!node) {
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 85199b6..f822f8d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -153,7 +153,7 @@ void of_alias_scan(void)
if (!root_node)
return;
- of_aliases = of_find_node_by_path(root_node, "/aliases");
+ of_aliases = of_find_node_by_path("/aliases");
if (!of_aliases)
return;
@@ -170,7 +170,7 @@ void of_alias_scan(void)
!of_prop_cmp(pp->name, "linux,phandle"))
continue;
- np = of_find_node_by_path(root_node, pp->value);
+ np = of_find_node_by_path(pp->value);
if (!np)
continue;
@@ -556,19 +556,18 @@ int of_machine_is_compatible(const char *compat)
EXPORT_SYMBOL(of_machine_is_compatible);
/**
- * of_find_node_by_path - Find a node matching a full OF path
- * @root: The root node of this tree
+ * of_find_node_by_path_from - Find a node matching a full OF path
+ * relative to a given root node.
* @path: The full path to match
*
- * Returns a node pointer with refcount incremented, use
- * of_node_put() on it when done.
+ * Returns a pointer to the node found or NULL.
*/
-struct device_node *of_find_node_by_path(struct device_node *root, const char *path)
+struct device_node *of_find_node_by_path_from(struct device_node *from,
+ const char *path)
{
char *slash, *p, *freep;
- struct device_node *dn = root;
- if (*path != '/')
+ if (!from || !path || *path != '/')
return NULL;
path++;
@@ -583,8 +582,8 @@ struct device_node *of_find_node_by_path(struct device_node *root, const char *p
if (slash)
*slash = 0;
- dn = of_find_child_by_name(dn, p);
- if (!dn)
+ from = of_get_child_by_name(from, p);
+ if (!from)
goto out;
if (!slash)
@@ -595,7 +594,19 @@ struct device_node *of_find_node_by_path(struct device_node *root, const char *p
out:
free(freep);
- return dn;
+ return from;
+}
+EXPORT_SYMBOL(of_find_node_by_path_from);
+
+/**
+ * of_find_node_by_path - Find a node matching a full OF path
+ * @path: The full path to match
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_path(const char *path)
+{
+ return of_find_node_by_path_from(root_node, path);
}
EXPORT_SYMBOL(of_find_node_by_path);
@@ -1156,12 +1167,12 @@ int of_probe(void)
if(!root_node)
return -ENODEV;
- of_chosen = of_find_node_by_path(root_node, "/chosen");
+ of_chosen = of_find_node_by_path("/chosen");
of_property_read_string(root_node, "model", &of_model);
__of_parse_phandles(root_node);
- memory = of_find_node_by_path(root_node, "/memory");
+ memory = of_find_node_by_path("/memory");
if (memory)
of_add_memory(memory, false);
@@ -1234,8 +1245,8 @@ int of_device_is_stdout_path(struct device_d *dev)
name = of_get_property(of_chosen, "linux,stdout-path", NULL);
if (name == NULL)
return 0;
- dn = of_find_node_by_path(root_node, name);
+ dn = of_find_node_by_path(name);
if (!dn)
return 0;
@@ -1264,7 +1275,7 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
struct device_node *chosen;
__be32 buf[2];
- chosen = of_find_node_by_path(root, "/chosen");
+ chosen = of_find_node_by_path("/chosen");
if (!chosen)
return -EINVAL;
diff --git a/include/of.h b/include/of.h
index 7ebde62..a56587f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
int of_n_addr_cells(struct device_node *np);
int of_n_size_cells(struct device_node *np);
-struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
-
struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
struct fdt_header *fdt_get_tree(void);
@@ -184,6 +182,10 @@ struct cdev;
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
+extern struct device_node *of_find_node_by_path_from(struct device_node *from,
+ const char *path);
+extern struct device_node *of_find_node_by_path(const char *path);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -235,6 +237,17 @@ static inline struct property *of_find_property(const struct device_node *np,
return NULL;
}
+static inline struct device_node *of_find_node_by_path_from(
+ struct device_node *from, const char *path)
+{
+ return NULL;
+}
+
+static inline struct device_node *of_find_node_by_path(const char *path)
+{
+ return NULL;
+}
+
static inline void of_alias_scan(void)
{
}
diff --git a/net/eth.c b/net/eth.c
index 7240b4d..09b3bd5 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -296,7 +296,7 @@ static int eth_of_fixup(struct device_node *root)
continue;
}
- node = of_find_node_by_path(root, edev->nodepath);
+ node = of_find_node_by_path(edev->nodepath);
if (!node) {
dev_dbg(&edev->dev, "%s: fixup node %s not found\n",
__func__, edev->nodepath);
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 08/22] OF: base: rename of_node_disabled to of_device_is_available
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (29 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 07/22] OF: base: sync of_find_node_by_path " Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 09/22] OF: base: import of_find_node_by_name from Linux OF API Sebastian Hesselbarth
` (13 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
According to ePAPR 1.1 spec, device tree nodes status can be either
"okay", "disabled", "fail", or "fail-sss". Barebox already has a function
to check for "disabled" nodes, while Linux checks for "okay" or "ok".
To synchronize Barebox and Linux OF APIs, rename of_node_disabled to
of_device_is_available and check for "okay" instead of "disabled" as it
also makes "fail"ed devices unavailable.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 26 ++++++++++++++++++++------
include/of.h | 6 ++++++
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index f822f8d..2176251 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -730,17 +730,31 @@ int of_set_root_node(struct device_node *node)
return 0;
}
-static int of_node_disabled(struct device_node *node)
+/**
+ * of_device_is_available - check if a device is available for use
+ *
+ * @device: Node to check for availability
+ *
+ * Returns 1 if the status property is absent or set to "okay" or "ok",
+ * 0 otherwise
+ */
+int of_device_is_available(const struct device_node *device)
{
- struct property *p;
+ const char *status;
+ int statlen;
+
+ status = of_get_property(device, "status", &statlen);
+ if (status == NULL)
+ return 1;
- p = of_find_property(node, "status", NULL);
- if (p) {
- if (!strcmp("disabled", p->value))
+ if (statlen > 0) {
+ if (!strcmp(status, "okay") || !strcmp(status, "ok"))
return 1;
}
+
return 0;
}
+EXPORT_SYMBOL(of_device_is_available);
void of_print_nodes(struct device_node *node, int indent)
{
@@ -934,7 +948,7 @@ static struct device_d *add_of_device(struct device_node *node,
{
const struct property *cp;
- if (of_node_disabled(node))
+ if (!of_device_is_available(node))
return NULL;
cp = of_get_property(node, "compatible", NULL);
diff --git a/include/of.h b/include/of.h
index a56587f..56b7be1 100644
--- a/include/of.h
+++ b/include/of.h
@@ -185,6 +185,7 @@ extern struct property *of_find_property(const struct device_node *np,
extern struct device_node *of_find_node_by_path_from(struct device_node *from,
const char *path);
extern struct device_node *of_find_node_by_path(const char *path);
+extern int of_device_is_available(const struct device_node *device);
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -248,6 +249,11 @@ static inline struct device_node *of_find_node_by_path(const char *path)
return NULL;
}
+static inline int of_device_is_available(const struct device_node *device)
+{
+ return 0;
+}
+
static inline void of_alias_scan(void)
{
}
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 09/22] OF: base: import of_find_node_by_name from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (30 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 08/22] OF: base: rename of_node_disabled to of_device_is_available Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 10/22] OF: base: import of_find_compatible_node " Sebastian Hesselbarth
` (12 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_find_node_by_name and corresponding for_each_node_by_name
helper from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 26 ++++++++++++++++++++++++++
include/of.h | 12 ++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 2176251..d736bef 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -312,6 +312,32 @@ int of_device_is_compatible(const struct device_node *device,
EXPORT_SYMBOL(of_device_is_compatible);
/**
+ * of_find_node_by_name - Find a node by its "name" property
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @name: The name string to match against
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name)
+{
+ struct device_node *np;
+
+ if (!from)
+ from = root_node;
+
+ of_tree_for_each_node(np, from)
+ if (np->name && !of_node_cmp(np->name, name))
+ return np;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_node_by_name);
+
+/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @matches: array of of device match structures to search in
* @node: the of device structure to match against
diff --git a/include/of.h b/include/of.h
index 56b7be1..8cbfe7a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -182,6 +182,8 @@ struct cdev;
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
+extern struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name);
extern struct device_node *of_find_node_by_path_from(struct device_node *from,
const char *path);
extern struct device_node *of_find_node_by_path(const char *path);
@@ -249,6 +251,12 @@ static inline struct device_node *of_find_node_by_path(const char *path)
return NULL;
}
+static inline struct device_node *of_find_node_by_name(struct device_node *from,
+ const char *name)
+{
+ return NULL;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -269,4 +277,8 @@ static inline const char *of_alias_get(struct device_node *np)
}
#endif
+#define for_each_node_by_name(dn, name) \
+ for (dn = of_find_node_by_name(NULL, name); dn; \
+ dn = of_find_node_by_name(dn, name))
+
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 10/22] OF: base: import of_find_compatible_node from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (31 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 09/22] OF: base: import of_find_node_by_name from Linux OF API Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 11/22] OF: base: import of_find_matching_node_and_match " Sebastian Hesselbarth
` (11 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_find_compatible_node and corresponding for_each_compatible_node
helper from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 30 ++++++++++++++++++++++++++++++
include/of.h | 13 +++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d736bef..50a4df0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -338,6 +338,36 @@ struct device_node *of_find_node_by_name(struct device_node *from,
EXPORT_SYMBOL(of_find_node_by_name);
/**
+ * of_find_compatible_node - Find a node based on type and one of the
+ * tokens in its "compatible" property
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @type: The type string to match "device_type" or NULL to ignore
+ * (currently always ignored in barebox)
+ * @compatible: The string to match to one of the tokens in the device
+ * "compatible" list.
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_compatible_node(struct device_node *from,
+ const char *type, const char *compatible)
+{
+ struct device_node *np;
+
+ if (!from)
+ from = root_node;
+
+ of_tree_for_each_node(np, from)
+ if (of_device_is_compatible(np, compatible))
+ return np;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_compatible_node);
+
+/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @matches: array of of device match structures to search in
* @node: the of device structure to match against
diff --git a/include/of.h b/include/of.h
index 8cbfe7a..b334e3a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -187,6 +187,8 @@ extern struct device_node *of_find_node_by_name(struct device_node *from,
extern struct device_node *of_find_node_by_path_from(struct device_node *from,
const char *path);
extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_compatible_node(struct device_node *from,
+ const char *type, const char *compat);
extern int of_device_is_available(const struct device_node *device);
extern void of_alias_scan(void);
@@ -257,6 +259,14 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
return NULL;
}
+static inline struct device_node *of_find_compatible_node(
+ struct device_node *from,
+ const char *type,
+ const char *compat)
+{
+ return NULL;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -280,5 +290,8 @@ static inline const char *of_alias_get(struct device_node *np)
#define for_each_node_by_name(dn, name) \
for (dn = of_find_node_by_name(NULL, name); dn; \
dn = of_find_node_by_name(dn, name))
+#define for_each_compatible_node(dn, type, compatible) \
+ for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
+ dn = of_find_compatible_node(dn, type, compatible))
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 11/22] OF: base: import of_find_matching_node_and_match from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (32 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 10/22] OF: base: import of_find_compatible_node " Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 12/22] OF: base: import of_find_node_with_property " Sebastian Hesselbarth
` (10 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_find_matching_node_and_match and corresponding helpers
from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 37 +++++++++++++++++++++++++++++++++++++
include/of.h | 24 ++++++++++++++++++++++++
2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 50a4df0..38d6789 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -389,6 +389,43 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
return NULL;
}
+/**
+ * of_find_matching_node_and_match - Find a node based on an of_device_id
+ * match table.
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @matches: array of of device match structures to search in
+ * @match Updated to point at the matches entry which matched
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_matching_node_and_match(struct device_node *from,
+ const struct of_device_id *matches,
+ const struct of_device_id **match)
+{
+ struct device_node *np;
+
+ if (match)
+ *match = NULL;
+
+ if (!from)
+ from = root_node;
+
+ of_tree_for_each_node(np, from) {
+ const struct of_device_id *m = of_match_node(matches, np);
+ if (m) {
+ if (match)
+ *match = m;
+ return np;
+ }
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_matching_node_and_match);
+
int of_match(struct device_d *dev, struct driver_d *drv)
{
const struct of_device_id *id;
diff --git a/include/of.h b/include/of.h
index b334e3a..a33ccfa 100644
--- a/include/of.h
+++ b/include/of.h
@@ -189,6 +189,10 @@ extern struct device_node *of_find_node_by_path_from(struct device_node *from,
extern struct device_node *of_find_node_by_path(const char *path);
extern struct device_node *of_find_compatible_node(struct device_node *from,
const char *type, const char *compat);
+extern struct device_node *of_find_matching_node_and_match(
+ struct device_node *from,
+ const struct of_device_id *matches,
+ const struct of_device_id **match);
extern int of_device_is_available(const struct device_node *device);
extern void of_alias_scan(void);
@@ -267,6 +271,14 @@ static inline struct device_node *of_find_compatible_node(
return NULL;
}
+static inline struct device_node *of_find_matching_node_and_match(
+ struct device_node *from,
+ const struct of_device_id *matches,
+ const struct of_device_id **match)
+{
+ return NULL;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -293,5 +305,17 @@ static inline const char *of_alias_get(struct device_node *np)
#define for_each_compatible_node(dn, type, compatible) \
for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
dn = of_find_compatible_node(dn, type, compatible))
+static inline struct device_node *of_find_matching_node(
+ struct device_node *from,
+ const struct of_device_id *matches)
+{
+ return of_find_matching_node_and_match(from, matches, NULL);
+}
+#define for_each_matching_node(dn, matches) \
+ for (dn = of_find_matching_node(NULL, matches); dn; \
+ dn = of_find_matching_node(dn, matches))
+#define for_each_matching_node_and_match(dn, matches, match) \
+ for (dn = of_find_matching_node_and_match(NULL, matches, match); \
+ dn; dn = of_find_matching_node_and_match(dn, matches, match))
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 12/22] OF: base: import of_find_node_with_property from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (33 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 11/22] OF: base: import of_find_matching_node_and_match " Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 13/22] OF: base: import parent/child functions " Sebastian Hesselbarth
` (9 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_find_node_with_property and corresponding helpers
from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 26 ++++++++++++++++++++++++++
include/of.h | 11 +++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 38d6789..39eddb2 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -368,6 +368,32 @@ struct device_node *of_find_compatible_node(struct device_node *from,
EXPORT_SYMBOL(of_find_compatible_node);
/**
+ * of_find_node_with_property - Find a node which has a property with
+ * the given name.
+ * @from: The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned.
+ * @prop_name: The name of the property to look for.
+ *
+ * Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_with_property(struct device_node *from,
+ const char *prop_name)
+{
+ struct device_node *np;
+
+ of_tree_for_each_node(np, from) {
+ struct property *pp = of_find_property(np, prop_name, NULL);
+ if (pp)
+ return np;
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_find_node_with_property);
+
+/**
* of_match_node - Tell if an device_node has a matching of_match structure
* @matches: array of of device match structures to search in
* @node: the of device structure to match against
diff --git a/include/of.h b/include/of.h
index a33ccfa..f508435 100644
--- a/include/of.h
+++ b/include/of.h
@@ -193,6 +193,8 @@ extern struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match);
+extern struct device_node *of_find_node_with_property(
+ struct device_node *from, const char *prop_name);
extern int of_device_is_available(const struct device_node *device);
extern void of_alias_scan(void);
@@ -279,6 +281,12 @@ static inline struct device_node *of_find_matching_node_and_match(
return NULL;
}
+static inline struct device_node *of_find_node_with_property(
+ struct device_node *from, const char *prop_name)
+{
+ return NULL;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -317,5 +325,8 @@ static inline struct device_node *of_find_matching_node(
#define for_each_matching_node_and_match(dn, matches, match) \
for (dn = of_find_matching_node_and_match(NULL, matches, match); \
dn; dn = of_find_matching_node_and_match(dn, matches, match))
+#define for_each_node_with_property(dn, prop_name) \
+ for (dn = of_find_node_with_property(NULL, prop_name); dn; \
+ dn = of_find_node_with_property(dn, prop_name))
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 13/22] OF: base: import parent/child functions from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (34 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 12/22] OF: base: import of_find_node_with_property " Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 14/22] OF: base: import of_property_read_* helpers " Sebastian Hesselbarth
` (8 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_get_parent, of_get_next_available_child, and
of_get_child_by_name and corresponding helpers from Linux OF API.
of_get_next_child is not imported but implemented as list iterator
instead. Also, of_get_child_count and of_get_available_child_count
are introduced.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
Changelog:
v1->v2:
- make of_get_parent return node->parent also for root_node
(Suggested by Sascha Hauer)
- use list iterator instead of of_get_next_child
(Suggested by Sascha Hauer)
- move of_get_child_count to base.c to avoid compile warnings
- introduce of_get_available_child_count
---
drivers/of/base.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++
include/of.h | 41 ++++++++++++++++++++++
2 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 39eddb2..ee0496d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -875,6 +875,103 @@ int of_device_is_available(const struct device_node *device)
}
EXPORT_SYMBOL(of_device_is_available);
+/**
+ * of_get_parent - Get a node's parent if any
+ * @node: Node to get parent
+ *
+ * Returns a pointer to the parent node or NULL if already at root.
+ */
+struct device_node *of_get_parent(const struct device_node *node)
+{
+ return (!node) ? NULL : node->parent;
+}
+EXPORT_SYMBOL(of_get_parent);
+
+/**
+ * of_get_next_available_child - Find the next available child node
+ * @node: parent node
+ * @prev: previous child of the parent node, or NULL to get first
+ *
+ * This function is like of_get_next_child(), except that it
+ * automatically skips any disabled nodes (i.e. status = "disabled").
+ */
+struct device_node *of_get_next_available_child(const struct device_node *node,
+ struct device_node *prev)
+{
+ for_each_child_of_node(node, prev)
+ if (of_device_is_available(prev))
+ return prev;
+ return NULL;
+}
+EXPORT_SYMBOL(of_get_next_available_child);
+
+/**
+ * of_get_child_count - Count child nodes of given parent node
+ * @parent: parent node
+ *
+ * Returns the number of child nodes or -EINVAL on NULL parent node.
+ */
+int of_get_child_count(const struct device_node *parent)
+{
+ struct device_node *child;
+ int num = 0;
+
+ if (!parent)
+ return -EINVAL;
+
+ for_each_child_of_node(parent, child)
+ num++;
+
+ return num;
+}
+EXPORT_SYMBOL(of_get_child_count);
+
+/**
+ * of_get_available_child_count - Count available child nodes of given
+ * parent node
+ * @parent: parent node
+ *
+ * Returns the number of available child nodes or -EINVAL on NULL parent
+ * node.
+ */
+int of_get_available_child_count(const struct device_node *parent)
+{
+ struct device_node *child;
+ int num = 0;
+
+ if (!parent)
+ return -EINVAL;
+
+ for_each_child_of_node(parent, child)
+ if (of_device_is_available(child))
+ num++;
+
+ return num;
+}
+EXPORT_SYMBOL(of_get_available_child_count);
+
+/**
+ * of_get_child_by_name - Find the child node by name for a given parent
+ * @node: parent node
+ * @name: child name to look for.
+ *
+ * This function looks for child node for given matching name
+ *
+ * Returns a node pointer if found or NULL.
+ */
+struct device_node *of_get_child_by_name(const struct device_node *node,
+ const char *name)
+{
+ struct device_node *child;
+
+ for_each_child_of_node(node, child)
+ if (child->name && (of_node_cmp(child->name, name) == 0))
+ return child;
+
+ return NULL;
+}
+EXPORT_SYMBOL(of_get_child_by_name);
+
void of_print_nodes(struct device_node *node, int indent)
{
struct device_node *n;
diff --git a/include/of.h b/include/of.h
index f508435..917466f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -197,6 +197,14 @@ extern struct device_node *of_find_node_with_property(
struct device_node *from, const char *prop_name);
extern int of_device_is_available(const struct device_node *device);
+extern struct device_node *of_get_parent(const struct device_node *node);
+extern struct device_node *of_get_next_available_child(
+ const struct device_node *node, struct device_node *prev);
+extern int of_get_child_count(const struct device_node *parent);
+extern int of_get_available_child_count(const struct device_node *parent);
+extern struct device_node *of_get_child_by_name(const struct device_node *node,
+ const char *name);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -241,6 +249,33 @@ static inline struct device_node *of_get_root_node(void)
return NULL;
}
+static inline struct device_node *of_get_parent(const struct device_node *node)
+{
+ return NULL;
+}
+
+static inline struct device_node *of_get_next_available_child(
+ const struct device_node *node, struct device_node *prev)
+{
+ return NULL;
+}
+
+static inline int of_get_child_count(const struct device_node *parent)
+{
+ return -ENOSYS;
+}
+
+static inline int of_get_available_child_count(const struct device_node *parent)
+{
+ return -ENOSYS;
+}
+
+static inline struct device_node *of_get_child_by_name(
+ const struct device_node *node, const char *name)
+{
+ return NULL;
+}
+
static inline struct property *of_find_property(const struct device_node *np,
const char *name,
int *lenp)
@@ -329,4 +364,10 @@ static inline struct device_node *of_find_matching_node(
for (dn = of_find_node_with_property(NULL, prop_name); dn; \
dn = of_find_node_with_property(dn, prop_name))
+#define for_each_child_of_node(parent, child) \
+ list_for_each_entry(child, &parent->children, parent_list)
+#define for_each_available_child_of_node(parent, child) \
+ for (child = of_get_next_available_child(parent, NULL); child != NULL; \
+ child = of_get_next_available_child(parent, child))
+
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 14/22] OF: base: import of_property_read_* helpers from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (35 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 13/22] OF: base: import parent/child functions " Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 15/22] OF: base: import of_parse_phandle " Sebastian Hesselbarth
` (7 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_property_read_* helpers from Linux OF API to allow
to read all kinds of properties.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 387 +++++++++++++++++++++++++++++++++++++++++------------
include/of.h | 132 ++++++++++++++++--
2 files changed, 420 insertions(+), 99 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ee0496d..d58ba4d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -467,12 +467,137 @@ int of_match(struct device_d *dev, struct driver_d *drv)
EXPORT_SYMBOL(of_match);
/**
+ * of_find_property_value_of_size
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @len: requested length of property value
+ *
+ * Search for a property in a device node and valid the requested size.
+ * Returns the property value on success, -EINVAL if the property does not
+ * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ */
+static void *of_find_property_value_of_size(const struct device_node *np,
+ const char *propname, u32 len)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ if (!prop)
+ return ERR_PTR(-EINVAL);
+ if (!prop->value)
+ return ERR_PTR(-ENODATA);
+ if (len > prop->length)
+ return ERR_PTR(-EOVERFLOW);
+
+ return prop->value;
+}
+
+/**
+ * of_property_read_u32_index - Find and read a u32 from a multi-value property.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @index: index of the u32 in the list of values
+ * @out_value: pointer to return value, modified only if no error.
+ *
+ * Search for a property in a device node and read nth 32-bit value from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * The out_value is modified only if a valid u32 value can be decoded.
+ */
+int of_property_read_u32_index(const struct device_node *np,
+ const char *propname,
+ u32 index, u32 *out_value)
+{
+ const u32 *val = of_find_property_value_of_size(np, propname,
+ ((index + 1) * sizeof(*out_value)));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ *out_value = be32_to_cpup(((__be32 *)val) + index);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u32_index);
+
+/**
+ * of_property_read_u8_array - Find and read an array of u8 from a property.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_value: pointer to return value, modified only if return value is 0.
+ * @sz: number of array elements to read
+ *
+ * Search for a property in a device node and read 8-bit value(s) from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * dts entry of array should be like:
+ * property = /bits/ 8 <0x50 0x60 0x70>;
+ *
+ * The out_value is modified only if a valid u8 value can be decoded.
+ */
+int of_property_read_u8_array(const struct device_node *np,
+ const char *propname, u8 *out_values, size_t sz)
+{
+ const u8 *val = of_find_property_value_of_size(np, propname,
+ (sz * sizeof(*out_values)));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ while (sz--)
+ *out_values++ = *val++;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u8_array);
+
+/**
+ * of_property_read_u16_array - Find and read an array of u16 from a property.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_value: pointer to return value, modified only if return value is 0.
+ * @sz: number of array elements to read
+ *
+ * Search for a property in a device node and read 16-bit value(s) from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * dts entry of array should be like:
+ * property = /bits/ 16 <0x5000 0x6000 0x7000>;
+ *
+ * The out_value is modified only if a valid u16 value can be decoded.
+ */
+int of_property_read_u16_array(const struct device_node *np,
+ const char *propname, u16 *out_values, size_t sz)
+{
+ const __be16 *val = of_find_property_value_of_size(np, propname,
+ (sz * sizeof(*out_values)));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ while (sz--)
+ *out_values++ = be16_to_cpup(val++);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u16_array);
+
+/**
* of_property_read_u32_array - Find and read an array of 32 bit integers
* from a property.
*
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_value: pointer to return value, modified only if return value is 0.
+ * @sz: number of array elements to read
*
* Search for a property in a device node and read 32-bit value(s) from
* it. Returns 0 on success, -EINVAL if the property does not exist,
@@ -485,22 +610,192 @@ int of_property_read_u32_array(const struct device_node *np,
const char *propname, u32 *out_values,
size_t sz)
{
+ const __be32 *val = of_find_property_value_of_size(np, propname,
+ (sz * sizeof(*out_values)));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ while (sz--)
+ *out_values++ = be32_to_cpup(val++);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+
+/**
+ * of_property_read_u64 - Find and read a 64 bit integer from a property
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_value: pointer to return value, modified only if return value is 0.
+ *
+ * Search for a property in a device node and read a 64-bit value from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * The out_value is modified only if a valid u64 value can be decoded.
+ */
+int of_property_read_u64(const struct device_node *np, const char *propname,
+ u64 *out_value)
+{
+ const __be32 *val = of_find_property_value_of_size(np, propname,
+ sizeof(*out_value));
+
+ if (IS_ERR(val))
+ return PTR_ERR(val);
+
+ *out_value = of_read_number(val, 2);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u64);
+
+/**
+ * of_property_read_string - Find and read a string from a property
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_string: pointer to null terminated return string, modified only if
+ * return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy). Returns 0 on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string(struct device_node *np, const char *propname,
+ const char **out_string)
+{
struct property *prop = of_find_property(np, propname, NULL);
- const __be32 *val;
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
+ *out_string = prop->value;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_string);
+
+/**
+ * of_property_read_string_index - Find and read a string from a multiple
+ * strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @index: index of the string in the list of strings
+ * @out_string: pointer to null terminated return string, modified only if
+ * return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy) in the list of strings
+ * contained in that property.
+ * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
+ * property does not have a value, and -EILSEQ if the string is not
+ * null-terminated within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string_index(struct device_node *np, const char *propname,
+ int index, const char **output)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ int i = 0;
+ size_t l = 0, total = 0;
+ const char *p;
if (!prop)
return -EINVAL;
if (!prop->value)
return -ENODATA;
- if ((sz * sizeof(*out_values)) > prop->length)
- return -EOVERFLOW;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
- val = prop->value;
- while (sz--)
- *out_values++ = be32_to_cpup(val++);
- return 0;
+ p = prop->value;
+
+ for (i = 0; total < prop->length; total += l, p += l) {
+ l = strlen(p) + 1;
+ if (i++ == index) {
+ *output = p;
+ return 0;
+ }
+ }
+ return -ENODATA;
}
-EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+EXPORT_SYMBOL_GPL(of_property_read_string_index);
+
+/**
+ * of_property_match_string() - Find string in a list and return index
+ * @np: pointer to node containing string list property
+ * @propname: string list property name
+ * @string: pointer to string to search for in string list
+ *
+ * This function searches a string list property and returns the index
+ * of a specific string value.
+ */
+int of_property_match_string(struct device_node *np, const char *propname,
+ const char *string)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ size_t l;
+ int i;
+ const char *p, *end;
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+
+ p = prop->value;
+ end = p + prop->length;
+
+ for (i = 0; p < end; i++, p += l) {
+ l = strlen(p) + 1;
+ if (p + l > end)
+ return -EILSEQ;
+ pr_debug("comparing %s with %s\n", string, p);
+ if (strcmp(string, p) == 0)
+ return i; /* Found it; return index */
+ }
+ return -ENODATA;
+}
+EXPORT_SYMBOL_GPL(of_property_match_string);
+
+/**
+ * of_property_count_strings - Find and return the number of strings from a
+ * multiple strings property.
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device tree node and retrieve the number of null
+ * terminated string contain in it. Returns the number of strings on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ */
+int of_property_count_strings(struct device_node *np, const char *propname)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ int i = 0;
+ size_t l = 0, total = 0;
+ const char *p;
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
+
+ p = prop->value;
+
+ for (i = 0; total < prop->length; total += l, p += l, i++)
+ l = strlen(p) + 1;
+
+ return i;
+}
+EXPORT_SYMBOL_GPL(of_property_count_strings);
/**
* of_property_write_u32_array - Write an array of u32 to a property. If
@@ -730,82 +1025,6 @@ struct device_node *of_find_node_by_path(const char *path)
EXPORT_SYMBOL(of_find_node_by_path);
/**
- * of_property_read_string - Find and read a string from a property
- * @np: device node from which the property value is to be read.
- * @propname: name of the property to be searched.
- * @out_string: pointer to null terminated return string, modified only if
- * return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy). Returns 0 on
- * success, -EINVAL if the property does not exist, -ENODATA if property
- * does not have a value, and -EILSEQ if the string is not null-terminated
- * within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string(struct device_node *np, const char *propname,
- const char **out_string)
-{
- struct property *prop = of_find_property(np, propname, NULL);
- if (!prop)
- return -EINVAL;
- if (!prop->value)
- return -ENODATA;
- if (strnlen(prop->value, prop->length) >= prop->length)
- return -EILSEQ;
- *out_string = prop->value;
- return 0;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string);
-
-/**
- * of_property_read_string_index - Find and read a string from a multiple
- * strings property.
- * @np: device node from which the property value is to be read.
- * @propname: name of the property to be searched.
- * @index: index of the string in the list of strings
- * @out_string: pointer to null terminated return string, modified only if
- * return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy) in the list of strings
- * contained in that property.
- * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
- * property does not have a value, and -EILSEQ if the string is not
- * null-terminated within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string_index(struct device_node *np, const char *propname,
- int index, const char **output)
-{
- struct property *prop = of_find_property(np, propname, NULL);
- int i = 0;
- size_t l = 0, total = 0;
- const char *p;
-
- if (!prop)
- return -EINVAL;
- if (!prop->value)
- return -ENODATA;
- if (strnlen(prop->value, prop->length) >= prop->length)
- return -EILSEQ;
-
- p = prop->value;
-
- for (i = 0; total < prop->length; total += l, p += l) {
- l = strlen(p) + 1;
- if (i++ == index) {
- *output = p;
- return 0;
- }
- }
- return -ENODATA;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string_index);
-
-/**
* of_modalias_node - Lookup appropriate modalias for a device node
* @node: pointer to a device tree node
* @modalias: Pointer to buffer that modalias value will be copied into
diff --git a/include/of.h b/include/of.h
index 917466f..d94527d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -106,17 +106,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
}
}
-int of_property_read_u32_array(const struct device_node *np,
- const char *propname, u32 *out_values,
- size_t sz);
-
-static inline int of_property_read_u32(const struct device_node *np,
- const char *propname,
- u32 *out_value)
-{
- return of_property_read_u32_array(np, propname, out_value, 1);
-}
-
int of_property_write_u32_array(struct device_node *np,
const char *propname, const u32 *values,
size_t sz);
@@ -163,10 +152,6 @@ struct property *of_new_property(struct device_node *node, const char *name,
const void *data, int len);
void of_delete_property(struct property *pp);
-int of_property_read_string(struct device_node *np, const char *propname,
- const char **out_string);
-int of_property_read_string_index(struct device_node *np, const char *propname,
- int index, const char **output);
int of_set_property(struct device_node *node, const char *p, const void *val, int len,
int create);
struct device_node *of_create_node(struct device_node *root, const char *path);
@@ -205,6 +190,32 @@ extern int of_get_available_child_count(const struct device_node *parent);
extern struct device_node *of_get_child_by_name(const struct device_node *node,
const char *name);
+extern int of_property_read_u32_index(const struct device_node *np,
+ const char *propname,
+ u32 index, u32 *out_value);
+extern int of_property_read_u8_array(const struct device_node *np,
+ const char *propname, u8 *out_values, size_t sz);
+extern int of_property_read_u16_array(const struct device_node *np,
+ const char *propname, u16 *out_values, size_t sz);
+extern int of_property_read_u32_array(const struct device_node *np,
+ const char *propname,
+ u32 *out_values,
+ size_t sz);
+extern int of_property_read_u64(const struct device_node *np,
+ const char *propname, u64 *out_value);
+
+extern int of_property_read_string(struct device_node *np,
+ const char *propname,
+ const char **out_string);
+extern int of_property_read_string_index(struct device_node *np,
+ const char *propname,
+ int index, const char **output);
+extern int of_property_match_string(struct device_node *np,
+ const char *propname,
+ const char *string);
+extern int of_property_count_strings(struct device_node *np,
+ const char *propname);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -283,6 +294,60 @@ static inline struct property *of_find_property(const struct device_node *np,
return NULL;
}
+static inline int of_property_read_u32_index(const struct device_node *np,
+ const char *propname, u32 index, u32 *out_value)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_u8_array(const struct device_node *np,
+ const char *propname, u8 *out_values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_u16_array(const struct device_node *np,
+ const char *propname, u16 *out_values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_u32_array(const struct device_node *np,
+ const char *propname, u32 *out_values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_u64(const struct device_node *np,
+ const char *propname, u64 *out_value)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_string(struct device_node *np,
+ const char *propname, const char **out_string)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_read_string_index(struct device_node *np,
+ const char *propname, int index, const char **output)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_match_string(struct device_node *np,
+ const char *propname, const char *string)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_count_strings(struct device_node *np,
+ const char *propname)
+{
+ return -ENOSYS;
+}
+
static inline struct device_node *of_find_node_by_path_from(
struct device_node *from, const char *path)
{
@@ -370,4 +435,41 @@ static inline struct device_node *of_find_matching_node(
for (child = of_get_next_available_child(parent, NULL); child != NULL; \
child = of_get_next_available_child(parent, child))
+/**
+ * of_property_read_bool - Findfrom a property
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device node.
+ * Returns true if the property exist false otherwise.
+ */
+static inline bool of_property_read_bool(const struct device_node *np,
+ const char *propname)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ return prop ? true : false;
+}
+
+static inline int of_property_read_u8(const struct device_node *np,
+ const char *propname,
+ u8 *out_value)
+{
+ return of_property_read_u8_array(np, propname, out_value, 1);
+}
+
+static inline int of_property_read_u16(const struct device_node *np,
+ const char *propname,
+ u16 *out_value)
+{
+ return of_property_read_u16_array(np, propname, out_value, 1);
+}
+
+static inline int of_property_read_u32(const struct device_node *np,
+ const char *propname,
+ u32 *out_value)
+{
+ return of_property_read_u32_array(np, propname, out_value, 1);
+}
+
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 15/22] OF: base: import of_parse_phandle from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (36 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 14/22] OF: base: import of_property_read_* helpers " Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 16/22] OF: base: import parse phandle functions " Sebastian Hesselbarth
` (6 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_parse_phandle from Linux OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 23 +++++++++++++++++++++++
include/of.h | 10 ++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d58ba4d..486758b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -839,6 +839,29 @@ int of_property_write_u32_array(struct device_node *np,
}
/**
+ * of_parse_phandle - Resolve a phandle property to a device_node pointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ * the table
+ *
+ * Returns the device_node pointer found or NULL.
+ */
+struct device_node *of_parse_phandle(const struct device_node *np,
+ const char *phandle_name, int index)
+{
+ const __be32 *phandle;
+ int size;
+
+ phandle = of_get_property(np, phandle_name, &size);
+ if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+ return NULL;
+
+ return of_find_node_by_phandle(be32_to_cpup(phandle + index));
+}
+EXPORT_SYMBOL(of_parse_phandle);
+
+/**
* of_parse_phandles_with_args - Find a node pointed by phandle in a list
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
diff --git a/include/of.h b/include/of.h
index d94527d..4f5470a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -216,6 +216,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 struct device_node *of_parse_phandle(const struct device_node *np,
+ const char *phandle_name,
+ int index);
+
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
@@ -348,6 +352,12 @@ static inline int of_property_count_strings(struct device_node *np,
return -ENOSYS;
}
+static inline struct device_node *of_parse_phandle(const struct device_node *np,
+ const char *phandle_name, int index)
+{
+ return NULL;
+}
+
static inline struct device_node *of_find_node_by_path_from(
struct device_node *from, const char *path)
{
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 16/22] OF: base: import parse phandle functions from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (37 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 15/22] OF: base: import of_parse_phandle " Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-20 8:33 ` Sascha Hauer
2013-06-19 9:09 ` [PATCH v2 17/22] OF: base: introduce property write for bool, u8, u16, and u64 Sebastian Hesselbarth
` (5 subsequent siblings)
44 siblings, 1 reply; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This imports of_parse_phandle_with_args and of_count_phandle_with_args
from Linux OF API. The slightly different of_parse_phandles_with_args
is removed and all users are converted to reflect the API change.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 188 +++++++++++++++++++++++++---------------
drivers/of/gpio.c | 9 +-
drivers/usb/imx/chipidea-imx.c | 11 +--
include/of.h | 30 ++++++-
4 files changed, 151 insertions(+), 87 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 486758b..1c385c8 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -862,17 +862,16 @@ struct device_node *of_parse_phandle(const struct device_node *np,
EXPORT_SYMBOL(of_parse_phandle);
/**
- * of_parse_phandles_with_args - Find a node pointed by phandle in a list
+ * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
* @cells_name: property name that specifies phandles' arguments count
* @index: index of a phandle to parse out
- * @out_node: optional pointer to device_node struct pointer (will be filled)
- * @out_args: optional pointer to arguments pointer (will be filled)
+ * @out_args: optional pointer to output arguments structure (will be filled)
*
* This function is useful to parse lists of phandles and their arguments.
- * Returns 0 on success and fills out_node and out_args, on error returns
- * appropriate errno value.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
*
* Example:
*
@@ -889,92 +888,139 @@ EXPORT_SYMBOL(of_parse_phandle);
* }
*
* To get a device_node of the `node2' node you may call this:
- * of_parse_phandles_with_args(node3, "list", "#list-cells", 2, &node2, &args);
+ * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
*/
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
- const char *cells_name, int index,
- struct device_node **out_node,
- const void **out_args)
-{
- int ret = -EINVAL;
- const __be32 *list;
- const __be32 *list_end;
- int size;
- int cur_index = 0;
+static int __of_parse_phandle_with_args(const struct device_node *np,
+ const char *list_name,
+ const char *cells_name, int index,
+ struct of_phandle_args *out_args)
+{
+ const __be32 *list, *list_end;
+ int rc = 0, size, cur_index = 0;
+ uint32_t count = 0;
struct device_node *node = NULL;
- const void *args = NULL;
+ phandle phandle;
+ /* Retrieve the phandle list property */
list = of_get_property(np, list_name, &size);
- if (!list) {
- ret = -ENOENT;
- goto err0;
- }
+ if (!list)
+ return -ENOENT;
list_end = list + size / sizeof(*list);
+ /* Loop over the phandles until all the requested entry is found */
while (list < list_end) {
- const __be32 *cells;
- phandle phandle;
+ rc = -EINVAL;
+ count = 0;
+ /*
+ * If phandle is 0, then it is an empty entry with no
+ * arguments. Skip forward to the next entry.
+ */
phandle = be32_to_cpup(list++);
- args = list;
-
- /* one cell hole in the list = <>; */
- if (!phandle)
- goto next;
-
- node = of_find_node_by_phandle(phandle);
- if (!node) {
- pr_debug("%s: could not find phandle %d\n",
- np->full_name, phandle);
- goto err0;
+ if (phandle) {
+ /*
+ * Find the provider node and parse the #*-cells
+ * property to determine the argument length
+ */
+ node = of_find_node_by_phandle(phandle);
+ if (!node) {
+ pr_err("%s: could not find phandle\n",
+ np->full_name);
+ goto err;
+ }
+ if (of_property_read_u32(node, cells_name, &count)) {
+ pr_err("%s: could not get %s for %s\n",
+ np->full_name, cells_name,
+ node->full_name);
+ goto err;
+ }
+
+ /*
+ * Make sure that the arguments actually fit in the
+ * remaining property data length
+ */
+ if (list + count > list_end) {
+ pr_err("%s: arguments longer than property\n",
+ np->full_name);
+ goto err;
+ }
}
- cells = of_get_property(node, cells_name, &size);
- if (!cells || size != sizeof(*cells)) {
- pr_debug("%s: could not get %s for %s\n",
- np->full_name, cells_name, node->full_name);
- goto err1;
- }
-
- list += be32_to_cpup(cells);
- if (list > list_end) {
- pr_debug("%s: insufficient arguments length\n",
- np->full_name);
- goto err1;
+ /*
+ * All of the error cases above bail out of the loop, so at
+ * this point, the parsing is successful. If the requested
+ * index matches, then fill the out_args structure and return,
+ * or return -ENOENT for an empty entry.
+ */
+ rc = -ENOENT;
+ if (cur_index == index) {
+ if (!phandle)
+ goto err;
+
+ if (out_args) {
+ int i;
+ if (WARN_ON(count > MAX_PHANDLE_ARGS))
+ count = MAX_PHANDLE_ARGS;
+ out_args->np = node;
+ out_args->args_count = count;
+ for (i = 0; i < count; i++)
+ out_args->args[i] =
+ be32_to_cpup(list++);
+ }
+
+ /* Found it! return success */
+ return 0;
}
-next:
- if (cur_index == index)
- break;
node = NULL;
- args = NULL;
+ list += count;
cur_index++;
}
- if (!node) {
- /*
- * args w/o node indicates that the loop above has stopped at
- * the 'hole' cell. Report this differently.
- */
- if (args)
- ret = -EEXIST;
- else
- ret = -ENOENT;
- goto err0;
- }
+ /*
+ * Unlock node before returning result; will be one of:
+ * -ENOENT : index is for empty phandle
+ * -EINVAL : parsing error on data
+ * [1..n] : Number of phandle (count mode; when index = -1)
+ */
+ rc = index < 0 ? cur_index : -ENOENT;
+ err:
+ return rc;
+}
- if (out_node)
- *out_node = node;
- if (out_args)
- *out_args = args;
+int of_parse_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name, int index,
+ struct of_phandle_args *out_args)
+{
+ if (index < 0)
+ return -EINVAL;
+ return __of_parse_phandle_with_args(np, list_name, cells_name,
+ index, out_args);
+}
+EXPORT_SYMBOL(of_parse_phandle_with_args);
- return 0;
-err1:
-err0:
- pr_debug("%s failed with status %d\n", __func__, ret);
- return ret;
+/**
+ * of_count_phandle_with_args() - Find the number of phandles references in a property
+ * @np: pointer to a device tree node containing a list
+ * @list_name: property name that contains a list
+ * @cells_name: property name that specifies phandles' arguments count
+ *
+ * Returns the number of phandle + argument tuples within a property. It
+ * is a typical pattern to encode a list of phandle and variable
+ * arguments into a single property. The number of arguments is encoded
+ * by a property in the phandle-target node. For example, a gpios
+ * property would contain a list of GPIO specifies consisting of a
+ * phandle and 1 or more arguments. The number of arguments are
+ * determined by the #gpio-cells property in the node pointed to by the
+ * phandle.
+ */
+int of_count_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name)
+{
+ return __of_parse_phandle_with_args(np, list_name, cells_name,
+ -1, NULL);
}
-EXPORT_SYMBOL(of_parse_phandles_with_args);
+EXPORT_SYMBOL(of_count_phandle_with_args);
/**
* of_machine_is_compatible - Test root of device tree for a given compatible value
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 83b72c0..87b9c0c 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -9,17 +9,16 @@ int of_get_named_gpio(struct device_node *np,
const char *propname, int index)
{
int ret;
- struct device_node *gpio_np;
- const void *gpio_spec;
+ struct of_phandle_args out_args;
- ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
- &gpio_np, &gpio_spec);
+ ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
+ index, &out_args);
if (ret) {
pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
return -EINVAL;
}
- ret = gpio_get_num(gpio_np->device, be32_to_cpup(gpio_spec));
+ ret = gpio_get_num(out_args.np->device, outargs.args[0]);
if (ret < 0)
return ret;
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 32b05aa..ee7c010 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -62,16 +62,15 @@ static int imx_chipidea_port_post_init(void *drvdata)
static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
{
- const void *out_args;
- struct device_node *usbmisc_np;
+ struct of_phandle_args out_args;
enum usb_dr_mode mode;
enum usb_phy_interface phymode;
- of_parse_phandles_with_args(ci->dev->device_node, "fsl,usbmisc",
- "#index-cells", 0, &usbmisc_np, &out_args);
-
- ci->portno = be32_to_cpup(out_args);
+ if (of_parse_phandle_with_args(ci->dev->device_node, "fsl,usbmisc",
+ "#index-cells", 0, &out_args))
+ return -ENODEV;
+ ci->portno = out_args.args[0];
ci->flags = MXC_EHCI_MODE_UTMI_8BIT;
mode = of_usb_get_dr_mode(ci->dev->device_node, NULL);
diff --git a/include/of.h b/include/of.h
index 4f5470a..e03bd40 100644
--- a/include/of.h
+++ b/include/of.h
@@ -42,6 +42,13 @@ struct of_device_id {
unsigned long data;
};
+#define MAX_PHANDLE_ARGS 8
+struct of_phandle_args {
+ struct device_node *np;
+ int args_count;
+ uint32_t args[MAX_PHANDLE_ARGS];
+};
+
#define OF_MAX_RESERVE_MAP 16
struct of_reserve_map {
uint64_t start[OF_MAX_RESERVE_MAP];
@@ -120,11 +127,6 @@ static inline int of_property_write_u32(struct device_node *np,
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp);
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
- const char *cells_name, int index,
- struct device_node **out_node,
- const void **out_args);
-
int of_get_named_gpio(struct device_node *np,
const char *propname, int index);
@@ -219,6 +221,11 @@ extern int of_property_count_strings(struct device_node *np,
extern struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name,
int index);
+extern int of_parse_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name, int index,
+ struct of_phandle_args *out_args);
+extern int of_count_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name);
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -358,6 +365,19 @@ static inline struct device_node *of_parse_phandle(const struct device_node *np,
return NULL;
}
+static inline int of_parse_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name, int index,
+ struct of_phandle_args *out_args)
+{
+ return -ENOSYS;
+}
+
+static inline int of_count_phandle_with_args(const struct device_node *np,
+ const char *list_name, const char *cells_name)
+{
+ return -ENOSYS;
+}
+
static inline struct device_node *of_find_node_by_path_from(
struct device_node *from, const char *path)
{
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* Re: [PATCH v2 16/22] OF: base: import parse phandle functions from Linux OF API
2013-06-19 9:09 ` [PATCH v2 16/22] OF: base: import parse phandle functions " Sebastian Hesselbarth
@ 2013-06-20 8:33 ` Sascha Hauer
0 siblings, 0 replies; 55+ messages in thread
From: Sascha Hauer @ 2013-06-20 8:33 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Hi Sebastian,
> diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
> index 83b72c0..87b9c0c 100644
> --- a/drivers/of/gpio.c
> +++ b/drivers/of/gpio.c
> @@ -9,17 +9,16 @@ int of_get_named_gpio(struct device_node *np,
> const char *propname, int index)
> {
> int ret;
> - struct device_node *gpio_np;
> - const void *gpio_spec;
> + struct of_phandle_args out_args;
>
> - ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
> - &gpio_np, &gpio_spec);
> + ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
> + index, &out_args);
> if (ret) {
> pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
> return -EINVAL;
> }
>
> - ret = gpio_get_num(gpio_np->device, be32_to_cpup(gpio_spec));
> + ret = gpio_get_num(out_args.np->device, outargs.args[0]);
Typo: s/outargs/out_args/
(No need to resend atm)
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 17/22] OF: base: introduce property write for bool, u8, u16, and u64
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (38 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 16/22] OF: base: import parse phandle functions " Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 18/22] OF: base: import property iterators from Linux OF API Sebastian Hesselbarth
` (4 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This adds functions to set an array of or a single value for bool,
u8, u16, and u64 properties.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++
include/of.h | 82 ++++++++++++++++++++++++----
2 files changed, 227 insertions(+), 11 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1c385c8..bf73acb 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -798,6 +798,119 @@ int of_property_count_strings(struct device_node *np, const char *propname)
EXPORT_SYMBOL_GPL(of_property_count_strings);
/**
+ * of_property_write_bool - Create/Delete empty (bool) property.
+ *
+ * @np: device node from which the property is to be set.
+ * @propname: name of the property to be set.
+ *
+ * Search for a property in a device node and create or delete the property.
+ * If the property already exists and write value is false, the property is
+ * deleted. If write value is true and the property does not exist, it is
+ * created. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_bool(struct device_node *np, const char *propname,
+ const bool value)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ if (!value) {
+ if (prop)
+ of_delete_property(prop);
+ return 0;
+ }
+
+ if (!prop)
+ prop = of_new_property(np, propname, NULL, 0);
+ if (!prop)
+ return -ENOMEM;
+
+ return 0;
+}
+
+/**
+ * of_property_write_u8_array - Write an array of u8 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write 8-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u8_array(struct device_node *np,
+ const char *propname, const u8 *values,
+ size_t sz)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ u8 *val;
+
+ if (!prop)
+ prop = of_new_property(np, propname, NULL, 0);
+ if (!prop)
+ return -ENOMEM;
+
+ free(prop->value);
+
+ prop->length = sizeof(*val) * sz;
+ prop->value = malloc(prop->length);
+ if (!prop->value)
+ return -ENOMEM;
+
+ val = prop->value;
+ while (sz--)
+ *val++ = *values++;
+
+ return 0;
+}
+
+/**
+ * of_property_write_u16_array - Write an array of u16 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write 16-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u16_array(struct device_node *np,
+ const char *propname, const u16 *values,
+ size_t sz)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ __be16 *val;
+
+ if (!prop)
+ prop = of_new_property(np, propname, NULL, 0);
+ if (!prop)
+ return -ENOMEM;
+
+ free(prop->value);
+
+ prop->length = sizeof(*val) * sz;
+ prop->value = malloc(prop->length);
+ if (!prop->value)
+ return -ENOMEM;
+
+ val = prop->value;
+ while (sz--)
+ *val++ = cpu_to_be16(*values++);
+
+ return 0;
+}
+
+/**
* of_property_write_u32_array - Write an array of u32 to a property. If
* the property does not exist, it will be created and appended to the given
* device node.
@@ -839,6 +952,49 @@ int of_property_write_u32_array(struct device_node *np,
}
/**
+ * of_property_write_u64_array - Write an array of u64 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np: device node to which the property value is to be written.
+ * @propname: name of the property to be written.
+ * @values: pointer to array elements to write.
+ * @sz: number of array elements to write.
+ *
+ * Search for a property in a device node and write 64-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u64_array(struct device_node *np,
+ const char *propname, const u64 *values,
+ size_t sz)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+ __be32 *val;
+
+ if (!prop)
+ prop = of_new_property(np, propname, NULL, 0);
+ if (!prop)
+ return -ENOMEM;
+
+ free(prop->value);
+
+ prop->length = 2 * sizeof(*val) * sz;
+ prop->value = malloc(prop->length);
+ if (!prop->value)
+ return -ENOMEM;
+
+ val = prop->value;
+ while (sz--) {
+ of_write_number(val, *values++, 2);
+ val += 2;
+ }
+
+ return 0;
+}
+
+/**
* of_parse_phandle - Resolve a phandle property to a device_node pointer
* @np: Pointer to device node holding phandle property
* @phandle_name: Name of property holding a phandle value
diff --git a/include/of.h b/include/of.h
index e03bd40..6abd906 100644
--- a/include/of.h
+++ b/include/of.h
@@ -113,17 +113,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
}
}
-int of_property_write_u32_array(struct device_node *np,
- const char *propname, const u32 *values,
- size_t sz);
-
-static inline int of_property_write_u32(struct device_node *np,
- const char *propname,
- u32 value)
-{
- return of_property_write_u32_array(np, propname, &value, 1);
-}
-
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp);
@@ -218,6 +207,21 @@ extern int of_property_match_string(struct device_node *np,
extern int of_property_count_strings(struct device_node *np,
const char *propname);
+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,
+ const char *propname, const u8 *values,
+ size_t sz);
+extern int of_property_write_u16_array(struct device_node *np,
+ const char *propname, const u16 *values,
+ size_t sz);
+extern int of_property_write_u32_array(struct device_node *np,
+ const char *propname, const u32 *values,
+ size_t sz);
+extern int of_property_write_u64_array(struct device_node *np,
+ const char *propname, const u64 *values,
+ size_t sz);
+
extern struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name,
int index);
@@ -359,6 +363,36 @@ static inline int of_property_count_strings(struct device_node *np,
return -ENOSYS;
}
+static inline int of_property_write_bool(struct device_node *np,
+ const char *propname, const bool value)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_write_u8_array(struct device_node *np,
+ const char *propname, const u8 *values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_write_u16_array(struct device_node *np,
+ const char *propname, const u16 *values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_write_u32_array(struct device_node *np,
+ const char *propname, const u32 *values, size_t sz)
+{
+ return -ENOSYS;
+}
+
+static inline int of_property_write_u64_array(struct device_node *np,
+ const char *propname, const u64 *values, size_t sz)
+{
+ return -ENOSYS;
+}
+
static inline struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name, int index)
{
@@ -502,4 +536,30 @@ static inline int of_property_read_u32(const struct device_node *np,
return of_property_read_u32_array(np, propname, out_value, 1);
}
+static inline int of_property_write_u8(struct device_node *np,
+ const char *propname, u8 value)
+{
+ return of_property_write_u8_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u16(struct device_node *np,
+ const char *propname, u16 value)
+{
+ return of_property_write_u16_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u32(struct device_node *np,
+ const char *propname,
+ u32 value)
+{
+ return of_property_write_u32_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u64(struct device_node *np,
+ const char *propname,
+ u64 value)
+{
+ return of_property_write_u64_array(np, propname, &value, 1);
+}
+
#endif /* __OF_H */
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 18/22] OF: base: import property iterators from Linux OF API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (39 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 17/22] OF: base: introduce property write for bool, u8, u16, and u64 Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 19/22] OF: base: remove of_tree_for_each_node from public API Sebastian Hesselbarth
` (3 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
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@gmail.com>
---
Cc: barebox@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 bf73acb..3e7a488 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 6abd906..30b5be5 100644
--- a/include/of.h
+++ b/include/of.h
@@ -207,6 +207,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,
@@ -363,6 +367,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
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 19/22] OF: base: remove of_tree_for_each_node from public API
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (40 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 18/22] OF: base: import property iterators from Linux OF API Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 20/22] OF: base: remove of_find_child_by_name Sebastian Hesselbarth
` (2 subsequent siblings)
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This patch converts users of of_tree_for_each_node to recently added
for_eacg_compatible_node helper. Also of_tree_for_each_node is removed
from public OF API.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
arch/arm/boards/at91sam9x5ek/hw_version.c | 10 +++-------
arch/arm/boards/highbank/init.c | 16 ++++++----------
drivers/of/base.c | 8 ++++++++
include/of.h | 8 --------
4 files changed, 17 insertions(+), 25 deletions(-)
diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 91af331..426bd35 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -234,13 +234,9 @@ static int cm_cogent_fixup(struct device_node *root)
int ret;
struct device_node *node;
- of_tree_for_each_node(node, root) {
- struct device_node *slotnode;
-
- if (!of_device_is_compatible(node, "atmel,hsmci"))
- continue;
-
- slotnode = of_find_child_by_name(node, "slot");
+ for_each_compatible_node(node, NULL, "atmel,hsmci") {
+ struct device_node *slotnode =
+ of_find_child_by_name(node, "slot");
if (!slotnode)
continue;
diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index 1aa713b..46ecc88 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -35,19 +35,15 @@ static int hb_fixup(struct device_node *root)
__be32 latency;
if (!(reg & HB_PWRDOM_STAT_SATA)) {
- of_tree_for_each_node(node, root) {
- if (of_device_is_compatible(node, "calxeda,hb-ahci"))
- of_set_property(node, "status", "disabled",
- sizeof("disabled"), 1);
- }
+ for_each_compatible_node(node, NULL, "calxeda,hb-ahci")
+ of_set_property(node, "status", "disabled",
+ sizeof("disabled"), 1);
}
if (!(reg & HB_PWRDOM_STAT_EMMC)) {
- of_tree_for_each_node(node, root) {
- if (of_device_is_compatible(node, "calxeda,hb-sdhci"))
- of_set_property(node, "status", "disabled",
- sizeof("disabled"), 1);
- }
+ for_each_compatible_node(node, NULL, "calxeda,hb-sdhci")
+ of_set_property(node, "status", "disabled",
+ sizeof("disabled"), 1);
}
if ((opp_table[0] >> 16) != HB_OPP_VERSION)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3e7a488..c8497f4 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -28,6 +28,14 @@
#include <linux/amba/bus.h>
#include <linux/err.h>
+/*
+ * Iterate over all nodes of a tree. As a devicetree does not
+ * have a dedicated list head, the start node (usually the root
+ * node) will not be iterated over.
+ */
+#define of_tree_for_each_node(node, root) \
+ list_for_each_entry(node, &root->list, list)
+
/**
* struct alias_prop - Alias property in 'aliases' node
* @link: List node to link the structure in aliases_lookup list
diff --git a/include/of.h b/include/of.h
index 30b5be5..2ef00be 100644
--- a/include/of.h
+++ b/include/of.h
@@ -85,14 +85,6 @@ int of_modalias_node(struct device_node *node, char *modalias, int len);
#define device_node_for_nach_child(node, child) \
list_for_each_entry(child, &node->children, parent_list)
-/*
- * Iterate over all nodes of a tree. As a devicetree does not
- * have a dedicated list head, the start node (usually the root
- * node) will not be iterated over.
- */
-#define of_tree_for_each_node(node, root) \
- list_for_each_entry(node, &root->list, list)
-
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 20/22] OF: base: remove of_find_child_by_name
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (41 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 19/22] OF: base: remove of_tree_for_each_node from public API Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 21/22] OF: base: convert and remove device_node_for_nach_child Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 22/22] OF: base: cleanup base function include Sebastian Hesselbarth
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
With of_get_child_by_name from Linux API, we can now convert and remove
of_find_child_by_name.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
arch/arm/boards/at91sam9x5ek/hw_version.c | 2 +-
drivers/of/base.c | 13 +------------
drivers/of/fdt.c | 9 +++++----
include/of.h | 2 --
4 files changed, 7 insertions(+), 19 deletions(-)
diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 426bd35..1207a3e 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -236,7 +236,7 @@ static int cm_cogent_fixup(struct device_node *root)
for_each_compatible_node(node, NULL, "atmel,hsmci") {
struct device_node *slotnode =
- of_find_child_by_name(node, "slot");
+ of_get_child_by_name(node, "slot");
if (!slotnode)
continue;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index c8497f4..1b351ee 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1905,17 +1905,6 @@ int of_probe(void)
return 0;
}
-struct device_node *of_find_child_by_name(struct device_node *node, const char *name)
-{
- struct device_node *_n;
-
- device_node_for_nach_child(node, _n)
- if (!of_node_cmp(_n->name, name))
- return _n;
-
- return NULL;
-}
-
/**
* of_create_node - create a new node including its parents
* @path - the nodepath to create
@@ -1940,7 +1929,7 @@ struct device_node *of_create_node(struct device_node *root, const char *path)
if (slash)
*slash = 0;
- tmp = of_find_child_by_name(dn, p);
+ tmp = of_get_child_by_name(dn, p);
if (tmp)
dn = tmp;
else
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a76396e..afaa4e0 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -61,7 +61,7 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
int len; /* length of the property */
const struct fdt_property *fdt_prop;
const char *pathp, *name;
- struct device_node *node = NULL, *n;
+ struct device_node *node = NULL;
struct property *p;
uint32_t dt_struct;
struct fdt_node_header *fnh;
@@ -135,9 +135,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
if (!node) {
node = root;
} else {
- if (merge && (n = of_find_child_by_name(node, pathp)))
- node = n;
- else
+ if (merge)
+ node = of_get_child_by_name(node,
+ pathp);
+ if (!merge || !node)
node = of_new_node(node, pathp);
}
diff --git a/include/of.h b/include/of.h
index 2ef00be..c3bcabe 100644
--- a/include/of.h
+++ b/include/of.h
@@ -74,8 +74,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
int of_n_addr_cells(struct device_node *np);
int of_n_size_cells(struct device_node *np);
-struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
-
struct fdt_header *fdt_get_tree(void);
struct fdt_header *of_get_fixed_tree(struct device_node *node);
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 21/22] OF: base: convert and remove device_node_for_nach_child
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (42 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 20/22] OF: base: remove of_find_child_by_name Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
2013-06-19 9:09 ` [PATCH v2 22/22] OF: base: cleanup base function include Sebastian Hesselbarth
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Remove device_node_for_nach_child and convert users to corresponding
imported OF API functions.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/i2c/i2c.c | 2 +-
drivers/mfd/stmpe-i2c.c | 7 ++-----
drivers/of/partition.c | 2 +-
drivers/spi/spi.c | 2 +-
include/of.h | 3 ---
5 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index b63d946..3e09547 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -278,7 +278,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.device_node)
return;
- device_node_for_nach_child(adap->dev.device_node, n) {
+ for_each_child_of_node(adap->dev.device_node, n) {
struct i2c_board_info info = {};
struct i2c_client *result;
const __be32 *addr;
diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
index d785430..c505bc1 100644
--- a/drivers/mfd/stmpe-i2c.c
+++ b/drivers/mfd/stmpe-i2c.c
@@ -116,11 +116,8 @@ static struct stmpe_platform_data *stmpe_of_probe(struct device_d *dev)
pdata = xzalloc(sizeof(*pdata));
- device_node_for_nach_child(dev->device_node, node) {
- if (!strcmp(node->name, "stmpe_gpio")) {
- pdata->blocks |= STMPE_BLOCK_GPIO;
- }
- }
+ if (of_get_child_by_name(dev->device_node, "stmpe_gpio"))
+ pdata->blocks |= STMPE_BLOCK_GPIO;
return pdata;
}
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 2d70cf5..e4b7d1e 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -29,7 +29,7 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node)
const char *partname;
char *filename;
- device_node_for_nach_child(node, n) {
+ for_each_child_of_node(node, n) {
const __be32 *reg;
unsigned long offset, size;
const char *name;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index eebf64c..5d4dfd6 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -107,7 +107,7 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
struct spi_board_info chip;
struct property *reg;
- device_node_for_nach_child(node, n) {
+ for_each_child_of_node(node, n) {
memset(&chip, 0, sizeof(chip));
chip.name = xstrdup(n->name);
chip.bus_num = master->bus_num;
diff --git a/include/of.h b/include/of.h
index c3bcabe..c61d002 100644
--- a/include/of.h
+++ b/include/of.h
@@ -80,9 +80,6 @@ struct fdt_header *of_get_fixed_tree(struct device_node *node);
int of_modalias_node(struct device_node *node, char *modalias, int len);
-#define device_node_for_nach_child(node, child) \
- list_for_each_entry(child, &node->children, parent_list)
-
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread
* [PATCH v2 22/22] OF: base: cleanup base function include
2013-06-18 17:29 [PATCH 00/22] Barebox OF API fixes, sync, and cleanup Sebastian Hesselbarth
` (43 preceding siblings ...)
2013-06-19 9:09 ` [PATCH v2 21/22] OF: base: convert and remove device_node_for_nach_child Sebastian Hesselbarth
@ 2013-06-19 9:09 ` Sebastian Hesselbarth
44 siblings, 0 replies; 55+ messages in thread
From: Sebastian Hesselbarth @ 2013-06-19 9:09 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This cleans up include/of.h by moving some function prototypes below
CONFIG_OFTREE and provide bogus stubs for !CONFIG_OFTREE.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
include/of.h | 138 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 109 insertions(+), 29 deletions(-)
diff --git a/include/of.h b/include/of.h
index c61d002..b392ca9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -71,15 +71,10 @@ int of_match(struct device_d *dev, struct driver_d *drv);
int of_add_initrd(struct device_node *root, resource_size_t start,
resource_size_t end);
-int of_n_addr_cells(struct device_node *np);
-int of_n_size_cells(struct device_node *np);
-
struct fdt_header *fdt_get_tree(void);
struct fdt_header *of_get_fixed_tree(struct device_node *node);
-int of_modalias_node(struct device_node *node, char *modalias, int len);
-
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
@@ -100,21 +95,12 @@ static inline void of_write_number(void *__cell, u64 val, int size)
}
}
-const void *of_get_property(const struct device_node *np, const char *name,
- int *lenp);
-
int of_get_named_gpio(struct device_node *np,
const char *propname, int index);
-struct device_node *of_find_node_by_phandle(phandle phandle);
void of_print_property(const void *data, int len);
void of_print_cmdline(struct device_node *root);
-int of_device_is_compatible(const struct device_node *device,
- const char *compat);
-
-int of_machine_is_compatible(const char *compat);
-
u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
@@ -123,41 +109,51 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
void of_print_nodes(struct device_node *node, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
-void of_free(struct device_node *node);
struct device_node *of_unflatten_dtb(struct device_node *root, void *fdt);
-struct device_node *of_new_node(struct device_node *parent, const char *name);
-struct property *of_new_property(struct device_node *node, const char *name,
- const void *data, int len);
-void of_delete_property(struct property *pp);
-
-int of_set_property(struct device_node *node, const char *p, const void *val, int len,
- int create);
-struct device_node *of_create_node(struct device_node *root, const char *path);
-
-int of_set_root_node(struct device_node *);
-
-const struct of_device_id *of_match_node(const struct of_device_id *matches,
- const struct device_node *node);
struct cdev;
#ifdef CONFIG_OFTREE
+extern int of_n_addr_cells(struct device_node *np);
+extern int of_n_size_cells(struct device_node *np);
+
extern struct property *of_find_property(const struct device_node *np,
const char *name, int *lenp);
+extern const void *of_get_property(const struct device_node *np,
+ const char *name, int *lenp);
+
+extern int of_set_property(struct device_node *node, const char *p,
+ const void *val, int len, int create);
+extern struct property *of_new_property(struct device_node *node,
+ const char *name, const void *data, int len);
+extern void of_delete_property(struct property *pp);
extern struct device_node *of_find_node_by_name(struct device_node *from,
const char *name);
extern struct device_node *of_find_node_by_path_from(struct device_node *from,
const char *path);
extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_node_by_phandle(phandle phandle);
extern struct device_node *of_find_compatible_node(struct device_node *from,
const char *type, const char *compat);
+extern const struct of_device_id *of_match_node(
+ const struct of_device_id *matches, const struct device_node *node);
extern struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
const struct of_device_id **match);
extern struct device_node *of_find_node_with_property(
struct device_node *from, const char *prop_name);
+
+extern struct device_node *of_new_node(struct device_node *parent,
+ const char *name);
+extern struct device_node *of_create_node(struct device_node *root,
+ const char *path);
+extern void of_free(struct device_node *node);
+
+extern int of_machine_is_compatible(const char *compat);
+extern int of_device_is_compatible(const struct device_node *device,
+ const char *compat);
extern int of_device_is_available(const struct device_node *device);
extern struct device_node *of_get_parent(const struct device_node *node);
@@ -225,6 +221,10 @@ extern int of_count_phandle_with_args(const struct device_node *np,
extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern const char *of_alias_get(struct device_node *np);
+extern int of_modalias_node(struct device_node *node, char *modalias, int len);
+
+extern struct device_node *of_get_root_node(void);
+extern int of_set_root_node(struct device_node *node);
int of_parse_partitions(struct cdev *cdev, struct device_node *node);
int of_device_is_stdout_path(struct device_d *dev);
@@ -233,7 +233,6 @@ void *of_flatten_dtb(struct device_node *node);
int of_add_memory(struct device_node *node, bool dump);
void of_add_memory_bank(struct device_node *node, bool dump, int r,
u64 base, u64 size);
-struct device_node *of_get_root_node(void);
#else
static inline int of_parse_partitions(struct cdev *cdev,
struct device_node *node)
@@ -266,6 +265,21 @@ static inline struct device_node *of_get_root_node(void)
return NULL;
}
+static inline int of_set_root_node(struct device_node *node)
+{
+ return -ENOSYS;
+}
+
+static inline int of_n_addr_cells(struct device_node *np)
+{
+ return 0;
+}
+
+static inline int of_n_size_cells(struct device_node *np)
+{
+ return 0;
+}
+
static inline struct device_node *of_get_parent(const struct device_node *node)
{
return NULL;
@@ -300,6 +314,28 @@ static inline struct property *of_find_property(const struct device_node *np,
return NULL;
}
+static inline const void *of_get_property(const struct device_node *np,
+ const char *name, int *lenp)
+{
+ return NULL;
+}
+
+static inline int of_set_property(struct device_node *node, const char *p,
+ const void *val, int len, int create)
+{
+ return -ENOSYS;
+}
+
+static inline struct property *of_new_property(struct device_node *node,
+ const char *name, const void *data, int len)
+{
+ return NULL;
+}
+
+static inline void of_delete_property(struct property *pp)
+{
+}
+
static inline int of_property_read_u32_index(const struct device_node *np,
const char *propname, u32 index, u32 *out_value)
{
@@ -432,6 +468,11 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
return NULL;
}
+static inline struct device_node *of_find_node_by_phandle(phandle phandle)
+{
+ return NULL;
+}
+
static inline struct device_node *of_find_compatible_node(
struct device_node *from,
const char *type,
@@ -440,6 +481,12 @@ static inline struct device_node *of_find_compatible_node(
return NULL;
}
+static inline const struct of_device_id *of_match_node(
+ const struct of_device_id *matches, const struct device_node *node)
+{
+ return NULL;
+}
+
static inline struct device_node *of_find_matching_node_and_match(
struct device_node *from,
const struct of_device_id *matches,
@@ -454,6 +501,33 @@ static inline struct device_node *of_find_node_with_property(
return NULL;
}
+static inline struct device_node *of_new_node(struct device_node *parent,
+ const char *name)
+{
+ return NULL;
+}
+
+static inline struct device_node *of_create_node(struct device_node *root,
+ const char *path)
+{
+ return NULL;
+}
+
+static inline void of_free(struct device_node *node)
+{
+}
+
+static inline int of_machine_is_compatible(const char *compat)
+{
+ return 0;
+}
+
+static inline int of_device_is_compatible(const struct device_node *device,
+ const char *compat)
+{
+ return 0;
+}
+
static inline int of_device_is_available(const struct device_node *device)
{
return 0;
@@ -472,6 +546,12 @@ static inline const char *of_alias_get(struct device_node *np)
{
return NULL;
}
+
+static inline int of_modalias_node(struct device_node *node, char *modalias,
+ int len)
+{
+ return -ENOSYS;
+}
#endif
#define for_each_node_by_name(dn, name) \
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 55+ messages in thread