在内核里,i2c 驱动框架大概分为两层,adapter 驱动 和 设备驱动,adapter 英文翻译过来为 “适配器”,适配器并不恰当,根据我的理解,adapter 指的是我们 mcu 里的 i2c 控制模块,就是那堆寄存器,因为一个 mcu 里的i2c控制模块是固定的(寄存器参数、以及收发数据的方法),因此大多数情况下,它们都有芯片厂商写好了,...
* i2c_adapter is the structure used to identify a physical i2c bus along * with the access algorithms necessary to access it. */ struct i2c_adapter { struct module *owner; unsigned int id; unsigned int class; /* classes to allow probing for */ const struct i2c_algorithm *algo; /* the...
adap->owner = THIS_MODULE; adap->algo = &stm32f7_i2c_algo; 1. 2. 注册:i2c_add_adapter/i2c_add_numbered_adapter ret = i2c_add_adapter(adap); // 不管adap->nr原来是什么,都动态设置adap->nr ret = i2c_add_numbered_adapter(adap); // 如果adap->nr == -1 则动态分配nr; 否则使用该n...
inti2c_add_adapter(structi2c_adapter*adapter)inti2c_add_numbered_adapter(structi2c_adapter*adap) 这两个函数的区别在于i2c_add_adapter会动态分配一个总线编号,而i2c_add_numbered_adapter函数则指定一个静态的总线编号。函数参数和返回值含义如下: - adapter或adap:要添加到Linux内核中的i2c_adapter,也就是I2C...
struct i2c_adapter { struct module *owner; unsigned int class; /* classes to allow probing for */ const struct i2c_algorithm *algo; /* the algorithm to access the bus */ void *algo_data; /* data fields that are valid for all devices */ ...
* i2c_adapter is the structure used to identify a physical i2c bus along * with the access algorithms necessary to access it. */ struct i2c_adapter { struct module *owner; unsigned int class; /* classes to allow probing for */
I2C总线驱动重点是 I2C 适配器驱动,这里要用到两个重要的数据结构:i2c_adapter 和 i2c_algorithm。其中,Linux内核将 SOC 的 I2C 适配器(控制器)抽象成 i2c_adapter。 对于一个 I2C 适配器,肯定要对外提供读写 API函数,设备驱动程序可以使用这些 API 函数来完成读写操作。i2c_algorithm 就是 I2C 适配器与 I2C...
删除 i2c_adapter (2)增加/删除 i2c_driver从设备驱动 int i2c_register_driver(struct module *owner...
4.1 i2c_adapter 结构体 定义位置:i2c.h结构体原型: struct i2c_adapter { struct module *owner; unsigned int class; /* classes to allow probing for */ const struct i2c_algorithm *algo; /* the algorithm to access the bus */ void *algo_data; ...
31. i2c_for_each_dev(NULL, i2cdev_detach_adapter); 32. class_destroy(i2c_dev_class); 33. unregister_chrdev(I2C_MAJOR, "i2c"); 34. } 35. module_init(i2c_dev_init); 36. module_exit(i2c_dev_exit); 首先注册了i2cdev_fops操作函数集,接着注册了一个名为”i2c-dev”的class,然后又注册...