Character Device Driver note-platform device driver mechanism (2)

Source: Internet
Author: User

 

/* 1. Construct a platform-driven struct */
Static struct platform_driver s3c2410fb_driver = {
. Probe = s3c2410fb_probe,
. Driver = {
. Name = "s3c2410-lcd ",
. Owner = this_module,
},
};

/* 2. register the driver structure of this platform */
Int _ devinit s3c2410fb_init (void)
{
Return platform_driver_register (& s3c2410fb_driver );
}

What did platform_driver_register do?
----------------------------------------------------------------------------
DRV-> driver. Bus = & platform_bus_type;/* set our driver bus to a virtual platform bus type */
Return driver_register (& DRV-> driver);/* register with the driver list of the virtual platform bus */
Return bus_add_driver (DRV);/* register the DRV driver to the bus where DRV-> bus is located */
/* What is implemented in it */
If (DRV-> bus-> drivers_autoprobe ){
Error = driver_attach (DRV);/* call this function to match the device list on the bus */
Return bus_for_each_dev (DRV-> bus, null, DRV, _ driver_attach);/* search for each device on the device linked list and call the bus match function */
Klist_iter_init_node (& bus-> klist_devices, & I,
(Start? & START-> knode_bus: NULL ));
While (Dev = next_device (& I ))&&! Error)
Error = FN (Dev, data); // _ driver_attach
Klist_iter_exit (& I );

_ Driver_attach analysis:
---------------------------------------------------------
If (! Dev-> driver)
Driver_probe_device (DRV, Dev );
If (DRV-> bus-> match &&! DRV-> bus-> match (Dev, DRV) // DRV-> bus-> platform_match
Goto done;
Ret = really_probe (Dev, DRV );
{
Else if (DRV-> probe ){
Ret = DRV-> probe (Dev); // s3c2410fb_probe,
}
}

Platform_bus_type struct definition:
--------------------------------------------------------
Struct bus_type platform_bus_type = {
. Name = "Platform ",
. Dev_attrs = platform_dev_attrs,
. Match = platform_match,
. Uevent = platform_uevent,
. Suspend = platform_suspend,
. Suspend_late = platform_suspend_late,
. Resume_early = platform_resume_early,
. Resume = platform_resume,
};
There is a very critical function platform_match.

What is done in platform_match: (matching drivers and devices)
---------------------------------------------------------------------------
Static int platform_match (struct device * Dev, struct device_driver * DRV)
{
Struct platform_device * pdev = container_of (Dev, struct platform_device, Dev );
/* Match by name, where the name comes from. Name = "s3c2410-lcd "*/
Return (strncmp (pdev-> name, DRV-> name, bus_id_size) = 0 );
}

 

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.