通用驱动i2c-dev分析
参考资料:
Linux驱动程序:
drivers/i2c/i2c-dev.cI2C-Tools-4.2:
https://mirrors.edge.kernel.org/pub/software/utils/i2c-tools/AT24cxx.pdf
通用的i2c-dev驱动走的还是字符设备驱动那一套,怎么编写字符设备驱动程序?
创建file_operations结构体吗,在里面填充drv_open/drv_read/drv_ioctl等函数
入口函数调用
register_chrdev(major, &fops, name)注册file_operations结构体创建类class_create
在类型创建设备节点 device_create
i2c-dev.c注册过程分析
i2c-dev驱动的注册过程
image-20210226164128588
file_operations函数分析
i2c-dev.c的核心:
static const struct file_operations i2cdev_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = i2cdev_read,
.write = i2cdev_write,
.unlocked_ioctl = i2cdev_ioctl,
.compat_ioctl = compat_i2cdev_ioctl,
.open = i2cdev_open,
.release = i2cdev_release,
};
主要的系统调用:open, ioctl:
image-20210226165250492
i2cdev_open
image-20210226170350844
i2cdev_ioctl: 设置器件地址 I2C_SLAVE/I2C_SLAVE_FORCE
image-20210226172800990
i2cdev_ioctl: 传输数据i2c的形式 I2C_RDWR
image-20210226173625871
i2cdev_ioctl: 传输数据smbus的形式I2C_SMBUS

总结
