aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorThierry Reding <thierry.reding@avionic-design.de>2012-06-14 03:12:35 -0400
committerRob Herring <rob.herring@calxeda.com>2012-06-14 21:29:40 -0400
commit107a84e61cdd3406c842a0e4be7efffd3a05dba6 (patch)
treeac901b609ccb98aab22b28f51a1d2639ffd60545 /drivers/of
parentd44115f28edba06d0844ab4b79682f48500020f6 (diff)
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>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c30
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:
511} 511}
512EXPORT_SYMBOL(of_find_node_with_property); 512EXPORT_SYMBOL(of_find_node_with_property);
513 513
514static const struct of_device_id *of_match_compat(const struct of_device_id *matches,
515 const char *compat)
516{
517 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
518 const char *cp = matches->compatible;
519 int len = strlen(cp);
520
521 if (len > 0 && of_compat_cmp(compat, cp, len) == 0)
522 return matches;
523
524 matches++;
525 }
526
527 return NULL;
528}
529
514/** 530/**
515 * of_match_node - Tell if an device_node has a matching of_match structure 531 * of_match_node - Tell if an device_node has a matching of_match structure
516 * @matches: array of of device match structures to search in 532 * @matches: array of of device match structures to search in
@@ -521,9 +537,18 @@ EXPORT_SYMBOL(of_find_node_with_property);
521const struct of_device_id *of_match_node(const struct of_device_id *matches, 537const struct of_device_id *of_match_node(const struct of_device_id *matches,
522 const struct device_node *node) 538 const struct device_node *node)
523{ 539{
540 struct property *prop;
541 const char *cp;
542
524 if (!matches) 543 if (!matches)
525 return NULL; 544 return NULL;
526 545
546 of_property_for_each_string(node, "compatible", prop, cp) {
547 const struct of_device_id *match = of_match_compat(matches, cp);
548 if (match)
549 return match;
550 }
551
527 while (matches->name[0] || matches->type[0] || matches->compatible[0]) { 552 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
528 int match = 1; 553 int match = 1;
529 if (matches->name[0]) 554 if (matches->name[0])
@@ -532,10 +557,7 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
532 if (matches->type[0]) 557 if (matches->type[0])
533 match &= node->type 558 match &= node->type
534 && !strcmp(matches->type, node->type); 559 && !strcmp(matches->type, node->type);
535 if (matches->compatible[0]) 560 if (match && !matches->compatible[0])
536 match &= of_device_is_compatible(node,
537 matches->compatible);
538 if (match)
539 return matches; 561 return matches;
540 matches++; 562 matches++;
541 } 563 }