LS1021A External interrupt

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

LS1021A External interrupt

2,299 Views
rahulr
Contributor II

I am trying to write an interrupt handler for LS1021A external interrupt IRQ5 using the QorIQ SDK 2.0. I have created a kernel module to handle the interrupt but the reset_irq function is always returning -22 (Invalid argument).

This is my code:

static unsigned int irqNum;

static irq_handler_t irq5_handler(unsigned int irq, void *dev_id, struct pt_regs *regs){
     printk(KERN_INFO "Interrupt received\n");
     return (irq_handler_t) IRQ_HANDLED;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

static int __init irq_init(void){
     int result = 0;
     irqNum = 201;  // IRQ number of IRQ5
     result = request_irq(irqNum, (irq_handler_t) irq5_handler, IRQF_TRIGGER_RISING, "irq5_handler", NULL);
     printk(KERN_INFO "request_irq result is %d\n", result);
     return result;
}

module_init(irq_init);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Is creating a kernel module the right approach to handle the interrupt?

Do I need to perform any actions like initializing the pin before requesting the interrupt (request_irq)?

It would be helpful if someone can point me to a document or a sample program that explains the usage of IRQ(0-5) from Linux; specifically for the LS1021A processor.

Labels (1)
0 Kudos
5 Replies

1,643 Views
Pavel
NXP Employee
NXP Employee

The LS1021a IRQ5 is GPIO1_25. NXP SDK 2.0 supports SYSFS possibility. Usually this possibility is used for interrupt on GPIO pins.

See attached file.


Have a great day,
Pavel Chubakov

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

1,643 Views
erdani80
Contributor III

Then if you want to use the irq from the gpio you have to use gpio_to_irq.

irqNum = gpio_to_irq(57); // IRQ number of gpio 1_25

You have add to the includes:

#include <linux/gpio.h>

The gpio number is bank*32 + offset.

I tested this mechanism with a LS1021A and an external device interrupting in a GPIO line (GPIO4_23).

1,643 Views
rahulr
Contributor II

I got -22 as the response for gpio_to_irq(); for all the GPIOs I tried. Pavel's document will be very helpful in debugging this issue. Unfortunately I wont be able to use the GPIO interrupt because on the final design, we are using IRQ0 pin for interrupt as far as I know this is a dedicated interrupt pin (no GPIO function). I was using IRQ5 only because it's easier to access using the LS1021A-TWR tower connector.

0 Kudos

1,643 Views
erdani80
Contributor III

The first 32 interrupt channels are for the core and are not exposed into linux.

In order to find the correspondence between the IRQ ID in the tables and the one used in linux you have to calculate the following:

Linux IRQ = Interrupt ID - 32

That is your Irq number is 169. You are trying to request the PEX2 link-up IRQ.

0 Kudos

1,643 Views
rahulr
Contributor II

Thanks Daniel!

I am getting the same error (-22) after correcting the IRQ number (irqNumber = 169;). Do I need to add something to the device tree before trying to request the IRQ?

I see that some of the IRQ pins has alternate functions like GPIO. Is it required to first set the pin to IRQ mode? I assumed this is done automatically by the request_irq function.

EDIT:

I added some printk statements to the kernel source code and found that the code is failing at the following statement in kernek/irq/manage.c.

desc = irq_to_desc(irq);
if (!desc)
 return -EINVAL;‍‍‍‍‍‍
0 Kudos