input子系统分为了input device drivers和input event drivers,看图
可以看到,在kernel space中,input -core 管理着 input device drivers 以及input event drivers,其中在 input device drivers中,当遇到有按键或者是TP触摸时甚至我们假定的sensor的中断时,调用一个函数即在input-core中的input_event的函数(input.c中定义,但是一般不直接调用,还有一层函数的封装),在input-core中input_event函数中,假如是正确的
事件的话,会通过input-core层之前注册的input event drivers 定义的event函数,将键值或者是坐标值写到已经定义的buffer中,当底层的input device drivers 进行input_sync时,作为一组数据保存,上层函数通过read 函数 ,函数中input_event_to_user将数据拷贝到用户空间。接下来我会一一分析。
最典型的input event drivers 是evdev的事件驱动 的drivers,基本管理着大部分的input device drivers。
static int
evdev_connect
(struct input_handler *handler, s
static const struct input_device_id evdev_ids[] = {
{ .driver_info = 1 }, /* Matches all devices */ //能够匹配到所有的已经注册在input子系统上dev
{ }, /* Terminating zero entry */
};
MODULE_DEVICE_TABLE(input, evdev_ids);
static struct input_handler evdev_handler = {
.event = evdev_event, //dev 进行input_event 时实际上调用的函数。
.connect = evdev_connect, //注册匹配成功后,调用connect函数
.disconnect = evdev_disconnect, //注册不成功时,调用disconnect函数
.fops = &evdev_fops, //进行读写等操作
.minor = EVDEV_MINOR_BASE, //次版本号是从64开始
.name = "evdev",
.id_table = evdev_ids, //和dev匹配时用到了id_table
};
static int __init evdev_init(void)
{
return input_register_handler(&evdev_handler);
}
static void __exit evdev_exit(void)
{
input_unregister_handler(&evdev_handler);
}
module_init(evdev_init);
module_exit(evdev_exit);
接下来讲一下evdev.c中定义的几个比较重要的函数。