diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-10-02 08:54:42 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-10-02 08:54:42 +0200 |
commit | 9d7cd03e2a285c0bbe7271afe46f6d717b0c1dfe (patch) | |
tree | 7a6ec7cbb08d534b733d810c33105f2d303a73ae /drivers | |
parent | 815288c59895ea48ff677ad8f575d3eec679c11b (diff) | |
parent | d21f496abaafcf828bd2dc0ec74d275c524fae65 (diff) | |
download | barebox-9d7cd03e2a285c0bbe7271afe46f6d717b0c1dfe.tar.gz barebox-9d7cd03e2a285c0bbe7271afe46f6d717b0c1dfe.tar.xz |
Merge branch 'for-next/of'
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/of/base.c | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index c440a69e6c..e9f0883f47 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -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); /* @@ -336,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. @@ -1110,16 +1151,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; @@ -1128,7 +1172,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); |