Specifications
CHAPTER 2. DRIVERS AND INTERFACES 6
Input Device
Input Device
Input Device
Input Device
Device Driver
Device Driver
Device Driver
Input Core
Event Handler
Event Handler
Event Handler
User Space
Kernel Space
Figure 2.1: Linux Input System
function input register device() first. The driver calling input register device() must
supply a pointer to a structure input dev as parameter.
void input_register_device(struct input_dev *);
The structure input dev is defined in <linux/input.h> and needs to be setup by the
input driver itself. It contains information about the input device’s capabilities and function
pointers required by the Linux kernel in order to access the device. Once a driver is loaded,
the input core initializes the timer of input dev and adds the new input device to a list. If
the kernel has enabled the hotplug subsystem (CONFIG HOTPLUG), the input core also notifies
the hotplug subsystem about the newly added device.
The function input unregister device() is called if an input device driver is removed.
The input core removes the device drivers’ data structures. Again, if hotplug is enabled, the
hotplug subsystem will be notified about the removal of the device. Event handlers register
themselves by calling the input core’s function input register handler(). Upon registration,
an event handler receives input events as a reference to a structure input event from the input
core. The structure input event represents an input event and is defined in <linux/input.h>:
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
The member time contains a timestamp when the event happened. All valid event types,
codes and values are defined in <linux/input.h>. For example, a keypress event and a key
release event have the same type and code but a different value. For both events, type is set
to EV KEY. The value of code is unique for each key and contains the scancode. If the event
was a keypress value equals 1, if the event was a key release value equals 0.
The timestamp time is generated by the input core. The other members of the struct—
type, code and value—are supplied by the calling input device driver. Both the data structure
of an input event and the function, which is invoked by an input device driver to report an