我找到了方法。我简要解释一下,也许它可能有用。我们可以使用的方法是device_find_child
. 该方法将指针作为第三个参数,该指针指向实现比较逻辑的函数。如果函数在使用特定设备作为第一个参数调用时返回不为零,device_find_child
则将返回该指针。
#include <linux/device.h>
#include <linux/of_platform.h>
static int custom_match_dev(struct device *dev, void *data)
{
/* this function implements the comaparison logic. Return not zero if device
pointed by dev is the device you are searching for.
*/
}
static struct device *find_dev()
{
struct device *ofdev = bus_find_device_by_name(&of_platform_bus_type,
NULL, "OF_device_name");
if (ofdev)
{
/* of device is the parent of device we are interested in */
struct device *real_dev = device_find_child(ofdev,
NULL, /* passed in the second param to custom_match_dev */
custom_match_dev);
if (real_dev)
return real_dev;
}
return NULL;
}