3

I am writing a kernel module intended to functionally test a device driver kernel module for an ARM+FPGA SOC system. My approach involves finding which interrupts the device driver is using by querying the device tree. In the device driver itself, I register a platform driver using platform_driver_register and in the .probe function I am passed a platform_device* pointer that contains the device pointer. With this I can call of_match_device and irq_of_parse_and_map, retrieving the irq numbers.

I don't want to register a second platform driver just to query the device tree this way in the test module. Is there some other way I can query the device tree (perhaps more directly, by name perhaps?)

benf
  • 915
  • 1
  • 9
  • 28
  • Do you know which bus it is on? If so maybe you can use [subsys_dev_iter_init](http://lxr.free-electrons.com/source/drivers/base/bus.c#L1060) and subsys_dev_iter_next to iterate over the bus and get a handle on the device pointer – harmic Nov 06 '14 at 10:48
  • According to the device tree it's on the sopc bus. – benf Nov 06 '14 at 18:49
  • Check http://stackoverflow.com/a/40928373/2007944 – SD. Dec 02 '16 at 09:09

1 Answers1

3

This is what I've found so far, and it seems to work. of_find_compatible_node does what I want. Once I have the device_node*, I can call irq_of_parse_and_map (since of_irq_get_byname doesn't seem to compile for me). I can use it something like the following:

#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;
}
benf
  • 915
  • 1
  • 9
  • 28