V5.10
参考文档:Documentation/i2c/writing-clients.rst
static struct i2c_device_id foo_idtable[] = {{ "foo", my_id_for_foo },{ "bar", my_id_for_bar },{ }};MODULE_DEVICE_TABLE(i2c, foo_idtable);static struct i2c_driver foo_driver = {.driver = {.name = "foo",.pm = &foo_pm_ops, /* optional */},.id_table = foo_idtable,.probe = foo_probe,.remove = foo_remove,/* if device autodetection is needed: */.class = I2C_CLASS_SOMETHING,.detect = foo_detect,.address_list = normal_i2c,.shutdown = foo_shutdown, /* optional */.command = foo_command, /* optional, deprecated */}
创建设备
章节:Device Creation
-
情景一、已知设备连接总线与地址
i2c_new_client_device(),通过实例化(地址与设备名)结构体i2c_board_info后即创建了设备,此时I2C核心会自动识别并匹配(调用probe)该设备对应的驱动。
-
情景二、已知设备连接的I2C总线号但不知道地址
i2c_new_scanned_device(),可以列出可能的匹配的I2C地址。
删除设备
i2c_unregister_device()
初始化设备
static int __init foo_init(void){return i2c_add_driver(&foo_driver);}module_init(foo_init);static void __exit foo_cleanup(void){i2c_del_driver(&foo_driver);}module_exit(foo_cleanup);
等效于:
module_i2c_driver(foo_driver);
待完善。。。