^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) =============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) Introduction to I2C and SMBus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) =============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) I²C (pronounce: I squared C and written I2C in the kernel documentation) is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) a protocol developed by Philips. It is a slow two-wire protocol (variable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) speed, up to 400 kHz), with a high speed extension (3.4 MHz). It provides
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) an inexpensive bus for connecting many types of devices with infrequent or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) low bandwidth communications needs. I2C is widely used with embedded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) systems. Some systems use variants that don't meet branding requirements,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) and so are not advertised as being I2C but come under different names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) e.g. TWI (Two Wire Interface), IIC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) The official I2C specification is the `"I2C-bus specification and user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) manual" (UM10204) <https://www.nxp.com/docs/en/user-guide/UM10204.pdf>`_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) published by NXP Semiconductors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) SMBus (System Management Bus) is based on the I2C protocol, and is mostly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) a subset of I2C protocols and signaling. Many I2C devices will work on an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) SMBus, but some SMBus protocols add semantics beyond what is required to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) achieve I2C branding. Modern PC mainboards rely on SMBus. The most common
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) devices connected through SMBus are RAM modules configured using I2C EEPROMs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) and hardware monitoring chips.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) Because the SMBus is mostly a subset of the generalized I2C bus, we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) use its protocols on many I2C systems. However, there are systems that don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) meet both SMBus and I2C electrical constraints; and others which can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) implement all the common SMBus protocol semantics or messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Terminology
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ===========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) Using the terminology from the official documentation, the I2C bus connects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) one or more *master* chips and one or more *slave* chips.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .. kernel-figure:: i2c_bus.svg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) :alt: Simple I2C bus with one master and 3 slaves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) Simple I2C bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) A **master** chip is a node that starts communications with slaves. In the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) Linux kernel implementation it is called an **adapter** or bus. Adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) drivers are in the ``drivers/i2c/busses/`` subdirectory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) An **algorithm** contains general code that can be used to implement a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) whole class of I2C adapters. Each specific adapter driver either depends on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) an algorithm driver in the ``drivers/i2c/algos/`` subdirectory, or includes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) its own implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) A **slave** chip is a node that responds to communications when addressed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) by the master. In Linux it is called a **client**. Client drivers are kept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) in a directory specific to the feature they provide, for example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ``drivers/media/gpio/`` for GPIO expanders and ``drivers/media/i2c/`` for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) video-related chips.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) For the example configuration in figure, you will need a driver for your
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) I2C adapter, and drivers for your I2C devices (usually one driver for each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) device).