1、总线配置结构体:
struct s3c2410_platform_i2c {
unsigned int flags;
unsigned int slave_addr; /* slave address for controller */
unsigned long bus_freq; /* standard bus frequency */
unsigned long max_freq; /* max frequency for the bus */
unsigned long min_freq; /* min frequency for the bus */
unsigned int sda_delay; /* pclks (s3c2440 only) */
};
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 */
};
这里有我画的简单i2c重要结构体分析图:
http://www.cnitblog.com/Files/luofuchong/i2c%E9%87%8D%E8%A6%81%E7%BB%93%E6%9E%84%E4%BD%93.rar
posted on 2008-09-15 23:38
lfc 阅读(2687)
评论(0) 编辑 收藏 引用