This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

request_irq failed

Other Parts Discussed in Thread: TCA9535

Hi Pavel,

I use gpio0_6 as an interrupt source.But it is failed to request irq.

It is my code as below.

  int res,irq_num;
  irq_num=gpio_to_irq(6);

  res=request_irq(irq_num,get_state,IRQF_DISABLED,"buttons",(void *)buf);
  if(res<0)
  {
    printk("request irq failed!\n");
    return -EIO;
  }
  set_irq_type(irq_num, IRQ_TYPE_LEVEL_LOW);

Would you please give me some suggestions about how to request irq by gpio?

Thank you

BR

Bob

  • Hi Pavel,
    I printed out the value of irq_num.It's 166.
    Is it right?
    BR
    Bob
  • Hi Bob,

    bob lee said:
    I printed out the value of irq_num.It's 166.

    Yes, it is right.

    Can you check if you already use this 166 interrupt in your board? I mean you should boot up your board without irq request and do:

    root@dm814x-evm:~# cat /proc/interrupts
               CPU0
      4:          0        INTC  omap2_elm
     12:       2665        INTC  edma
     14:          0        INTC  edma_error
     16:          0        INTC  ahci
     17:          0        INTC  cppi41_dma
     18:          0        INTC  musb-hdrc.0
     20:          0        INTC  gpmc
     28:       8091        INTC  mmc0
     30:          0        INTC  omap_i2c
     37:          0        INTC  SGX ISR
     38:          0        INTC  HDMI
     40:          0        INTC  cpsw.0
     41:        296        INTC  cpsw.0
     42:          7        INTC  cpsw.0
     43:          0        INTC  cpsw.0
     44:          0        INTC  serial idle
     45:          0        INTC  serial idle
     46:          0        INTC  serial idle
     67:       3984        INTC  gp timer
     70:       1010        INTC  omap_i2c
     72:        396        INTC  serial idle, OMAP UART0
     73:          0        INTC  serial idle
     74:          0        INTC  serial idle
     75:          0        INTC  rtc0
     76:          0        INTC  rtc0
     77:       1061        INTC  mailbox-dsp, mailbox-video, mailbox-vpss
    122:          0        INTC  omap-iommu.1
    123:          0        INTC  omap-iommu.0
    191:          2        GPIO  qt602240_ts
    Err:          0
    root@dm814x-evm:~#


    As you can see, in the DM814x TI EVM, 166 is free to use, what about your side? As you can see, in the DM814x TI EVM, gpio0_31 is used as interrupt (191 -> qt602240_ts). See how this is done in the board-ti8148evm.c ti814x_tsc_init(void) function.

    Regards,
    Pavel

  • Bob,

    bob lee said:
    request_irq(irq_num,get_state,IRQF_DISABLED,"buttons",(void *)buf);

    I suspect irq_num (166) is fine, the problem should be in other arguments (get_state, "buttons"). Could you please provide more info on these?

    BR
    Pavel

  • Hi Bob,

    First make sure you have enabled the GP0[6] in pinmux, have a look at the following code which uses gp0[6], and you can use it as is
    to test and later configure irq as per your requirements.

    #include <linux/module.h>
    #include <linux/version.h>
    #include <linux/delay.h>
    #include <linux/irq.h>
    #include <linux/interrupt.h>
    #include <linux/completion.h>
    #include <mach/hardware.h>
    #include <asm/gpio.h>


    static int gpio_num;

    DECLARE_COMPLETION(work);

    static irqreturn_t handler (int irq, void * dev)
    {
    complete_all(&work);
    return IRQ_HANDLED;
    }

    int init_module()
    {
    int status;
    int irq;

    init_completion(&work);

    /* gp0[6] */
    gpio_num = 6;

    status = gpio_request(gpio_num, "gpio_test\n");
    if (status < 0) {
    printk("ERROR can not open GPIO %d\n", gpio_num);
    return status;
    }

    gpio_direction_input(gpio_num);
    gpio_export(gpio_num, true);

    if(gpio_get_value(gpio_num) == 0)
    printk("OFF. \n\tWaiting for the pin to be on..\n");
    else
    printk("ON. \n\tWaiting for the pin to be off..\n");

    irq = gpio_to_irq(gpio_num);
    status = request_irq(irq, handler, 0, "gpio_test", NULL);
    if(status < 0) {
    printk(KERN_ERR "error %d requesting GPIO IRQ %d\n", status, gpio_num);
    return status;
    }

    set_irq_type(irq, IRQ_TYPE_EDGE_RISING);

    wait_for_completion_interruptible(&work);

    printk(".. done\n");

    return 0;
    }

    void cleanup_module(void) {
    free_irq(gpio_to_irq(gpio_num), NULL);
    gpio_free(gpio_num);
    }

    MODULE_LICENSE("GPL");

    Thanks And Regards,
    Mike

  • Hi Mike ,
    I have enabled the GP0[6].It is ok by using your code to test.
    Thank you very much.
    BR
    Bob
  • Hi Pavel,

    Here is the get_state function as below.

    static irqreturn_t get_state(int irq_num,void *dev)

    {

    printk("get_state run again!\n");

    return IRQ_HANDLED;

    }

    I could request irq now and there is no error. But the function isn't to be executed when interrupt occurs.

    I don't know why.

    Another question,After requested irq successfully,how to get the value of gpio0_6?

    That is to say ,I want to know the status of gpio0_6,high level or low?

    BR

    Bob

  • Hi Bob,

    what is the GP0[6] connected to a switch/button ?
    If you are using the same code posted by mike it does 'gpio_export' which means you will find
    a entry in /sys, so to check the value do 'cat /sys/class/gpio/gpio6/value'.

    Thanks,
    --Prabhakar Lad
  • Hi Prabhakar,

    The gpio0[6] connect to the chip tca9535.We want to check the interrupts outside by GPIO0[6].

    BR

    Bob

  • Hi Prabhakar,
    Sorry for uploading the screenshot failed.
    BR
    Bob
  • Hi,

    Just to avoid dependency to testing whether GP0[6] is working or not what you can do is give some voltage to GP0[6] pin and see the value.

    Thanks,
    --Prabhakar Lad
  • Hi Prabhakar,

    It is ok now .

    Thank you very much.

    Bob

  • Hi Bob,

    I have the same issue request_irq is successful, but the interrupt is not called...
    I also used the exact example given above from TI, but I still can't get the gpio interrupt to be called.
    With sysfs entries the same gpio irq works just well ...

    How did you solve this issue ? Can you please share the solution ?

    Thank you,
    Ran

  • Sorry,I haven't solved it.

    Bob

  • I have success with request_irq, but the interrupt handler is not called...
    Maybe I need to configure the gpio differently ? (strangely, with sysfs it works)
  • This have been resolved in the below e2e thread:

    e2e.ti.com/.../1570581

    BR
    Pavel
  • Hi Pavel,

    That's Right, it was solved.
    It is related to LVCMOD in registers
    MLBP_SIG_IO_CTRL
    MLBP_DAT_IO_CTRL

    Regards,
    Ran