Linux kernel 谁调用驱动程序的probe()
如何调用Linux kernel 谁调用驱动程序的probe(),linux-kernel,linux-device-driver,Linux Kernel,Linux Device Driver,如何调用probe()调用?谁叫它?根据我的理解,\uu init()注册驱动程序,然后调用探测(),以注册设备数据和irq等。具体情况如何 我正在使用触摸屏驱动程序,它的\uu init将自己注册到i2c驱动程序。然后探测expecti2c\u client返回null的数据。我想跟踪它的填充位置。长话短说:调用特定总线的寄存器驱动程序后,会调用驱动程序的probe()函数。更准确地说,它由bus\u类型的probe()结构调用。在您的情况下:i2c\u总线类型 以下是I2C案例中的调用链:
probe()
调用?谁叫它?根据我的理解,\uu init()
注册驱动程序
,然后调用探测()
,以注册设备数据和irq
等。具体情况如何
我正在使用触摸屏驱动程序,它的\uu init
将自己注册到i2c驱动程序。然后探测expecti2c\u clien
t返回null的数据。我想跟踪它的填充位置。长话短说:调用特定总线的寄存器驱动程序后,会调用驱动程序的probe()函数。更准确地说,它由bus\u类型的probe()
结构调用。在您的情况下:i2c\u总线类型
以下是I2C案例中的调用链:
- i2c_寄存器_驱动器
- 驱动寄存器
- 总线添加驱动程序
- 驾驶员附加
- __驱动程序\u连接(适用于您的设备)
- 驱动探头装置
- 真的吗
- i2c_设备_探测器(这是i2c驱动程序的dev->bus->probe)
- 你的探测功能
当name将窗体驱动程序结构与设备结构匹配时,将调用探测函数。下面提到了驱动程序和设备结构的eg
1:驱动器结构
static struct driver your_driver = {
.driver = {
.name = YUR_NAME,
},
static structure device your_devices = {
.name = YUR_NAME,
},
例如
2:器件结构
static struct driver your_driver = {
.driver = {
.name = YUR_NAME,
},
static structure device your_devices = {
.name = YUR_NAME,
},
例如
注意:当驱动程序和设备的名称(l3gd20_gyr)匹配时,您的探测器将被调用。@iSegFault:将调用probe(),以确保设备存在且功能正常。如果设备不可热插拔,则probe()的功能可以放在init()中方法。这将减少驱动程序的运行时内存占用。附言
Probe()发生在设备启动时或设备连接时。对于“平台”设备,当平台设备注册且其设备名称与设备驱动程序上指定的名称匹配时,将调用Probe函数。附言
i2c_detect函数探测i2c适配器,查找addr_数据结构中指定的不同地址。如果找到设备,则调用芯片检测功能。附言
一个链接肯定会消除你的疑虑。附言
在内核2.4.29中,我可以向您展示探测是如何发生的?请参见下面(文件名:drivers/acorn/char/pcf8583.c)
文件名:驱动程序/i2c/i2c核心.c
static struct i2c_driver pcf8583_driver = {
name: "PCF8583",
id: I2C_DRIVERID_PCF8583,
flags: I2C_DF_NOTIFY,
attach_adapter: pcf8583_probe, /* This will be called from i2c-core.c P.S see below function i2c_add_driver()*/
detach_client: pcf8583_detach,
command: pcf8583_command
};
int i2c_add_driver(struct i2c_driver *driver)
{
........................
........................
/* now look for instances of driver on our adapters
*/
if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
for (i=0;i<I2C_ADAP_MAX;i++)
if (adapters[i]!=NULL)
/* Ignore errors */
driver->attach_adapter(adapters[i]); /*This is a location from where probe is called. Pointer **driver** is of type **pcf8583_driver** which you have passed into this function*/
}
ADAP_UNLOCK();
return 0;
}
static int pci_announce_device(struct pci_driver *drv, struct pci_dev *dev)
{
const struct pci_device_id *id;
int ret = 0;
if (drv->id_table) {
id = pci_match_device(drv->id_table, dev); /* check for device presence*/
if (!id) {
ret = 0;
goto out;
}
} else
id = NULL;
dev_probe_lock();
if (drv->probe(dev, id) >= 0) { /* This is a location from where probe is called*/
dev->driver = drv;
ret = 1;
}
dev_probe_unlock();
out:
return ret;
}
除已注册的接口外,检测设备的每个接口都将调用Probe函数 我已经准备了一张图表来跟踪平台驱动器的探测功能。您正在使用I2C驱动程序,AFAIK是一个平台驱动程序。我希望这有助于你追踪这个问题
另外,查看下面的链接以查看关于内核新手的讨论
让我们考虑一个例子:<代码>平台设备驱动程序< /代码>:
driver->probe()
回调的启动触发函数是加载驱动程序时调用的模块初始化()
宏;此宏
在include/linux/module.h
中定义
module\u init(my\u driver\u init)
具有对my\u driver\u init()
函数的回调my\u driver\u init()
函数应该调用platform\u driver\u寄存器(my\u driver)
platform\u driver\u register(my\u driver)
将my\u driver->probe()
句柄分配给genericdrv->probe()
并调用driver\u register(my\u driver)
函数
driver\u register(my\u driver)
函数将my\u driver
添加到平台总线,并调用driver\u attach()
函数
同样,即使是platform\u设备
也需要连接到平台总线
最后,只有当驱动程序的匹配\u设备()
基于驱动程序的名称和.id\u表
在来自ACPI/DTS
的平台设备列表中匹配时,才会调用具有drv->probe()的驱动程序探测设备()
回调
什么时候调用i2c\u寄存器\u驱动程序?是在调用i2cdetect
并在总线上找到一个名称与注册的struct i2c\u驱动程序匹配的设备时发生的吗?