@@ -1201,6 +1201,88 @@ void of_print_phandle_args(const char *msg, const struct of_phandle_args *args)
printk("\n");
}
+int __of_parse_next_phandle_with_args(const __be32 **plist,
+ const char *cells_name, int cell_count,
+ struct of_phandle_args *out_args)
+{
+ phandle phandle;
+ int i, count = 0, err;
+ struct device_node *dn;
+ const __be32 *list;
+
+ BUG_ON(!out_args);
+ BUG_ON(!cells_name && !cell_count);
+
+ /*
+ * "*plist" should hold phandle, and it's updated to the next
+ * phandle at return if no error.
+ */
+ list = *plist;
+ out_args->np = NULL;
+
+ phandle = be32_to_cpup(list);
+ if (!phandle)
+ goto err_out;
+
+ dn = of_find_node_by_phandle(phandle);
+ if (!dn)
+ goto err_out;
+
+ if (cells_name) {
+ err = of_property_read_u32(dn, cells_name, &count);
+ if (err)
+ goto err_out;
+ } else {
+ count = cell_count;
+ }
+
+ out_args->np = dn;
+ out_args->args_count = count;
+ for (i = 0; i < count; i++)
+ out_args->args[i] = be32_to_cpup(list + 1 + i);
+
+ *plist = list + count + 1; /* update to the next list */
+ return count + 1;
+
+err_out:
+ *plist = NULL;
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(__of_parse_next_phandle_with_args);
+
+int __of_parse_first_phandle_with_args(const struct device_node *np,
+ const __be32 **out_list,
+ const char *list_name,
+ const char *cells_name,
+ int cell_count,
+ struct of_phandle_args *out_args)
+{
+ int rem, count;
+ const __be32 *list;
+
+ list = of_get_property(np, list_name, &rem);
+ if (!list)
+ goto err_out;
+
+ rem /= sizeof(*list);
+ if (!rem)
+ goto err_out;
+
+ count = __of_parse_next_phandle_with_args(&list, cells_name,
+ cell_count, out_args);
+ if (!list)
+ goto err_out;
+
+ rem -= count;
+ *out_list = list; /* update to the next list */
+ return rem;
+
+err_out:
+ *out_list = NULL;
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(__of_parse_first_phandle_with_args);
+
static int __of_parse_phandle_with_args(const struct device_node *np,
const char *list_name,
const char *cells_name,
@@ -303,6 +303,35 @@ extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
extern int of_count_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name);
+extern int __of_parse_first_phandle_with_args(const struct device_node *np,
+ const __be32 **out_list,
+ const char *list_name,
+ const char *cells_name,
+ int cell_count,
+ struct of_phandle_args *out_args);
+
+extern int __of_parse_next_phandle_with_args(const __be32 **plist,
+ const char *cells_name,
+ int cell_count,
+ struct of_phandle_args *out_args);
+
+static inline int of_parse_first_phandle_with_args(const struct device_node *np,
+ const __be32 **out_list,
+ const char *list_name,
+ const char *cells_name,
+ struct of_phandle_args *out_args)
+{
+ return __of_parse_first_phandle_with_args(np, out_list, list_name,
+ cells_name, 0, out_args);
+}
+
+static inline int of_parse_next_phandle_with_args(const __be32 **plist,
+ const char *cells_name,
+ struct of_phandle_args *out_args)
+{
+ return __of_parse_next_phandle_with_args(plist, cells_name, 0, out_args);
+}
+
extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -527,6 +556,24 @@ static inline int of_count_phandle_with_args(struct device_node *np,
return -ENOSYS;
}
+static inline int __of_parse_first_phandle_with_args(
+ const struct device_node *np, const __be32 **out_list,
+ const char *list_name, const char *cells_name, int cell_count,
+ struct of_phandle_args *out_args)
+{
+ *out_list = NULL;
+ return -ENOSYS;
+}
+
+
+static inline int __of_parse_next_phandle_with_args(
+ const __be32 **plist, const char *cells_name, int cell_count,
+ struct of_phandle_args *out_args)
+{
+ *plist = NULL;
+ return -ENOSYS;
+}
+
static inline int of_alias_get_id(struct device_node *np, const char *stem)
{
return -ENOSYS;
@@ -613,6 +660,11 @@ static inline int of_property_read_u32(const struct device_node *np,
s; \
s = of_prop_next_string(prop, s))
+#define of_property_for_each_phandle_with_args(node, list, list_name, cells_name, rem, args) \
+ for (rem = of_parse_first_phandle_with_args(node, &list, list_name, cells_name, &args); \
+ list && rem >= 0; \
+ rem -= of_parse_next_phandle_with_args(&list, cells_name, &args))
+
#if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE)
extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);