了解了i2c总线的主要结构成员及适配器、设备驱动的注册后,现在我们从上而下的来研究一下i2c总线的使用(仍然以i2c-dev.c为例):
1、这是面向用户的虚拟字符设备所提供的所有i2c总线操作接口函数:
static const struct file_operations i2cdev_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = i2cdev_read,
.write = i2cdev_write,
.ioctl = i2cdev_ioctl,
.open = i2cdev_open,
.release = i2cdev_release,
};
1)drivers/i2c/i2c-dev.c
static int i2cdev_open(struct inode *inode, struct file *file)
{
unsigned int minor = iminor(inode);
struct i2c_client *client;
struct i2c_adapter *adap;
struct i2c_dev *i2c_dev;
i2c_dev = i2c_dev_get_by_minor(minor); //通过设备文件的从设备号查找对应的i2c_dev
if (!i2c_dev)
return -ENODEV;
adap = i2c_get_adapter(i2c_dev->adap->nr); //查找对于的adap
if (!adap)
return -ENODEV;
client = kzalloc(sizeof(*client), GFP_KERNEL); //i2c从设备描述结构体
if (!client) {
i2c_put_adapter(adap);
return -ENOMEM;
}
snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
client->driver = &i2cdev_driver;
/* registered with adapter, passed as client to user */
client->adapter = adap;
file->private_data = client;
return 0;
}
注:
i2cdev_open的主要作用是构建并初始化用于描述i2c从设备的结构体struct i2c_client。
2)drivers/i2c/i2c-dev.c
i2cdev_read
-> i2c_master_recv
-> i2c_transfer
-> adap->algo->master_xfer(s3c24xx_i2c_xfer)
3)drivers/i2c/i2c-dev.c
i2cdev_write
-> i2c_master_send
-> i2c_transfer
-> adap->algo->master_xfer(s3c24xx_i2c_xfer)
7)drivers/i2c/busses/i2c-s3c2410.c
s3c24xx_i2c_xfer
-> s3c24xx_i2c_doxfer(wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5)) <----|
-> s3c24xx_i2c_irq |
-> i2s_s3c_irq_nextbyte |
-> s3c24xx_i2c_stop |
-> s3c24xx_i2c_master_complete(wake_up(&i2c->wait))------------------|
posted on 2008-10-05 23:44
lfc 阅读(3776)
评论(0) 编辑 收藏 引用