A real Linux Device and driver usually need to be attached to a bus. This is naturally not a problem for devices that are attached to PCI, USB, IIC, and SPI. However, in an embedded system, the independent peripheral controller integrated in the SoC system and peripherals attached to the SOC memory space are not attached to this type of bus. Based on this background, Linux invented a virtual bus called platform bus. The corresponding device is called platform_device, and the driver becomes platform_driver.In this way, all our drivers adopt the bus, device, and driver framework idea, regardless of bus (IIC/USB/PCI ...) a device driver model can be used for mounted device drivers..
Note: the so-called platform_device is not tied with character devices, Block devices, and network devices, but an additional means provided by the Linux system, the integrated IIC, RTC, SPI, LCD, and watchdog controllers are all classified as platform_device, which are character devices.
The concept of platform in device drivers has at least two benefits:
1. the device is mounted to a bus. Therefore, it complies with the linux2.6 device model. As a result, supporting sysfs nodes and device movie management are all possible.
2. Isolated BSP and driver. Define the resources used by platform devices and the specific configuration information of devices in BSP. In the driver, you only need to obtain resources and data through common APIs, the separation of board-related code and driver code makes the driver more scalable and cross-platform.
The structure of platform_driver is defined as follows:
Struct platform_driver {<br/> int (* probe) (struct platform_device *); <br/> int (* remove) (struct platform_device *); <br/> void (* shutdown) (struct platform_device *); <br/> int (* suspend) (struct platform_device *, pm_message_t State ); // mainly used for power management <br/> int (* suspend_late) (struct platform_device *, pm_message_t State); <br/> int (* resume_early) (struct platform_device *); <br/> int (* resume) (struct platform_device *); // mainly used for power management <br/> struct pm_ext_ops * PM; <br/> struct device_driver driver; <br/> };
The platform_device struct is defined as follows:
Struct platform_device {<br/> const char * Name; <br/> intid; <br/> struct devicedev; <br/> u32num_resources; <br/> struct resource * resource; // manage resources <br/> };