Hua Qing vision shares with you: Platform in Linux driver

Source: Internet
Author: User

Author: Li Zhimin, Shanghai Center lecturer of Huaqing vision embedded College.

From the Linux kernel, a new driver management and registration mechanism is introduced: platform_device and platform_driver. Most device drivers in Linux can use this mechanism. The device is represented by platform_device, and the driver is registered by platform_driver.

Compared with the traditional device driver mechanism (that is, registration through the driver_register function), the Linux platform driver mechanism has a significant advantage in registering the resources of the device into the kernel, it is centrally managed by the kernel. When these resources are used in the driver, they are applied for and used through the standard interface provided by platform device.

Platform is a virtual address bus. Compared with PCI and USB, it is mainly used to describe on-chip resources on SOC. The resources described by platform have one thing in common: directly fetch addresses on the CPU bus. The platform device is assigned a name (used in driver binding) and a series of resources such as addresses and interrupt request numbers (IRQ.

The driver development steps under the platform bus are as follows:

1. Device

The struct to be implemented is platform_device.

1) initialize the Resource Structure Variable
2) initialize the platform_device structure variable.
3) register a device with the system: platform_device_register.

The above three steps must be completed before the device driver is loaded, that is, before platform_driver_register () is executed, because the driver registration must match all registered device names in the kernel. Add the device to the kernel in platform_driver_register () and then call the device_add function. The main difference between platform_device_add and device_add is that one step more insert_resource (P, R) is added to the kernel, which is centrally managed by the kernel.

2. Driver

In driver registration, the structure to be implemented is platform_driver.

In the driver's initialization function, platform_driver_register () is called to register platform_driver. Note that the value of the name variable in platform_driver and platform_device must be the same. In this way, when platform_driver_register () is registered, the value of the name variable in the currently registered platform_driver will be compared with the value of the name variable in all registered platform_device, and only the platform_device with the same name will be found.
To register successfully. When the registration is successful, the platform_driver structure element probe function pointer is called.

Registration Process of platform_driver_register:

1. platform_driver_register (& s3c2410fb_driver)
2. driver_register (& DRV-> driver)
3. bus_add_driver (DRV)
4. driver_attach (DRV)
5. bus_for_each_dev (DRV-> bus, null, DRV, _ driver_attach)
6. _ driver_attach (struct device * Dev, void * Data)
7. driver_probe_device (DRV, Dev)
8. really_probe (Dev, DRV)

In really_probe (), assign the driver to manage the device: Dev-> driver = DRV. Call the probe () function to initialize the device: DRV-> probe (Dev ).

Source: http://tieba.baidu.com/p/1008102666

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.