dm: core: support reading a single indexed u32 value
[oweals/u-boot.git] / drivers / core / of_access.c
index 29e705e0b660c4ee7fd3a59852b3fde2af51c0d2..8b2ce7a0c21b5272548007af8a67087e78fac080 100644 (file)
@@ -485,6 +485,28 @@ int of_read_u32_array(const struct device_node *np, const char *propname,
        return 0;
 }
 
+int of_read_u32_index(const struct device_node *np, const char *propname,
+                     int index, 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) * (index + 1));
+       if (IS_ERR(val)) {
+               debug("(not found)\n");
+               return PTR_ERR(val);
+       }
+
+       *outp = be32_to_cpup(val + index);
+       debug("%#x (%d)\n", *outp, *outp);
+
+       return 0;
+}
+
 int of_read_u64(const struct device_node *np, const char *propname, u64 *outp)
 {
        const __be64 *val;