linux的i2c体系结构

i2c体系结构分为3个组成部分:

(1)i2c核心

(2)i2c总线驱动

(3)i2c设备驱动

i2c核心:提供了i2c总线驱动和设备驱动的注册,注销方法,i2c通信方法的上层的,与具体适配器无关的代码以及探测设备,检测设备地址的上层代码等。

i2c总线驱动:对i2c硬件体系结构中适配器的实现,适配器可由CPU控制,甚至可以直接集成在CPU内部。主要包含了i2c适配器数据结构i2c_adapter,i2c适配器的algorithm数据结构i2c_algorithm和控制i2c适配器产生通信信号的函数。

i2c设备驱动:对i2c硬件体系结构中设备端的实现,设备一般挂接在受CPU控制的i2c适配器上,通过i2c适配器与CPU交换数据。


接下来主要描述一下i2c设备驱动的几个关键函数。

1.在内核的i2c.h文件中有这样四个结构体:

i2c_adapter结构体:

333 struct i2c_adapter {
334     struct module *owner;
335     unsigned int id;
336     unsigned int class;       /* classes to allow probing for */
337     const struct i2c_algorithm *algo; /* the algorithm to access the bus */
338     void *algo_data;
339
340     /* data fields that are valid for all devices   */
341     u8 level;           /* nesting level for lockdep */
342     struct mutex bus_lock;
343
344     int timeout;            /* in jiffies */
345     int retries;
346     struct device dev;      /* the adapter device */
347
348     int nr;
349     char name[48];
350     struct completion dev_released;

351 };


i2c_algorithm结构体


struct i2c_algorithm {
313     /* If an adapter algorithm can't do I2C-level access, set master_xfer
314        to NULL. If an adapter algorithm can do SMBus access, set
315        smbus_xfer. If set to NULL, the SMBus protocol is simulated
316        using common I2C messages */
317     /* master_xfer should return the number of messages successfully
318        processed, or a negative value on error */
319     int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
320                int num);
321     int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
322                unsigned short flags, char read_write,
323                u8 command, int size, union i2c_smbus_data *data);
324
325     /* To determine what the adapter supports */
326     u32 (*functionality) (struct i2c_adapter *);

327 };


i2c_driver结构体


136 struct i2c_driver {
137     unsigned int class;
138
139     /* Notifies the driver that a new bus has appeared or is about to be
140      * removed. You should avoid using this if you can, it will probably
141      * be removed in a near future.
142      */
143     int (*attach_adapter)(struct i2c_adapter *);
144     int (*detach_adapter)(struct i2c_adapter *);
145
146     /* Standard driver model interfaces */
147     int (*probe)(struct i2c_client *, const struct i2c_device_id *);
148     int (*remove)(struct i2c_client *);
149
150     /* driver model interfaces that don't relate to enumeration  */
151     void (*shutdown)(struct i2c_client *);
152     int (*suspend)(struct i2c_client *, pm_message_t mesg);
153     int (*resume)(struct i2c_client *);
154
155     /* a ioctl like command that can be used to perform specific functions
156      * with the device.
157      */
158     int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
159
160     struct device_driver driver;
161     const struct i2c_device_id *id_table;
162
163     /* Device detection callback for automatic device creation */
164     int (*detect)(struct i2c_client *, int kind, struct i2c_board_info *);
165     const struct i2c_client_address_data *address_data;
166     struct list_head clients;
167 };


i2c_client结构体

188 struct i2c_client {
189     unsigned short flags;       /* div., see below      */
190     unsigned short addr;        /* chip address - NOTE: 7bit    */
191                     /* addresses are stored in the  */
192                     /* _LOWER_ 7 bits       */
193     char name[I2C_NAME_SIZE];
194     struct i2c_adapter *adapter;    /* the adapter we sit on    */
195     struct i2c_driver *driver;  /* and our access routines  */
196     struct device dev;      /* the device structure     */
197     int irq;            /* irq issued by device     */
198     struct list_head detected;
199 };


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux中的I2C驱动框架包括以下组件: 1. I2C总线驱动:Linux内核中提供了I2C总线的驱动程序,它负责管理I2C总线的物理层面,包括信号线的控制和时序的生成等。 2. I2C核心框架:I2C核心框架是一个抽象层,它提供了一系列API,用于控制I2C总线上的设备。I2C核心框架还提供了一些设备模型的接口,用于管理I2C设备对象。 3. I2C设备驱动:I2C设备驱动负责控制I2C设备的功能,并提供一系列操作接口,供上层应用程序使用。I2C设备驱动通常是实现在内核中的一个模块。 4. 设备树:设备树是一种描述硬件设备的数据结构,它提供了一种统一的方式来描述硬件设备的属性和连接关系。在Linux内核中,每个I2C设备都会被描述为一个设备树节点,设备树节点中包含了I2C设备的地址、频率、寄存器地址等信息。 5. I2C适配器:I2C适配器是一个硬件模块,它负责将I2C总线上的数据转换成物理信号,并将其发送到I2C设备上。I2C适配器可以是一个单独的芯片,也可以是一个集成在SoC中的模块。 6. I2C从设备:I2C从设备是指连接在I2C总线上的各种外设,包括传感器、存储器、温度传感器等。每个I2C从设备都有一个唯一的地址,用于在总线上进行寻址和访问。 总之,Linux中的I2C驱动框架提供了一套完整的体系结构,用于管理和控制I2C总线上的各种设备。开发者可以利用这些组件,轻松地实现自己的I2C设备驱动程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值