linux驱动子系统之输入子系统(2)
2. 输入核心层
2.1 概述
核心层对下提供了设备驱动层的编程接口,对上有提供了事件处理层的编程接口。input.c是核心层实现的文件。
2.2 驱动代码分析
l 初始化模块
static int __init input_init(void)
{
err= class_register(&input_class);
err= input_proc_init();
err= register_chrdev(INPUT_MAJOR, "input", &input_fops);
}
初始化模块完成了三件事情:注册input类,导出设备信息到proc,注册input字符设备
l File_operations
static const struct file_operationsinput_fops = {
.owner= THIS_MODULE,
.open= input_open_file,
.llseek= noop_llseek,
};
很奇怪,怎么就只实现了open。不急,我们先来看下open函数
static int input_open_file(struct inode*inode, struct file *file)
{
handler= input_table[iminor(inode) >> 5];
if(handler)
new_fops= fops_get(handler->fops);
old_fops= file->f_op;
file->f_op= new_fops;
err= new_fops->open(inode, file);
fops_put(old_fops);
}
原来是重定向到了事件处理层实现的fops,因为对不同的事件处理的方法都不同