我们知道,按platform结构写驱动,我们只需注册platform_device和platform_driver而不需要我们自己去注册platform总线,因为系统启动就有那条总线,那么它是怎么得到的呢?这里进行具体跟踪一下:

start_kernel——>rest_init——>kernel_thread(这个线程创建很重要)——>kernel_init——>do_basic_setup——>driver_init——>platform_bus_init

int __init platform_bus_init(void)
{
 int error;

early_platform_cleanup();

error = device_register(&platform_bus);
 if (error)
  return error;
 error =  bus_register(&platform_bus_type);
 if (error)
  device_unregister(&platform_bus);
 return error;
}

根据platform_bus_type总线类型得

struct bus_type platform_bus_type = {
 .name  = "platform",
 .dev_attrs = platform_dev_attrs,
 .match  = platform_match,//永远记住总线的match函数才是最终的设备与驱动的匹配函数,成功后会调用驱动的probe函数
 .uevent  = platform_uevent,
 .pm  = &platform_dev_pm_ops,
};

这里继续分析匹配过程:

platform_driver_register——>driver_register——>bus_add_driver——>driver_attach——>bus_for_each_dev——>__driver_attach——>driver_match_device——>drv->bus->match——>(*match)(struct device *dev, struct device_driver *drv);
这里找到总线类型中的match函数,这里只是个函数指针,很明显platform_bus_type结构下有具体match的实现,匹配后会自动调用驱动下的probe函数

struct bus_type {
 const char  *name;
 struct bus_attribute *bus_attrs;
 struct device_attribute *dev_attrs;
 struct driver_attribute *drv_attrs;
 do_basic_setup

int (*match)(struct device *dev, struct device_driver *drv);
 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
 int (*probe)(struct device *dev);
 int (*remove)(struct device *dev);
 void (*shutdown)(struct device *dev);

int (*suspend)(struct device *dev, pm_message_t state);
 int (*resume)(struct device *dev);

const struct dev_pm_ops *pm;

struct bus_type_private *p;
};

static int platform_match(struct device *dev, struct device_driver *drv)//platform_bustype匹配函数
{
 struct platform_device *pdev = to_platform_device(dev);
 struct platform_driver *pdrv = to_platform_driver(drv);

/* match against the id table first */
 if (pdrv->id_table)
  return platform_match_id(pdrv->id_table, pdev) != NULL;

/* fall-back to driver name match */
 return (strcmp(pdev->name, drv->name) == 0);
}

接下来看driver的probe函数是如何被调用的:

platform_driver_register——>driver_register——>bus_add_driver——>driver_attach——>bus_for_each_dev——>__driver_attach——>driver_probe_device——>really_probe——>drv->probe——>int (*probe) (struct device *dev)(这个函数指针就指向我们真正填写的device+driver下的probe)

注意:总线、设备、驱动结构中,总线的match函数负责匹配驱动与设备;然后匹配成功后会调用驱动中的probe函数,卸载驱动或设备的时候后调用release函数

platform总线注册过程及platform_driver与platform_device的匹配相关推荐

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. platform总线(Linux驱动开发篇)

    简单介绍platform驱动中的led驱动,input设备驱动,i2c驱动,spi驱动 1.Platform led驱动 最简单的了解platform平台的例子,可以理解为3部分,由驱动层,系统核心层 ...

  10. platform总线

    1.什么是platform总线? platform是Linux内核抽象出来的软件代码,用于设备与驱动的连接,设备与驱动通过总线进行匹配:匹配成功后会执行驱动中的probe函数,在probe函数中可以获 ...

最新文章

  1. 感知器调参之梯度下降法
  2. Android的Style的使用
  3. js图片懒加载的第二种方式
  4. 【Python】调用百度云API人脸搜索服务 Face Search
  5. 大数据Java基础第十九天作业
  6. 洛谷 2759 奇怪的函数
  7. AX2012导Demo数据
  8. mac android 投屏幕,将android/ios屏幕投射到windows/mac的良好参考
  9. 欲练JS,必先攻CSS——前端修行之路
  10. Java模拟文件管理器
  11. java实习实训管理系统ssm
  12. Axure元件-内联框架设计网页
  13. Word 文档中的图片另存为 .jpg 格式图片方法
  14. 页眉怎样从特定的一页开始以及word页眉页脚第几页共几页格式设置
  15. 【现代密码学原理】——消息认证码(学习笔记)
  16. 腾讯数据库TcaplusDB X 黎明觉醒,热血不散,探索不止!
  17. 智能车八邻域图像算法_二
  18. trove 配置文件
  19. 文件名称: 项目利用循环求和 、分数的累加、乘法表
  20. L2-009 抢红包 排序+模拟

热门文章

  1. 如何往一个指定的地址写入一个值呢
  2. 业务层应该返回DataSet/DataTable,还是对象/对象集合?
  3. 游戏娱乐计算机配置方案,计算机配置方案.doc
  4. Linux 进程间通信的六种机制
  5. 【Docker篇之三】Dockerfile创建镜像
  6. ES6的这些新知识你记住了没?
  7. 【22】Vue 之 Vue Devtools
  8. 4.4 Hibernate高级功能
  9. android手机debian 编译nodejs
  10. Windows下安装elastic search