233/**
234* struct i2c_board_info-template for device creation235* @type: Chip type, to initialize I2c_client.name236* @flags: to initialize I2c_client.flags237* @addr: stored in i2c_client.addr238* @platform_data: stored in I2c_client.dev.platform_data239* @archdata: copied into I2c_client.dev.archdata240* @of_node: Pointer to openfirmware device node241* @irq: stored in I2C_CLIENT.IRQ242 *243* I2C doesn ' t actually support hardware probing, although controllers and244* Devices May is able to use I2c_smbus_quick to tell whether or not there ' s245* A device at a given address. Drivers commonly need more information than246* That is, such as chip type, configuration, associated IRQ, and so on.247 *248* I2c_board_info is used to build tables of information listing I2C devices249* that are present. This information was used to grow the driver Model tree.250* For mainboards The This are done statically using i2c_register_board_info ();251* Bus numbers identify adapters that aren ' t yet available. For add-on boards,252* I2c_new_device () Does this dynamically with the adapter already known.253 */254 struct I2c_board_info {255 char type[i2c_name_size]; 256 unsigned short flags; 257
unsigned short addr;
258 void *platform_data;
259 struct Dev_archdata *archdata;
struct Device_node *of_node;
261 int IRQ;
262}; 263 264/**265* I2c_board_info-macro used to list a I2C device and its266* @dev_type: Identifies the device type267* @dev_addr: The device ' s address in the bus.268 *269* This macro initializes essential fields of a struct i2c_board_info,270* Declaring what has been provided on a particular board. Optional271* fields (such as associated IRQ, or device-specific platform_data)272* are provided using conventional syntax.273 */274 #define I2C_BOARD_INFO (dev_type, dev_addr) \ 275. Type = Dev_type,. Addr = (DEV_ADDR)
Probe mode (new style)
Building I2c_driver
As with the legacy approach, you need to build i2c_driver, but the content is different.
static struct I2c_driver Pca953x_driver = {
. Driver = {
. Name= "Pca953x",
},
. probe= Pca953x_probe,//When a i2c_client and I2c_driver match is called
. remove= pca953x_remove,//Called when logoff
. id_table= pca953x_id,//Matching rules
};
Register I2c_driver
static int __init pca953x_init (void)
{
Return I2c_add_driver (&pca953x_driver);
}
Module_init (Pca953x_init);
In the process of registering the I2c_driver, the driver is registered to the I2c_bus_type bus. The matching rule for this bus is:
static const struct I2C_DEVICE_ID *i2c_match_id (const struct I2C_DEVICE_ID *id,