From: http://blog.chinaunix.net/space.php? Uid = 20643761 & Do = Blog & id = 1594837
Platform_device_add eventually calls the old interface device_add, but adds the process of registering the resource into the kernel.
Platform_driver_register also calls driver_register. In driver_register, the probe function of driver is called.
Platform_device_register () registration process
------------------------------------
/*
ARCH/ARM/mach-s3c2410/mach-smdk2410.c */
Struct platform_device
Initi_device_i2c = {
. Name = "s3c2410-i2c ",
. ID =-1,
. Num_resources = array_size (cloud_i2c_resource ),
. Resource =
Initi_i2c_resource,
};
/*
*
Platform_device_register-Add a platform-level device
*
@ Pdev: platform device we're adding
*
*/
Int platform_device_register (struct
Platform_device * pdev)
{
Device_initialize (& pdev-> Dev); // initialize the device structure
Return platform_device_add (pdev); // Add a device on the device to the device layer.
}
/**
* Platform_device_add-Add
Platform device to device hierarchy
* @ Pdev: platform device we're
Adding
*
* This is part 2
Platform_device_register (), though may be called
* Separately _ IFF _ pdev was
Allocated by platform_device_alloc ().
*/
Int platform_device_add (struct platform_device * pdev)
{
Int I, ret =
0;
If
(! Pdev)
Return-einval;
If
(! Pdev-> Dev. Parent)
Pdev-> Dev. Parent = & platform_bus;
Pdev-> Dev. Bus =
& Platform_bus_type;
If (pdev-> ID! =
-1)
Snprintf (pdev-> Dev. bus_id, bus_id_size, "% S. % d ",
Pdev-> name,
Pdev-> ID);/* if multiple devices of the same type are supported, use pdev-> name and pdev-> ID to identify the device on the bus */
Else
Strlcpy (pdev-> Dev. bus_id, pdev-> name, bus_id_size);/* Otherwise, identify the device on the bus with pdev-> name (such as "s3c2410-i2c */
For (I = 0; I <
Pdev-> num_resources; I ++) {/* traverse the number of resources and allocate requests for each address space in the bus */
Struct Resource
* P, * r = & pdev-> resource [I];
If (R-> name
= NULL)
R-> name = pdev-> Dev. bus_id;
P =
R-> parent;
If (! P)
{
If
(R-> flags & ioresource_mem)
P = & iomem_resource;/* allocates Io memory resources */
Else
If (R-> flags & ioresource_io)
P = & ioport_resource;/* allocates IO port resources */
}
If (P & insert_resource (P, R) {/* Insert the new resource into the kernel Resource Tree */
Printk (kern_err
"% S: failed to claim Resource
% D \ n ",
Pdev-> Dev. bus_id,
I );
Ret =
-Ebusy;
Goto
Failed;
}
}
Pr_debug ("registering
Platform device '% s'. Parent at % s \ n ",
Pdev-> Dev. bus_id,
Pdev-> Dev. Parent-> bus_id );
Ret = device_add (& pdev-> Dev );
If (ret =
0)
Return
RET;
Failed:
While (-- I> =
0)
If
(Pdev-> resource [I]. Flags &
(Ioresource_mem | ioresource_io ))
Release_resource (& pdev-> resource [I]);
Return
RET;
}
It is found that the device_add function is still called after the device is added to the kernel. The main difference between platform_device_add and device_add is that one step more insert_resource (p,
R) adds platform resources to the kernel for unified management.
Platform_driver_register ()Registration Process
--------------------------------------
Static struct platform_driver s3c2410_i2c_driver =
{
. Probe =
S3c24xx_i2c_probe,
. Remove =
S3c24xx_i2c_remove,
. Resume =
S3c24xx_i2c_resume,
. Driver = {
. Owner = this_module,
. Name = "s3c2410-i2c ",
},
};
Platform_driver_register (& s3c2410fb_driver) ----->
Driver_register (& DRV-> driver) ----->
Bus_add_driver (DRV) ----->
Driver_attach (DRV) ----->
Bus_for_each_dev (DRV-> bus, null, DRV, _ driver_attach) ----->
_ Driver_attach (struct device * Dev, void * Data) ----->
Driver_probe_device (DRV, Dev) ----->
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)