我当时正在理解一个I2C驱动程序的adxl34x传感器。如果我只保留of_device_id,那么我的探测就不会被调用,但是如果我包含i2c_device_id探测就会被调用。我检查了一些解释,但我知道i2c_device_id用于遗留目的或板文件匹配。这里我使用的是设备树。i2c_device_id怎么可能让这个设备被识别?I2C驱动程序中是否存在同时使用i2c_Device_id和of_device_id的依赖关系?下面是我对这个顶级id_table用于遗留i2c设备的理解。参见这段代码
static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,
const struct i2c_client *client)
{
while (id->name[0]) {
if (strcmp(client->name, id->name) == 0)
return id;
id++;
}
return NULL;
}
没有设备id表引用,而of_device_id
/**
* of_match_device - Tell if a struct device matches an of_device_id list
* @ids: array of of device match structures to search in
* @dev: the of device structure to match against
*
* Used by a driver to check whether an platform_device present in the
* system is in its list of supported devices.
*/
const struct of_device_id *of_match_device(const struct of_device_id *matches,
const struct device *dev)
{
if ((!matches) || (!dev->of_node))
return NULL;
return of_match_node(matches, dev->of_node);
}
使用dev->of_node
因此,可以安全地说,这两种机制是孤立的,不相互依赖。为什么我的司机不用这个来探测,
/*
static const struct i2c_device_id adxl34x_id[] = {
{ "adxl345", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, adxl34x_id);
*/
#ifdef CONFIG_OF
static const struct of_device_id adxl34x_of_id[] = {
/*
* The ADXL346 is backward-compatible with the ADXL345. Differences are
* handled by runtime detection of the device model, there's thus no
* need for listing the "adi,adxl346" compatible value explicitly.
*/
{ .compatible = "adi,adxl345", },
/*
* Deprecated, DT nodes should use one or more of the device-specific
* compatible values "adi,adxl345" and "adi,adxl346".
*/
{ .compatible = "adi,adxl34x", },
{ }
};
MODULE_DEVICE_TABLE(of, adxl34x_of_id);
#endif
static struct i2c_driver adxl34x_driver = {
.driver = {
.name = "adxl34x",
//.pm = &adxl34x_i2c_pm,
.of_match_table = of_match_ptr(adxl34x_of_id),
},
.probe = adxl34x_i2c_probe,
.remove = adxl34x_i2c_remove,
//.id_table = adxl34x_id, /*commented i2c_device_id*/
};
以下是一些我通过的链接,以获得一些了解
https://patches.linaro.org/patch/16873/
https://lists.ozlabs.org/pipermail/linuxppc-dev/2015-July/131965.html
我知道第一次of_*风格的匹配会发生,然后是i2c_device_id类型的匹配。
在我的例子中,那么of_*如何不能绑定呢?
如果i2c_device_table遗留的东西,为什么需要它呢?
发布于 2022-02-11 20:02:45
你是正确的。确实,如果使用探测回调,则需要将id_table与I2C的驱动程序结构一起传递。
这是因为早期的I2C驱动程序框架使用了老式的探测函数签名,该签名要求将i2c_device_id作为第二个参数传递。但是,它现在已经被i2c_probe_new回调所取代,它的函数签名表明它不再需要i2c_device_id参数了。
以下是此代码更改的链接,以供参考:https://elixir.bootlin.com/linux/v5.16.9/source/include/linux/i2c.h#L281
https://stackoverflow.com/questions/50413196
复制相似问题