我可以在不创建平台设备的情况下查询设备树项目吗



我正在编写一个内核模块,旨在对ARM+FPGA SOC系统的设备驱动程序内核模块进行功能测试。我的方法包括通过查询设备树来查找设备驱动程序正在使用的中断。在设备驱动程序本身中,我使用platform_driver_register注册平台驱动程序,在.probe函数中,我收到一个包含device指针的platform_device*指针。有了这个,我可以调用of_match_deviceirq_of_parse_and_map,检索irq号码。

我不想注册第二个平台驱动程序,只是为了在测试模块中以这种方式查询设备树。有没有其他方法可以查询设备树(也许更直接,也许按名称?)

这就是我迄今为止所发现的,而且它似乎有效。of_find_compatible_node做我想做的事。一旦我有了device_node*,我就可以调用irq_of_parse_and_map(因为of_irq_get_byname似乎不适合我编译)。我可以像下面这样使用它:

#include <linux/of.h>
#include <linux/of_irq.h>
....
int get_dut_irq(char* dev_compatible_name)
{
    struct device_node* dev_node;
    int irq = -1;
    dev_node = of_find_compatible_node(NULL, NULL, dev_compatible_name);
    if (!dev_node)
        return -1;
    irq = irq_of_parse_and_map(dev_node, 0);
    of_node_put(dev_node);
    return irq;
}

最新更新