mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] driver: add support for requesting resource by name
Date: Wed, 17 Oct 2012 15:05:14 +0200	[thread overview]
Message-ID: <1350479115-29192-1-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20121017130320.GF30038@game.jcrosoft.org>

this will allow to avoid issue with resource order

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-10-17 13:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-17 13:03 [PATCH 0/2] allow to use named resources Jean-Christophe PLAGNIOL-VILLARD
2012-10-17 13:05 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-10-17 13:05   ` [PATCH 2/2] nomadik_nand: switch to named resource Jean-Christophe PLAGNIOL-VILLARD
2012-10-23  8:44 ` [PATCH 0/2] allow to use named resources Sascha Hauer
2012-10-23 10:22   ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-27 12:38 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350479115-29192-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox