Skip to content

Input Subsystem

The Linux input subsystem is used for handling input devices such as:

  • Keyboard
  • Mouse
  • Touchscreen
  • GPIO buttons

It provides a standard interface between kernel drivers and userspace.


Architecture

Input Driver
Input Core
Event Handler (evdev)
/dev/input/eventX
Userspace (evtest / application)

Key Components

1. input_dev

Represents an input device.

struct input_dev *input;
input = devm_input_allocate_device(dev);

2. Capability

Defines what events the device can generate.

input_set_capability(input, EV_KEY, KEY_ENTER);

3. Event Reporting

input_report_key(input, KEY_ENTER, 1); // press
input_sync(input);

input_report_key(input, KEY_ENTER, 0); // release
input_sync(input);

4. input_event (userspace)

struct input_event {
    struct timeval time;
    __u16 type;
    __u16 code;
    __s32 value;
};

Event Model

Value Meaning
1 Key press
0 Key release
2 Auto-repeat

SYN_REPORT

input_sync() generates:

EV_SYN / SYN_REPORT

It indicates the end of one event frame.


Design Philosophy

Kernel:
    provides events (mechanism)

Userspace:
    decides behavior (policy)

Input vs IIO

Feature Input IIO
Data type Event Streaming data
Example Button ADC / sensor
Model Event-driven Buffered
Userspace evdev iio buffer

Summary

Input = "something happened"
IIO   = "data is flowing"