platform平台device和driver如何匹配【转】

转自:https://www.cnblogs.com/sky-heaven/p/6869591.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Obsession2015/article/details/77933852

device方面:

platform_device_register(struct platform_device *dev)
------platform_device_add(pdev);
----------device_add(&pdev->dev);
--------------bus_probe_device(dev);
-------------------device_attach(dev);
-------------------------bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
-------------------------------driver_match_device(drv, dev);成功才向下执行probe!
-------------------------------------driver_probe_device(drv, dev);
--------------------------------------------really_probe(dev, drv);
----------------------------------------------------dev->bus->probe(dev);或者drv->probe(dev);platform_device_add(pdev);

driver方面:
platform_driver_register(struct platform_driver * drv)
--------driver_register(&drv->driver);
------------bus_add_driver(drv);
-----------------driver_attach(drv);
------------------------bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); 遍历所有节点!
-------------------------------driver_match_device(drv, dev);成功才向下执行probe!
---------------------------------------driver_probe_device(drv, dev);
------------------------------------------------really_probe(dev, drv);
---------------------------------------------------------dev->bus->probe(dev);或者drv->probe(dev);


driver_match_device()  是匹配的关键,实质是上执行:
--------return drv->bus->match ? drv->bus->match(dev, drv) : 1;
------------------.match = platform_match  最终调用bus中的platform_match函数来匹配。


bus_for_each_drv/dev()  函数中:
---------while ((dev = next_device(&i)) && !error)  遍历所有节点;
---------------error = fn(dev, data); 使用id_table匹配方式则可匹配多个设备。
————————————————
版权声明:本文为CSDN博主「Linux匿名者」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/obsession2015/article/details/77933852

posted @ 2019-11-15 16:24  Sky&Zhang  阅读(513)  评论(0编辑  收藏  举报