[PATCH 1/2] driver: add support for requesting resource by name

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Wed Oct 17 09:05:14 EDT 2012


this will allow to avoid issue with resource order

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 drivers/base/driver.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/driver.h      |   15 +++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 64fe289..d0d20ce 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -247,6 +247,52 @@ void *dev_get_mem_region(struct device_d *dev, int num)
 }
 EXPORT_SYMBOL(dev_get_mem_region);
 
+struct resource *dev_get_resource_by_name(struct device_d *dev,
+					  const char *name)
+{
+	int i;
+
+	for (i = 0; i < dev->num_resources; i++) {
+		struct resource *res = &dev->resource[i];
+		if (resource_type(res) != IORESOURCE_MEM)
+			continue;
+		if (!res->name)
+			continue;
+		if (!strcmp(name, res->name))
+			return res;
+	}
+
+	return NULL;
+}
+
+void *dev_get_mem_region_by_name(struct device_d *dev, const char *name)
+{
+	struct resource *res;
+
+	res = dev_get_resource_by_name(dev, name);
+	if (!res)
+		return NULL;
+
+	return (void __force *)res->start;
+}
+EXPORT_SYMBOL(dev_get_mem_region_by_name);
+
+void __iomem *dev_request_mem_region_by_name(struct device_d *dev, const char *name)
+{
+	struct resource *res;
+
+	res = dev_get_resource_by_name(dev, name);
+	if (!res)
+		return NULL;
+
+	res = request_iomem_region(dev_name(dev), res->start, res->end);
+	if (!res)
+		return NULL;
+
+	return (void __force __iomem *)res->start;
+}
+EXPORT_SYMBOL(dev_request_mem_region_by_name);
+
 void __iomem *dev_request_mem_region(struct device_d *dev, int num)
 {
 	struct resource *res;
diff --git a/include/driver.h b/include/driver.h
index 4918054..f8d815c 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -193,6 +193,21 @@ static inline const char *dev_name(const struct device_d *dev)
 }
 
 /*
+ * get resource base 'name' for a device
+ */
+struct resource *dev_get_resource_by_name(struct device_d *dev,
+					  const char *name);
+/*
+ * get register base 'name' for a device
+ */
+void *dev_get_mem_region_by_name(struct device_d *dev, const char *name);
+
+/*
+ * exlusively request register base 'name' for a device
+ */
+void __iomem *dev_request_mem_region_by_name(struct device_d *dev,
+					     const char *name);
+/*
  * get register base 'num' for a device
  */
 void *dev_get_mem_region(struct device_d *dev, int num);
-- 
1.7.10.4




More information about the barebox mailing list