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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值