当前位置:网站首页>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 .
边栏推荐
猜你喜欢
Easyrecovery靠谱不收费的数据恢复电脑软件
捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
How to estimate the population with samples? (mean, variance, standard deviation)
The most detailed and comprehensive update content and all functions of guitar pro 8.0
Basic explanation of turtle module - draw curve
满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
Visio draw fan
coreldraw2022新版本新功能介绍cdr2022
English Vocabulary - life scene memory method
RTP gb28181 document testing tool
随机推荐
Sentinel sliding window traffic statistics
Complete list of common functions of turtle module
[Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
C. The Third Problem(找规律)
几种RS485隔离通讯的方案介绍
二叉树基本知识和例题
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
力扣(LeetCode)186. 翻转字符串里的单词 II(2022.07.05)
Digital children < daily question> (Digital DP)
Mixed development of QML and QWidget (preliminary exploration)
The most detailed and comprehensive update content and all functions of guitar pro 8.0
[FreeRTOS interrupt experiment]
Can Flink SQL read multiple topics at the same time. How to write in with
Certbot failed to update certificate solution
Recommendation | recommendation of 9 psychotherapy books
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
Coreldraw2022 new version new function introduction cdr2022
Luogu deep foundation part 1 Introduction to language Chapter 2 sequential structure programming