[U-Boot] [PATCH 1/2] ofnode: add {ofnode, dev}_read_resource_byname()
Masahiro Yamada
yamada.masahiro at socionext.com
Fri Aug 25 16:12:30 UTC 2017
Linux supports platform_get_resource_byname() to look up a resource
by name.
We want a similar helper. It is useful when a device node has two
or more named register regions.
Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
---
drivers/core/ofnode.c | 12 ++++++++++++
drivers/core/read.c | 6 ++++++
include/dm/ofnode.h | 2 ++
include/dm/read.h | 20 +++++++++++++++++++-
4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index c1a2e9f0daef..0685b689d846 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -627,3 +627,15 @@ int ofnode_read_resource(ofnode node, uint index, struct resource *res)
return 0;
}
}
+
+int ofnode_read_resource_byname(ofnode node, const char *name,
+ struct resource *res)
+{
+ int index;
+
+ index = ofnode_stringlist_search(node, "reg-names", name);
+ if (index < 0)
+ return index;
+
+ return ofnode_read_resource(node, index, res);
+}
diff --git a/drivers/core/read.c b/drivers/core/read.c
index fe40bed64de3..6acb33388f56 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -164,3 +164,9 @@ int dev_read_resource(struct udevice *dev, uint index, struct resource *res)
{
return ofnode_read_resource(dev_ofnode(dev), index, res);
}
+
+int dev_read_resource_byname(struct udevice *dev, const char *name,
+ struct resource *res)
+{
+ return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
+}
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 210ddb2e5d74..de2769ed5376 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -625,5 +625,7 @@ 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);
+int ofnode_read_resource_byname(ofnode node, const char *name,
+ struct resource *res);
#endif
diff --git a/include/dm/read.h b/include/dm/read.h
index c3a4a5611a70..49d69c990f6e 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -359,13 +359,24 @@ int dev_read_enabled(struct udevice *dev);
/**
* dev_read_resource() - obtain an indexed resource from a device.
*
- * @dev: devuce to examine
+ * @dev: device 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);
+/**
+ * dev_read_resource_byname() - obtain a named resource from a device.
+ *
+ * @dev: device to examine
+ * @name: name of the resource to retrieve
+ * @res: returns the resource
+ * @return 0 if ok, negative on error
+ */
+int dev_read_resource_byname(struct udevice *dev, const char *name,
+ struct resource *res);
+
#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
static inline int dev_read_u32_default(struct udevice *dev,
@@ -513,6 +524,13 @@ static inline int dev_read_resource(struct udevice *dev, uint index,
return ofnode_read_resource(dev_ofnode(dev), index, res);
}
+static inline int dev_read_resource_byname(struct udevice *dev,
+ const char *name,
+ struct resource *res)
+{
+ return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
+}
+
#endif /* CONFIG_DM_DEV_READ_INLINE */
/**
--
2.7.4
More information about the U-Boot
mailing list