]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: add ofnode_count_phandle_with_args()
authorPatrice Chotard <patrice.chotard@st.com>
Tue, 18 Jul 2017 09:57:08 +0000 (11:57 +0200)
committerMarek Vasut <marex@denx.de>
Fri, 28 Jul 2017 21:34:08 +0000 (23:34 +0200)
This function is usefull to get phandle number contained
in a property list.
For example,  this allows to allocate the right amount
of memory to keep clock's reference contained into the
"clocks" property.

To implement it, either of_count_phandle_with_args() or
fdtdec_parse_phandle_with_args() are used respectively
for live tree and flat tree.
By passing index = -1, these 2 functions returns the
number of phandle contained into the property list.

Add also the dev_count_phandle_with_args() based on
ofnode_count_phandle_with_args()

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/core/of_access.c
drivers/core/ofnode.c
include/dm/of_access.h
include/dm/ofnode.h
include/dm/read.h

index 2bb23eef8850743d2e68a8af57b88fcca5a3af71..c31cba7fd6b501fd6ffcb5ee0c5ba0a239f52dfa 100644 (file)
@@ -665,6 +665,13 @@ int of_parse_phandle_with_args(const struct device_node *np,
                                            index, out_args);
 }
 
+int of_count_phandle_with_args(const struct device_node *np,
+                              const char *list_name, const char *cells_name)
+{
+       return __of_parse_phandle_with_args(np, list_name, cells_name, 0,
+                                           -1, NULL);
+}
+
 static void of_alias_add(struct alias_prop *ap, struct device_node *np,
                         int id, const char *stem, int stem_len)
 {
index fd068b06ef3c3a6d2f1c3035746fb6fcf68a4690..5fc77c52a05356307fd434c1acbbd1c6a2c89ec6 100644 (file)
@@ -313,6 +313,18 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
        return 0;
 }
 
+int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
+                                  const char *cells_name)
+{
+       if (ofnode_is_np(node))
+               return of_count_phandle_with_args(ofnode_to_np(node),
+                               list_name, cells_name);
+       else
+               return fdtdec_parse_phandle_with_args(gd->fdt_blob,
+                               ofnode_to_offset(node), list_name, cells_name,
+                               0, -1, NULL);
+}
+
 ofnode ofnode_path(const char *path)
 {
        if (of_live_active())
index c5ea391aec169a2c8a17666b0257896dbc4bf45c..c49d287dd6004d9727398d734129c16dbb784139 100644 (file)
@@ -352,6 +352,24 @@ 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);
 
+/**
+ * of_count_phandle_with_args() - Count the number of phandle in a list
+ *
+ * @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
+ * @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_count_phandle_with_args(const struct device_node *np,
+                              const char *list_name, const char *cells_name);
+
 /**
  * of_alias_scan() - Scan all properties of the 'aliases' node
  *
index 15ad5199c2f017784a0796215da94339e18532eb..8eecce59d1059a4f78564d216f0c2da91bc25537 100644 (file)
@@ -432,6 +432,23 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
                                   int index,
                                   struct ofnode_phandle_args *out_args);
 
+/**
+ * ofnode_count_phandle_with_args() - Count number of phandle in a list
+ *
+ * This function is useful to count phandles into a list.
+ * Returns number of phandle on success, on error returns appropriate
+ * errno value.
+ *
+ * @node:      device tree node containing a list
+ * @list_name: property name that contains a list
+ * @cells_name:        property name that specifies phandles' arguments count
+ * @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 ofnode_count_phandle_with_args(ofnode node, const char *list_name,
+                                  const char *cells_name);
+
 /**
  * ofnode_path() - find a node by full path
  *
index b86a2f5feceb862967e912519003ff900a641b16..d09b04d110a4649715d691ee98a199ea90b4ebfb 100644 (file)
@@ -208,6 +208,24 @@ int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
                                int index,
                                struct ofnode_phandle_args *out_args);
 
+/**
+ * dev_count_phandle_with_args() - Return phandle number in a list
+ *
+ * This function is usefull to get phandle number contained in a property list.
+ * For example, this allows to allocate the right amount of memory to keep
+ * clock's reference contained into the "clocks" property.
+ *
+ *
+ * @dev:       device whose node containing a list
+ * @list_name: property name that contains a list
+ * @cells_name:        property name that specifies phandles' arguments count
+ * @Returns number of phandle found on success, on error returns appropriate
+ * errno value.
+ */
+
+int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
+                               const char *cells_name);
+
 /**
  * dev_read_addr_cells() - Get the number of address cells for a device's node
  *
@@ -416,6 +434,13 @@ static inline int dev_read_phandle_with_args(struct udevice *dev,
                                              out_args);
 }
 
+static inline int dev_count_phandle_with_args(struct udevice *dev,
+               const char *list_name, const char *cells_name)
+{
+       return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
+                                             cells_name);
+}
+
 static inline int dev_read_addr_cells(struct udevice *dev)
 {
        /* NOTE: this call should walk up the parent stack */