当前位置: 代码迷 >> 驱动开发 >> linux 下的I2C驱动怎么管理多个相同的设备,设备地址不同
  详细解决方案

linux 下的I2C驱动怎么管理多个相同的设备,设备地址不同

热度:137   发布时间:2016-04-28 10:07:35.0
linux 下的I2C驱动如何管理多个相同的设备,设备地址不同
使用linux提供的I2C的框架,通过id来匹配设备。
如何管理多个相同的设备,设备地址不同

static int pca9548_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
int err;

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 
{
err = -EPFNOSUPPORT;
goto err_out;
}

err = sysfs_create_group(&client->dev.kobj, &attr_group);
if (err)
kobject_put(&client->dev.kobj);

err_out:
return err;
}

static int pca9548_remove(struct i2c_client *client)
{
sysfs_create_group(&client->dev.kobj, &attr_group);
return 0;
}

static const struct i2c_device_id pca9548_id[] = {
{"pca9548", 1},
{}
};
MODULE_DEVICE_TABLE(i2c, pca9548_id);

static struct i2c_driver pca9548_driver = {
.driver = 
{
.name  = "pca9548",
.owner = THIS_MODULE,
},
.probe = pca9548_probe,
.remove = pca9548_remove,
.id_table = pca9548_id,
};

static int __init pca9548_init(void)
{
return i2c_add_driver(&pca9548_driver);
}
module_init(pca9548_init);

static void __exit pca9548_exit(void)
{
i2c_del_driver(&pca9548_driver);
}
module_exit(pca9548_exit)

------解决方案--------------------
管理多个设备?这个完全就是i2c协议定义中的。从设备是发了自己的地址了才会回信息的,这个就好比班上老师点名回答问题一样样的。本来就可以管理了的。
------解决方案--------------------
驱动程序可能不需要做太多工作。
三个设备接入系统之后,I2C总线会创建3个不同的Node,然后,你的驱动程序就会被加载。最后结果是,每个设备都有自己的驱动程序实例,互相之间不会有干扰和依赖。