]> xenbits.xensource.com Git - xen.git/commitdiff
xen/device-tree: Add dt_count_phandle_with_args helper
authorOleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Tue, 21 May 2019 17:37:33 +0000 (20:37 +0300)
committerJulien Grall <julien.grall@arm.com>
Mon, 10 Jun 2019 19:39:54 +0000 (20:39 +0100)
Port Linux helper of_count_phandle_with_args for counting
number of phandles in a property.

Please note, this helper is ported from Linux v4.6.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Acked-by: Julien Grall <julien.grall@arm.com>
xen/common/device_tree.c
xen/include/xen/device_tree.h

index 8fc401d91cf0cd2bf419641b84248cc41d92fa58..65862b58bb50bb2f18530637cf043baf7ddd9bf8 100644 (file)
@@ -1663,6 +1663,13 @@ int dt_parse_phandle_with_args(const struct dt_device_node *np,
                                         index, out_args);
 }
 
+int dt_count_phandle_with_args(const struct dt_device_node *np,
+                               const char *list_name,
+                               const char *cells_name)
+{
+    return __dt_parse_phandle_with_args(np, list_name, cells_name, 0, -1, NULL);
+}
+
 /**
  * unflatten_dt_node - Alloc and populate a device_node from the flat tree
  * @fdt: The parent device tree blob
index 7408a6c48ca92a3960cf40b0f5f99d9ae5baf118..83156297e2296a3324bd1a0f1daf2ff0b70a2daa 100644 (file)
@@ -738,6 +738,25 @@ int dt_parse_phandle_with_args(const struct dt_device_node *np,
                                const char *cells_name, int index,
                                struct dt_phandle_args *out_args);
 
+/**
+ * dt_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 dt_count_phandle_with_args(const struct dt_device_node *np,
+                               const char *list_name,
+                               const char *cells_name);
+
 #ifdef CONFIG_DEVICE_TREE_DEBUG
 #define dt_dprintk(fmt, args...)  \
     printk(XENLOG_DEBUG fmt, ## args)