From 0cb87c4d1e273b2acb71db8f5b0a8842df5af68d Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sun, 19 May 2013 08:53:47 +0200 Subject: [PATCH] of: Add of_match_node function To match a of_device_id arrays against a device_node. Same functionality as in the kernel. Signed-off-by: Sascha Hauer --- drivers/of/base.c | 39 +++++++++++++++++++++++++++------------ include/driver.h | 2 +- include/of.h | 3 +++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index c3395cf14..85d9dc042 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); -int of_match(struct device_d *dev, struct driver_d *drv) +/** + * 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) { - struct of_device_id *id; - - id = drv->of_compatible; - - while (id->compatible) { - if (of_device_is_compatible(dev->device_node, id->compatible) == 1) { - dev->of_id_entry = id; - return 0; - } - id++; + while (matches->compatible) { + if (of_device_is_compatible(node, matches->compatible) == 1) + return matches; + matches++; } - return 1; + return NULL; +} + +int of_match(struct device_d *dev, struct driver_d *drv) +{ + const struct of_device_id *id; + + id = of_match_node(drv->of_compatible, dev->device_node); + if (!id) + return 1; + + dev->of_id_entry = id; + + return 0; } EXPORT_SYMBOL(of_match); diff --git a/include/driver.h b/include/driver.h index 716f792af..7d5f65e79 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 4dcf37e14..3f64667b6 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