我们知道,platform总线提供了设备和驱动的mach函数,当设备和驱动匹配完成后,就会执行驱动的probe函数,但是这个probe函数是如何被调用的呢。

probe函数在设备驱动注册最后收尾工作,当设备的device 和其对应的driver 在总线上完成配对之后,系统就调用platform设备的probe函数完成驱动注册最后工作。资源、中断调用函数以及其他相关工作。下面是probe被调用的一些程序流程。

1:从注册函数platform_driver_register()函数开始

int platform_driver_register(struct platform_driver *drv)
{drv->driver.bus = &platform_bus_type;if (drv->probe)drv->driver.probe = platform_drv_probe;if (drv->remove)drv->driver.remove = platform_drv_remove;if (drv->shutdown)drv->driver.shutdown = platform_drv_shutdown;return driver_register(&drv->driver);
}

这个函数首先是对驱动进行填充,然后调用driver_register()函数,这个函数是向内核注册驱动的函数,不同的总线最终都是调用这个函数向内核进行驱动的注册。

driver_register(&drv->driver);

bus_add_driver(drv);

driver_attach(drv);

bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);

__driver_attach

__driver_attach函数如下


static int __driver_attach(struct device *dev, void *data)
{struct device_driver *drv = data;/** Lock device and try to bind to it. We drop the error* here and always return 0, because we need to keep trying* to bind to devices and some drivers will return an error* simply if it didn't support the device.** driver_probe_device() will spit a warning if there* is an error.*/if (!driver_match_device(drv, dev))return 0;if (dev->parent)    /* Needed for USB */device_lock(dev->parent);device_lock(dev);if (!dev->driver)driver_probe_device(drv, dev);device_unlock(dev);if (dev->parent)device_unlock(dev->parent);return 0;
}

分析可知,首先是调用driver_mach_device函数进行设备和驱动的匹配(这里应该根据具体的总线来调用相应的mach函数),如果匹配失败则直接return 0,如果匹配成功,则进行下一步,probe函数的调用,probe函数的调用通过driver_probe_device()函数来引出。调用层次如下

driver_probe_device(drv, dev);

really_probe(dev, drv);

really_probe()函数的部分代码如下

if (dev->bus->probe) {ret = dev->bus->probe(dev);if (ret)goto probe_failed;} else if (drv->probe) {ret = drv->probe(dev);if (ret)goto probe_failed;}

分析可知,在驱动和设备匹配成功后,首先会判断总线的的probe指针是否为空,如果不为空,则执行总线的prboe函数,如果总线的prboe函数为空,则进一步判断驱动的probe函数是否为空,如果不为空,则执行驱动的probe函数

转载于:https://blog.51cto.com/11674570/1952431

platform总线的probe函数调用相关推荐

  1. linux驱动模型开发——linux platform总线机制讲解与实例开发

    1.概述: 通常在Linux中,把SoC系统中集成的独立外设单元(如:I2C.IIS.RTC.看门狗等)都被当作平台设备来处理. 从Linux2.6起,引入了一套新的驱动管理和注册机制:Platfor ...

  2. linux platform匹配机制,Linux驱动中的platform总线详解

    platform总线是学习linux驱动必须要掌握的一个知识点. 一.概念 嵌入式系统中有很多的物理总线:I2c.SPI.USB.uart.PCIE.APB.AHB linux从2.6起就加入了一套新 ...

  3. Linux platform总线(1):总体框架

    PlatForm设备驱动: 一.platform总线.设备与驱动 1.一个现实的Linux设备和驱动通常都需要挂接在一种总线上,对于本身依附于PCI.USB.I2 C.SPI等的设备而言,这自然不是问 ...

  4. Linux设备驱动模型之platform总线

    1 平台设备和驱动初识 platform是一个虚拟的地址总线,相比pci,usb,它主要用于描述SOC上的片上资源,比如s3c2410上集成的控制器(lcd,watchdog,rtc等),platfo ...

  5. 【Linux开发】linux设备驱动归纳总结(九):1.platform总线的设备和驱动

    linux设备驱动归纳总结(九):1.platform总线的设备和驱动 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  6. Linux驱动下的platform总线架构(转)

    从 Linux 2.6 内核起,引入一套新的驱动管理和注册机制:platform_device 和 platform_driver .     Linux 中大部分的设备驱动,都可以使用这套机制,设备 ...

  7. 从零开始之驱动发开、linux驱动(二十三、platform总线之数据驱动分离)

    本节开始引入总线概念. 总线是一种虚拟的概念,不针对任何具体的外设,但是它可以比较好的管理外设. 总线对外设的管理从设备和驱动两个方面说明. 比如我们有3个led灯要控制,一种是向我们之前的那样在软件 ...

  8. [linux]platform总线机制与wtd驱动开发

    Linux之platform总线机制与wtd驱动开发 1.概述: 通常在Linux中,把SoC系统中集成的独立外设单元(如:I2C.IIS.RTC.看门狗等)都被当作平台设备来处理. 从Linux2. ...

  9. 设备树下的platform总线-21

    设备树下的platform总线 of _iomap 函数 作用:of iomap函数用于直接内存映射,以前我们会通过ioremap函数来完成物理地址到虚拟地址的映射. 函数原型: #include & ...

最新文章

  1. MIT对话马斯克:关于自动驾驶、爱和未来世界|厚势汽车
  2. Docker 容器技术 — 安装
  3. 浅谈高性能数据库集群——读写分离
  4. 【职场】税前110万
  5. python中case的用法_用 Python 实现简单的 switch/case 语句
  6. 如何不部署Keras / TensorFlow模型
  7. 如何在mysql查询结果集中得到记录行号_获取MySQL查询结果集中记录行号的方法...
  8. 单例销毁_TypeScript 设计模式之单例模式
  9. 夜间排障某省某电信公司后台数据库故障
  10. macOS Big Sur无法识别USB外置驱动器怎么办
  11. 开工利是!循序渐进~
  12. 交易系统开发(二)——行情数据
  13. 依赖hutool压缩文件
  14. python中输入字符串_python如何输入字符串
  15. 实现自动化测试,首先不是一个技术问题
  16. xml 入门 shema_02
  17. 由键盘输入正数n,要求输出如下2*n+1行的菱形图案。用c语言实现。
  18. 特征工程 特征选择 reliefF算法
  19. Linux中定位JAVAHOME
  20. 表单提交成功如何弹出提示

热门文章

  1. dart 替代java_Dart与Java的语法区别
  2. sql 分组后按时间降序排列再取出每组的第一条记录
  3. [HAOI2007]理想的正方形
  4. php和mysql两种不同方式的分割字符串和类型转换
  5. 阿里笔试-二叉树由前序遍历和中序遍历推导后序遍历
  6. Java—数据库技术
  7. 怎么查看SQL SERVER 2000是否打过SP4的补丁
  8. 《城市建筑美学》读书笔记
  9. mysql中数据库覆盖导入的几种方式
  10. 每个Form类都实现了IWin32Window接口!