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.