Reprint: http://hi.baidu.com/zengzhaonong/blog/item/720f935403a7d20e3a2935bf.html
1. dtb file parsing, generating a list of resource items
-------------------------------------------------------------------
Start_kernel ()-Setup_arch ()-Unflatten_device_tree ()
This function resolves the dtb file and constructs a single-necklace table that is connected by the Device_node structure. As follows after this function is executed, there will be a list of the following in memory
All subsequent functions, if required to read the device data from the tree structure, are traversed and read from the linked list.
2. Display the allnodes in the/proc/device-tree directory
-------------------------------------------------------------------
linux-2.6.26
Start_kernel ()--
#ifdef CONFIG_PROC_FS
Proc_root_init (); -
#endif
#ifdef Config_proc_devicetree
Proc_device_tree_init (); -
#endif
Proc_device_tree_add_node (Root, Proc_device_tree);
The device node is generated under the/proc/device-tree directory
# Ls-al/proc/device-tree
3. Registration/initialization of Of_platform_bus_type
-------------------------------------------------------------------
Linux2.6.28/arch/powerpc/kernel/of_platform.c
struct Bus_type Of_platform_bus_type = {
. uevent = Of_device_uevent,
};
Export_symbol (Of_platform_bus_type);
static int __init of_bus_driver_init (void)
{
Return Of_bus_type_init (&of_platform_bus_type, "of_platform");
}
Postcore_initcall (Of_bus_driver_init);
Of_platform_bus_type Bus registration is complete.
The/sys/bus/directory will now have Of_platform
4. Add the Allnodes device node to the bus of_platform_bus_type
-------------------------------------------------------------------
Arch/powerpc/platform/83xx/mpc831x_rdb.c
Machine_device_initcall (Mpc831x_rdb, declare_of_platform_devices);
Declare_of_platform_devices ()--
Of_platform_bus_probe (NULL, of_bus_ids, NULL)
Arch/powerpc/kernel/of_platform.c
Iterate through the child nodes of all the SoCs that generated the linked list in memory in the first step, adding all the SOC child node devices to the Of_platform bus.
Of_platform_bus_probe ()--
Of_platform_device_create ()--
Of_device_register ()--
Device_add ()
All devices on the Of_platform bus are added, and the E0024000.ethernet,e0024520.mdio and so on are now on the bus. At this point the device node will appear in the /sys/devices/platform/
3 Registration of Mdio bus
--------------------------------------------
/driver/net/phy_device.c
Subsys_initcall (Phy_init)
Phy_init--Mdio_bus_init-Bus_register (&mdio_bus_type)
After the bus is registered, a default PHY driver Genphy_driver is registered on the bus:
. phy_id = 0xFFFFFFFF,
. Phy_id_mask = 0xFFFFFFFF,
. Name = "Generic PHY",
Mdio Bus registration is complete.
/sys/bus/mdio
5 Mdio Bus-driven add-on
--------------------------------------------/DRIVER/NET/PHY/MARVELL.C
Module_init (Marvell_init)
Marvell_init ()--
Phy_driver_register (&marvell_drivers[i])--
Driver_register ()
In the third step, after registering the Mdio bus, a default PHY driver has been added, and all PHY drivers are now added to the bus, where all Marvell PHY is added.
After this step, the kernel/sys/bus/mdio/driver has a variety of PHY drivers, but there is no specific device binding.
6 Of_platform The Mdio device driver on the bus (the purpose of the drive is to add PHY devices on the Mdio bus) and bind the device: E0024520.mdio and E0025520.MDIO/DRIVER/NET/FSL_PQ_MDIO.C
Module_init (Fsl_pq_mdio_init)
Fsl_pq_mdio_init-Of_register_platform_driver (&fsl_pq_mdio_driver)-Of_register_driver-Driver _register--Bus_add_driver-Driver_attach
Traverse the entire Of_platform bus to find the matching device and locate the E0024520.mdio
Driver_attach--__driver_attach-Driver_match_device
The information in the match_table of the driver is compared with the Dev_nod, and if it conforms to the probe of driver, it is fsl_pq_mdio_probe.
Now the device E0024520.mdio and E0025520.mdio on the Of_platform bus are already bound to the driver.
7 Mdio The device on the bus to add, find and bind the corresponding driver.
/driver/net/fsl_pq_mdio.c
Fsl_pq_mdio_probe--Of_mdiobus_register--Phy_device_register-Device_register (&phydev->dev)- -Device_add--Bus_probe_device-Device_attach-->bus_for_each_drv
Scan all the drivers on the Mdio bus, if found match, bind, and probe.
__device_attach--Driver_probe_device--Really_probe-Phy_probe
All PHY and tbi-phy devices are added to the Mdio bus, and two PHY devices and two tbi-phy devices will find their own drivers based on their own phyid.