gpt4 book ai didi

c - 谁在驱动代码中调用了 "probe"函数?

转载 作者:太空狗 更新时间:2023-10-29 17:19:12 26 4
gpt4 key购买 nike

我正在努力理解 this omap2 Pandas 板的mcspi驱动代码。

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

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

最佳答案

spi-omap2-mcspi.c中的探测函数保存在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__platform_driver_register 函数

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 传递给 driver_register 函数

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)。

对探测器的实际调用是通过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;

关于c - 谁在驱动代码中调用了 "probe"函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22722520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com