- 论坛徽章:
- 0
|
本帖最后由 frank529 于 2012-11-01 11:19 编辑
给你个范例吧,XXX是你的设备名,随便定义:- struct xxx_i2c_client;
- struct i2c_driver xxx_i2c_driver ;
- static int xxx_i2c_attach_adapter(struct i2c_adapter *adap)
- {
- xxx_i2c_client.addr = (i2c地址);
- xxx_i2c_client.driver = &xxx_i2c_driver ;
- xxx_i2c_client.adpter = adap;
- i2c_attach_client(&xxx_i2c_client);
- }
- static int xxx_i2c_detach_client(struct i2c_client *client)
- {
- i2c_detach_client(client);
- }
- static struct i2c_driver xxx_i2c_driver =
- {
- .driver = {
- .name = "xxx",
- },
- .attach_adapter = xxx_i2c_attach_adapter,
- .detach_client = xxx_i2c_detach_client,
- };
- static int xxx_i2c_init(void)
- {
- i2c_add_driver(&xxx_i2c_driver);
- }
- static void xxx_i2c_exit(void)
- {
- i2c_del_driver(&xxx_i2c_driver);
- }
- module_init(xxx_i2c_init);
- module_exit(xxx_i2c_exit);
复制代码 通过i2c_add_driver添加I2C设备驱动,内核会调用struct i2c_driver的回调函数attach_adapter,内核传入的参数就是指向你所说的adapter。后面就可以用xxx_i2c_client.adapter作为i2c_transfer的参数。
|
|