mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 7/8] of: Add of_match_node function
Date: Mon, 20 May 2013 16:14:19 +0200	[thread overview]
Message-ID: <1369059260-28872-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1369059260-28872-1-git-send-email-s.hauer@pengutronix.de>

To match a of_device_id arrays against a device_node. Same functionality
as in the kernel.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c | 35 +++++++++++++++++++++++++----------
 include/driver.h  |  2 +-
 include/of.h      |  3 +++
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index c3395cf..85d9dc0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -295,21 +295,36 @@ int of_device_is_compatible(const struct device_node *device,
 }
 EXPORT_SYMBOL(of_device_is_compatible);
 
+/**
+ * of_match_node - Tell if an device_node has a matching of_match structure
+ *      @matches:       array of of device match structures to search in
+ *      @node:          the of device structure to match against
+ *
+ *      Low level utility function used by device matching.
+ */
+const struct of_device_id *of_match_node(const struct of_device_id *matches,
+					 const struct device_node *node)
+{
+	while (matches->compatible) {
+		if (of_device_is_compatible(node, matches->compatible) == 1)
+			return matches;
+		matches++;
+	}
+
+	return NULL;
+}
+
 int of_match(struct device_d *dev, struct driver_d *drv)
 {
-	struct of_device_id *id;
+	const struct of_device_id *id;
 
-	id = drv->of_compatible;
+	id = of_match_node(drv->of_compatible, dev->device_node);
+	if (!id)
+		return 1;
 
-	while (id->compatible) {
-		if (of_device_is_compatible(dev->device_node, id->compatible) == 1) {
-			dev->of_id_entry = id;
-			return 0;
-		}
-		id++;
-	}
+	dev->of_id_entry = id;
 
-	return 1;
+	return 0;
 }
 EXPORT_SYMBOL(of_match);
 
diff --git a/include/driver.h b/include/driver.h
index 716f792..7d5f65e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -106,7 +106,7 @@ struct device_d {
 	struct platform_device_id *id_entry;
 	struct device_node *device_node;
 
-	struct of_device_id *of_id_entry;
+	const struct of_device_id *of_id_entry;
 };
 
 /** @brief Describes a driver present in the system */
diff --git a/include/of.h b/include/of.h
index 4dcf37e..3f64667 100644
--- a/include/of.h
+++ b/include/of.h
@@ -170,6 +170,9 @@ struct device_node *of_create_node(struct device_node *root, const char *path);
 struct device_node *of_get_root_node(void);
 int of_set_root_node(struct device_node *);
 
+const struct of_device_id *of_match_node(const struct of_device_id *matches,
+					 const struct device_node *node);
+
 struct cdev;
 
 #ifdef CONFIG_OFTREE
-- 
1.8.2.rc2


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

  parent reply	other threads:[~2013-05-20 14:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 14:14 [PATCH] devicetree misc updates Sascha Hauer
2013-05-20 14:14 ` [PATCH 1/8] ARM: dtb: Add $(obj)/$(BUILTIN_DTB).dtb.S as secondary target Sascha Hauer
2013-05-20 14:14 ` [PATCH 2/8] ARM: build dtbs during build process using extra-y Sascha Hauer
2013-05-20 14:14 ` [PATCH 3/8] scripts: fixdep: update from v3.10-rc1 Sascha Hauer
2013-05-20 14:14 ` [PATCH 4/8] kbuild: always run gcc -E on *.dts, remove cmd_dtc_cpp Sascha Hauer
2013-05-20 14:14 ` [PATCH 5/8] of: When checking for existing devices also check resource end Sascha Hauer
2013-05-20 14:14 ` [PATCH 6/8] of: Call of_add_memory from of_probe Sascha Hauer
2013-05-20 14:14 ` Sascha Hauer [this message]
2013-05-20 14:14 ` [PATCH 8/8] of: populate devices based on "simple-bus" property 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=1369059260-28872-8-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --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