i2c关键结构体分析

1、总线配置结构体:
struct s3c2410_platform_i2c {
    int        bus_num; //总线条数
    unsigned int    flags;
    unsigned int    slave_addr;//从机地址
    unsigned long    frequency;//频率
    unsigned int    sda_delay;//sda传送延时

    void    (*cfg_gpio)(struct platform_device *dev);
};

2、总线描述结构体:
struct s3c24xx_i2c {
        spinlock_t              lock;        //自选锁(防止总线资源被并发访问)
        wait_queue_head_t       wait;        //等待队列(当有数据需要收/发时启动总线,然后守候在等待队列,直到数据收/发结束后被唤醒返回)

        struct i2c_msg          *msg;        //i2c信息指针
        unsigned int            msg_num;    //需要传输的i2c msg数
        unsigned int            msg_idx;    //成功传输的i2c msg数
        unsigned int            msg_ptr;    //当前i2c msg内指针

        unsigned int            tx_setup;    //延时值(保证总线启动时数据已经传输到总线上)

        enum s3c24xx_i2c_state  state;        //i2c总线状态

        void __iomem            *regs;:
        struct clk              *clk;
        struct device           *dev;
        struct resource         *irq;
        struct resource         *ioarea;
        struct i2c_adapter      adap;        //总线适配器(个人觉得它更像设备驱动中的设备而非驱动)
};

3、总线适配器:
struct i2c_adapter {
        struct module *owner;
        unsigned int id;
        unsigned int class;
        const struct i2c_algorithm *algo;             //i2c总线访问算法
        void *algo_data;                    //用来保存struct s3c24xx_i2c结构指针

        /* --- administration stuff. */
        int (*client_register)(struct i2c_client *);
        int (*client_unregister)(struct i2c_client *);

        /* data fields that are valid for all devices   */
        u8 level;                                   //nesting level for lockdep
        struct mutex bus_lock;
        struct mutex clist_lock;

        int timeout;
        int retries;
        struct device dev;                          //the adapter device

        int nr;
        struct list_head clients;
        struct list_head list;
        char name[48];
        struct completion dev_released;
};

4、总线访问算法:
struct i2c_algorithm {
        /* If an adapter algorithm can't do I2C-level access, set master_xfer
           to NULL. If an adapter algorithm can do SMBus access, set
           smbus_xfer. If set to NULL, the SMBus protocol is simulated
           using common I2C messages */
        /* master_xfer should return the number of messages successfully
           processed, or a negative value on error */
        int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg *msgs,    //i2c msg发送函数
                           int num);
        int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
                           unsigned short flags, char read_write,
                           u8 command, int size, union i2c_smbus_data * data);

        /* --- ioctl like call to set div. parameters. */
        int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);

        /* To determine what the adapter supports */
        u32 (*functionality) (struct i2c_adapter *);                //标志i2c适配器所支持的功能
};

struct i2c_msg {
        __u16 addr;     /* slave address                        */
        __u16 flags;
#define I2C_M_TEN       0x10    /* we have a ten bit chip address       */
#define I2C_M_RD        0x01
#define I2C_M_NOSTART   0x4000
#define I2C_M_REV_DIR_ADDR      0x2000
#define I2C_M_IGNORE_NAK        0x1000
#define I2C_M_NO_RD_ACK         0x0800
#define I2C_M_RECV_LEN          0x0400 /* length will be first received byte */
        __u16 len;              /* msg length                           */
        __u8 *buf;              /* pointer to msg data                  */
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值