dm: core: support reading a single indexed u64 value

Add helper function to allow reading a single indexed u64 value from a
device-tree property containing multiple u64 values, that is an array of
u64's.

Co-developed-by: Ashok Reddy Soma <ashok.reddy.soma@amd.com>
Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@amd.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Michal Simek <michal.simek@amd.com>
Link: https://lore.kernel.org/r/08043c8d204d0068f04c27de86afe78c75c50b69.1692956263.git.michal.simek@amd.com
This commit is contained in:
Michal Simek
2023-09-21 13:20:10 +02:00
parent 91ed45a24f
commit fa12dfa08a
6 changed files with 82 additions and 4 deletions
+30
View File
@@ -344,6 +344,36 @@ int ofnode_read_u32_index(ofnode node, const char *propname, int index,
return 0;
}
int ofnode_read_u64_index(ofnode node, const char *propname, int index,
u64 *outp)
{
const fdt64_t *cell;
int len;
assert(ofnode_valid(node));
if (ofnode_is_np(node))
return of_read_u64_index(ofnode_to_np(node), propname, index,
outp);
cell = fdt_getprop(ofnode_to_fdt(node), ofnode_to_offset(node),
propname, &len);
if (!cell) {
debug("(not found)\n");
return -EINVAL;
}
if (len < (sizeof(u64) * (index + 1))) {
debug("(not large enough)\n");
return -EOVERFLOW;
}
*outp = fdt64_to_cpu(cell[index]);
debug("%#llx (%lld)\n", *outp, *outp);
return 0;
}
u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
u32 def)
{