Lines Matching refs:I2C
4 Linux I2C Sysfs
10 I2C topology can be complex because of the existence of I2C MUX
11 (I2C Multiplexer). The Linux
12 kernel abstracts the MUX channels into logical I2C bus numbers. However, there
13 is a gap of knowledge to map from the I2C bus physical number and MUX topology
14 to logical I2C bus number. This doc is aimed to fill in this gap, so the
16 the concept of logical I2C buses in the kernel, by knowing the physical I2C
17 topology and navigating through the I2C sysfs in Linux shell. This knowledge is
24 People who need to use Linux shell to interact with I2C subsystem on a system
32 2. General knowledge of I2C, I2C MUX and I2C topology.
34 Location of I2C Sysfs
38 so you can find the I2C Sysfs under ``/sys/bus/i2c/devices``
41 start with ``i2c-`` are I2C buses, which may be either physical or logical. The
42 other links that begin with numbers and end with numbers are I2C devices, where
43 the first number is I2C bus number, and the second number is I2C address.
51 ``i2c-2`` is an I2C bus whose number is 2, and ``2-0049`` is an I2C device
59 (Physical) I2C Bus Controller
63 physical I2C bus controllers. The controllers are hardware and physical, and the
65 controllers. Linux kernel has I2C bus drivers under source directory
66 ``drivers/i2c/busses`` to translate kernel I2C API into register
70 I2C Bus Physical Number
73 For each physical I2C bus controller, the system vendor may assign a physical
74 number to each controller. For example, the first I2C bus controller which has
75 the lowest register addresses may be called ``I2C-0``.
77 Logical I2C Bus
80 Every I2C bus number you see in Linux I2C Sysfs is a logical I2C bus with a
84 Each logical I2C bus may be an abstraction of a physical I2C bus controller, or
85 an abstraction of a channel behind an I2C MUX. In case it is an abstraction of a
86 MUX channel, whenever we access an I2C device via a such logical bus, the kernel
87 will switch the I2C MUX for you to the proper channel as part of the
90 Physical I2C Bus
93 If the logical I2C bus is a direct abstraction of a physical I2C bus controller,
94 let us call it a physical I2C bus.
99 This may be a confusing part for people who only know about the physical I2C
100 design of a board. It is actually possible to rename the I2C bus physical number
101 to a different number in logical I2C bus level in Device Tree Source (DTS) under
105 Best Practice: **(To kernel software developers)** It is better to keep the I2C
106 bus physical number the same as their corresponding logical I2C bus number,
108 users. These physical I2C buses can be served as good starting points for I2C
109 MUX fanouts. For the following examples, we will assume that the physical I2C
110 bus has a number same as their I2C bus physical number.
112 Walk through Logical I2C Bus
115 For the following content, we will use a more complex I2C topology as an
116 example. Here is a brief graph for the I2C topology. If you do not understand
122 i2c-7 (physical I2C bus controller 7)
123 `-- 7-0071 (4-channel I2C MUX at 0x71)
126 | |-- 73-0040 (I2C sensor device with hwmon directory)
127 | |-- 73-0070 (I2C MUX at 0x70, exists in DTS, but failed to probe)
128 | `-- 73-0072 (8-channel I2C MUX at 0x72)
135 Distinguish Physical and Logical I2C Bus
138 One simple way to distinguish between a physical I2C bus and a logical I2C bus,
139 is to read the symbolic link ``device`` under the I2C bus directory by using
143 in logical I2C bus directory which is fanned out from another I2C bus.
144 Reading this link will also tell you which I2C MUX device created
145 this logical I2C bus.
148 physical I2C bus, directly abstracting a physical I2C bus controller. For
156 In this case, ``i2c-7`` is a physical I2C bus, so it does not have the symbolic
158 follows the common practice by not renaming physical I2C buses, this should also
159 mean the physical I2C bus controller 7 of the system.
161 On the other hand, if the symbolic link points to another I2C bus, the I2C bus
162 presented by the current directory has to be a logical bus. The I2C bus pointed
163 by the link is the parent bus which may be either a physical I2C bus or a
164 logical one. In this case, the I2C bus presented by the current directory
165 abstracts an I2C MUX channel under the parent bus.
174 ``i2c-73`` is a logical bus fanout by an I2C MUX under ``i2c-7``
175 whose I2C address is 0x71.
176 Whenever we access an I2C device with bus 73, the kernel will always
177 switch the I2C MUX addressed 0x71 to the proper channel for you as part of the
180 Finding out Logical I2C Bus Number
183 In this section, we will describe how to find out the logical I2C bus number
184 representing certain I2C MUX channels based on the knowledge of physical
185 hardware I2C topology.
187 In this example, we have a system which has a physical I2C bus 7 and not renamed
190 navigate through Sysfs and find out the logical I2C bus number of the channel 3
216 with a logical I2C bus number of 73.
219 # cd to i2c-73 under I2C Sysfs root
232 we can now find the 0x72 MUX and what logical I2C bus numbers
251 There, we find out the logical I2C bus number of the channel 3 of the 0x72 MUX
252 is 81. We can later use this number to switch to its own I2C Sysfs directory or
255 Tip: Once you understand the I2C topology with MUX, command
259 `I2C Tools
262 an overview of the I2C topology easily, if it is available on your system. For
266 i2c-7 i2c npcm_i2c_7 I2C adapter
267 i2c-73 i2c i2c-7-mux (chan_id 1) I2C adapter
268 i2c-78 i2c i2c-73-mux (chan_id 0) I2C adapter
269 i2c-79 i2c i2c-73-mux (chan_id 1) I2C adapter
270 i2c-80 i2c i2c-73-mux (chan_id 2) I2C adapter
271 i2c-81 i2c i2c-73-mux (chan_id 3) I2C adapter
272 i2c-82 i2c i2c-73-mux (chan_id 4) I2C adapter
273 i2c-83 i2c i2c-73-mux (chan_id 5) I2C adapter
274 i2c-84 i2c i2c-73-mux (chan_id 6) I2C adapter
275 i2c-85 i2c i2c-73-mux (chan_id 7) I2C adapter
277 Pinned Logical I2C Bus Number
280 If not specified in DTS, when an I2C MUX driver is applied and the MUX device is
288 logical I2C bus number in the DTS. This doc will not go through the details on
292 In the above example, there is an 8-channel I2C MUX at address 0x70 on physical
293 I2C bus 2. The channel 2 of the MUX is defined as ``imux18`` in DTS,
294 and pinned to logical I2C bus number 18 with the line of ``i2c18 = &imux18;``
297 Take it further, it is possible to design a logical I2C bus number schema that
303 I2C Devices
306 In previous sections, we mostly covered the I2C bus. In this section, let us see
307 what we can learn from the I2C device directory whose link name is in the format
308 of ``${bus}-${addr}``. The ``${bus}`` part in the name is a logical I2C bus
309 decimal number, while the ``${addr}`` part is a hex number of the I2C address
312 I2C Device Directory Content
315 Inside each I2C device directory, there is a file named ``name``.
344 Depending on what the I2C device is and what kernel driver was used to probe the
347 I2C MUX Device
350 While you may be already aware of this in previous sections, an I2C MUX device
352 These symbolic links point to their logical I2C bus directories::
364 I2C Sensor Device / Hwmon
367 I2C sensor device is also common to see. If they are bound by a kernel hwmon
369 inside the I2C device directory. Keep digging into it, you will find the Hwmon
370 Sysfs for the I2C sensor device::
384 Instantiate I2C Devices in I2C Sysfs