Kernel driver registration GPIO no response

mailonghua
mailonghua New Member Posts: 2

I am currently using the UP2-Celeron processor

The kernel successfully registers the GPIO interrupt, but when the GPIO external signal changes, the interrupt function is not triggered and the number of corresponding interrupts counted by /proc/interrupts is always 0

My test code:

define IMU_TDK_42688_IRQ_NUM 430

static irqreturn_t irq_handler(int irq, void *dev_id)
{
printk("Interrupt in ");
return IRQ_HANDLED;
}
int init_irq_gpio_num(int gpio_num)
{
int irq_num = 0 ;
int ret = 0;
if(gpio_num <= 0)
{
pr_err("%s:Get gpio num error...",FUNCTION);
return -1;
}
if(gpio_request_one(gpio_num, GPIOF_IN, "MCU_sel") < 0) {
printk(KERN_ALERT "GPIO %d cannot be used\n", IMU_TDK_42688_IRQ_NUM);
return -EBUSY;
}
irq_num = gpio_to_irq(gpio_num);//GPIO to IRQ NUM
if(irq_num < 0)
{
pr_err("%s:gpio_to_irq error",FUNCTION);
return -5;
}

// ret = request_irq(irq_num,irq_handler , IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, "my_test_interrupt", NULL); 
ret = request_irq(irq_num,irq_handler , IRQF_TRIGGER_HIGH, "my_test_interrupt", NULL); //IRQF_TRIGGER_HIGH
if(ret != 0) {
    printk(KERN_ERR "can not get irq\n");
    return ret;
} 
printk("%s:Get imu irq succsess(irq_num=%d,gpio_num=%d)...",__FUNCTION__,irq_num,gpio_num);
ret = enable_irq_wake(irq_num);
printk("the enable_irq_wake  result is: %d\n", ret);



return irq_num;

}

static int __init test_interrupt_init(void)
{
printk("Start test_interrupt_init");
irq_num_test = init_irq_gpio_num(IMU_TDK_42688_IRQ_NUM);
if(irq_num_test < 0){
printk("test_interrupt_init failed!!");
return irq_num_test;
}
else{
printk("requist irq num =%d\r\n",irq_num_test);
return 0;
}

}
static void __exit test_interrupt_exit(void)
{

if(irq_num_test >0)
    free_irq(irq_num_test,irq_handler);
else
    printk("Skip free_irq irq_num=%d",irq_num_test);

gpio_free(IMU_TDK_42688_IRQ_NUM);

printk("Exit test_interrupt_exit");

}

Tagged:

Answers

Privacy Policy