当前位置:网站首页>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 .
边栏推荐
- Use sentinel to interface locally
- Fedora/rehl installation semanage
- Visio draw fan
- 二叉树基本知识和例题
- Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
- flink sql 能同时读多个topic吗。with里怎么写
- After learning classes and objects, I wrote a date class
- VPP performance test
- Yyds dry goods inventory OSI & tcp/ip
- 解决“C2001:常量中有换行符“编译问题
猜你喜欢
Programmers' position in the Internet industry | daily anecdotes
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
Is the mode of education together - on campus + off campus reliable
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
[数学建模] 微分方程--捕鱼业的持续发展
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
8. Static file
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
JVM garbage collector concept
[detailed steps of FreeRTOS shift value for the first time]
随机推荐
Lagrange polynomial
Hashlimit rate control
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
English Vocabulary - life scene memory method
Lombok principle and the pit of ⽤ @data and @builder at the same time
Word cover underline
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
Microservice resource address
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
Knowledge consolidation source code implementation 3: buffer ringbuffer
Yyds dry goods inventory OSI & tcp/ip
Easyrecovery靠谱不收费的数据恢复电脑软件
Database - MySQL storage engine (deadlock)
[HBZ sharing] how to locate slow queries in cloud database
[leetcode question brushing day 33] 1189 The maximum number of "balloons", 201. The number range is bitwise AND
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
Meet diverse needs: jetmade creates three one-stop development packages to help efficient development
tengine 内核参数