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,因為對不同的事件處理的方法都不同