diff options
Diffstat (limited to 'include/dm')
-rw-r--r-- | include/dm/of_access.h | 18 | ||||
-rw-r--r-- | include/dm/ofnode.h | 17 | ||||
-rw-r--r-- | include/dm/read.h | 25 |
3 files changed, 60 insertions, 0 deletions
diff --git a/include/dm/of_access.h b/include/dm/of_access.h index c5ea391aec..c49d287dd6 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -353,6 +353,24 @@ int of_parse_phandle_with_args(const struct device_node *np, 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 * * The function scans all the properties of the 'aliases' node and populates diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 966ca9309a..210ddb2e5d 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -435,6 +435,23 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name, 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 * * @path: Full path to node, e.g. "/bus/spi@1" diff --git a/include/dm/read.h b/include/dm/read.h index c2ca7ae34d..c3a4a5611a 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -199,6 +199,24 @@ int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, 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 * * This walks back up the tree to find the closest #address-cells property @@ -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 */ |