The driver lm75.c registers itself with the kernel as a handler for ALL i2c devices with any of the 7bit addresses listed in normal_i2c array.
/* Addresses scanned */
static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
Next, the array is pointed to by struct lm75_driver (of type i2c_driver)
.address_list = normal_i2c,
Also note that the class and detect members of the i2c_driver struct are initialised appropriately
.class = I2C_CLASS_HWMON,
.detect = lm75_detect,
- various options for
.class are listed here.
.detect is a function that will be called whenever a new i2c-bus or i2c-driver is being initialised.
When the driver registers with the Linux kernel, this i2c_driver struct is passed on to the Linux kernel (with the list of i2c addresses to be associated with this driver).
module_i2c_driver(lm75_driver);
At runtime, what occurs next is summarised in the following call-graph:
i2c_register_driver()
__process_new_adapter()
i2c_do_add_adapter()
i2c_detect()
lm75_detect() called using driver->detect()
The lm75_detect() function contains the device-specific logic to determine whether an i2c device detected on the current i2c bus should be handled by the current driver (in this case lm75.c) or not.
For automatic device detection, both detect and address_list must be defined. class should also be set, otherwise only devices forced with module parameters will be created.
The detect function must fill at least the name field of the i2c_board_info structure it is handed upon successful detection, and possibly also the flags field.