aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSimon Glass2017-07-25 08:29:55 -0600
committerSimon Glass2017-07-28 12:02:47 -0600
commitdcf988525f6e2045b9122ba7c3bf6a9bf44f146e (patch)
tree066e1e3e7a3f2aaceb5e407f85cf2a39ff1b486d /drivers
parentc61d0009feb966e0e93254a8c435a1889085e6b8 (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/core/ofnode.c21
-rw-r--r--drivers/core/read.c5
-rw-r--r--drivers/core/read_extra.c25
3 files changed, 27 insertions, 24 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index fd068b06ef3..e4b2a85f19c 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -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;
+ }
+}
diff --git a/drivers/core/read.c b/drivers/core/read.c
index 85705836938..fe40bed64de 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -159,3 +159,8 @@ int dev_read_enabled(struct udevice *dev)
return fdtdec_get_is_enabled(gd->fdt_blob,
ofnode_to_offset(node));
}
+
+int dev_read_resource(struct udevice *dev, uint index, struct resource *res)
+{
+ return ofnode_read_resource(dev_ofnode(dev), index, res);
+}
diff --git a/drivers/core/read_extra.c b/drivers/core/read_extra.c
index a6d2f342d9d..e94648f1b58 100644
--- a/drivers/core/read_extra.c
+++ b/drivers/core/read_extra.c
@@ -11,27 +11,4 @@
#include <dm/read.h>
#include <linux/ioport.h>
-int dev_read_resource(struct udevice *dev, uint index, struct resource *res)
-{
- ofnode node = dev_ofnode(dev);
-
-#ifdef CONFIG_OF_LIVE
- if (ofnode_is_np(node)) {
- return of_address_to_resource(ofnode_to_np(node), index, res);
- } else
-#endif
- {
- 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;
- }
-}
+/* This file can hold non-inlined dev_read_...() functions */