[DESCRIPTION]
在调试光感驱动的过程中,发现调用 i2c_add_driver() 函数注册驱动时没有运行 probe 函数,即没有运行下面示例的 als_i2c_probe() 函数:
#ifdef CONFIG_OF
static const struct of_device_id als_of_match[] =
{
{.compatible = "mediatek,new_als"},
{},
};
#endif
static struct i2c_driver als_i2c_driver =
{
.probe = als_i2c_probe,
.remove = als_i2c_remove,
.detect = als_i2c_detect,
.id_table = als_i2c_id,
.driver = {
.name = ALS_DEV_NAME,
#ifdef CONFIG_OF
.of_match_table = als_of_match,
#endif
},
};
static int als_local_init(void)
{
if (i2c_add_driver(&als_i2c_driver))
{
return -1;
}
return 0;
}
... // 省略部分代码
[SOLUTION]
(1)项目 dts 文件的 i2c 节点配置中存在另一个设备地址相同的 i2c 设备:
&i2c0 {
als_old@46 {
compatible = "mediatek,old_als";
reg = <0x46>;
... // 省略部分属性
status = "okay";
};
als_new@46 {
compatible = "mediatek,new_als";
reg = <0x46>;
... // 省略部分属性
status = "okay";
};
... // 省略部分节点
};
(2)把项目 dts 文件中 i2c 设备节点 als_old@46 删除,als_i2c_probe() 函数可正常运行:
&i2c0 {
als_new@46 {
compatible = "mediatek,new_als";
reg = <0x46>;
... // 省略部分属性
status = "okay";
};
... // 省略部分节点
};