21,597
社区成员
发帖
与我相关
我的任务
分享
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)
static const struct i2c_device_id pca9548_id[] = {
{"pca9548", 1},
{"xxxx-newID", 1}
{}
};
MODULE_DEVICE_TABLE(i2c, pca9548_id);
每个设备加入系统的时候都应该会调用一次probe函数,由probe函数来确定是否支持该设备。