Another Way To Register I2C devices
2016-07-27 14:39
411 查看
In embedded Linux, the “classic” mean of registering a device is to add the device’s info into board within arch/ folder. There is another approach to do this, without interfering the arch/ directory but just within the driver/ module.
I needed to add 4 PCA9539 chips to my project, which is based on TCC8900 Linux BSP.
The driver is located at drivers/i2c/chips/tcc_pca953x.c, but i failed to find out the device-register code within arch/arm/mach-tcc8900/, what the hell?
Accidentally, I found below code in driver:
Turns out the list probe_i2C is used to register devices. The syntax is:
{ adapter/client pairs, I2C_CLIENT_END};
in which, an adaptor/client pair is:
{ adapter No., client’s address}
for example, I can attach 4 PCA9539 clients (which addresses are 0x74 - 0x77) to i2c core 0 like below:
Another example is the RX8025, which driver is drivers/rtc/rtc_rx8025.c
The driver itself registers a RX8025 device, which is attached to i2c core 1.
I needed to add 4 PCA9539 chips to my project, which is based on TCC8900 Linux BSP.
The driver is located at drivers/i2c/chips/tcc_pca953x.c, but i failed to find out the device-register code within arch/arm/mach-tcc8900/, what the hell?
Accidentally, I found below code in driver:
static unsigned short probe_i2c[] = {0, PCA9539_U2_SLAVE_ADDR, I2C_CLIENT_END}; /* { i2c_num, i2c_addr } */ static unsigned short dummy[] = {I2C_CLIENT_END}; static struct i2c_client_address_data addr_data = { .normal_i2c = dummy, .probe = probe_i2c, .ignore = dummy, };
Turns out the list probe_i2C is used to register devices. The syntax is:
{ adapter/client pairs, I2C_CLIENT_END};
in which, an adaptor/client pair is:
{ adapter No., client’s address}
for example, I can attach 4 PCA9539 clients (which addresses are 0x74 - 0x77) to i2c core 0 like below:
{ 0, 0x74, 0, 0x75, 0, 0x76, 0, 0x77, I2C_CLENT_END };
Another example is the RX8025, which driver is drivers/rtc/rtc_rx8025.c
#define RX8025_SLAVE_ADDR 0x32 static unsigned short probe_i2c[] = {1, RX8025_SLAVE_ADDR, I2C_CLIENT_END}; /* { i2c_num, i2c_addr } */ static unsigned short dummy[] = {I2C_CLIENT_END}; static struct i2c_client_address_data addr_data = { .normal_i2c = dummy, .probe = probe_i2c, .ignore = dummy, };
The driver itself registers a RX8025 device, which is attached to i2c core 1.
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍