orange-piarmbian

Failing to request_irq() on PC0x pins


I'm trying to use pin PC3 as an interrupt, but it returns the error code -22 in the gpio_to_irq() function. In user-space i can use it normally as a GPIO, but I need it to function as an interrupt in a driver.

#define GPIO_PIN 67
#define GPIO_PIN_DESC "GPIO PC3"

static int __init mytapp_controller_proc_init(void)
{
    int ret,gpio_irq;

    uint8_t idx = 0;

    printk("mytapp_controller_proc_init 444%d\n",GPIO_PIN);

    msg = kmalloc(PROCFS_MAX_SIZE, GFP_KERNEL);
    if(!msg){
        printk(KERN_ALERT "Error: kmalloc error\n");
        return -ENOMEM;
    }

   if (gpio_request(GPIO_PIN, GPIO_PIN_DESC)) {
      printk("GPIO request failure: %s\n", GPIO_PIN_DESC);
      return -1;
   }

   if (gpio_direction_input(GPIO_PIN)) {
      printk("GPIO set direction input failure %s\n", GPIO_PIN_DESC);
      return -1;
   }
 
   if ( (gpio_irq = gpio_to_irq(GPIO_PIN)) < 0 ) {
      printk("GPIO to IRQ mapping failure %s\n", GPIO_PIN_DESC);
      return -1;
   }

    ret = request_irq(gpio_irq, sample_irq, IRQF_TRIGGER_FALLING, "flow_sensor", 0);
    if (ret < 0) {
        printk(KERN_ALERT "%s: request_irg failed with %u\n", __func__, ret);
        return -1;
    }

   return 0;
}

It shows as GPIO IN:

root@orangepione:/home/mytapp# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-223, parent: platform/1c20800.pinctrl, 1c20800.pinctrl:
 gpio-15  (                    |orangepi:red:status ) out lo 
 gpio-67  (                    |GPIO PC3            ) in  hi 
 gpio-166 (                    |cd                  ) in  lo ACTIVE LOW
 gpio-204 (                    |usb0_id_det         ) in  hi IRQ 

gpiochip1: GPIOs 352-383, parent: platform/1f02c00.pinctrl, 1f02c00.pinctrl:
 gpio-354 (                    |usb0-vbus           ) out hi 
 gpio-355 (                    |sw4                 ) in  hi IRQ ACTIVE LOW
 gpio-358 (                    |vdd-cpux            ) out lo 
 gpio-362 (                    |orangepi:green:pwr  ) out hi 

I also tryied PC0 and doesn't work too. The PA3 and works fine.

I also make a loop throught 0 to 69 and the function gpio_to_irq() only return a valid irq value from 0 to 21. The number above 21 returns -22. It looks like only works on PA pins.

Board: Orange Pi One, Armbian 23.8.0

Any ideia? Best regards


Solution

  • The Orange Pi One uses the Allwinner H3, and according to its datasheet only the PA and PG pins support EINT. You can't get interrupts from pins that don't support it, so you need to change to a pin that does.