One 1 I2C bus: Two-line serial bus interface, SDA (data line) and SCL (clock signal line). The SCL is generally controlled by the main device, it is used to control the start, end, and direction of data transmission (R/W ).
2 when the SCL is in a high-power period, SDA jumps from high to low, that is, the master device sends a start signal through I2C (all slave devices are in the ready state); when the SCL is in a high level, SDA jumps from low to high, that is, the master device sends a stop signal through the I2C bus.
3. During data transmission, the master device sends data from the device address and corresponding data (transmitted in bytes ), all slave devices mounted on the I2C bus match their addresses, if yes, the system will receive the receipt (the port of the I2C device (configured in the device driver). After receiving the data from the device, the system will respond to the master device. If no response is received, the master device determines that the slave device is faulty and sends a stop signal.
4. When data transmission is complete, the master device sends a stop signal.
2-1 I2C bus driver, each I2C bus has a corresponding driver, bus driver does not do any operation, just to provide a read/write mechanism for this bus. The real read/write operations are completed by a device driver.
2. After the machine is powered on, register the I2C bus driver to the kernel, and then register the I2C device driver to the kernel (during this process, the device will be registered to the system, usually, the model driver provided by the kernel is used in the PC ).
3. during system initialization, call the i2c_register_board_info interface to add the device information to _ i2c_board_list, add the adapter to the I2C host (microprocessor), and the adapter will scan _ i2c_board_list, register the devices to the bus one by one.
The device driver is a three-1 I2C device driver. After the device driver registers to the kernel, it calls the corresponding interface to traverse all the I2C bus drivers in the system to detect the device, multiple devices may be detected because the microcontroller may have multiple I2C bus interfaces, at the same time, multiple I2C devices can be mounted on each I2C bus (mounted on the bus in parallel), and the device driver may serve I2C devices on multiple I2C buses.
2 after the I2C Device Driver detects the I2C device, a struct i2c_client struct (attributes include bus drivers, device drivers, device information, and so on) will be created to identify the device, the I2C device is associated with the device driver. If there is communication, the bus driver will call i2c_master_send & i2c_master_recv to write data to or read data from the device.
The quad-1 driver is essentially a software abstraction of hardware devices (or chips.
Port 2, which is a register for the CPU.
Five specific source code can refer to the kernel driver/I2C/i2c-core.c & driver/I2C/i2c-dev.c source file