diff options
author | Thierry Reding <thierry.reding@avionic-design.de> | 2012-06-14 09:12:35 +0200 |
---|---|---|
committer | Rob Herring <rob.herring@calxeda.com> | 2012-06-14 20:29:40 -0500 |
commit | 107a84e61cdd3406c842a0e4be7efffd3a05dba6 (patch) | |
tree | ac901b609ccb98aab22b28f51a1d2639ffd60545 | |
parent | d44115f28edba06d0844ab4b79682f48500020f6 (diff) | |
download | linux-3.10-107a84e61cdd3406c842a0e4be7efffd3a05dba6.tar.gz linux-3.10-107a84e61cdd3406c842a0e4be7efffd3a05dba6.tar.bz2 linux-3.10-107a84e61cdd3406c842a0e4be7efffd3a05dba6.zip |
of: match by compatible property first
When matching devices against an OF device ID table, the first string of
the compatible property that is listed in the table should match,
regardless of its position in the table.
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: devicetree-discuss@lists.ozlabs.org
Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
-rw-r--r-- | drivers/of/base.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index d9bfd49b193..eada3f4ef80 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -511,6 +511,22 @@ out: } EXPORT_SYMBOL(of_find_node_with_property); +static const struct of_device_id *of_match_compat(const struct of_device_id *matches, + const char *compat) +{ + while (matches->name[0] || matches->type[0] || matches->compatible[0]) { + const char *cp = matches->compatible; + int len = strlen(cp); + + if (len > 0 && of_compat_cmp(compat, cp, len) == 0) + return matches; + + matches++; + } + + return NULL; +} + /** * of_match_node - Tell if an device_node has a matching of_match structure * @matches: array of of device match structures to search in @@ -521,9 +537,18 @@ EXPORT_SYMBOL(of_find_node_with_property); const struct of_device_id *of_match_node(const struct of_device_id *matches, const struct device_node *node) { + struct property *prop; + const char *cp; + if (!matches) return NULL; + of_property_for_each_string(node, "compatible", prop, cp) { + const struct of_device_id *match = of_match_compat(matches, cp); + if (match) + return match; + } + while (matches->name[0] || matches->type[0] || matches->compatible[0]) { int match = 1; if (matches->name[0]) @@ -532,10 +557,7 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches, if (matches->type[0]) match &= node->type && !strcmp(matches->type, node->type); - if (matches->compatible[0]) - match &= of_device_is_compatible(node, - matches->compatible); - if (match) + if (match && !matches->compatible[0]) return matches; matches++; } |