]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: add cells_count parameter in *_count_phandle_with_args
authorPatrick Delaunay <patrick.delaunay@st.com>
Fri, 25 Sep 2020 07:41:14 +0000 (09:41 +0200)
committerSimon Glass <sjg@chromium.org>
Tue, 6 Oct 2020 15:07:54 +0000 (09:07 -0600)
The cell_count argument is required when cells_name is NULL.

This patch adds this parameter in live tree API
- of_count_phandle_with_args
- ofnode_count_phandle_with_args
- dev_count_phandle_with_args

This parameter solves issue when these API is used to count
the number of element of a cell without cell name. This parameter
allow to force the size cell.

For example:
  count = dev_count_phandle_with_args(dev, "array", NULL, 3);

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
15 files changed:
board/st/stm32mp1/stm32mp1.c
drivers/clk/clk-uclass.c
drivers/core/of_access.c
drivers/core/ofnode.c
drivers/core/read.c
drivers/net/designware.c
drivers/phy/phy-uclass.c
drivers/power/domain/power-domain-uclass.c
drivers/reset/reset-uclass.c
drivers/usb/host/ehci-generic.c
drivers/usb/host/ohci-da8xx.c
drivers/usb/host/ohci-generic.c
include/dm/of_access.h
include/dm/ofnode.h
include/dm/read.h

index 3b677d339b72dd39b615d1cd3fbc560f50c6c653..03a19af93021c608e75e520738223bff75a82cc7 100644 (file)
@@ -314,7 +314,7 @@ static int board_check_usb_power(void)
         * for each of them
         */
        adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
-                                                  "#io-channel-cells");
+                                                  "#io-channel-cells", 0);
        if (adc_count < 0) {
                if (adc_count == -ENOENT)
                        return 0;
index 4076535271b1bccdf2c5b6a45a22c4fc0a6a16ed..31c5997aead8cedac5f46a52ae5255514ea37047 100644 (file)
@@ -161,7 +161,7 @@ int clk_get_bulk(struct udevice *dev, struct clk_bulk *bulk)
        
        bulk->count = 0;
 
-       count = dev_count_phandle_with_args(dev, "clocks", "#clock-cells");
+       count = dev_count_phandle_with_args(dev, "clocks", "#clock-cells", 0);
        if (count < 1)
                return count;
 
@@ -213,7 +213,7 @@ static int clk_set_default_parents(struct udevice *dev, int stage)
        int ret;
 
        num_parents = dev_count_phandle_with_args(dev, "assigned-clock-parents",
-                                                 "#clock-cells");
+                                                 "#clock-cells", 0);
        if (num_parents < 0) {
                debug("%s: could not read assigned-clock-parents for %p\n",
                      __func__, dev);
index bcf1644d0501c9bd2ea4eb7ca52642c99f76dcec..0a12e9b26f89d0efeadb12527098713213613497 100644 (file)
@@ -756,10 +756,11 @@ int of_parse_phandle_with_args(const struct device_node *np,
 }
 
 int of_count_phandle_with_args(const struct device_node *np,
-                              const char *list_name, const char *cells_name)
+                              const char *list_name, const char *cells_name,
+                              int cell_count)
 {
-       return __of_parse_phandle_with_args(np, list_name, cells_name, 0,
-                                           -1, NULL);
+       return __of_parse_phandle_with_args(np, list_name, cells_name,
+                                           cell_count, -1, NULL);
 }
 
 static void of_alias_add(struct alias_prop *ap, struct device_node *np,
index 79fcdf5ce210bcfe841b754c47a7effc9c64a831..7d1b89514c7d81047e8e7f70b4f3b2146aa7651e 100644 (file)
@@ -432,15 +432,15 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
 }
 
 int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
-                                  const char *cells_name)
+                                  const char *cells_name, int cell_count)
 {
        if (ofnode_is_np(node))
                return of_count_phandle_with_args(ofnode_to_np(node),
-                               list_name, cells_name);
+                               list_name, cells_name, cell_count);
        else
                return fdtdec_parse_phandle_with_args(gd->fdt_blob,
                                ofnode_to_offset(node), list_name, cells_name,
-                               0, -1, NULL);
+                               cell_count, -1, NULL);
 }
 
 ofnode ofnode_path(const char *path)
index 86f3f881706e046bffc8338502922a6a8e40c194..076125824cab007ba858ccb9508bfb5ea48b77fa 100644 (file)
@@ -214,10 +214,11 @@ int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
 }
 
 int dev_count_phandle_with_args(const struct udevice *dev,
-                               const char *list_name, const char *cells_name)
+                               const char *list_name, const char *cells_name,
+                               int cell_count)
 {
        return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
-                                             cells_name);
+                                             cells_name, cell_count);
 }
 
 int dev_read_addr_cells(const struct udevice *dev)
index 1c0e8294078a745512a2d6f28d28f6dac3656b65..4c19abbaf0c7101cae625f41f19feb8baf8848f1 100644 (file)
@@ -688,7 +688,8 @@ int designware_eth_probe(struct udevice *dev)
        int i, clock_nb;
 
        priv->clock_count = 0;
-       clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells");
+       clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells",
+                                              0);
        if (clock_nb > 0) {
                priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk),
                                            GFP_KERNEL);
index 8f456f33d27d551274c134fbba2036d9d6212113..f344e94b438d4f599919df2aedd0adc7befa18de 100644 (file)
@@ -214,7 +214,7 @@ int generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk)
        if (!dev_read_prop(dev, "phys", NULL))
                return 0;
 
-       count = dev_count_phandle_with_args(dev, "phys", "#phy-cells");
+       count = dev_count_phandle_with_args(dev, "phys", "#phy-cells", 0);
        if (count < 1)
                return count;
 
index c2c7c3bd507fcfb6bb2ae6ab2fa4ca5e32254004..af829db9da1f3b48abca16748d01c5119e437956 100644 (file)
@@ -117,7 +117,7 @@ static int dev_power_domain_ctrl(struct udevice *dev, bool on)
        int i, count, ret = 0;
 
        count = dev_count_phandle_with_args(dev, "power-domains",
-                                           "#power-domain-cells");
+                                           "#power-domain-cells", 0);
        for (i = 0; i < count; i++) {
                ret = power_domain_get_by_index(dev, &pd, i);
                if (ret)
index e7e407ca3503622b97bf976d5a22991792400784..071c389ca073baf975ed8ba47c07023370cdb8ce 100644 (file)
@@ -108,7 +108,8 @@ static int __reset_get_bulk(struct udevice *dev, ofnode node,
 
        bulk->count = 0;
 
-       count = ofnode_count_phandle_with_args(node, "resets", "#reset-cells");
+       count = ofnode_count_phandle_with_args(node, "resets", "#reset-cells",
+                                              0);
        if (count < 1)
                return count;
 
index 304a3437d56cb60dcea097e44f1bafb5d719f184..c93a7051a795b6add03699b5c0a314578e646a57 100644 (file)
@@ -86,7 +86,7 @@ static int ehci_usb_probe(struct udevice *dev)
        err = 0;
        priv->clock_count = 0;
        clock_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "clocks",
-                                                 "#clock-cells");
+                                                 "#clock-cells", 0);
        if (clock_nb > 0) {
                priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk),
                                            GFP_KERNEL);
@@ -116,7 +116,7 @@ static int ehci_usb_probe(struct udevice *dev)
 
        priv->reset_count = 0;
        reset_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "resets",
-                                                 "#reset-cells");
+                                                 "#reset-cells", 0);
        if (reset_nb > 0) {
                priv->resets = devm_kcalloc(dev, reset_nb,
                                            sizeof(struct reset_ctl),
index 22e7b565b5bf3552c8254892bed57be0a5153602..aa1eba262a9ee2da1bc673f63da7b94982f89bfa 100644 (file)
@@ -95,7 +95,8 @@ static int ohci_da8xx_probe(struct udevice *dev)
 
        err = 0;
        priv->clock_count = 0;
-       clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells");
+       clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells",
+                                              0);
 
        if (clock_nb < 0)
                return clock_nb;
index ed5e500b2c98e88e77f16093ed833ba6f5db1f17..ac9b7e1e3c0280a99d55580b18ca35efdd3ec738 100644 (file)
@@ -85,7 +85,8 @@ static int ohci_usb_probe(struct udevice *dev)
 
        err = 0;
        priv->clock_count = 0;
-       clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells");
+       clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells",
+                                              0);
        if (clock_nb > 0) {
                priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk),
                                            GFP_KERNEL);
@@ -111,7 +112,8 @@ static int ohci_usb_probe(struct udevice *dev)
        }
 
        priv->reset_count = 0;
-       reset_nb = dev_count_phandle_with_args(dev, "resets", "#reset-cells");
+       reset_nb = dev_count_phandle_with_args(dev, "resets", "#reset-cells",
+                                              0);
        if (reset_nb > 0) {
                priv->resets = devm_kcalloc(dev, reset_nb,
                                            sizeof(struct reset_ctl),
index 2fa65c9332e60a0f8c2b6d13fcf8763cf2942048..cc382b1671cb0802abd9d633e7b53a1bf8c0461e 100644 (file)
@@ -450,6 +450,7 @@ int of_parse_phandle_with_args(const struct device_node *np,
  * @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
@@ -460,7 +461,8 @@ int of_parse_phandle_with_args(const struct device_node *np,
  *
  */
 int of_count_phandle_with_args(const struct device_node *np,
-                              const char *list_name, const char *cells_name);
+                              const char *list_name, const char *cells_name,
+                              int cells_count);
 
 /**
  * of_alias_scan() - Scan all properties of the 'aliases' node
index 98c64fece302463fbe447c84232139fa38756341..4b7af37056018b433d83f51c8f1c493991429a1f 100644 (file)
@@ -556,12 +556,13 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
  * @node:      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 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);
+                                  const char *cells_name, int cell_count);
 
 /**
  * ofnode_path() - find a node by full path
index 67db94adfc14b0870ed89b348538e40f486840cc..0585eb12281c792761404885728f891fb18a816e 100644 (file)
@@ -429,12 +429,14 @@ int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
  * @dev:       device whose 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
  * @Returns number of phandle found on success, on error returns appropriate
  * errno value.
  */
 
 int dev_count_phandle_with_args(const struct udevice *dev,
-                               const char *list_name, const char *cells_name);
+                               const char *list_name, const char *cells_name,
+                               int cell_count);
 
 /**
  * dev_read_addr_cells() - Get the number of address cells for a device's node
@@ -880,10 +882,10 @@ static inline int dev_read_phandle_with_args(const struct udevice *dev,
 }
 
 static inline int dev_count_phandle_with_args(const struct udevice *dev,
-               const char *list_name, const char *cells_name)
+               const char *list_name, const char *cells_name, int cell_count)
 {
        return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
-                                             cells_name);
+                                             cells_name, cell_count);
 }
 
 static inline int dev_read_addr_cells(const struct udevice *dev)