linuxok6410的I2C驱动分析
发布时间:2016-02-24 21:00:03
3 i2c-dev3.1 概述之前在介绍I2C子系统时,提到过使用i2c-dev.c文件在应用程序中实现我们的I2C从设备驱动。不过,它实现的是一个虚拟,临时的i2c_client,随着设备文件的打开而产生,并随着设备文件的关闭而撤销。I2c-dev.c针对每个I2C适配器 ...
3 i2c-dev
3.1 概述
之前在介绍I2C子系统时,提到过使用i2c-dev.c文件在应用程序中实现我们的I2C从设备驱动。不过,它实现的是一个虚拟,临时的i2c_client,随着设备文件的打开而产生,并随着设备文件的关闭而撤销。I2c-dev.c针对每个I2C适配器生成一个主设备号为89的设备文件,实现了i2c_driver的成员函数以及文件操作接口,所以i2c-dev.c的主题是”i2c_driver成员函数+字符设备驱动”。
3.2 i2c-dev.c源码分析
初始化模块
[cpp] view plaincopy
- static int __init i2c_dev_init(void)
- {
- res= register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops);
-
- i2c_dev_class= class_create(THIS_MODULE, "i2c-dev");
-
- /*Keep track of adapters which will be added or removed later */
- res= bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
-
- /*绑定已经存在的适配器 */
- i2c_for_each_dev(NULL,i2cdev_attach_adapter);
- }
- /* This is the structure as used in theI2C_RDWR ioctl call */
- struct i2c_rdwr_ioctl_data {
- structi2c_msg __user *msgs; /* pointersto i2c_msgs */
- __u32nmsgs; /* number ofi2c_msgs */
- };
- struct i2c_msg {
- __u16addr; /* slave address */
- __u16flags; /* 默认为写入 */
- #define I2C_M_TEN 0x0010 /*this is a ten bit chip address */
- #define I2C_M_RD 0x0001 /* read data,from slave to master */
- #define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */
- #define I2C_M_REV_DIR_ADDR 0x2000 /*if I2C_FUNC_PROTOCOL_MANGLING */
- #define I2C_M_IGNORE_NAK 0x1000 /*if I2C_FUNC_PROTOCOL_MANGLING */
- #define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
- #define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
- __u16len; /* msg length */
- __u8*buf; /* pointer to msgdata */
- };
原标题:linuxok6410的I2C驱动分析
关键词:linux
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。
关键词:https://www.goluckyvip.com/tag/3349.html
海外众筹指南:https://www.goluckyvip.com/tag/33490.html
海外专线:https://www.goluckyvip.com/tag/33492.html
海外专线多少钱:https://www.goluckyvip.com/tag/33493.html
海外专线价格:https://www.goluckyvip.com/tag/33494.html
海外转运:https://www.goluckyvip.com/tag/33495.html
在古巴做游轮 古巴旅游项目:https://www.vstour.cn/a/363194.html
西藏旅游攻略自驾游需要多少天 去西藏旅游自驾游要多久时间:https://www.vstour.cn/a/363195.html