当前位置:网站首页>内核判断i2c地址上是否挂载外设
内核判断i2c地址上是否挂载外设
2022-07-06 04:38:00 【永不秃头的程序员】
记录一个方法去判断i2c地址上是否挂载外设。
使用场景,两个驱动使用同一个复位脚和中断脚,使用同一个外设接口,不允许同时使用,只是挂载的i2c地址不一样,思路为注册驱动的时候去读取这个寄存器的值,通过返回值去判断是存在对因的外设。
一、代码修改
dits配置
i2c4{
[email protected]2a {
reg = <0x2a>;
compatible = "eeti,egalax_i2c";
interrupt-parent = <&gpio4>;
interrupts = <13 2>;
int-gpios = <&gpio4 13 0>;
reset-gpios = <&gpio4 12 0>;
};
[email protected]5d {
compatible = "goodix,gt928_ts";
reg = <0x5d>;
irq-gpios = <&gpio4 13 0>;
reset-gpios = <&gpio4 12 0>;
};
};
再对应的peobe函数里添加如下判断:
使用函数为i2c_smbus的读取接口:
/*相关函数再 kernel的 inlcude/linux/i2c.h中 *s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command); *const struct i2c_client *client 是你外设指定的i2c总线 *u8 command 8位地址 */
/*vol是返回值,如果不存在那么就返回一个负数*/
/*使用这个函数之前需要将client的值先赋予这样才能通过I2C接口函数去读取*/
vol = i2c_smbus_read_byte_data(p_egalax_i2c_dev->client, p_egalax_i2c_dev->client->addr);
if (vol < 0) {
printk("cluo---> vol 0x%x = %d", client->addr, vol);
return -ENODEV;
}
通过插入不同的外设,可以看到不同的打印信息。
[ 3.430773] cluo---> vol 0x2a = -6
[ 3.434279] cluo---> eglax_tp probe error
[ 4.542063] cluo---> vol 0x5d = 0
[ 4.596902] cluo---> goodix probe success
[ 3.448004] cluo---> nret 0x2a = -6
[ 3.451509] cluo---> eglax_tp probe error
[ 4.571818] cluo---> vol 0x5d = -6
[ 4.575928] cluo---> goodix probe error
[ 3.455065] cluo---> nret 0x2a = 2
[ 3.466904] cluo---> egalax probe success
[ 4.592851] cluo---> vol 0x5d = -6
[ 4.596902] cluo---> goodix probe error
二、实现原理
因为驱动都能单独加载成功,目的是避免驱动去对gpio进行操作,因为他们使用的都是同一个gpio,所以不能让他们再驱动中对gpio进行申请,因为一旦申请后就会导致宁外一个gpio不能对该gpio进行操作。所以需要将这个判断函数添加再gpio申请之前。
边栏推荐
- CADD课程学习(8)-- 化合物库虚拟筛选(Virtual Screening)
- ETCD数据库源码分析——etcdserver bootstrap初始化存储
- Digital children < daily question> (Digital DP)
- 729. 我的日程安排表 I(set or 动态开点线段树)
- Figure application details
- Coreldraw2022 new version new function introduction cdr2022
- View 工作流程
- JVM garbage collector concept
- [HBZ sharing] how to locate slow queries in cloud database
- Delete subsequence < daily question >
猜你喜欢
ETCD数据库源码分析——etcdserver bootstrap初始化存储
电脑钉钉怎么调整声音
RTP GB28181 文件测试工具
[face recognition series] | realize automatic makeup
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
Coreldraw2022 new version new function introduction cdr2022
Embedded development program framework
随机推荐
NPM command -- install dependent packages -- Usage / explanation
Fuzzy -- basic application method of AFL
Lambda expression learning
How does vs change the project type?
QML和QWidget混合开发(初探)
我想问一下 按照现在mysql-cdc的设计,全量阶段,如果某一个chunk的binlog回填阶段,
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
电脑钉钉怎么调整声音
2328. Number of incremental paths in the grid graph (memory search)
C'est un petit résumé de l'étude.
Lagrange polynomial
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
Overturn your cognition? The nature of get and post requests
Quick sort
Lombok原理和同时使⽤@Data和@Builder 的坑
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
ue5 小知识点 开启lumen的设置
几种RS485隔离通讯的方案介绍
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems