版权声明:本文为博主原创文章,任何组织或者个人可以在任何媒介上发表或转载我的文章、图片等.且转载后必须注明出处和邮箱,博客地址(https://blog.csdn.net/u011011827),本人邮箱([email protected]) https://blog.csdn.net/u011011827/article/details/87891181
很多纯输入设备都是用的 input 子系统
input 子系统 是 驱动里面一个非常重要的概念
- input 子系统的基础
该系统 基于 class (class 基于 bbd 总线设备驱动模型)
bbd 利用了 sysfs kobject_uevent 等等
该系统又利用了 cdev 字符设备驱动模型
该系统 利用了 内核链表 rcu链表
该系统利用了 proc
该系统利用了 mdev udev
- input 子系统的 匹配 和 bdd 中的匹配 区别
input 的匹配是 device 和 handler 的匹配
这里的device 和 handler 都是驱动的一部分
device 就是所说的 input 驱动
handler 就是 input core 之上的handler ,其提供cdev (cdev 提供 file_operations)
bdd 中的匹配 是 device 和 driver 的匹配
这里的device 是 dts 中的信息
这里的 driver 是驱动的一部分,就是所说的 input 驱动
- input 相关的目录
/proc/bus/input/
input_init->input_proc_init 中创建的
input.c:1269: entry = proc_create("devices", 0, proc_bus_input_dir,
input.c:1274: entry = proc_create("handlers", 0, proc_bus_input_dir,
/sys/class/input/
input_register_device 中的 device_add 中创建的
/dev/input/
handler->connect 中的 device_add 中
mdev 或者 udev 通过 kobject_uevent 创建的
- input 子系统模块代码划分
input 子系统代码完全在kernel 源代码中.input 子系统完全运行在内核空间
用户空间 /dev/input/eventX
----------------
内核空间
层1 handler // 通过 input_register_handler 注册的 handler
层2 core // 提供 input_register_handler
层3 device // 通过 input_register_device 注册的 device
层1 代码 所在位置 drivers/input/evdev.c drivers/input/joydev.c drivers/input/mousedev.c
其实层1 所在代码可以在kernel 中搜索 input_register_handler 来获得
这些文件都调用了 input_register_handler
层2 代码 所在位置 drivers/input/input.c
其实还有 ff-core.c input-compat.c input-mt.c
层3 代码所在位置 drivers/input/gameport drivers/input/keyboard
每个文件夹表示一类设备的input驱动的集合, 每个文件都调用了 input_register_device
- 功能划分
core
提供 device 和 handler 的注册 匹配 ,提供 device 到 handler 的数据传输
在传输过程中可以 过滤 事件 ,分发 事件 , 阻断事件.
device
调用 input_register_device 注册设备
并在合适的时候上报事件的源头,上报到 core
handler
调用 input_register_handler 注册 handler
handler 用来处理 bdd 中 的设备的注册, cdev(用来提供file_operations) 的注册
- input 驱动 中的 module_xxx_driver 中调用的 driver_register 和 input_register_device 中的 device_add 和 handler->connect 中调用的 device_add 区别是什么
driver_register
是为了和 dts 中的 device 匹配
创建一个 /sys/.../ device
----------------------- 下面是 input 系统比 一般 bdd 特有的
input_register_device 中的 device_add
是为了 创建 /sys/class/input/
handler->connect 中的 device_add
是为了让系统帮助 添加一个 event 设备
在 /dev/input/ 下面添加一个设备
/sys 下没变化