Input 子系统架构与源码总览

Input 子系统架构与源码总览

1. 架构

1
2
3
4
5
6
7
8
9
10
11
hardware: GPIO/IIO/I2C/SPI/USB/PMIC/PWM IR
|
device driver -> input_dev
|
Input Core
|
input_handle connects device and handler
| | |
evdev mousedev joydev
|
/dev/input/eventN -> libinput/Android/Linux application

2. 核心对象

  • input_dev:能力、状态、坐标、回调与事件缓存;
  • input_handler:evdev 等消费者;
  • input_handle:device-handler连接;
  • input_valuetype/code/value
  • input_mt:多点触控 slot 状态;
  • ff_device:力反馈 effect。

3. 构建

input-core.o 由:

1
input.o input-compat.o input-mt.o input-poller.o ff-core.o touchscreen.o

组成。evdev/mousedev/joydev是独立 handler module。

4. 设备注册

1
2
3
4
5
6
7
8
9
10
11
probe
-> devm_input_allocate_device()
-> set name/phys/id/parent
-> set evbit/keybit/absbit
-> input_set_abs_params()
-> input_register_device()
-> cleanse capabilities
-> allocate event values
-> device_add()
-> append input_dev_list
-> match all handlers

5. Handler 注册

1
2
3
4
5
input_register_handler()
-> append input_handler_list
-> match all input devices
-> handler->connect()
-> input_register_handle()

设备和 handler 无论谁先注册,Core都可完成匹配。

6. 事件

1
2
3
4
5
6
7
8
9
10
IRQ/poll
-> input_report_key/abs/rel()
-> input_event()
-> state validation/filter
-> queue input_value
-> input_sync()
-> input_pass_values()
-> handler->events()
-> evdev client ring buffer
-> read(eventN)

7. 用户接口

  • evdev:主通用 ABI;
  • mousedev:PS/2 mouse兼容流;
  • joydev:旧 joystick ABI;
  • sysfs:能力、ID、name、phys、properties;
  • procfs:devices/handlers;
  • uinput:用户态创建虚拟 input device。

8. 事件类型

主要 EV_KEYEV_RELEV_ABSEV_MSCEV_SWEV_LEDEV_SNDEV_REPEV_FFEV_SYN

9. RK3588

本树常见来源:

  • SARADC adc-keys
  • RK806 MFD创建的 rk805-pwrkey
  • I2C GT1X/Hynitron/FocalTech touch;
  • Rockchip PWM IR remotectl;
  • USB/Bluetooth HID经 drivers/hid
  • GPIO keys(具体板 DTS);
  • uinput虚拟设备。

10. 边界

drivers/input 提供 Input Core和许多 native driver;USB/Bluetooth键鼠触控主要先由 HID解析,再注册 input_dev。因此 eventX 的上游不一定在本目录。

文章互动

阅读 --

留言

0 条留言

正在加载留言…