linux 设备驱动支持多个设备写法

compatible = “aaa,bbb”

当一个驱动支持多个设备的时候,在每个设备的dts中,都会配置各自的compatible,当与driver中的compatible匹配后,会取各自的data。在 __of_match_node中有match++。

Example1

static const struct of_device_id plat_drv_match[] = {
   
    {
    .compatible = "aaa,bbb", .data = &bbb_hw_data},
    {
    .compatible = "aaa,ccc", .data = &ccc_hw_data},
    {
   }
};

data = of_device_get_match_data(dev);

在bbb.dts中,匹配到第1条,data就用第1条
在ccc.dts中,匹配到第2条,data就用第2条

Example2

static const struct of_device_id maxim4c_of_match[] = {
	{
		.compatible = "maxim4c,max96712",
		.data = (const void *)MAX96712_CHIP_ID
	}, {
		.compatible = "maxim4c,max96722",
		.data = (const void *)MAX96722_CHIP_ID
	},
	{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, maxim4c_of_match);

static struct i2c_driver maxim4c_i2c_driver = {
	.driver = {
		.name = MAXIM4C_NAME,
		.pm = &maxim4c_pm_ops,
		.of_match_table = of_match_ptr(maxim4c_of_match),
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值