[Q&A23102]调用 i2c_add_driver() 函数注册驱动时没有运行 probe 函数

[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";
	};

    ... // 省略部分节点
};

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值