努力成为linux kernel hacker的人李万鹏原创作品,为梦而战。转载请标明出处
http://blog.csdn.net/woshixingaaa/archive/2011/05/21/6436172.aspx
首先看一下我的系统中都有什么设备挂在了platform虚拟总线上:
platform的初始化:首先系统启动的时候会调用platform_bus_init来初始化这个虚拟总线,让后向虚拟总线注册即将挂载这条总线上的设备。platform_bus_type部分是内核为我们实现好的,我们只关系platform_device与platform_driver就行了。
记住总线也是一种设备,所以首先注册总线设备,然后注册总线。
把设备挂到platform总线上:
首先来看一个重要的数据结构:
设备的分配:
设备的注册:
获取资源:
/*dev:资源所属的设备,type:获取的资源类型,num:获取的资源数*/
这里详述platform_device与platform_driver是怎样匹配上的,这里跟踪函数的执行过程,首先是platform_driver_register:
这里来看__driver_attach这个函数,其中分别调用了driver_match_device,driver_probe_device函数。如果匹配成果调用probe函数,否则返回。
匹配的时候调用的bus的match函数。
找到platform_match:
最后一行可以看到通过pdev->name与drv->name进行匹配,也就是说是通过设备与驱动的名字进行匹配。匹配成功后调用驱动的probe函数。
由relly_probe函数可以看出,如果bus定义了probe函数,则调用bus的probe函数;如果bus,没有定义而driver定义了probe函数,则调用driver的probe函数。由上边的platform_bus_type可以看出bus并没有定义probe函数,所以调用driver的probe函数。
测试程序:
device.c
driver.c
测试效果:
分享到:
相关推荐
Linux驱动修炼之道-platform.pdf Linux驱动修炼之道-LCD背光与gpio控制.pdf Linux驱动修炼之道-INPUT子系统(下).pdf Linux驱动修炼之道-INPUT子系统(上).pdf Linux驱动修炼之道-framebuffer(中).pdf ...
赠送jar包:jna-platform-5.10.0.jar; 赠送原API文档:jna-platform-5.10.0-javadoc.jar; 赠送源代码:jna-platform-5.10.0-sources.jar; 赠送Maven依赖信息文件:jna-platform-5.10.0.pom; 包含翻译后的API文档...
junit-platform-launcher-1.7.0.jarjunit-platform-launcher-1.7.0.jar
artoolkitplus-linux-armhf.jar artoolkitplus-linux-ppc64le.jar artoolkitplus-linux-x86.jar artoolkitplus-linux-x86_64.jar artoolkitplus-platform.jar artoolkitplus-windows-x86.jar artoolkitplus-windows-...
javacv-platform-1.5.1-source.zip
junit-platform-launcher-1.6.2.jarjunit-platform-launcher-1.6.2.jarjunit-platform-launcher-1.6.2.jar
get-platformio.py get-platformio.py get-platformio.py get-platformio.py
赠送jar包:junit-platform-launcher-1.8.0-M1.jar; 赠送原API文档:junit-platform-launcher-1.8.0-M1-javadoc.jar; 赠送源代码:junit-platform-launcher-1.8.0-M1-sources.jar; 赠送Maven依赖信息文件:junit-...
赠送jar包:jna-platform-4.1.0.jar; 赠送原API文档:jna-platform-4.1.0-javadoc.jar; 赠送源代码:jna-platform-4.1.0-sources.jar; 赠送Maven依赖信息文件:jna-platform-4.1.0.pom; 包含翻译后的API文档:...
赠送jar包:junit-platform-launcher-1.8.0-M1.jar; 赠送原API文档:junit-platform-launcher-1.8.0-M1-javadoc.jar; 赠送源代码:junit-platform-launcher-1.8.0-M1-sources.jar; 赠送Maven依赖信息文件:junit-...
junit-platform-launcher-1.3.1.jar
JNA-5.7.0 jna-platform-5.7.0
javacv-platform-1.5.5-bin,javacv运行所需jar包,包含samples
赠送jar包:junit-platform-commons-1.8.2.jar; 赠送原API文档:junit-platform-commons-1.8.2-javadoc.jar; 赠送源代码:junit-platform-commons-1.8.2-sources.jar; 赠送Maven依赖信息文件:junit-platform-...
Write native cross-platform applications with Xamarin Design user interfaces that can be shared across Android, iOS, and Windows Phone using Xamarin.Forms Practical cross-platform development ...
jna-platform-5.5.0.jar
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition by Mark J. Price English | 24 Mar. 2017 | ASIN: B01N8UG78Q | 594 Pages | AZW3 | 23.26 MB Modern Cross-Platform Development ...
赠送jar包:junit-platform-launcher-1.6.1.jar; 赠送原API文档:junit-platform-launcher-1.6.1-javadoc.jar; 赠送源代码:junit-platform-launcher-1.6.1-sources.jar; 赠送Maven依赖信息文件:junit-platform-...
赠送jar包:junit-platform-commons-1.8.2.jar; 赠送原API文档:junit-platform-commons-1.8.2-javadoc.jar; 赠送源代码:junit-platform-commons-1.8.2-sources.jar; 赠送Maven依赖信息文件:junit-platform-...