I have a similar case and finally found the explanation:
There seems to be an undocumented twist in the device tree i2c device binding.
Lets look at i2c_device_match() (i2c-core-base.c):
/* Attempt an OF style match */
if (i2c_of_match_device(drv->of_match_table, client))
return 1;
And what actually happens in i2c_of_match_device() (i2c-core-of.c)?:
*i2c_of_match_device(const struct of_device_id *matches,
struct i2c_client *client){
const struct of_device_id *match;
if (!(client && matches))
return NULL;
match = of_match_device(matches, &client->dev);
if (match)
return match;
return i2c_of_match_device_sysfs(matches, client); }
Hmm, we first try Open Firmware-style match with compatible fields, but if that fails, we still call i2c_of_match_device_sysfs().
And what does it do?
i2c_of_match_device_sysfs(const struct of_device_id *matches,
struct i2c_client *client) {
const char *name;
for (; matches->compatible[0]; matches++) {
/*
* Adding devices through the i2c sysfs interface provides us
* a string to match which may be compatible with the device
* tree compatible strings, however with no actual of_node the
* of_match_device() will not match
*/
if (sysfs_streq(client->name, matches->compatible))
return matches;
name = strchr(matches->compatible, ',');
if (!name)
name = matches->compatible;
else
name++;
if (sysfs_streq(client->name, name))
return matches;
}
return NULL; }
BINGO!
As you can see in the code, i2c_of_match_device_sysfs() compares the compatible string from the Device Tree to name field of the driver i2c_device_id.
In addition, if there is a comma in the compatible field, the matching will be done for the part following the comma.
So in your case, device tree data
compatible = "adv7ex"
is matched against "adv7ex" in
static struct i2c_device_id adv7ex_id[] = {
{ "adv7ex", ADV7EX },
{ } };
MODULE_DEVICE_TABLE(i2c, adv7ex_id);
Even if your compatible would be "acme-inc,adv7ex", as is the recommended notation for Device tree, it would still be matched.