mini2440 I2C驱动的分析与学习(一)

本文详细介绍了作者在mini2440平台上学习I2C驱动的过程,探讨了如何通过I2C与EEPROM芯片进行数据交互,并分析了I2C驱动中的关键结构体和数据传输流程。在驱动分析中,提到了设备注册、管脚配置以及通过/dev/i2c0进行操作的方法。
摘要由CSDN通过智能技术生成

花了近一个星期的时间学习I2C的驱动,将心得描述如下。I2C是一个典型的较简单的子系统,比较适合学习,因为I2C协议要比PCI等等简单得多。

在mini2440上用I2C连了一块EEPROM的芯片。因此,在mini2440上面说I2C的驱动,主要是说怎么样通过I2C在这块EERPOM上面读写数据。有点像是这个EEPROM的驱动。

先分析几个相关的结构体。其实有时觉得C语言就是以结构体为中心的,基本上把重要的结构体看明白了,程序也就看懂了。

struct s3c24xx_i2c {
	spinlock_t		lock;
	wait_queue_head_t	wait;
	unsigned int		suspended:1;

	struct i2c_msg		*msg;
	unsigned int		msg_num;
	unsigned int		msg_idx;
	unsigned int		msg_ptr;

	unsigned int		tx_setup;
	unsigned int		irq;

	enum s3c24xx_i2c_state	state;
	unsigned long		clkrate;

	void __iomem		*regs;
	struct clk		*clk;
	struct device		*dev;
	struct resource		*ioarea;
	struct i2c_adapter 	adap;

#ifdef CONFIG_CPU_FREQ
	struct notifier_block	freq_transition;
#endif
};

这个结构体其实是代表着i2c所连着的设备。其中state代表设备的状态,resource代表设备相关的IO资源,dev是所有设备都包括的。adap其实代表的就是这个设备连着的I2C总线,I2C总线本身就是一个dev。因为在struct i2c_adapter里面包含有struct device结构体。如下:

/*
 * 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 algorithm to access the bus */
	void *algo_data;

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

	int timeout;			/* in jiffies */
	int retries;
	struct device dev;		/* the adapter device */

	int nr;
	char name[48];
	struct completion dev_released;
};
#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值