]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: refactor functions reading an u32 from dt
authorDario Binacchi <dariobin@libero.it>
Sun, 29 Mar 2020 16:04:42 +0000 (18:04 +0200)
committerSimon Glass <sjg@chromium.org>
Thu, 16 Apr 2020 14:07:58 +0000 (08:07 -0600)
Now reading a 32 bit value from a device-tree property can be expressed
as reading the first element of an array with a single value.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/core/of_access.c
drivers/core/ofnode.c

index 8b2ce7a0c21b5272548007af8a67087e78fac080..c54baa140adc98a2cb1a4d49147f9ae70f0466ef 100644 (file)
@@ -449,21 +449,7 @@ static void *of_find_property_value_of_size(const struct device_node *np,
 
 int of_read_u32(const struct device_node *np, const char *propname, u32 *outp)
 {
-       const __be32 *val;
-
-       debug("%s: %s: ", __func__, propname);
-       if (!np)
-               return -EINVAL;
-       val = of_find_property_value_of_size(np, propname, sizeof(*outp));
-       if (IS_ERR(val)) {
-               debug("(not found)\n");
-               return PTR_ERR(val);
-       }
-
-       *outp = be32_to_cpup(val);
-       debug("%#x (%d)\n", *outp, *outp);
-
-       return 0;
+       return of_read_u32_index(np, propname, 0, outp);
 }
 
 int of_read_u32_array(const struct device_node *np, const char *propname,
index 5bc3b02996ebf972d2575804830b5829f9a8af61..b0be7cbe1981a2ae17c33847f234349a11df2c2e 100644 (file)
 
 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
 {
-       assert(ofnode_valid(node));
-       debug("%s: %s: ", __func__, propname);
-
-       if (ofnode_is_np(node)) {
-               return of_read_u32(ofnode_to_np(node), propname, outp);
-       } else {
-               const fdt32_t *cell;
-               int len;
-
-               cell = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node),
-                                  propname, &len);
-               if (!cell || len < sizeof(int)) {
-                       debug("(not found)\n");
-                       return -EINVAL;
-               }
-               *outp = fdt32_to_cpu(cell[0]);
-       }
-       debug("%#x (%d)\n", *outp, *outp);
-
-       return 0;
+       return ofnode_read_u32_index(node, propname, 0, outp);
 }
 
 u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def)
 {
        assert(ofnode_valid(node));
-       ofnode_read_u32(node, propname, &def);
+       ofnode_read_u32_index(node, propname, 0, &def);
 
        return def;
 }