参考链接
https://blog.csdn.net/pwl999/article/details/109411919
硬件设计
设备树
驱动程序
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>int irq;//中断服务函数
irqreturn_t test_interrupt(int irq , void * args){/* 文件系统同步 */printk("powerdown detect sync filesystem!\n ");sys_sync();/* 系统reboot */printk("powerdown detect reboot system!\n ");kernel_power_off();
}//驱动入口函数
static int interrupt_irq_init(void){int ret;irq = gpio_to_irq(110); //填写要申请的gpio编号printk("irq is %d\n", irq);ret = request_irq(irq, test_interrupt, IRQF_TRIGGER_RISING, "test", NULL); //引脚上升沿触发中断服务函数if(ret < 0){printk("request_irq is error\n");return -1;}return 0;
}//驱动出口函数
static void interrupt_irq_exit(void){free_irq(irq, NULL);printk("bye bye\n");
}module_init(interrupt_irq_init);
module_exit(interrupt_irq_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("YU");