aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-10-30 11:49:09 -0400
committerGrant Likely <grant.likely@secretlab.ca>2011-01-01 15:03:25 -0500
commita4f740cf33f7f6c164bbde3c0cdbcc77b0c4997c (patch)
tree62d061939000c65d91cf760a51509d388270f4c9 /drivers/of
parent73930a85cf38d72851305fcf640c07b4c13aa405 (diff)
of/flattree: Add of_flat_dt_match() helper function
This patch adds of_flat_dt_match() which tests a node for compatibility with a list of values and converts the relevant powerpc platform code to use it. This approach simplifies the board support code a bit. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Reviewed-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/fdt.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 8a90ee42071a..c787c3d95c60 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -78,19 +78,23 @@ void *of_fdt_get_property(struct boot_param_header *blob,
78 * @blob: A device tree blob 78 * @blob: A device tree blob
79 * @node: node to test 79 * @node: node to test
80 * @compat: compatible string to compare with compatible list. 80 * @compat: compatible string to compare with compatible list.
81 *
82 * On match, returns a non-zero value with smaller values returned for more
83 * specific compatible values.
81 */ 84 */
82int of_fdt_is_compatible(struct boot_param_header *blob, 85int of_fdt_is_compatible(struct boot_param_header *blob,
83 unsigned long node, const char *compat) 86 unsigned long node, const char *compat)
84{ 87{
85 const char *cp; 88 const char *cp;
86 unsigned long cplen, l; 89 unsigned long cplen, l, score = 0;
87 90
88 cp = of_fdt_get_property(blob, node, "compatible", &cplen); 91 cp = of_fdt_get_property(blob, node, "compatible", &cplen);
89 if (cp == NULL) 92 if (cp == NULL)
90 return 0; 93 return 0;
91 while (cplen > 0) { 94 while (cplen > 0) {
95 score++;
92 if (of_compat_cmp(cp, compat, strlen(compat)) == 0) 96 if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
93 return 1; 97 return score;
94 l = strlen(cp) + 1; 98 l = strlen(cp) + 1;
95 cp += l; 99 cp += l;
96 cplen -= l; 100 cplen -= l;
@@ -99,6 +103,27 @@ int of_fdt_is_compatible(struct boot_param_header *blob,
99 return 0; 103 return 0;
100} 104}
101 105
106/**
107 * of_fdt_match - Return true if node matches a list of compatible values
108 */
109int of_fdt_match(struct boot_param_header *blob, unsigned long node,
110 const char **compat)
111{
112 unsigned int tmp, score = 0;
113
114 if (!compat)
115 return 0;
116
117 while (*compat) {
118 tmp = of_fdt_is_compatible(blob, node, *compat);
119 if (tmp && (score == 0 || (tmp < score)))
120 score = tmp;
121 compat++;
122 }
123
124 return score;
125}
126
102static void *unflatten_dt_alloc(unsigned long *mem, unsigned long size, 127static void *unflatten_dt_alloc(unsigned long *mem, unsigned long size,
103 unsigned long align) 128 unsigned long align)
104{ 129{
@@ -511,6 +536,14 @@ int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
511 return of_fdt_is_compatible(initial_boot_params, node, compat); 536 return of_fdt_is_compatible(initial_boot_params, node, compat);
512} 537}
513 538
539/**
540 * of_flat_dt_match - Return true if node matches a list of compatible values
541 */
542int __init of_flat_dt_match(unsigned long node, const char **compat)
543{
544 return of_fdt_match(initial_boot_params, node, compat);
545}
546
514#ifdef CONFIG_BLK_DEV_INITRD 547#ifdef CONFIG_BLK_DEV_INITRD
515/** 548/**
516 * early_init_dt_check_for_initrd - Decode initrd location from flat tree 549 * early_init_dt_check_for_initrd - Decode initrd location from flat tree