Drivers/input. c
Is the so-called input core program.
Analyze this file and start with input_init.
1: static int __init input_init(void)
2: {
3: err = class_register(&input_class);
4: err = input_proc_init();
5: err = register_chrdev(INPUT_MAJOR, "input", &input_fops);
6: }
_ Init put it in the init. text segment, which will be called during initialization. This is the case when the function removes the check. Class_register registers the class type in the device model. In _ class_register
1:/* initialize the private data of the class */
2:/* cp is a class_private type, private type of class */
3: cp = kzalloc(sizeof(*cp), GFP_KERNEL);
4:/* initialize the get/put function of klist. Actually, get_device and put_device are called */
5: klist_init(&cp->class_devices, klist_class_dev_get, klist_class_dev_put);
6: INIT_LIST_HEAD(&cp->class_interfaces);
7: kset_init(&cp->class_dirs);
8: __mutex_init(&cp->class_mutex, "struct class mutex", key);
9: error = kobject_set_name(&cp->class_subsys.kobj, "%s", cls->name);
10:
11: /* set the default /sys/dev directory for devices of this class */
12: if (!cls->dev_kobj)
13: cls->dev_kobj = sysfs_dev_char_kobj;
14:/* register the kset. initialize the kset first. Obtain the kobject here and create a directory */
15: error = kset_register(&cp->class_subsys);
16:/* Create an attribute file and traverse its attribute. If you are familiar with the device model, you will know that the attribute actually corresponds to the file */
17: error = add_class_attrs(class_get(cls));
18:
In input_init, the next input_proc_init function is used to create a directory, file, and register the corresponding fops In the proc file system.
This is simple:
1:/* set up the input directory under proc */
2: proc_bus_input_dir = proc_mkdir("bus/input", NULL);
3:/* create two devices and handlers files under bus/input, and register their fops. The two fops are in the input. defined in c, the fops function is also in input. c. */
4: entry = proc_create("devices", 0, proc_bus_input_dir,
5: &input_devices_fileops);
6: entry = proc_create("handlers", 0, proc_bus_input_dir,
7: &input_handlers_fileops);
8:
The following register_chardev registers a character device with the primary device number being INPUT_MAJOR, the secondary device number ranging from 0 to 256, and the file operator being input_fops.
After reading input_init, let's look at input. c. The second half is the fops function. The first part is some interface functions, and the middle part is
Handle and handler functions.
To be continued