Input subsystem of Linux driver subsystem (3)
3. Device Driver Layer
3.1 Overview
Communicates with the input device at the underlying layer to implement the driver of the specific hardware device and obtain the event information generated by the hardware and report it to the upper layer. We need to implement this layer, and the kernel also provides many device drivers.
3.2 data structures and functions
L input_dev: This struct is used in the subsystem to describe an input device.
Struct input_dev {
/* Export the information to the user space, which can be seen in the SYS file */
Const char * Name;
Const char * phys;
Const char * uniq;
Struct input_id ID;
Unsigned longevbit [bits_to_longs (ev_cnt)];/* supports bitmap for input device events */
Unsigned longkeybit [bits_to_longs (key_cnt)];/* Event code bitmap supported by the key device */
INT (* open) (struct input_dev * Dev );
Void (* close) (struct input_dev * Dev );
INT (* flush) (struct input_dev * Dev, struct file * file );
INT (* event) (struct input_dev * Dev, unsigned int type, unsigned int code, int value );
Struct device dev;/* apply to the device driver model */
Struct list_head h_list;/* input processing list related to the input device */
Struct list_head node;/* used to link input_dev to the global input_dev_list linked list */
......
}
L register the function to register the input device to the core layer. before registration, the input device must call input_allocate_device to allocate the device, and then set the device processing capability.
Intinput_register_device (struct input_dev * Dev)
{
Error = device_add (& Dev-> Dev);/* register a device and drive the model idea */
List_add_tail (& Dev-> node, & input_dev_list );
List_for_each_entry (handler, & input_handler_list, node)
Input_attach_handler (Dev, Handler );
}
1. The list_add_tail function adds the input device to the global variable input_dev_list;
2. The list_for_each_entry function traverses handler on input_handler_list (Global linked list, connected to all input_handler) and calls input_attach_handler to associate the input device with the processing method.
L The input_match_handler function is mainly implemented by the input_match_device and Handler-> connect functions.
Static intinput_attach_handler (struct input_dev * Dev, struct input_handler * Handler)
{
Id = input_match_device (handler, Dev );
If (! ID)
Return-enodev;
Error = Handler-> connect (handler, Dev, ID );
}
After successful match, call the Handler-> connect function at the event processing layer to register handle and create processing layer devices (evdev, mousedev, keybdev and so on.