谁在驱动程序代码中调用"探测"功能?

Sag*_*ain 6 c spi linux-device-driver linux-kernel

我想了解这个 mcspi对OMAP2熊猫主板驱动程序代码.

我不明白谁调用了这个probe函数,这个驱动代码中的调用链是什么?

连接设备时如何通知驱动程序?

osg*_*sgx 11

探针功能从spi-omap2-mcspi.c保存在static struct platform_driver omap2_mcspi_driver,其与注册module_platform_driver(omap2_mcspi_driver);(在文件的结尾).module_platform_driverplatform_device.h中定义的 宏将把结构传递给platform_driver_registermacro,并 __platform_driver_registerdrivers/base/platform.c传递

527 /**
528  * __platform_driver_register - register a driver for platform-level devices
529  * @drv: platform driver structure
530  * @owner: owning module/driver
531  */
532 int __platform_driver_register(struct platform_driver *drv,
533                                 struct module *owner)
534 {
...
536         drv->driver.bus = &platform_bus_type;
537         if (drv->probe)
538                 drv->driver.probe = platform_drv_probe;
...
544         return driver_register(&drv->driver);
545 }
546 EXPORT_SYMBOL_GPL(__platform_driver_register);
Run Code Online (Sandbox Code Playgroud)

探针现在driver_registerdrivers/base/driver.c传递给函数

139 /**
140  * driver_register - register driver with bus
141  * @drv: driver to register
142  *
143  * We pass off most of the work to the bus_add_driver() call,
144  * since most of the things we have to do deal with the bus
145  * structures.
146  */
147 int driver_register(struct device_driver *drv)
148 {
...
154         if ((drv->bus->probe && drv->probe) ||
...
167         ret = bus_add_driver(drv);
...
178 }
Run Code Online (Sandbox Code Playgroud)

所以,现在驱动程序已在总线(platform_bus_type)中注册.

实际调用探测是通过driver_probe_device drivers/base/dd.c完成的,然后really_probe(同一文件行265):

265 static int really_probe(struct device *dev, struct device_driver *drv)
266 {
...
270         pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
271                  drv->bus->name, __func__, drv->name, dev_name(dev));
...
287         if (dev->bus->probe) {
288                 ret = dev->bus->probe(dev);       /// <<<< HERE
289                 if (ret)
290                         goto probe_failed;
291         } else if (drv->probe) {
292                 ret = drv->probe(dev);            /// <<<< OR HERE
293                 if (ret)
294                         goto probe_failed;
295         }
296 
297         driver_bound(dev);
298         ret = 1;
299         pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
300                  drv->bus->name, __func__, dev_name(dev), drv->name);
301         goto done;
Run Code Online (Sandbox Code Playgroud)

  • 真的我不能.我只能在互联网上搜索代码或某些网站,可能是这样的:http://www.cprogramdevelop.com/1120807/"注册阶段:Platform_driver_register()> driver_register()> bus_add_driver()> driver_attach()> bus_for_each_dev( ),在每个挂起..平台BUS设备为__driver_attach(),> driver_probe_device()确定drv-> bus-> match()执行成功,通过指针执行platform_match> strncmp(pdev> name,the drv> name,BUS_ID_SIZE)调用really_probe(实际对应设备platform_driver> probe(platform_device)" (2认同)