Another Way To Register I2C devices

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:

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值