当前位置:网站首页>The kernel determines whether peripherals are attached to the I2C address
The kernel determines whether peripherals are attached to the I2C address
2022-07-06 04:43:00 【Never bald programmer】
List of articles
Record a way to judge i2c Whether peripherals are attached to the address .
Use scenarios , Both drivers use the same reset pin and interrupt pin , Use the same peripheral interface , It is not allowed to use at the same time , Just mounted i2c Different addresses , The idea is to read the value of this register when registering the driver , The return value is used to determine whether there is a cause peripheral .
One 、 Code changes
dits To configure
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>;
};
};
Then the corresponding peobe Add the following judgment to the function :
The function used is i2c_smbus Read interface of :
/* Correlation function again kernel Of inlcude/linux/i2c.h in *s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command); *const struct i2c_client *client It's designated by your peripheral i2c Bus *u8 command 8 Bit address */
/*vol Is the return value , If it doesn't exist, then it returns a negative number */
/* Before using this function, you need to set client The value of is given first so that it can pass I2C Interface function to read */
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;
}
By inserting different peripherals , You can see different printing information .
[ 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
Two 、 Realization principle
Because drivers can be loaded successfully alone , The purpose is to avoid driving to the right gpio To operate , Because they all use the same gpio, So we can't let them drive the right gpio To apply for , Because once you apply, it will lead to ningwai gpio You can't be right gpio To operate . So you need to add this judgment function gpio Before applying .
边栏推荐
- [HBZ sharing] how to locate slow queries in cloud database
- Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
- Ue5 small knowledge points to enable the setting of lumen
- 关于imx8mp的es8316的芯片调试
- Is the mode of education together - on campus + off campus reliable
- Flink kakfa data read and write to Hudi
- Microservice resource address
- Orm-f & Q object
- 团队协作出了问题,项目经理怎么办?
- The web project imported the MySQL driver jar package but failed to load it into the driver
猜你喜欢
Embedded development program framework
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
Dry goods collection | Vulkan game engine video tutorial
满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
Introduction of several RS485 isolated communication schemes
几种RS485隔离通讯的方案介绍
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
Solve the compilation problem of "c2001: line breaks in constants"
随机推荐
2328. Number of incremental paths in the grid graph (memory search)
ISP学习(2)
内核判断i2c地址上是否挂载外设
几种RS485隔离通讯的方案介绍
程序员在互联网行业的地位 | 每日趣闻
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
SharedPreferences source code analysis
[数学建模] 微分方程--捕鱼业的持续发展
It is also a small summary in learning
CADD course learning (8) -- virtual screening of Compound Library
Implementation of knowledge consolidation source code 2: TCP server receives and processes half packets and sticky packets
Sqlserver query results are not displayed in tabular form. How to modify them
Distributed transaction solution
English Vocabulary - life scene memory method
MIT CMS. 300 session 8 – immersion / immersion
Coreldraw2022 new version new function introduction cdr2022
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
win10电脑系统里的视频不显示缩略图
Supreme Court, judgment standard of divorce cases