9
0
Fork 0

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 <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2013-05-19 08:53:47 +02:00
parent 580a508945
commit 0cb87c4d1e
3 changed files with 31 additions and 13 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -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