在设备树中创建I2C节点,使用i2c_register_board_info()或i2c_new_device()注册设备,并向驱动程序提供I2C地址和设备ID。示例如下:
static struct i2c_board_info i2c_info = {
I2C_BOARD_INFO("device_id", 0x01)
};
static void __init my_driver_i2c_init(void)
{
i2c_register_board_info(0, &i2c_info, 1);
}
static struct i2c_device_id my_driver_i2c_id[] = {
{ "device_id", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, my_driver_i2c_id);
static struct i2c_driver my_driver = {
.driver = {
.name = "my_driver",
.owner = THIS_MODULE,
},
.probe = my_driver_probe,
.remove = my_driver_remove,
.id_table = my_driver_i2c_id,
};
static int my_driver_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
// 驱动程序的处理逻辑
}
static int my_driver_remove(struct i2c_client *client)
{
// 驱动程序的卸载逻辑
}
module_i2c_driver(my_driver);
上一篇:acpiubuntu异常
下一篇:acp认证证书