]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/core/ofnode.c
dm: core: Add ofnode_read_resource()
[people/ms/u-boot.git] / drivers / core / ofnode.c
index fd068b06ef3c3a6d2f1c3035746fb6fcf68a4690..e4b2a85f19ccc69c4a0ca965d7b449bc0e13d9a4 100644 (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;
+       }
+}