Input Subsystem Use Cases¶
This note summarizes when the Linux input subsystem should be used, what kinds of events it supports, and how to choose between Input, IIO, and other subsystems.
1. What Is the Input Subsystem?¶
The Linux input subsystem is designed for devices that generate human interaction events.
Typical examples:
- Keyboard
- Mouse
- Touchscreen
- Touchpad
- GPIO button
- Rotary encoder
- IR remote controller
- Lid switch
- Headphone jack switch
- Stylus / pen tablet
The key idea is:
It is not mainly for continuous sensor measurement data.
2. Input Subsystem Data Model¶
Input devices report events to the kernel input core.
The common flow is:
Hardware
↓
Input Driver
↓
Input Core
↓
evdev
↓
/dev/input/eventX
↓
Userspace application / libinput / GUI / terminal
The driver reports events by using APIs such as:
Userspace reads events from:
3. Mechanism vs Policy¶
A very important Linux design concept:
For input devices:
Example:
KEY_ENTER event:
terminal may treat it as newline
GUI may treat it as confirm
custom app may treat it as LED toggle
The same input event can produce different behavior depending on the userspace application.
4. Common Input Event Types¶
Input events are grouped by EV_* types.
4.1 EV_KEY¶
EV_KEY is used for buttons, keys, and binary press/release events.
Typical examples:
- Keyboard keys
- GPIO buttons
- Mouse buttons
- Remote control buttons
- Power button
- Volume buttons
Example key codes:
Typical usage:
input_report_key(input, KEY_ENTER, 1); // press
input_sync(input);
input_report_key(input, KEY_ENTER, 0); // release
input_sync(input);
Event value meaning:
| Value | Meaning |
|---|---|
| 0 | Released |
| 1 | Pressed |
| 2 | Auto-repeat |
Use EV_KEY when the device produces a discrete action or button-like event.
4.2 EV_REL¶
EV_REL is used for relative movement.
Typical examples:
- Mouse movement
- Mouse wheel
- Trackball
Common codes:
Example:
Use EV_REL when the device reports movement relative to the previous position.
4.3 EV_ABS¶
EV_ABS is used for absolute position or analog-like input values.
Typical examples:
- Touchscreen
- Touchpad
- Joystick
- Stylus
- Slider
- Touch IC with position output
Common codes:
Example:
input_report_key(input, BTN_TOUCH, 1);
input_report_abs(input, ABS_X, x);
input_report_abs(input, ABS_Y, y);
input_sync(input);
Use EV_ABS when the device reports a position or absolute value.
4.4 EV_SW¶
EV_SW is used for switch state.
Typical examples:
- Laptop lid switch
- Headphone inserted
- Tablet mode switch
- Docking state
Common codes:
Use EV_SW when the device state is persistent rather than a momentary press.
Example:
4.5 EV_SYN¶
EV_SYN is used to mark event synchronization.
Most drivers do not report EV_SYN directly. Instead, they call:
This generates:
Meaning:
Example:
input_report_key(input, BTN_TOUCH, 1);
input_report_abs(input, ABS_X, x);
input_report_abs(input, ABS_Y, y);
input_sync(input);
Userspace receives these events as one logical input frame.
5. Button-like Devices¶
For a simple GPIO button, use:
Example mapping:
| Hardware Action | Input Event |
|---|---|
| Button press | KEY_ENTER press |
| Button release | KEY_ENTER release |
Example:
input_report_key(input, KEY_ENTER, 1);
input_sync(input);
input_report_key(input, KEY_ENTER, 0);
input_sync(input);
For higher-level patterns such as short click, long click, or double click, there are two possible designs.
5.1 Kernel-side Gesture Detection¶
The driver detects patterns and maps them to key events.
Example:
| Gesture | Input Event |
|---|---|
| Short click | KEY_ENTER |
| Long click | KEY_ESC |
| Double click | KEY_SPACE |
This is useful for learning or simple embedded systems.
However, it puts more policy into the kernel.
5.2 Userspace Gesture Detection¶
The driver reports raw press/release events only.
Userspace detects:
- Short click
- Long click
- Double click
- Combination actions
This is usually more flexible.
Recommended design:
6. Touch IC Use Cases¶
A touch IC may be used in different ways.
The correct input event type depends on what the IC provides.
6.1 Touch IC with Touch / No-touch Only¶
If the IC only reports whether a finger is touching:
Example:
input_report_key(input, BTN_TOUCH, 1);
input_sync(input);
input_report_key(input, BTN_TOUCH, 0);
input_sync(input);
This represents a binary touch state.
6.2 Touch IC with Position Data¶
If the IC reports X/Y position:
Example:
input_report_key(input, BTN_TOUCH, 1);
input_report_abs(input, ABS_X, x);
input_report_abs(input, ABS_Y, y);
input_sync(input);
This is suitable for:
- Touchpad
- Touch slider
- Touch surface
- Touchscreen-like input
6.3 Touch IC with Multi-touch Data¶
If the IC supports multiple fingers:
Common events:
This is more complex and usually follows the Linux multi-touch protocol.
6.4 Touch IC with Built-in Gesture Recognition¶
If the IC already detects gestures, such as:
- Tap
- Swipe left
- Swipe right
- Swipe up
- Swipe down
Then the driver may map them to EV_KEY.
Example:
| IC Gesture | Input Event |
|---|---|
| Tap | KEY_ENTER |
| Swipe left | KEY_LEFT |
| Swipe right | KEY_RIGHT |
| Swipe up | KEY_UP |
| Swipe down | KEY_DOWN |
Example:
input_report_key(input, KEY_LEFT, 1);
input_sync(input);
input_report_key(input, KEY_LEFT, 0);
input_sync(input);
This is suitable when the IC itself already provides high-level gesture results.
7. ABS_PRESSURE¶
ABS_PRESSURE is used when the device reports pressure or touch strength.
It is not the same as BTN_TOUCH.
| Event | Meaning |
|---|---|
| BTN_TOUCH | Touch or no touch |
| ABS_PRESSURE | How strong the touch is |
Typical use cases:
- Stylus pressure
- Drawing tablet
- Force touch sensor
- Pressure-sensitive touchpad
- Touch IC reporting capacitance strength
- Resistive touch panel pressure
Example:
input_report_key(input, BTN_TOUCH, 1);
input_report_abs(input, ABS_X, x);
input_report_abs(input, ABS_Y, y);
input_report_abs(input, ABS_PRESSURE, pressure);
input_sync(input);
Do not fake ABS_PRESSURE if the hardware does not provide meaningful pressure or strength data.
If the hardware only provides touch/no-touch, use:
If the hardware provides touch strength, use:
8. IR Devices¶
IR devices can belong to different subsystems depending on their purpose.
8.1 IR Remote Controller¶
An IR remote is a human input device.
Use:
Example:
| Remote Button | Input Event |
|---|---|
| Power | KEY_POWER |
| Volume Up | KEY_VOLUMEUP |
| Volume Down | KEY_VOLUMEDOWN |
| OK | KEY_ENTER |
The driver or IR subsystem decodes the remote signal and reports key events.
8.2 IR Distance / Proximity Sensor¶
An IR distance sensor measures physical data.
Use:
Examples:
- Distance
- Proximity level
- Light intensity
- Reflectance
These are measurement values, not human input events.
9. Ultrasonic Sensor¶
An ultrasonic sensor usually measures distance.
Example data:
This is measurement data.
Use:
Do not use the input subsystem unless the ultrasonic sensor is converted into a human-facing event, such as:
But in most cases, ultrasonic sensors belong to IIO.
10. Input vs IIO Decision Rule¶
A practical rule:
Examples:
| Device | Recommended Subsystem |
|---|---|
| GPIO button | Input |
| Keyboard | Input |
| Mouse | Input |
| Touchscreen | Input |
| Touchpad | Input |
| Touch slider | Input |
| IR remote | Input |
| Rotary encoder | Input |
| Ultrasonic distance sensor | IIO |
| IR distance sensor | IIO |
| Temperature sensor | IIO / hwmon |
| ADC | IIO |
| Accelerometer | IIO / Input depending on use |
| Light sensor | IIO |
| Proximity sensor | IIO, sometimes bridged to Input |
11. Hybrid Cases¶
Some devices can be modeled in more than one way.
11.1 Accelerometer¶
If used for measurement:
Example:
If used as an input device for simple orientation or tap detection:
Example:
11.2 Proximity Sensor¶
If reporting distance or proximity value:
If used to generate a specific user interaction event:
Example:
In many systems, the kernel exposes raw measurement via IIO, and userspace decides the behavior.
12. Commercial Sensing IC Design¶
For a sensing IC company, a good Linux architecture is often:
Kernel driver:
exposes standard input or IIO events/data
Userspace library:
implements proprietary algorithm, gesture recognition, calibration, or policy
This allows:
- Use of Linux standard subsystems
- Better compatibility
- Protection of proprietary algorithms
- Cleaner separation of mechanism and policy
Example for touch IC:
Example for sensor IC:
Using the input subsystem does not require exposing proprietary userspace algorithms.
13. Design Guidelines¶
Prefer Raw Events When Possible¶
If the hardware provides raw position or state:
Example:
Use Key Events for Already-decoded Gestures¶
If the IC already outputs high-level gestures:
Example:
Avoid Putting Too Much Policy in Kernel¶
Avoid complex behavior logic in kernel unless necessary.
Examples of logic better placed in userspace:
- UI behavior
- Gesture policy
- Application action
- Mode-dependent behavior
- Product-specific mapping
14. Summary¶
Use Input when the device represents:
- Button
- Key
- Switch
- Touch
- Pointer movement
- Human gesture
- Remote control input
Use IIO when the device represents:
- Temperature
- Voltage
- Distance
- Light
- Acceleration
- Raw sensor measurement
Final rule: