summaryrefslogtreecommitdiffstats
path: root/drivers/of/device.c
blob: 7e9dc95dd3bbbf4c18d86ce53ff7145dd07b3517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: GPL-2.0
#include <common.h>
#include <of.h>
#include <of_device.h>

/**
 * of_match_device - Tell if a struct device matches an of_device_id list
 * @ids: array of of device match structures to search in
 * @dev: the of device structure to match against
 *
 * Used by a driver to check whether an platform_device present in the
 * system is in its list of supported devices.
 */
const struct of_device_id *of_match_device(const struct of_device_id *matches,
					   const struct device_d *dev)
{
	if ((!matches) || (!dev->device_node))
		return NULL;

	return of_match_node(matches, dev->device_node);
}
EXPORT_SYMBOL(of_match_device);

const void *of_device_get_match_data(const struct device_d *dev)
{
	const struct of_device_id *match;

	match = of_match_device(dev->driver->of_compatible, dev);
	if (!match)
		return NULL;

	return match->data;
}
EXPORT_SYMBOL(of_device_get_match_data);

const char *of_device_get_match_compatible(const struct device_d *dev)
{
	const struct of_device_id *match;

	match = of_match_device(dev->driver->of_compatible, dev);
	if (!match)
		return NULL;

	return match->compatible;
}
EXPORT_SYMBOL(of_device_get_match_compatible);