#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/interrupt.h>
int irqno;
irqreturn_t key_irq_handler(int irqno, void *devid)
{
printk("--------------%s------------------",__FUNCTION__);
return IRQ_HANDLED;
}
int get_irqno_from_node(void)
{
struct device_node *np = of_find_node_by_path("/key_int_node");
if(np){
printk("find node ok\n");
}
else{
printk("find node failed\n");
}
irqno = irq_of_parse_and_map(np,0);
printk("irqno = %d\n",irqno);
return irqno;
}
static int __init key_drv_init(void)
{
int irqno,ret;
irqno = get_irqno_from_node();
ret = request_irq(irqno, key_irq_handler, IRQF_TRIGGER_FALLING|IRQF_TRIGGER_RISING, "IRQ_EINT10", NULL);
if(ret != 0)
{
printk("request_irq ERROR!\n");
return ret;
}
return 0;
}
static void __exit key_drv_exit(void)
{
free_irq(irqno,NULL);
}
module_init(key_drv_init);
module_exit(key_drv_exit);
MODULE_LICENSE("GPL");
ROOTFS_DIR = /home/linux/Level11
CROSS_COMPILE = arm-none-linux-gnueabi-
CC = $(CROSS_COMPILE)gcc
ifeq ($(KERNELRELEASE), )
KERNEL_DIR = /home/linux/Level10/day6/linux-5.4.79
CUR_DIR = $(shell pwd)
all :
make -C $(KERNEL_DIR) M=$(CUR_DIR) modules -j6 ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
clean :
make -C $(KERNEL_DIR) M=$(CUR_DIR) clean
clear
install:
cp -raf *.ko $(APP_NAME) ./1/
else
obj-m += key_drv.o
endif
[root@farsight ]
[ 17.570120] key_drv: loading out-of-tree module taints kernel.
[ 17.575433] find node ok
[ 17.577120] irqno = 107
[root@farsight ]
CPU0 CPU1 CPU2 CPU3
36: 0 0 0 0 GIC-0 89 Level mct_comp_irq
37: 20031 3406 1122 6958 GIC-0 28 Level MCT
38: 0 0 0 0 COMBINER 18 Edge arm-pmu
39: 0 0 0 0 COMBINER 26 Edge arm-pmu
...
106: 19237 0 0 0 exynos4210_wkup_irq_chip 6 Level eth0
107: 0 0 0 0 exynos4210_wkup_irq_chip 2 Edge IRQ_EINT10
IPI0: 0 1 1 1 CPU wakeup interrupts
...
按下按键K3
[root@farsight ]
[ 2983.202843] --------------key_irq_handler------------------
[root@farsight ]