The Inter-Integrated Circuit Protocol
Inter-Integrated Circuit, or “i2c” (pronounced “I squared C”), is a serial bus/protocol that’s widely used to interface hosts with devices such as EEPROM memory, audio codecs, and specialized chips that monitor parameters like temperature and power supply voltages. Take a look at how the kernel supports i2c.
Inter-Integrated Circuit, or “i2c” (pronounced “I squared C”), is a serial bus/protocol that’s widely used to interface hosts with devices such as EEPROM memory, audio codecs, and specialized chips that monitor parameters like temperature and power supply voltages. Additionally, i2c is widely used in embedded devices to communicate with real time clocks, with transmitters to link LCD monitors to a host, and so on. The System Management Bus (SMBus) is a subset of i2c.
i2c and SMBus are master-slave protocols, where communication takes place between a host adapter and client devices. The host adapter is usually part of the south bridge chipset on desktops and part of the microcontroller on embedded devices.
This month, let’s discuss how the Linux kernel supports i2c/SMBus host adapters and client devices, and let’s implement a very simple client device driver to access an SMBus memory device. To maximize the driver’s usefulness, we’ll use only the SMBus commands supported by the i2c core, yielding a driver that works with both SMBus and i2c adapters.
The Kernel i2c/SMBus Layer
Figure One illustrates the Linux i2c subsystem. The kernel i2c infrastructure consists of:
* The i2c-core, a code-base consisting of routines and data structures available to host adapter drivers and client drivers. The presence of common code in the core makes driver implementations easier. Additionally, the core provides a level of indirection that makes client drivers independent of the host adapter, allowing the client driver to work unchanged even if the device is used on a board that has a different host adapter. (This core layer” philosophy” is also present in various other kernel subsystems, such as the USB layer.)
* Device drivers for i2c host adapters. These device drivers usually consist of an adapter driver and an algorithm driver.
* Device drivers for i2c client devices.
* The i2c-dev module, which allows the implementation of user mode i2c client device drivers, and the i2c-proc module, which collects device information into /proc/sys/dev/sensors (which isn’t relevant for the example driver developed here).
Figure One also shows these kernel modules talking to a host adapter and a client device on the i2c bus.