of: base: Add for_each_node_by_name_from
PATCH v3 1/5 of: base: Add for_each_node_by_name_from
Added for_each_node_by_name_from() to be able to
pass external root node.
--- include/of.h | 3 +++ 1 file changed, 3 insertions(+)
include/of.h +3 -0
@@ -568,6 +568,9 @@ static inline struct device_d *of_find_device_by_node(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_node_by_name_from (dn, root, name) \ + for (dn = of_find_node_by_name(root, 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))
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 2/5 of: base: Add of_find_node_by_phandle_from
Added of_find_node_by_phandle_from() to find nodes by phandle with a given root node.
--- drivers/of/base.c | 28 ++++++++++++++++++++++++---- include/of.h | 8 ++++++++ 2 files changed, 32 insertions(+), 4 deletions(-)
drivers/of/base.c +24 -4
@@ -265,19 +265,39 @@ struct device_node *of_find_node_by_alias(struct device_node *root, const char *EXPORT_SYMBOL_GPL (of_find_node_by_alias);/* -* of_find_node_by_phandle - Find a node given a phandle -* @handle: phandle of the node to find +* of_find_node_by_phandle_from - Find a node given a phandle from given +* root node. +* @handle: phandle of the node to find +* @root: root node of the tree to search in. If NULL use the +* internal tree. */ -struct device_node *of_find_node_by_phandle (phandle phandle) +struct device_node *of_find_node_by_phandle_from (phandle phandle, +struct device_node *root) {struct device_node *node; -of_tree_for_each_node_from (node, root_node) +if (!root) + root = root_node; + +if (!root) +return 0 ; + +of_tree_for_each_node_from (node, root)if (node->phandle == phandle)return node;return NULL ; } +EXPORT_SYMBOL (of_find_node_by_phandle_from); + +/* +* of_find_node_by_phandle - Find a node given a phandle +* @handle: phandle of the node to find +*/ +struct device_node *of_find_node_by_phandle (phandle phandle) +{ +return of_find_node_by_phandle_from (phandle, root_node); +}EXPORT_SYMBOL (of_find_node_by_phandle);/*
include/of.h +8 -0
@@ -123,6 +123,8 @@ 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_node_by_phandle_from (phandle phandle, +struct device_node *root);extern struct device_node *of_find_node_by_type (struct device_node *from,const char *type); extern struct device_node *of_find_compatible_node(struct device_node *from,
@@ -472,6 +474,12 @@ static inline struct device_node *of_find_node_by_phandle(phandle phandle)return NULL ; } +static inline struct device_node *of_find_node_by_phandle_from (phandle phandle, +struct device_node *root) +{ +return NULL ; +} + static inline struct device_node *of_find_compatible_node( struct device_node *from, const char *type,
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 3/5 of: base: Add of_parse_phandle_from
In reply to Teresa GámezAdded of_parse_phandle_from() to be able to use external root nodes.
--- drivers/of/base.c | 28 ++++++++++++++++++++++++---- include/of.h | 11 +++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-)
drivers/of/base.c +24 -4
@@ -1130,16 +1130,19 @@ int of_property_write_u64_array(struct device_node *np, }/** -* of_parse_phandle - Resolve a phandle property to a device_node pointer +* of_parse_phandle_from - Resolve a phandle property to a device_node pointer from +* a given root node * @np: Pointer to device node holding phandle property +* @root: root node of the tree to search in. If NULL use the internal tree. * @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) +struct device_node *of_parse_phandle_from (const struct device_node *np, +struct device_node *root, +const char *phandle_name,int index) {const __be32 *phandle;int size;
@@ -1148,7 +1151,24 @@ struct device_node *of_parse_phandle(const struct device_node *np,if ((!phandle) || (size <sizeof (*phandle) * (index +1 )))return NULL ; -return of_find_node_by_phandle (be32_to_cpup (phandle + index)); +return of_find_node_by_phandle_from (be32_to_cpup (phandle + index), + root); +} +EXPORT_SYMBOL (of_parse_phandle_from); + +/** +* 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) +{ +return of_parse_phandle_from (np, root_node, phandle_name, index); }EXPORT_SYMBOL (of_parse_phandle);
include/of.h +11 -0
@@ -205,6 +205,10 @@ extern int of_property_write_u64_array(struct device_node *np,extern struct device_node *of_parse_phandle (const struct device_node *np,const char *phandle_name,int index); +extern struct device_node *of_parse_phandle_from (const struct device_node *np, +struct device_node *root, +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);
@@ -439,6 +443,13 @@ static inline struct device_node *of_parse_phandle(const struct device_node *np,return NULL ; } +static inline struct device_node *of_parse_phandle_from (const struct device_node *np, +struct device_node *root, +const char *phandle_name,int index) +{ +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)
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 4/5 of: Added of_set_property_to_child_phandle
In reply to Teresa GámezSet a property to a phandle of a child node. This may be used for selections like display-timings.
--- drivers/of/base.c | 21 +++++++++++++++++++++ include/of.h | 1 + 2 files changed, 22 insertions(+)
drivers/of/base.c +21 -0
@@ -356,6 +356,27 @@ phandle of_node_create_phandle(struct device_node *node) }EXPORT_SYMBOL (of_node_create_phandle); +int of_set_property_to_child_phandle (struct device_node *node,char *prop_name) +{ +int ret; +phandle p; + +/* Check if property exist */ +if (!of_get_property (of_get_parent (node), prop_name,NULL )) +return -EINVAL ; + +/* Create or get existing phandle of child node */ + p =of_node_create_phandle (node); + p =cpu_to_be32 (p); + + node =of_get_parent (node); + + ret =of_set_property (node, prop_name, &p,sizeof (p),0 ); + +return ret; +} +EXPORT_SYMBOL (of_set_property_to_child_phandle); +/* * Find a property with a given name for a given node * and return the value.
include/of.h +1 -0
@@ -714,6 +714,7 @@ int of_device_disable_path(const char *path);phandle of_get_tree_max_phandle (struct device_node *root);phandle of_node_create_phandle (struct device_node *node); +int of_set_property_to_child_phandle (struct device_node *node,char *prop_name);struct device_node *of_find_node_by_alias (struct device_node *root,const char *alias); struct device_node *of_find_node_by_path_or_alias(struct device_node *root,
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 5/5 commands: add of_display_timings
In reply to Teresa GámezA lot of boards use display-timings nodes to define the timings of one or more displays. This command makes it possible to list and select displays which are defined in a device tree.
---
Changes v3:
- removed overwriting of root node
- using now for_each_node_by_name_from and of_parse_phandle_from
- eliminated ret variable
Changes v2:
- removed cast
- added free(ftd)
- freed root
commands/Kconfig | 15 ++++ commands/Makefile | 1 + commands/of_display_timings.c | 164 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 commands/of_display_timings.c
commands/Kconfig +15 -0
@@ -1973,6 +1973,21 @@ config CMD_OF_PROPERTY [00 11 22 .. nn] - byte stream If the value does not start with '<' or '[' it is interpreted as string +config CMD_OF_DISPLAY_TIMINGS + tristate + select OFTREE + prompt "of_display_timings" + help + List and select display timings + + Usage: of_display_timings [-lS] [-s path] [-f dtb] + + Options: + -l list path of all available display-timings + -S list path of all selected display-timings + -s path select display-timings and register oftree fixup + -f dtb work on dtb. Has no effect on -s option + config CMD_OFTREE tristate select OFTREE
commands/Makefile +1 -0
@@ -76,6 +76,7 @@ obj-$(CONFIG_CMD_OFTREE) += oftree.o obj-$(CONFIG_CMD_OF_PROPERTY) += of_property.o obj-$(CONFIG_CMD_OF_NODE) += of_node.o obj-$(CONFIG_CMD_OF_DUMP) += of_dump.o +obj-$(CONFIG_CMD_OF_DISPLAY_TIMINGS) += of_display_timings.o obj-$(CONFIG_CMD_MAGICVAR) += magicvar.o obj-$(CONFIG_CMD_IOMEM) += iomemport.o obj-$(CONFIG_CMD_LINUX_EXEC) += linux_exec.o
commands/of_display_timings.c new file +164 -0
164 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 4 lines · Teresa Gámez
Added
for_each_node_by_name_from()to be able to
pass external root node.Signed-off-by Teresa Gámez <[email protected]>
Applied all, thanks
Sascha
Quoted 26 lines
--- include/of.h | 3 +++ 1 file changed, 3 insertions(+)include/of.h +3
-0@@ -568,6 +568,9 @@ static inline struct device_d *of_find_device_by_node(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_node_by_name_from (dn, root, name) \ + for (dn = of_find_node_by_name(root, 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))Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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 [email protected] http://lists.infradead.org/mailman/listinfo/barebox