当前位置: 首页 > news >正文

Linux网络驱动之Fixed-Link(18)

接前一篇文章:Linux网络驱动之Fixed-Link(17)

本文内容参考:

linux phy fixed-link-CSDN博客

linux phy处理流程一:探测phy设备_phy link过程-CSDN博客

linux phy处理流程三:fixed-link处理-CSDN博客

ARM与交换芯片mac_to_mac固定模式总结_mac to mac-CSDN博客

rk3399 mac to mac 连接switch - tccxy - 博客园

特此致谢!

三、深入了解

前边用了几个回目的篇幅讲解了of_mdiobus_register和mdiobus_register函数的区别。本回要回归到当初引出这段讲解的地方,参见Linux网络驱动之Fixed-Link(13)-CSDN博客:

之前先围绕着第3个函数调用:

ret = mdiobus_register(fmb->mii_bus);

进行了深入解析。现在要拉回来,讲解第1个函数调用:

pdev = platform_device_register_simple("Fixed MDIO bus", 0, NULL, 0); if (IS_ERR(pdev)) return PTR_ERR(pdev);

platform_device_register_simple函数是一个内联函数,在kernel/linux-5.10-origin/include/linux/platform_device.h中,代码如下:

/** * platform_device_register_simple - add a platform-level device and its resources * @name: base name of the device we're adding * @id: instance id * @res: set of resources that needs to be allocated for the device * @num: number of resources * * This function creates a simple platform device that requires minimal * resource and memory management. Canned release function freeing memory * allocated for the device allows drivers using such devices to be * unloaded without waiting for the last reference to the device to be * dropped. * * This interface is primarily intended for use with legacy drivers which * probe hardware directly. Because such drivers create sysfs device nodes * themselves, rather than letting system infrastructure handle such device * enumeration tasks, they don't fully conform to the Linux driver model. * In particular, when such drivers are built as modules, they can't be * "hotplugged". * * Returns &struct platform_device pointer on success, or ERR_PTR() on error. */ static inline struct platform_device *platform_device_register_simple( const char *name, int id, const struct resource *res, unsigned int num) { return platform_device_register_resndata(NULL, name, id, res, num, NULL, 0); }

platform_device_register_simple函数说明如下:

函数原型

static inline struct platform_device *platform_device_register_simple(
const char *name, int id,
const struct resource *res, unsigned int num);

函数功能

添加平台级设备及其资源。

此函数创建了一个需要最少资源和内存管理的简单平台设备。释放为设备所分配内存的封装函数,允许使用此类设备的驱动程序被卸载,而无需等待删除对设备的最后一次引用。

此接口主要用于直接探测硬件的传统驱动程序。因为这样的驱动程序自己创建sysfs设备结点,而不是让系统基础设施处理这样的设备枚举任务,因此它们并不完全符合Linux驱动程序模型。特别地,当这些驱动程序被构建(编译)为模块时,它们不能被“热插拔”。

参数说明

  • name:要添加的设备的基本名称
  • id:实例id
  • res:需要为设备分配的资源集
  • num:资源的数量

返回值

成功返回指向struct platform_device的指针;失败返回ERR_PTR。

对照着上边实际调用进行理解:

pdev = platform_device_register_simple("Fixed MDIO bus", 0, NULL, 0); if (IS_ERR(pdev)) return PTR_ERR(pdev);

要添加的平台级设备名称为"Fixed MDIO bus";实例id为0;不需要分配资源(集);资源的数量为0。

真正完成工作的是platform_device_register_resndata函数。它也在include/linux/platform_device.h中(就在上边),代码如下:

/** * platform_device_register_resndata - add a platform-level device with * resources and platform-specific data * * @parent: parent device for the device we're adding * @name: base name of the device we're adding * @id: instance id * @res: set of resources that needs to be allocated for the device * @num: number of resources * @data: platform specific data for this platform device * @size: size of platform specific data * * Returns &struct platform_device pointer on success, or ERR_PTR() on error. */ static inline struct platform_device *platform_device_register_resndata( struct device *parent, const char *name, int id, const struct resource *res, unsigned int num, const void *data, size_t size) { struct platform_device_info pdevinfo = { .parent = parent, .name = name, .id = id, .res = res, .num_res = num, .data = data, .size_data = size, .dma_mask = 0, }; return platform_device_register_full(&pdevinfo); }

对于该函数的解析,请看下回。

http://www.jsqmd.com/news/483545/

相关文章:

  • Leather Dress Collection参数详解:Sampling Method对皮革纹理锐度的影响分析
  • 永磁同步电机最大转矩电流比控制(MTPA)+弱磁控制的仿真模型设计与实现
  • 收藏!2026程序员破局指南:高价值赛道已切换,大模型应用开发才是高薪密码
  • 基于SVPWM改进的异步电机/感应电机直接转矩控制的纹波优化“参考文献:[此处可添加具...
  • 【活动获奖作品】基于MPS MP28167-A与CH244K的3A升降压电源适配器设计与调试全记录
  • 甲方云安全:阿里云 / 华为云安全配置最佳实践
  • all-MiniLM-L6-v2进阶使用:多格式模型管理与版本控制策略解析
  • 2 模型预训练、微调、强化学习的格式
  • C语言学习-2.编程基础篇
  • 2026年黑龙江基坑支护实力企业综合评估与选购指南 - 2026年企业推荐榜
  • 【黑马点评二刷日记】优惠券秒杀下单
  • 第八章 第一性原理:人生决策与自我管理的底层公理
  • MATLAB代码:拉丁超立方采样技术在风光场景生成与削减中的应用
  • 2026年Q1武汉租车连锁店综合实力深度评测 - 2026年企业推荐榜
  • 复试第十四天
  • 2026年专业寻猫服务价格解析与品牌推荐 - 2026年企业推荐榜
  • 为什么DataGrip进软件的时候连接超时:connect timed out X Check region settings......如何解决?
  • 光伏PCS:储能双向功率换流器-包含双向DC/DC、3 Level逆变器、仿真与源码、原理图P...
  • 2026.3.13+14 CAD学习六--【第二张图】椭圆EL、等轴测圆EL-i、多边形POL
  • 感应电机MPTC实战手记:从代码里看磁场舞蹈
  • Linux 的 base32 命令
  • 2026年3月14日GESP五级现场直击
  • Flutter 三方库 translations_code_gen 鸿蒙适配指南 - 实现强类型国际化资产自动化编译、在 OpenHarmony 上打造编译时安全的多语言工作流实战
  • Simulink中的Boost电路模块搭建与多种闭环控制策略:传递函数验证、参数整定与伯德图分析
  • 探索 M00292:多算法雷达一维恒虚警检测 CFAR 可视化系统
  • 57c1-2四轮轮毂电机驱动汽车的DYC直接横摆力矩稳定性控制,上层控制器DYC产生横摆力矩Mz
  • Qwen2.5-72B-GPTQ-Int4效果惊艳:128K长文档关键信息定位与问答
  • 亚像素以及实现原理、方法
  • PMSM传统滑模观测器+PLL仿真模型,加上了相位补偿观测波形与实际波形基本重合。 以下图一为...
  • Flutter 三方库 aws_sqs_api 鸿蒙适配指南 - 实现分布式消息异步解耦、在 OpenHarmony 上打造高可用云端队列控制中枢实战