HOW to configure a GPIO as an interrupt and change the configuration of it using the kernal API's

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

HOW to configure a GPIO as an interrupt and change the configuration of it using the kernal API's

2,846 Views
gurucharan
Contributor I

Hi All,

I am using i.mx6q-sabresd board.

I want to configure the GPIO(1,2) i.e SABRESD_USR_DEF_RED_LED as in input pin and I want to configure it as an interrupt which should be detected on ACTIVE high or LOW.

The following are the function calls which I used so far.

gpio_free(SABRESD_USR_DEF_RED_LED);

gpio_request(SABRESD_USR_DEF_RED_LED,"init");

gpio_direction_input(SABRESD_USR_DEF_RED_LED);

reques_irq(gpio_to_irq(SABRESD_USR_DEF_RED_LED),interrupt_handler,IRQF_SHARED|IRQF_TRIGGER_LOW,"init",device);

With these settings I am not getting the expected interrupt.I hace connecetd the correct GPIO pin. and I am reading the value of '0' for gpio_get_value(SABRESD_USR_DEF_RED_LED) and gpio_direction_input(SABRESD_USR_DEF_RED_LED).

Please advice

Thanks in advance

0 Kudos
6 Replies

1,244 Views
jimmychan
NXP TechSupport
NXP TechSupport
0 Kudos

1,244 Views
gurucharan
Contributor I

I Have followed the link and tried the configuration but no results.Could you please advice more on this.

0 Kudos

1,244 Views
rickchu
Contributor IV

Hi Gurucharan,

The process seems no problem in your source codes; can you add error check with request_irq()? Such like below.

interr = 0;

err = reques_irq(gpio_to_irq(SABRESD_USR_DEF_RED_LED),interrupt_handler,IRQF_SHARED|IRQF_TRIGGER_LOW,"init",device);

if (err) {

dev_err(&pdev->dev, "failed to allocate irq.\n");

}

And in original board-mx6q_sabresd.c, the GPIO(1, 2) has assigned to SABRESD_BT_RESET too, so you may have error with gpio_request() if not mark it.

Hope this help you.

Rick

0 Kudos

1,244 Views
gurucharan
Contributor I

Hi Rick,

Thanks for the reply.

I have verified the request_irq() and gpio_request() return values both are giving success messages only.

It seems the host is getting the interrupt but it keeps on in the interrupt routine.So I assume it might be because of the mask and unmask of the interrupt issue.

Can you please let me know,how to mask the interrupt and unmask the interrupt using kernal API's.

Currently I am using raw_writel() ffunction call to set the ICR1 register bit 2 as active high  and IMR register bit 2 as mask or unmask.Is that correct procedure?

0 Kudos

1,244 Views
rickchu
Contributor IV

Hi Gurucharan,

In your device set interrupt type as "IRQF_TRIGGER_LOW", the behavior will similar as GPIO keys.

I suggest you can reference with /drivers/input/keyboard/gpio_keys.c, all answer will be found there.

Rick

0 Kudos

1,244 Views
gurucharan
Contributor I

Hi Rick,

I am able to get the interrupt on HIGH but the interrupt is keep on rotating in the interrupt routine.

So could you please let me know what can cause me to come out of the routine.I have tried with disable_irq(gpio_to_irq(gpio->pin)); but it stop only in the routine and completed halted.

0 Kudos