Using DTS file to setup IRQ

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using DTS file to setup IRQ

9,053 Views
yensid
Contributor III

Hi,

We have our own board designed after the P1010RDB and I am trying to setup IRQ2 through the DTS file.  I only have a little experiance with the device tree and would like to setup the IRQ the recommended way. This is the first project I have worked on with a newer kernel using a device tree.

Currently I have the IRQ setup this way (I understand this is not recommeneded & I remove this before tyring the DTS code below):

  virq = irq_create_mapping(NULL, 0x02);

  printk(KERN_INFO"hello_IRQHandler: ISR Setup VIRQ: %d \n", virq); 

  if (0 > (error=request_irq(virq, (int)&hello_IRQHandler, IRQF_SHARED, gDrvrName, "hello"))) {

    printk(KERN_WARNING"hello_IRQHandler: Init: Unable to allocate IRQ error = %dd\n\n", error);

    return -1;

}

This is my unsuccessful attempt at using the DTS file to setup the IRQ

     DTS file code snippet (This is added under board_soc)

hello {
compatible = "fsl,hello";
interrupts = <2 3>;
interrupt-parent = <&mpic>;
};

Code to setup the IRQ:

struct device_node * np = NULL;

.....

np = of_find_compatible_node(NULL,NULL,"hello");

  if (np == NULL)

    {

    printk("Error node not found\n");

    }

  virq = irq_of_parse_and_map(np,0);

   

  printk(KERN_INFO"hello_IRQHandler: ISR Setup VIRQ: %d \n" , virq); 

  if (0 > (error=request_irq(virq, (int)&hello_IRQHandler, IRQF_SHARED, gDrvrName, "hello"))) {

      printk(KERN_WARNING"hello_IRQHandler: Init: Unable to allocate IRQ error = %dd\n\n", error);

    return -1;

  }

When the code to use node from the dts file runs, request_irq returns -22.  If you have any ideas on this or info on how to debug it would be greatly appreciated.

Thanks

0 Kudos
6 Replies

3,072 Views
scottwood
NXP Employee
NXP Employee

Your node has a compatible of "fsl,hello", but your code is looking for a node with a compatible of "hello".  Are you seeing the "Error node not found" print?

Note that you should not use the "fsl," vendor prefix on things that aren't Freescale components.

What is the virq value printed?  If it's zero, that means that irq_of_parse_and_map() failed.

Why are you casting the interrupt handler to int?

0 Kudos

3,072 Views
yensid
Contributor III

Hi Scott,

Thanks for your and Yiping's reply. I have gotten the driver to work and access IRQ2. I hope what I have is correct.  I'm posting answers to your questions as well as my updated code below.

Thanks!

Scott Wood wrote:

Your node has a compatible of "fsl,hello", but your code is looking for a node with a compatible of "hello".  Are you seeing the "Error node not found" print?

I was not seeing the error message despite this being incorrect.  Thanks for the note about the use of fsl, that was helpful.  I changed it to hello, however it still did not work.  I ended up having to change of_find_compatible_node(NULL,NULL,"hello"); to of_find_node_by_name(NULL,"hello"); for the node to be found.

Scott Wood wrote:

What is the virq value printed?  If it's zero, that means that irq_of_parse_and_map() failed.

The value of virq was zero until the change above, and dts change below.

Scott Wood wrote:

Why are you casting the interrupt handler to int?

This was carried over, accidently, from the xbmd driver that we are using for Xilinx hardware.  I missed that and have changed the interrupt handler to "irqreturn_t" which I have used in the past.  I'm really not sure why the xbmd driver sets the interrupt handler to a static int fuction rather than irqreturn_t.

Update code:

DTS File:

I modified and moved this to pq3-mpic.dtsi.  Note that IRQ2 is not a GPIO line.

I found these website helpful:

Device Tree Usage - FDTWiki

A Tutorial on the Device Tree (Zynq) -- Part I | xillybus.com

  hello@1,0{

  compatible = "hello";

  #address-cells = <1>;

  #size-cells = <0>;

  reg = <1 0 0x1000>;

  interrupts = <2 0 0 0>;

  };

Driver:

np = of_find_node_by_name(NULL,"hello");

  if (np == NULL)

    {

    printk("Error node not found\n");

    }

  printk("Node np = 0x%0x\n",np);

  virq = irq_of_parse_and_map(np,0);

  

  printk(KERN_INFO"hello_IRQHandler: ISR Setup VIRQ: %d \n" , virq);

  if (0 > (error=request_irq(virq, &hello_IRQHandler, IRQF_SHARED, gDrvrName, "hello_label"))) {

      printk(KERN_WARNING"hello_IRQHandler: Init: Unable to allocate IRQ error = %dd\n\n", error);

    return -1;

  }

0 Kudos

3,072 Views
rans
Senior Contributor I

Hi yensid,

What is gDrvrName ?

What is the prupose of the "reg" entry in your hello node ? Why does it have 3 parameters inside (I am familiar with only 2) ?

  reg = <1 0 0x1000>;

It return compile warning: "Warning (reg_format): "reg" property in /hello@1,0 has invalid length (12 bytes) (#address-cells == 1, #size-cells == 1)"

Regards,

Ran

0 Kudos

3,072 Views
yensid
Contributor III

Hi Ran,

If you still need this info here you go:

gDrvrName is an char array (string) which is used as the name of the driver in the /proc directory

If my memory serves me the extra value in the reg entry is for the chip select of the device on the bus.  See the second link in my prior post, the second section under memory mapped devices.  The reg entry has to be setup for your hardware.

0 Kudos

3,072 Views
yipingwang
NXP TechSupport
NXP TechSupport

In dts, you need to define a device and the interrupt connecting to it, please refer to the following binging for gpio controller.

gpio: gpio-controller@f000 {

#gpio-cells = <2>;

compatible = "fsl,mpc8572-gpio";

reg = <0xf000 0x100>;

interrupts = <47 0x2>;

interrupt-parent = <&mpic>;

gpio-controller;

};


The IRQ number in the dts is local to the MPIC and it should be remapped differently by Linux, and irq_of_parse_and_map followed by request_irq should be correct. You could refer to drivers/gpio/gpio-mpc8xxx.c.


Have a great day,
Yiping Wang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

3,072 Views
soilfish
Contributor I

  HI my board reset button is connected to IRQ1 the DTS file how to make ??? can you help me for it or some information!!! thanks

0 Kudos