diff options
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r-- | drivers/of/base.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 9377f3bc410a..b306fef1ac41 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -273,3 +273,61 @@ struct device_node *of_find_compatible_node(struct device_node *from, | |||
273 | return np; | 273 | return np; |
274 | } | 274 | } |
275 | EXPORT_SYMBOL(of_find_compatible_node); | 275 | EXPORT_SYMBOL(of_find_compatible_node); |
276 | |||
277 | /** | ||
278 | * of_match_node - Tell if an device_node has a matching of_match structure | ||
279 | * @matches: array of of device match structures to search in | ||
280 | * @node: the of device structure to match against | ||
281 | * | ||
282 | * Low level utility function used by device matching. | ||
283 | */ | ||
284 | const struct of_device_id *of_match_node(const struct of_device_id *matches, | ||
285 | const struct device_node *node) | ||
286 | { | ||
287 | while (matches->name[0] || matches->type[0] || matches->compatible[0]) { | ||
288 | int match = 1; | ||
289 | if (matches->name[0]) | ||
290 | match &= node->name | ||
291 | && !strcmp(matches->name, node->name); | ||
292 | if (matches->type[0]) | ||
293 | match &= node->type | ||
294 | && !strcmp(matches->type, node->type); | ||
295 | if (matches->compatible[0]) | ||
296 | match &= of_device_is_compatible(node, | ||
297 | matches->compatible); | ||
298 | if (match) | ||
299 | return matches; | ||
300 | matches++; | ||
301 | } | ||
302 | return NULL; | ||
303 | } | ||
304 | EXPORT_SYMBOL(of_match_node); | ||
305 | |||
306 | /** | ||
307 | * of_find_matching_node - Find a node based on an of_device_id match | ||
308 | * table. | ||
309 | * @from: The node to start searching from or NULL, the node | ||
310 | * you pass will not be searched, only the next one | ||
311 | * will; typically, you pass what the previous call | ||
312 | * returned. of_node_put() will be called on it | ||
313 | * @matches: array of of device match structures to search in | ||
314 | * | ||
315 | * Returns a node pointer with refcount incremented, use | ||
316 | * of_node_put() on it when done. | ||
317 | */ | ||
318 | struct device_node *of_find_matching_node(struct device_node *from, | ||
319 | const struct of_device_id *matches) | ||
320 | { | ||
321 | struct device_node *np; | ||
322 | |||
323 | read_lock(&devtree_lock); | ||
324 | np = from ? from->allnext : allnodes; | ||
325 | for (; np; np = np->allnext) { | ||
326 | if (of_match_node(matches, np) && of_node_get(np)) | ||
327 | break; | ||
328 | } | ||
329 | of_node_put(from); | ||
330 | read_unlock(&devtree_lock); | ||
331 | return np; | ||
332 | } | ||
333 | EXPORT_SYMBOL(of_find_matching_node); | ||