[PATCH 7/8] of: Add of_match_node function
Sascha Hauer
s.hauer at pengutronix.de
Mon May 20 10:14:19 EDT 2013
To match a of_device_id arrays against a device_node. Same functionality
as in the kernel.
Signed-off-by: Sascha Hauer <s.hauer at 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
More information about the barebox
mailing list