当前位置:网站首页>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 .
边栏推荐
- How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
- Is the mode of education together - on campus + off campus reliable
- Programmers' position in the Internet industry | daily anecdotes
- SharedPreferences source code analysis
- BOM - location, history, pop-up box, timing
- View workflow
- Excellent PM must experience these three levels of transformation!
- Fedora/REHL 安装 semanage
- Knowledge consolidation source code implementation 3: buffer ringbuffer
- Basic explanation of turtle module - draw curve
猜你喜欢

Flink kakfa data read and write to Hudi

Certbot failed to update certificate solution

Database - MySQL storage engine (deadlock)

Distributed transaction solution

Delete subsequence < daily question >

CertBot 更新证书失败解决

11. Intranet penetration and automatic refresh
![[05-1, 05-02, 05-03] network protocol](/img/25/2e9ccc3f31a1fd46c9ab643d48064b.jpg)
[05-1, 05-02, 05-03] network protocol

How does computer nail adjust sound

Visio draw fan
随机推荐
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
Delete subsequence < daily question >
Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
关于es8316的音频爆破音的解决
[HBZ sharing] how to locate slow queries in cloud database
CADD课程学习(8)-- 化合物库虚拟筛选(Virtual Screening)
Basic explanation of turtle module - draw curve
Sqlserver query results are not displayed in tabular form. How to modify them
1008 circular right shift of array elements (20 points)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Etcd database source code analysis -- etcdserver bootstrap initialization storage
Easyrecovery靠谱不收费的数据恢复电脑软件
View 工作流程
Uva1592 Database
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
2328. Number of incremental paths in the grid graph (memory search)
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
newton interpolation
11. Intranet penetration and automatic refresh
What should the project manager do if there is something wrong with team collaboration?