1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-01 16:52:14 +02:00

dm: core: Add ofnode_read_resource()

We sometimes need to read a resource from an arbitrary node. In any case
for consistency we should not put the live-tree switching code in
a dev_read_...() function. Update this to suit.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Tested-on: Beaver, Jetson-TK1
Tested-by: Stephen Warren <swarren@nvidia.com>
This commit is contained in:
Simon Glass
2017-07-25 08:29:55 -06:00
parent c61d0009fe
commit dcf988525f
5 changed files with 47 additions and 34 deletions

View File

@@ -14,6 +14,7 @@
#include <dm/of_addr.h>
#include <dm/ofnode.h>
#include <linux/err.h>
#include <linux/ioport.h>
int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
{
@@ -593,3 +594,23 @@ bool ofnode_pre_reloc(ofnode node)
return false;
}
int ofnode_read_resource(ofnode node, uint index, struct resource *res)
{
if (ofnode_is_np(node)) {
return of_address_to_resource(ofnode_to_np(node), index, res);
} else {
struct fdt_resource fres;
int ret;
ret = fdt_get_resource(gd->fdt_blob, ofnode_to_offset(node),
"reg", index, &fres);
if (ret < 0)
return -EINVAL;
memset(res, '\0', sizeof(*res));
res->start = fres.start;
res->end = fres.end;
return 0;
}
}