]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dm: core: Add ofnode_read_resource()
authorSimon Glass <sjg@chromium.org>
Tue, 25 Jul 2017 14:29:55 +0000 (08:29 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 28 Jul 2017 18:02:47 +0000 (12:02 -0600)
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>
drivers/core/ofnode.c
drivers/core/read.c
drivers/core/read_extra.c
include/dm/ofnode.h
include/dm/read.h

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;
+       }
+}
index 85705836938cf61d202fe15808918095f7fbe228..fe40bed64de3c8f6d164b05a4e13e15eec377d35 100644 (file)
@@ -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);
+}
index a6d2f342d9da8ff692e41ecfe4f359e110b8b28f..e94648f1b588e53f4a04c38a9917131b264a8d1b 100644 (file)
 #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 */
index 15ad5199c2f017784a0796215da94339e18532eb..966ca9309a3c776fbeb1385852b681b01f7f9ca3 100644 (file)
@@ -15,6 +15,8 @@
 /* Enable checks to protect against invalid calls */
 #undef OF_CHECKS
 
+struct resource;
+
 /**
  * ofnode - reference to a device tree node
  *
@@ -605,4 +607,6 @@ int ofnode_read_simple_size_cells(ofnode node);
  */
 bool ofnode_pre_reloc(ofnode node);
 
+int ofnode_read_resource(ofnode node, uint index, struct resource *res);
+
 #endif
index edf468fdd1958364e7695a5797cb8ee6e7dfbaad..c2ca7ae34d4b48e31bcb4eba3a1d9c17cde35448 100644 (file)
@@ -44,16 +44,6 @@ static inline bool dev_of_valid(struct udevice *dev)
        return ofnode_valid(dev_ofnode(dev));
 }
 
-/**
- * dev_read_resource() - obtain an indexed resource from a device.
- *
- * @dev: devuce to examine
- * @index index of the resource to retrieve (0 = first)
- * @res returns the resource
- * @return 0 if ok, negative on error
- */
-int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
-
 #ifndef CONFIG_DM_DEV_READ_INLINE
 /**
  * dev_read_u32_default() - read a 32-bit integer from a device's DT property
@@ -348,6 +338,16 @@ const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
  */
 int dev_read_enabled(struct udevice *dev);
 
+/**
+ * dev_read_resource() - obtain an indexed resource from a device.
+ *
+ * @dev: devuce to examine
+ * @index index of the resource to retrieve (0 = first)
+ * @res returns the resource
+ * @return 0 if ok, negative on error
+ */
+int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 
 static inline int dev_read_u32_default(struct udevice *dev,
@@ -482,6 +482,12 @@ static inline int dev_read_enabled(struct udevice *dev)
        return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
 }
 
+static inline int dev_read_resource(struct udevice *dev, uint index,
+                                   struct resource *res)
+{
+       return ofnode_read_resource(dev_ofnode(dev), index, res);
+}
+
 #endif /* CONFIG_DM_DEV_READ_INLINE */
 
 /**