request_irq fails with errno -22 - sama5d3 kernel 3.15.7

Discussion around products based on ARM Cortex-A5 core.

Moderator: nferre

Posts: 25
Joined: Wed Jul 30, 2014 9:17 pm

request_irq fails with errno -22 - sama5d3 kernel 3.15.7

Wed Aug 06, 2014 4:53 pm


I am trying to implement and SPI kernel driver to connect TI ADS1282 ADC to sama5d33ek.

I am using SPI1 with spidev driver, what works quite nice. I can read / write to the ADC via SPI.

No I want to start implementing my own SPI protocol driver to increase performance. Especially it should be able to react in IRQs caused by the ADCs Data Ready signal.

I tried to configure GPIO PIOB28 as GPIO and interrupt source. I can correctly see the data raeady signal, if exporting the gpio and checking its value inside the sys file system.

But if I try to configure the GPIO as interrupt source inside my test kernel module, it fails to configure the GPIO as IRQ. Reason is that the request_irq function always returns with errno -22.

I tried to add gpio_to_irq, but this does not seem to exist anymore for 3.15.7 and sama5d33ek.

Can anyone tell me what I am missing?

Below the test kernel module:

Code: Select all

 * This is a demo Linux kernel module.

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/spi/spi.h>

#include <asm/irq.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>

#include <mach/../../board.h>
#include <mach/gpio.h>
#include <mach/sama5d3.h>

 * template_init - function to insert this module into kernel space
 * This is the first of two exported functions to handle inserting this
 * code into a running kernel
 * Returns 0 if successfull, otherwise -1

#define C_GPIO_TO_HANDLE AT91_PIN_PB28	// PIOB 28 - RXD1 - auf sama5d33 nicht belegt

 * Simple IRQ handler, that just acks the IRQ for GPIO.
irqreturn_t gpio_irq_handler(int irq, void *dev_id)
    printk("[wake_on_gpio]: handled IRQ for GPIO %i\n", irq);
    return IRQ_HANDLED;

static int __init template_init(void)
    int gpio_irq = 0;
    int ret      = 0;
    printk("[wake_on_gpio]: initialising IRQ for GPIO %u ...\n", C_GPIO_TO_HANDLE);
    //gpio_irq = gpio_to_irq(C_GPIO_TO_HANDLE);
    at91_set_GPIO_periph(C_GPIO_TO_HANDLE, 0);
    at91_set_gpio_input (C_GPIO_TO_HANDLE, 0);
    at91_set_deglitch   (C_GPIO_TO_HANDLE, 1);
    ret = request_irq(C_GPIO_TO_HANDLE, gpio_irq_handler, (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING), "gpio irq handler", NULL);
    if (ret)
        printk("[wake_on_gpio]: gpio interrupt request failed: %i\n", ret);
        printk("[wake_on_gpio]: gpio interrupt request succeeded\n");    
        enable_irq_wake (C_GPIO_TO_HANDLE);

    return 0;

 * template_cleanup - function to cleanup this module from kernel space
 * This is the second of two exported functions to handle cleanup this
 * code from a running kernel

static void __exit template_cleanup(void)
    printk("Short life for a small module...\n");


MODULE_DESCRIPTION("Kernel module to handle IRQ requests of GPIO 60 (DRDY of connected ADC).");
Posts: 25
Joined: Wed Jul 30, 2014 9:17 pm

Re: request_irq fails with errno -22 - sama5d3 kernel 3.15.7

Wed Aug 06, 2014 5:13 pm

I found after some searching, that blue_z already answered partually this question in another post.


1.) defintely use gpio_to_irq function

2.) is defined inside linux/gpio.h

3.) hence, do not use the at91 gpio api anymore, but the generic gpio api in linux/gpio.h

works for me now

Return to “SAMA5D Cortex-A5 MPU”

Who is online

Users browsing this forum: No registered users and 2 guests