How to request GPIOH_5 as INT mode

Hi, TomasFilip

You can following below steps to request GPIOH_5 as INT


1.Add config for GPIOH_5 in dts file

example {
  compatible = "amlogic, example";
  dev_name = "example";
  status = "okay";
  interrupts = <0 66 1>;
  interrupt_pin = <&gpio GPIOH_5 GPIO_ACTIVE_HIGH>;
  interrupt-names = "example";

2.Request GPIOH_5 as INT mode in driver file

Include the header file

#include <linux/interrupt.h>
#include <linux/irq.h>
#include <asm/irq.h>
#include <linux/of_irq.h>
#include <linux/amlogic/aml_gpio_consumer.h>
#include <linux/amlogic/gpio-amlogic.h>
#include <linux/amlogic/iomap.h>

Request GPIOH_5 as INT mode

struct gpio_desc *desc;
int interrupt_pin;
int irq_num;
int ret;
uint flag;

desc = of_get_named_gpiod_flags(node, "interrupt_pin", 0, NULL);
interrupt_pin = desc_to_gpio(desc);
irq_num = irq_of_parse_and_map(node, 0);
if (interrupt_pin) {
       ret = gpio_request(interrupt_pin, "example");
      if (ret)
         printk("interrupt_pin request failed(%d)\n", ret);
      ret = gpio_set_pullup(interrupt_pin, 1);
      if (ret)
         printk("interrupt_pin disable pullup failed(%d)\n",ret);
      ret = gpio_direction_input(interrupt_pin);
      if (ret)
         printk("set interrupt_pin input failed(%d)\n", ret);
      if (irq_num) {
                 flag = AML_GPIO_IRQ(irq_num, FILTER_NUM7, GPIO_IRQ_LOW);
       } else {
                 printk("example : unsupported irq number - %d\n", irq_num);
                 return -1;
       ret = gpio_for_irq(interrupt_pin, flag);
       if (ret)
           printk("gpio to irq failed(%d)\n", ret);
       if (request_irq(irq_num, &example_isr, IRQF_SHARED , "example", NULL))
            printk("Failed to request GPIOH_5 irq.\n");

Define interrupt function

static irqreturn_t example_isr(int irq ,  void *data)
   return IRQ_HANDLED;
1 Like

@Terry Consider to build GPIOH_5 as INT mode as default in the future build.