/* 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 );
}