File_operations cannot be discarded. It is the basic structure of character devices,
Various device models or bus, but character devices are packaged.
The driver must be a kernel module. The kernel module may not be a driver.
The original intention of the device model is to create a global Device Tree with all devices attached to power-saving
Communication with user space: communication between devices is implemented through the sysfs File System to expose the interface of the device model to the user as a file.
You can configure devices by reading and writing files.
The economic basis of the device model determines the superstructure of the device model.
Kobject is the smallest unit that forms the device model. It is the core structure of the device model. It puts the attributes or operations common to different devices in one structure for easy management. Kobject is equivalent to an object-oriented base class. Embed kobject into a larger object. These objects are joined through kobject to form a tree structure for easy management. Kobject_type is a set of kobject structures with the same operation.
It manages operations of a class of kobject under sysfs. Kset is a collection of kobject. Kobject uses kset to form a hierarchical set. kobject is equivalent to a leaf node. The kobject and kset are connected to form a tree structure. kobject_type cares about the kobject type. Kset is concerned with the collection of kobject. Kset is the top-level container class of kobject. As long as a kset is set and registered in the system, a directory kset is added to the sysfs file system to establish the correlation between the upper and lower layers. kobject uses kset to identify which type it belongs.
In this way, you can establish the correct directory location in the sysfs file system, kobject uses the kset in the kobject_type structure to determine its own kset and points the kobject_type field in the kobject to the kobject_type field in the corresponding kset. All devices in the device model are connected to the driver through the bus, which is the software program for the kernel to communicate with the device.
When we talk about device drivers, we should say that they are devices and drivers under a bus (for example, Nic drivers under USB or Nic drivers under PCI Bus)
The device_driver structure is often embedded into a larger structure. For example, in platform_driver, bus device drivers are in a perfect triangular relationship. Two-to-one bus device drivers are mutually included. The stock object kobject is their base class implementation. functions and interfaces
Kset is implemented using a linked list.
Usb_register inserts the device -- driver structure into the driver chain table of USB bus -- type. The match function is used to bridge device and driver.
Spec Protocol Specification
Static struct platform_driver s3c2412fb_driver = {
. Probe = s3c2412fb_probe,
. Remove = s3c2410fb_remove,
. Suspend = s3c2410fb_suspend,
. Resume = s3c2410fb_resume,
. Driver = {
. Name = "s3c2412-lcd", // after the name field is defined, the link source file with the corresponding name will be generated in the/sys/bus/platform/devices/directory under the devices/platform/s3c2410-lcd directory
. Owner = this_module,
},
};
Struct bus_type platform_bus_type = {
. Name = "Platform ",
. Dev_attrs = platform_dev_attrs,
. Match = platform_match,
. Uevent = platform_uevent,
. PM = platform_pm_ops_ptr,
};
Platform_driver_register (struct platform_driver * DRV)
Struct platform_driver {
INT (* probe) (struct platform_device *);
INT (* remove) (struct platform_device *);
Void (* shutdown) (struct platform_device *);
INT (* suspend) (struct platform_device *, pm_message_t State );
INT (* suspend_late) (struct platform_device *, pm_message_t State );
INT (* resume_early) (struct platform_device *);
INT (* resume) (struct platform_device *);
Struct device_driver driver;
}; Structure
And mount struct platform_driver
Two linked lists are mounted on the bus. One is driver and the other is devices. When registering devices, the device is mounted to the devices linked list and the driver linked list is traversed, find the driver that can drive the device. If yes, call the probe function in the driver and the device will be driven;
The same process occurs when the registration driver
Any device model, such as various final characters, is encapsulated by the character device file_opration struct bus device driver as a large frame to form an object
The above is my brief understanding of the Linux device model. In case of any errors, I hope you can help us to point out them.