summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/core/of_access.c61
-rw-r--r--drivers/core/ofnode.c51
-rw-r--r--include/dm/of_access.h86
-rw-r--r--include/dm/ofnode.h66
4 files changed, 244 insertions, 20 deletions
diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c
index 77acd766262..b11e36202c1 100644
--- a/drivers/core/of_access.c
+++ b/drivers/core/of_access.c
@@ -666,11 +666,12 @@ int of_property_read_string_helper(const struct device_node *np,
return i <= 0 ? -ENODATA : i;
}
-static int __of_parse_phandle_with_args(const struct device_node *np,
- const char *list_name,
- const char *cells_name,
- int cell_count, int index,
- struct of_phandle_args *out_args)
+static int __of_root_parse_phandle_with_args(struct device_node *root,
+ const struct device_node *np,
+ const char *list_name,
+ const char *cells_name,
+ int cell_count, int index,
+ struct of_phandle_args *out_args)
{
const __be32 *list, *list_end;
int rc = 0, cur_index = 0;
@@ -706,7 +707,7 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
* below.
*/
if (cells_name || cur_index == index) {
- node = of_find_node_by_phandle(NULL, phandle);
+ node = of_find_node_by_phandle(root, phandle);
if (!node) {
dm_warn("%s: could not find phandle\n",
np->full_name);
@@ -783,39 +784,65 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
return rc;
}
-struct device_node *of_parse_phandle(const struct device_node *np,
- const char *phandle_name, int index)
+struct device_node *of_root_parse_phandle(struct device_node *root,
+ const struct device_node *np,
+ const char *phandle_name, int index)
{
struct of_phandle_args args;
if (index < 0)
return NULL;
- if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0, index,
- &args))
+ if (__of_root_parse_phandle_with_args(root, np, phandle_name, NULL, 0,
+ index, &args))
return NULL;
return args.np;
}
+int of_root_parse_phandle_with_args(struct device_node *root,
+ const struct device_node *np,
+ const char *list_name, const char *cells_name,
+ int cell_count, int index,
+ struct of_phandle_args *out_args)
+{
+ if (index < 0)
+ return -EINVAL;
+
+ return __of_root_parse_phandle_with_args(root, np, list_name, cells_name,
+ cell_count, index, out_args);
+}
+
+int of_root_count_phandle_with_args(struct device_node *root,
+ const struct device_node *np,
+ const char *list_name, const char *cells_name,
+ int cell_count)
+{
+ return __of_root_parse_phandle_with_args(root, np, list_name, cells_name,
+ cell_count, -1, NULL);
+}
+
+struct device_node *of_parse_phandle(const struct device_node *np,
+ const char *phandle_name, int index)
+{
+ return of_root_parse_phandle(NULL, np, phandle_name, index);
+}
+
int of_parse_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name,
int cell_count, int index,
struct of_phandle_args *out_args)
{
- if (index < 0)
- return -EINVAL;
-
- return __of_parse_phandle_with_args(np, list_name, cells_name,
- cell_count, index, out_args);
+ return of_root_parse_phandle_with_args(NULL, np, list_name, cells_name,
+ cell_count, index, out_args);
}
int of_count_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name,
int cell_count)
{
- return __of_parse_phandle_with_args(np, list_name, cells_name,
- cell_count, -1, NULL);
+ return of_root_count_phandle_with_args(NULL, np, list_name, cells_name,
+ cell_count);
}
static void of_alias_add(struct alias_prop *ap, struct device_node *np,
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 950895e72a9..b9cc9419407 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -879,11 +879,11 @@ int ofnode_read_string_list(ofnode node, const char *property,
return count;
}
-static void ofnode_from_fdtdec_phandle_args(struct fdtdec_phandle_args *in,
+static void ofnode_from_fdtdec_phandle_args(ofnode node, struct fdtdec_phandle_args *in,
struct ofnode_phandle_args *out)
{
assert(OF_MAX_PHANDLE_ARGS == MAX_PHANDLE_ARGS);
- out->node = offset_to_ofnode(in->node);
+ out->node = noffset_to_ofnode(node, in->node);
out->args_count = in->args_count;
memcpy(out->args, in->args, sizeof(out->args));
}
@@ -923,7 +923,40 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
cell_count, index, &args);
if (ret)
return ret;
- ofnode_from_fdtdec_phandle_args(&args, out_args);
+ ofnode_from_fdtdec_phandle_args(node, &args, out_args);
+ }
+
+ return 0;
+}
+
+int oftree_parse_phandle_with_args(oftree tree, ofnode node, const char *list_name,
+ const char *cells_name, int cell_count,
+ int index,
+ struct ofnode_phandle_args *out_args)
+{
+ if (ofnode_is_np(node)) {
+ struct of_phandle_args args;
+ int ret;
+
+ ret = of_root_parse_phandle_with_args(tree.np,
+ ofnode_to_np(node),
+ list_name, cells_name,
+ cell_count, index,
+ &args);
+ if (ret)
+ return ret;
+ ofnode_from_of_phandle_args(&args, out_args);
+ } else {
+ struct fdtdec_phandle_args args;
+ int ret;
+
+ ret = fdtdec_parse_phandle_with_args(tree.fdt,
+ ofnode_to_offset(node),
+ list_name, cells_name,
+ cell_count, index, &args);
+ if (ret)
+ return ret;
+ ofnode_from_fdtdec_phandle_args(node, &args, out_args);
}
return 0;
@@ -941,6 +974,18 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
cell_count, -1, NULL);
}
+int oftree_count_phandle_with_args(oftree tree, ofnode node, const char *list_name,
+ const char *cells_name, int cell_count)
+{
+ if (ofnode_is_np(node))
+ return of_root_count_phandle_with_args(tree.np, ofnode_to_np(node),
+ list_name, cells_name, cell_count);
+ else
+ return fdtdec_parse_phandle_with_args(tree.fdt,
+ ofnode_to_offset(node), list_name, cells_name,
+ cell_count, -1, NULL);
+}
+
ofnode ofnode_path(const char *path)
{
if (of_live_active())
diff --git a/include/dm/of_access.h b/include/dm/of_access.h
index de740d44674..44143a5a391 100644
--- a/include/dm/of_access.h
+++ b/include/dm/of_access.h
@@ -454,6 +454,92 @@ static inline int of_property_count_strings(const struct device_node *np,
}
/**
+ * of_root_parse_phandle - Resolve a phandle property to a device_node pointer
+ * from a root node
+ * @root: Pointer to root device tree node (default root node if NULL)
+ * @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
+ *
+ * Return:
+ * the device_node pointer with refcount incremented. Use
+ * of_node_put() on it when done.
+ */
+struct device_node *of_root_parse_phandle(struct device_node *root,
+ const struct device_node *np,
+ const char *phandle_name, int index);
+
+/**
+ * of_root_parse_phandle_with_args() - Find a node pointed by phandle in a list
+ * from a root node
+ *
+ * @root: pointer to root device tree node (default root node if NULL)
+ * @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
+ * @cells_count: Cell count to use if @cells_name is NULL
+ * @index: index of a phandle to parse out
+ * @out_args: optional pointer to output arguments structure (will be filled)
+ * Return:
+ * 0 on success (with @out_args filled out if not NULL), -ENOENT if
+ * @list_name does not exist, -EINVAL if a phandle was not found,
+ * @cells_name could not be found, the arguments were truncated or there
+ * were too many arguments.
+ *
+ * This function is useful to parse lists of phandles and their arguments.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
+ *
+ * Caller is responsible to call of_node_put() on the returned out_args->np
+ * pointer.
+ *
+ * Example:
+ *
+ * .. code-block::
+ *
+ * phandle1: node1 {
+ * #list-cells = <2>;
+ * };
+ * phandle2: node2 {
+ * #list-cells = <1>;
+ * };
+ * node3 {
+ * list = <&phandle1 1 2 &phandle2 3>;
+ * };
+ *
+ * To get a device_node of the `node2' node you may call this:
+ * of_root_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
+ */
+int of_root_parse_phandle_with_args(struct device_node *root,
+ const struct device_node *np,
+ const char *list_name, const char *cells_name,
+ int cells_count, int index,
+ struct of_phandle_args *out_args);
+
+/**
+ * of_root_count_phandle_with_args() - Count the number of phandle in a list
+ * from a root node
+ *
+ * @root: pointer to root device tree node (default root node if NULL)
+ * @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
+ * @cells_count: Cell count to use if @cells_name is NULL
+ * Return:
+ * number of phandle found, -ENOENT if @list_name does not exist,
+ * -EINVAL if a phandle was not found, @cells_name could not be found,
+ * the arguments were truncated or there were too many arguments.
+ *
+ * Returns number of phandle found on success, on error returns appropriate
+ * errno value.
+ */
+int of_root_count_phandle_with_args(struct device_node *root,
+ const struct device_node *np,
+ const char *list_name, const char *cells_name,
+ int cells_count);
+
+/**
* 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/dm/ofnode.h b/include/dm/ofnode.h
index 0787758926f..7ece68874ae 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -910,6 +910,72 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
const char *cells_name, int cell_count);
/**
+ * oftree_parse_phandle_with_args() - Find a node pointed by phandle in a list
+ * from a root node
+ *
+ * This function is useful to parse lists of phandles and their arguments.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
+ *
+ * Caller is responsible to call of_node_put() on the returned out_args->np
+ * pointer.
+ *
+ * Example:
+ *
+ * .. code-block::
+ *
+ * phandle1: node1 {
+ * #list-cells = <2>;
+ * };
+ * phandle2: node2 {
+ * #list-cells = <1>;
+ * };
+ * node3 {
+ * list = <&phandle1 1 2 &phandle2 3>;
+ * };
+ *
+ * To get a device_node of the `node2' node you may call this:
+ * oftree_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
+ *
+ * @tree: device tree to use
+ * @node: device tree node containing a list
+ * @list_name: property name that contains a list
+ * @cells_name: property name that specifies phandles' arguments count
+ * @cell_count: Cell count to use if @cells_name is NULL
+ * @index: index of a phandle to parse out
+ * @out_args: optional pointer to output arguments structure (will be filled)
+ * Return:
+ * 0 on success (with @out_args filled out if not NULL), -ENOENT if
+ * @list_name does not exist, -EINVAL if a phandle was not found,
+ * @cells_name could not be found, the arguments were truncated or there
+ * were too many arguments.
+ */
+int oftree_parse_phandle_with_args(oftree tree, ofnode node, const char *list_name,
+ const char *cells_name, int cell_count,
+ int index,
+ struct ofnode_phandle_args *out_args);
+
+/**
+ * oftree_count_phandle_with_args() - Count number of phandle in a list
+ * from a root node
+ *
+ * This function is useful to count phandles into a list.
+ * Returns number of phandle on success, on error returns appropriate
+ * errno value.
+ *
+ * @tree: device tree to use
+ * @node: device tree node containing a list
+ * @list_name: property name that contains a list
+ * @cells_name: property name that specifies phandles' arguments count
+ * @cell_count: Cell count to use if @cells_name is NULL
+ * Return:
+ * number of phandle on success, -ENOENT if @list_name does not exist,
+ * -EINVAL if a phandle was not found, @cells_name could not be found.
+ */
+int oftree_count_phandle_with_args(oftree tree, ofnode node, const char *list_name,
+ const char *cells_name, int cell_count);
+
+/**
* ofnode_path() - find a node by full path
*
* This uses the control FDT.