Lines Matching +full:mux +full:- +full:controller
1 .. SPDX-License-Identifier: GPL-2.0
10 I2C topology can be complex because of the existence of I2C MUX
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
18 useful and essential to use ``i2c-tools`` for the purpose of development and
22 ---------------
28 -------------
32 2. General knowledge of I2C, I2C MUX and I2C topology.
41 start with ``i2c-`` are I2C buses, which may be either physical or logical. The
48 0-0008 0-0061 1-0028 3-0043 4-0036 4-0041 i2c-1 i2c-3
49 0-000c 0-0066 2-0049 4-000b 4-0040 i2c-0 i2c-2 i2c-4
51 ``i2c-2`` is an I2C bus whose number is 2, and ``2-0049`` is an I2C device
60 (Physical) I2C Bus Controller
61 -----------------------------
72 -----------------------
74 For each physical I2C bus controller, the system vendor may assign a physical
75 number to each controller. For example, the first I2C bus controller which has
76 the lowest register addresses may be called ``I2C-0``.
79 ---------------
85 Each logical I2C bus may be an abstraction of a physical I2C bus controller, or
86 an abstraction of a channel behind an I2C MUX. In case it is an abstraction of a
87 MUX channel, whenever we access an I2C device via a such logical bus, the kernel
88 will switch the I2C MUX for you to the proper channel as part of the
92 ----------------
94 If the logical I2C bus is a direct abstraction of a physical I2C bus controller,
98 ------
104 `arch/arm/boot/dts/nuvoton-npcm730-gsj.dts
105 <../../arch/arm/boot/dts/nuvoton-npcm730-gsj.dts>`_
112 MUX fanouts. For the following examples, we will assume that the physical I2C
125 i2c-7 (physical I2C bus controller 7)
126 `-- 7-0071 (4-channel I2C MUX at 0x71)
127 |-- i2c-60 (channel-0)
128 |-- i2c-73 (channel-1)
129 | |-- 73-0040 (I2C sensor device with hwmon directory)
130 | |-- 73-0070 (I2C MUX at 0x70, exists in DTS, but failed to probe)
131 | `-- 73-0072 (8-channel I2C MUX at 0x72)
132 | |-- i2c-78 (channel-0)
133 | |-- ... (channel-1...6, i2c-79...i2c-84)
134 | `-- i2c-85 (channel-7)
135 |-- i2c-86 (channel-2)
136 `-- i2c-203 (channel-3)
139 ----------------------------------------
143 command ``ls -l`` or ``readlink``.
147 Reading this link will also tell you which I2C MUX device created
151 physical I2C bus, directly abstracting a physical I2C bus controller. For
154 $ readlink /sys/bus/i2c/devices/i2c-7/device
156 $ ls /sys/bus/i2c/devices/i2c-7/mux_device
157 ls: /sys/bus/i2c/devices/i2c-7/mux_device: No such file or directory
159 In this case, ``i2c-7`` is a physical I2C bus, so it does not have the symbolic
162 mean the physical I2C bus controller 7 of the system.
168 abstracts an I2C MUX channel under the parent bus.
172 $ readlink /sys/bus/i2c/devices/i2c-73/device
173 ../../i2c-7
174 $ readlink /sys/bus/i2c/devices/i2c-73/mux_device
175 ../7-0071
177 ``i2c-73`` is a logical bus fanout by an I2C MUX under ``i2c-7``
180 switch the I2C MUX addressed 0x71 to the proper channel for you as part of the
184 ----------------------------------
187 representing certain I2C MUX channels based on the knowledge of physical
191 in DTS. There is a 4-channel MUX at address 0x71 on that bus. There is another
192 8-channel MUX at address 0x72 behind the channel 1 of the 0x71 MUX. Let us
194 of the 0x72 MUX.
196 First of all, let us go to the directory of ``i2c-7``::
198 ~$ cd /sys/bus/i2c/devices/i2c-7
199 /sys/bus/i2c/devices/i2c-7$ ls
200 7-0071 i2c-60 name subsystem
201 delete_device i2c-73 new_device uevent
202 device i2c-86 of_node
203 i2c-203 i2c-dev power
205 There, we see the 0x71 MUX as ``7-0071``. Go inside it::
207 /sys/bus/i2c/devices/i2c-7$ cd 7-0071/
208 /sys/bus/i2c/devices/i2c-7/7-0071$ ls -l
209 channel-0 channel-3 modalias power
210 channel-1 driver name subsystem
211 channel-2 idle_state of_node uevent
213 Read the link ``channel-1`` using ``readlink`` or ``ls -l``::
215 /sys/bus/i2c/devices/i2c-7/7-0071$ readlink channel-1
216 ../i2c-73
218 We find out that the channel 1 of 0x71 MUX on ``i2c-7`` is assigned
220 Let us continue the journey to directory ``i2c-73`` in either ways::
222 # cd to i2c-73 under I2C Sysfs root
223 /sys/bus/i2c/devices/i2c-7/7-0071$ cd /sys/bus/i2c/devices/i2c-73
224 /sys/bus/i2c/devices/i2c-73$
227 /sys/bus/i2c/devices/i2c-7/7-0071$ cd channel-1
228 /sys/bus/i2c/devices/i2c-7/7-0071/channel-1$
231 /sys/bus/i2c/devices/i2c-7/7-0071$ cd ../i2c-73
232 /sys/bus/i2c/devices/i2c-7/i2c-73$
234 Either ways, you will end up in the directory of ``i2c-73``. Similar to above,
235 we can now find the 0x72 MUX and what logical I2C bus numbers
238 /sys/bus/i2c/devices/i2c-73$ ls
239 73-0040 device i2c-83 new_device
240 73-004e i2c-78 i2c-84 of_node
241 73-0050 i2c-79 i2c-85 power
242 73-0070 i2c-80 i2c-dev subsystem
243 73-0072 i2c-81 mux_device uevent
244 delete_device i2c-82 name
245 /sys/bus/i2c/devices/i2c-73$ cd 73-0072
246 /sys/bus/i2c/devices/i2c-73/73-0072$ ls
247 channel-0 channel-4 driver of_node
248 channel-1 channel-5 idle_state power
249 channel-2 channel-6 modalias subsystem
250 channel-3 channel-7 name uevent
251 /sys/bus/i2c/devices/i2c-73/73-0072$ readlink channel-3
252 ../i2c-81
254 There, we find out the logical I2C bus number of the channel 3 of the 0x72 MUX
256 issue ``i2c-tools`` commands.
258 Tip: Once you understand the I2C topology with MUX, command
259 `i2cdetect -l
260 <https://manpages.debian.org/unstable/i2c-tools/i2cdetect.8.en.html>`_
268 $ i2cdetect -l | grep -e '\-73' -e _7 | sort -V
269 i2c-7 i2c npcm_i2c_7 I2C adapter
270 i2c-73 i2c i2c-7-mux (chan_id 1) I2C adapter
271 i2c-78 i2c i2c-73-mux (chan_id 0) I2C adapter
272 i2c-79 i2c i2c-73-mux (chan_id 1) I2C adapter
273 i2c-80 i2c i2c-73-mux (chan_id 2) I2C adapter
274 i2c-81 i2c i2c-73-mux (chan_id 3) I2C adapter
275 i2c-82 i2c i2c-73-mux (chan_id 4) I2C adapter
276 i2c-83 i2c i2c-73-mux (chan_id 5) I2C adapter
277 i2c-84 i2c i2c-73-mux (chan_id 6) I2C adapter
278 i2c-85 i2c i2c-73-mux (chan_id 7) I2C adapter
281 -----------------------------
283 If not specified in DTS, when an I2C MUX driver is applied and the MUX device is
284 successfully probed, the kernel will assign the MUX channels with a logical bus
286 example, if the system has ``i2c-15`` as the highest logical bus number, and a
287 4-channel MUX is applied successfully, we will have ``i2c-16`` for the
288 MUX channel 0, and all the way to ``i2c-19`` for the MUX channel 3.
290 The kernel software developer is able to pin the fanout MUX channels to a static
293 `arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
294 <../../arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts>`_
296 In the above example, there is an 8-channel I2C MUX at address 0x70 on physical
297 I2C bus 2. The channel 2 of the MUX is defined as ``imux18`` in DTS,
303 can pin the fanout channels of a MUX on bus 3 to start at 30. So 30 will be the
304 logical bus number of the channel 0 of the MUX on bus 3, and 37 will be the
305 logical bus number of the channel 7 of the MUX on bus 3.
312 of ``${bus}-${addr}``. The ``${bus}`` part in the name is a logical I2C bus
317 ----------------------------
323 /sys/bus/i2c/devices/i2c-73$ cat 73-0040/name
325 /sys/bus/i2c/devices/i2c-73$ cat 73-0070/name
327 /sys/bus/i2c/devices/i2c-73$ cat 73-0072/name
333 /sys/bus/i2c/devices/i2c-73$ readlink -f 73-0040/driver
335 /sys/bus/i2c/devices/i2c-73$ readlink -f 73-0072/driver
342 /sys/bus/i2c/devices/i2c-73$ ls 73-0070/driver
343 ls: 73-0070/driver: No such file or directory
344 /sys/bus/i2c/devices/i2c-73$ dmesg | grep 73-0070
345 pca954x 73-0070: probe failed
346 pca954x 73-0070: probe failed
351 I2C MUX Device
352 --------------
354 While you may be already aware of this in previous sections, an I2C MUX device
355 will have symbolic link ``channel-*`` inside its device directory.
358 /sys/bus/i2c/devices/i2c-73$ ls -l 73-0072/channel-*
359 lrwxrwxrwx ... 73-0072/channel-0 -> ../i2c-78
360 lrwxrwxrwx ... 73-0072/channel-1 -> ../i2c-79
361 lrwxrwxrwx ... 73-0072/channel-2 -> ../i2c-80
362 lrwxrwxrwx ... 73-0072/channel-3 -> ../i2c-81
363 lrwxrwxrwx ... 73-0072/channel-4 -> ../i2c-82
364 lrwxrwxrwx ... 73-0072/channel-5 -> ../i2c-83
365 lrwxrwxrwx ... 73-0072/channel-6 -> ../i2c-84
366 lrwxrwxrwx ... 73-0072/channel-7 -> ../i2c-85
369 -------------------------
376 /sys/bus/i2c/devices/i2c-73/73-0040/hwmon/hwmon17$ ls
387 <../hwmon/sysfs-interface.rst>`_
390 ------------------------------------
394 `How to instantiate I2C devices, Method 4: Instantiate from user-space
395 <instantiating-devices.rst#method-4-instantiate-from-user-space>`_