How to use GPIO as Interrupt in imx7d

I want to use GPIO as interrupt, could someone please help to point the code?

Dear @neeraj.verma,

Thank you for contacting Toradex Support!

The following articles give a nice overview of accessing GPIO pins in Colibri iMX7:

Hope this helps.

Thanks and Regards, Janani.

Thanks for the details… Do I have to modify device tree to add PIN name/number? if yes, please help me to find file and code, because I followed steps given in example but I don’t see poll() receiving any INT whereas actually I can see pin is setting HIGH at every milli second.

Pin name/number conversion listed here - Basic GPIO usage - Iris Carrier Board - Colibri iMX7
and here - Basic GPIO usage - Iris Carrier Board - Colibri iMX7

At device tree you should configure selected pin as a gpio. There is no way to assign GPIO name/number to selected pin at device tree.

Thanks for the reply… I have the board vs linux mapping.
Could you please point me on how and where to add GPIO as INT entry in device tree?
I want interrupt for SPI interface, can I add below in SPI group like:
it’s for pin GPIO1.IO[1] = linux pin 1 (SODIMM_45)

interrupt-parent = <&group1>;
interrupts = <1 IRQ_TYPE_EDGE_RISING>;
gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;

SODIMM_45 has no relation to SPI, so could you explain how are you going to use it as “interrupt for SPI interface” ?
And when you are talking about code - are you going to write your own device driver or use interrupts from user level?

Hi Alex,
sorry for confusion here…
I mean to say that I have SPI device which generates one INT (based on some functionality) which I want to connect to iMX7d evl board.
so once I get LOW to HIGH INT, I go ahead and read SPI device.

So you need to configure selected pin as a GPIO at device tree and then poll corresponding /sys/class/gpio/gpio file.
There is one to one relation between pin and gpio so you can not alter it.

Hi Alex, Thanks for your reply. How to configure selected pin as a GPIO at device tree ? any example or sample code for my boards… please point me.

Hi Alex,
I attaching dmesg, device tree & c code snipt for your reference.
Trying to get LOW to HIGH interrupt from SODIMM_43 (GPIO1.IO[0]) but no luck.
Please help me on this.

hi @neeraj.verma

Could you share your changes ( git diff) in text format and not in screenshots?

Regarding the interrupt on rising ede of SODIMM_43, you should have a look here.

Thanks and best regards,

Hi Jaski,
Please find details of device tree & C code changes:

uint8_t value = 0; int fd = 0; struct pollfd poll_gpio; = POLLPRI;
 printf("%s() called thread ID: %d\n", __FUNCTION__, mydata);
 fd = open("/sys/class/gpio/export", O_WRONLY);
 write(fd, "1", 1); 
 //config as input
 fd = open("/sys/class/gpio/gpio0/direction", O_WRONLY);
 write(fd, "in", 2); 
 //config as int
 fd = open("/sys/class/gpio/gpio0/edge", O_WRONLY);
 write(fd, "rising", 6); 
 //read value
 fd = open("/sys/class/gpio/gpio0/value", O_RDONLY);
 poll_gpio.fd = fd; 
 printf("GPIO1 is set to receive INT\n");
 poll(&poll_gpio, 1, -1);
 read(fd, &value, 1); 
 printf("Got GPIO1 INT\n");
 do {
     poll(&poll_gpio, 1, -1);
     if((poll_gpio.revents & POLLPRI) == POLLPRI) {
         lseek(fd, 0, SEEK_SET);
         read(fd, &value, 1); 
         printf("INT generated: %d", value);
//////////////// device tree aliases { rtc0 = &rtc; rtc1 = &snvs_rtc; gpio0 = &gpio0; };

 pinctrl@80018000 {
     compatible = "fsl,imx28-pinctrl", "simple-bus";
     reg = <0x80018000 2000>;
     cd-gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
     status = "okay";
     gpio0: gpio@0 {
         compatible = "fsl,imx28-gpio";
         interrupts = <127>;
         status = "okay";

Could you please help me on this?

Hi @jaski.tx @alex.tx
Could you please help I need to implement Gyro INT?

Hi, how did you test the interrupt?
Can you see the change of the value of the Pin if you change the voltage level on the carrier board?

Hi @jaski.tx
I have connected Gyro sensor INT pin to oscilloscope and I can see pin goes high (3V for 50 ns). but don’t see my poll function call.

Could you please start with pins already configured as GPIO?
For example PIN 113 (gpio2.IO[1])? It has a Linux N 33

Hi Alex,
I connected pin 113 (connector X3 B14) to INT pin from sensor and hooked oscilloscope, modified my user code as (linux pin num 33) but still no luck.
Please find attached (pic of the pin connected, INT generation, code).

Waiting for your next advice.

Thank text

Hi @neeraj.verma

Could you check the output of cat /proc/interrupts | grep gpiolib if the second number is increasing?

What is the output of cat /sys/class/gpio/gpio33/edge?

Best regards,