was understanding an I2C driver for adxl34x sensor. If I only keep of_device_id, my probe does not gets called, but if I include i2c_device_id probe gets called. I checked for some explanation but I get to know that i2c_device_id is used for legacy purpose or board file matching. Here I am using device tree. How is it possible that i2c_device_id is making the device recognised? Is there a dependency in I2C drivers to use both i2c_Device_id and of_device_id?? here is my understanding on this top id_table is used for legacy i2c devices. See in this code
Code:
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;
}
There is no device id table reference, while of_device_id
Code:
/**
* 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);
}
Uses dev->of_node
So its safe to say both mechanism are isolated and does not depend on each other. Then why my driver is not getting probed by only using this,
Code:
/*
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*/
};
Here are some links that I have gone through in order to get some understanding
https://patches.linaro.org/patch/16873/
https://lists.ozlabs.org/pipermail/l...ly/131965.html
https://i2c.wiki.kernel.org/index.php/OF_Modalias
I understood that first of_* style match will happen, then i2c_device_id type match.
In my case, then how of_* is not able to bind then?
Why i2c_device_table is needed if its legacy thing?