谁称之为“探针"?驱动程序代码中的功能? [英] Who calls "probe" function in driver code?

查看:22
本文介绍了谁称之为“探针"?驱动程序代码中的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解这个 用于 omap2 熊猫板的 mcspi 驱动程序代码.

I am trying to understand this driver code of mcspi for omap2 panda board.

我不明白谁调用了probe 函数以及这个驱动代码?

I don't understand who calls the probe function and what is the call chain in this driver code?

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

How does the driver is informed when the device is connected?

推荐答案

spi-omap2-mcspi.c中的probe函数保存在static struct platform_driver omap2_mcspi_driver, 使用 module_platform_driver(omap2_mcspi_driver); 注册(在文件末尾).module_platform_driver 宏,定义在 platform_device.h 会将结构传递给 platform_driver_register 宏和 drivers/base/platform.c

The probe function from spi-omap2-mcspi.c is saved in the static struct platform_driver omap2_mcspi_driver, which is registered with module_platform_driver(omap2_mcspi_driver); (at the end of file). The module_platform_driver macro, defined in platform_device.h will pass the struct to platform_driver_register macro and __platform_driver_register function from drivers/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);

探针现在从 drivers/base/driver.c

The probe now passed to driver_register function from drivers/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 }

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

So, now the driver is registered in the bus (platform_bus_type).

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

Actual call to probe is done via driver_probe_device drivers/base/dd.c, then really_probe (same file line 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
",
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
",
300                  drv->bus->name, __func__, dev_name(dev), drv->name);
301         goto done;

这篇关于谁称之为“探针"?驱动程序代码中的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆