phy device的添加流程 .

本文详细介绍了PHY设备在Linux内核中的添加流程,从mdiobus_register到最终的device_add过程,涉及phy_device_register等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

phy device的添加流程,了解linux驱动中的 驱动、设备、总线 模型。

  1.  87 int mdiobus_register(struct mii_bus *bus)  
  2.  88 {  
  3. //  省略。。。。。。   
  4. 115         for (i = 0; i < PHY_MAX_ADDR; i++) {  
  5. 116                 if ((bus->phy_mask & (1 << i)) == 0) {  
  6. 117                         struct phy_device *phydev;  
  7. 118   
  8. 119                         phydev = mdiobus_scan(bus, i);  
  9. 120                         if (IS_ERR(phydev)) {  
  10. 121                                 err = PTR_ERR(phydev);  
  11. 122                                 goto error;  
  12. 123                         }  
  13. 124                 }  
  14. 125         }  
  15. //  省略。。。。。。   
  16. 138 }  

 

 

phydev = mdiobus_scan(bus, i) 这里的scan,并不仅仅是扫描,而且还包括创建。mdiobus_scan()主要调用了get_phy_device()和phy_device_register()。get_phy_device()里面主要有get_phy_id() 和 phy_device_create() 。 函数int get_phy_id()通过MII BUS总线,读寄存器MII_PHYSID1(高16位)、MII_PHYSID2(低16位)得到。phy_device_create() 创建了一个phy设备,完成了一些speed、duplex 、addr、phy_id等等默认初始化。看一下函数定义

  1. 182 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)  
  2. 183 {  
  3. 184         struct phy_device *phydev;  
  4. //  省略。。。。。。   
  5. 187         phydev = get_phy_device(bus, addr);  
  6. //  省略。。。。。。   
  7. 191         err = phy_device_register(phydev);  
  8. //  省略。。。。。。   
  9. 198 }  

 

 

 

phy_device_register() 调用device_register()

  1. 251 int phy_device_register(struct phy_device *phydev)  
  2. 252 {  
  3. //  省略。。。。。。   
  4. 264         err = device_register(&phydev->dev);  
  5. //  省略。。。。。。   
  6. 275 }  
  7. device_register()调用 device_add()  
  8. 1040 int device_register(struct device *dev)  
  9. 1041 {  
  10. 1042         device_initialize(dev);  
  11. 1043         return device_add(dev);  
  12. 1044 }  

 

 

 

device_add()东西比较多,以后再看。

  1. 891 int device_add(struct device *dev)  
  2. 892 {  
  3. 893         struct device *parent = NULL;  
  4. //  省略。。。。。。   
  5. 929         /* first, register with generic layer. */  
  6. 930         /* we require the name to be set before, and pass NULL */  
  7. 931         error = kobject_add(&dev->kobj, dev->kobj.parent, NULL);  
  8. //  省略。。。。。。   
  9. 939         error = device_create_file(dev, &uevent_attr);  
  10. //  省略。。。。。。   
  11. 943         if (MAJOR(dev->devt)) {  
  12. 944                 error = device_create_file(dev, &devt_attr);  
  13. 945                 if (error)  
  14. 946                         goto ueventattrError;  
  15. 947   
  16. 948                 error = device_create_sys_dev_entry(dev);  
  17. 949                 if (error)  
  18. 950                         goto devtattrError;  
  19. 951   
  20. 952                 devtmpfs_create_node(dev);  
  21. 953         }  
  22. //  省略。。。。。。   
  23. 955         error = device_add_class_symlinks(dev);  
  24. 956         if (error)  
  25. 957                 goto SymlinkError;  
  26. 958         error = device_add_attrs(dev);  
  27. 959         if (error)  
  28. 960                 goto AttrsError;  
  29. 961         error = bus_add_device(dev);  
  30. 962         if (error)  
  31. 963                 goto BusError;  
  32. 964         error = dpm_sysfs_add(dev);  
  33. 965         if (error)  
  34. 966                 goto DPMError;  
  35. 967         device_pm_add(dev);  
  36. //  省略。。。。。。   
  37. 1023 }  

 

 

由此可见,phy设备的添加,是在注册mdio总线的时候。

 

简单地,phy device设备的添加流程:mdiobus_register() ----> mdiobus_scan() ----> phy_device_register() ----> device_register() ----> device_add() 。
platform device 的添加流程:platform_add_devices() ----> device_add()

 

 

原文见:http://blog.youkuaiyun.com/yuanzhenhai/article/details/6394724

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值