Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I am working with a system that uses an I/O expander accesed through SPI. The SPI can be configured to trigger an IRQ when any device conected to the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2010
    Location
    Madrid
    Posts
    32

    Shared interrupt triggered without control


    Hi,
    I am working with a system that uses an I/O expander accesed through SPI. The SPI can be configured to trigger an IRQ when any device conected to the bus (in my case the I/O expander) generates an interrupt.

    My idea is to program a small module (I am using kernel 2.6.30) to catch that interrupt, so I need to register an interrupt handler to share IRQ 10.
    (In /proc/interrupts I can see that no one is using that IRQ line)


    Code:
    #include <linux/module.h>
    #include <linux/init.h>
    #include <linux/interrupt.h>
    
    #define SHARED_IRQ  10
    
    static int irq = SHARED_IRQ;
    static int dev_id;
    
    module_param(irq, int , S_IRUGO);
    
    static irqreturn_t irq_handler(int irq, void *dev_id){
    
        pr_info("IRQ %d detected\n", irq);  // for now just inform
        return IRQ_HANDLED;
    }
    
    static int __init m_init(void){
    
        if(request_irq(irq, irq_handler, IRQF_SHARED, "gpio_irq", &dev_id)){
            pr_info("Failed to reserve irq %d\n", irq);
            return -1;
        }
        pr_info("Successfully loaded ISR handler\n");
        return 0;
    }
    
    static void __exit m_exit(void){
    
        synchronize_irq(irq);
        free_irq(irq, &dev_id);
        pr_info("Successfully unloading gpio_irq\n");
    }
    
    module_init(m_init);
    module_exit(m_exit);
    
    MODULE_AUTHOR("Alf");
    MODULE_DESCRIPTION("GPIO INTERRUPT");
    MODULE_LICENSE("GPL v2");
    Also, in system BIOS setup I have reserved IRQ line 10 in order to let ISA (and not plug-n-play) use it.

    The problem is that when I insmod the module I see in the log that the irq_handler is constinuosly called, no matter what IRQ I use and even if I disable the SPI.
    Besides that, /proc/interrupts does not show any increase in the number of interrupts (it shows 0 if you use IRQ 10). Why my module triggers the interrupt handler if no interrupt is happening?

    Any idea about what I am missing?

    Thanks

    EDIT: if I don't share the IRQ (IRQF_DISABLED) it is not triggered in that uncotrolled way
    Last edited by occam25; 12-09-2013 at 04:54 PM.

  2. #2
    Just Joined!
    Join Date
    Dec 2013
    Posts
    6
    Quote Originally Posted by occam25 View Post
    The problem is that when I insmod the module I see in the log that the irq_handler is constinuosly called, no matter what IRQ I use and even if I disable the SPI.
    While I am not experienced in Linux driver writing, don't you have to reset your interrupt in the handling routine?

  3. #3
    Just Joined!
    Join Date
    May 2010
    Location
    Madrid
    Posts
    32
    Quote Originally Posted by berndbausch View Post
    While I am not experienced in Linux driver writing, don't you have to reset your interrupt in the handling routine?
    I return IRQ_HANDLED and I think that it is the kernel who acks the IRQ. Probably I would have to reset the I/O expander interrupt, but the issue is that this happen even when I share a known IRQ. For example, if I share the IRQ that eth0 is using. In that case, I return IRQ_NONE because I am just observing and it is up to other driver and kernel to handle the interrupts. Even then I see the log full of messages regarding to the call of my handler and /proc/interrupts shows no interrupt at all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •