- ...
- base images
- SDK
- ...
- ...
- tools
- premade packages
How to use I2C#
Attention
sm2s-al/sm2s-el may require some of I2C interfaces to be enabled in BIOS setup, see corresponding User Manual for SMARC module in question.
i2c-tools
package should be installed on the target image if userspace access to I2C is required.
Bus information#
You can list available buses using following command
$ ls -l /dev/bus/i2c/by-id/
total 0
lrwxrwxrwx 1 root root 14 Apr 28 17:42 I2C0 -> ../../../i2c-0
lrwxrwxrwx 1 root root 14 Apr 28 17:42 SMBUS -> ../../../i2c-1
lrwxrwxrwx 1 root root 15 Apr 28 17:42 UNKNOWN_10 -> ../../../i2c-10
lrwxrwxrwx 1 root root 15 Apr 28 17:42 UNKNOWN_11 -> ../../../i2c-11
lrwxrwxrwx 1 root root 15 Apr 28 17:42 UNKNOWN_12 -> ../../../i2c-12
lrwxrwxrwx 1 root root 15 Apr 28 17:42 UNKNOWN_13 -> ../../../i2c-13
lrwxrwxrwx 1 root root 14 Apr 28 17:42 UNKNOWN_2 -> ../../../i2c-2
lrwxrwxrwx 1 root root 14 Apr 28 17:42 UNKNOWN_3 -> ../../../i2c-3
lrwxrwxrwx 1 root root 14 Apr 28 17:42 UNKNOWN_4 -> ../../../i2c-4
lrwxrwxrwx 1 root root 14 Apr 28 17:42 UNKNOWN_5 -> ../../../i2c-5
lrwxrwxrwx 1 root root 14 Apr 28 17:42 UNKNOWN_6 -> ../../../i2c-6
lrwxrwxrwx 1 root root 14 Apr 28 17:42 UNKNOWN_7 -> ../../../i2c-7
lrwxrwxrwx 1 root root 14 Apr 28 17:42 UNKNOWN_8 -> ../../../i2c-8
lrwxrwxrwx 1 root root 14 Apr 28 17:42 UNKNOWN_9 -> ../../../i2c-9
lrwxrwxrwx 1 root root 14 Apr 28 17:42 USER -> ../../../i2c-0
USER bus is the general purpose bus exposed on a SMARC connector, other buses are special purpose, please see corresponding User Manual for information about other I2C buses available on your SMARC module.
Kernel drivers#
If kernel driver for particular I2C device exists and compiled in or compiled as a module, device should be claimed automatically. To check what devices are detected by kernel you can explore following sysfs path:
$ ls -l /sys/bus/i2c/devices/
total 0
lrwxrwxrwx 1 root root 0 Apr 28 17:42 1-0050 -> ../../../devices/pci0000:00/0000:00:1f.4/i2c-1/1-0050
lrwxrwxrwx 1 root root 0 Apr 28 18:32 1-0055 -> ../../../devices/pci0000:00/0000:00:1f.4/i2c-1/1-0055
lrwxrwxrwx 1 root root 0 Apr 28 17:42 i2c-0 -> ../../../devices/pci0000:00/0000:00:19.0/i2c_designware.0/i2c-0
lrwxrwxrwx 1 root root 0 Apr 28 17:42 i2c-1 -> ../../../devices/pci0000:00/0000:00:1f.4/i2c-1
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-10 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-10
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-11 -> ../../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-1/i2c-11
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-12 -> ../../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-DP-2/i2c-12
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-13 -> ../../../devices/pci0000:00/0000:00:18.0/i2c-13
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-2 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-2
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-3 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-3
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-4 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-4
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-5 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-5
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-6 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-6
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-7 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-7
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-8 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-8
lrwxrwxrwx 1 root root 0 Apr 28 18:32 i2c-9 -> ../../../devices/pci0000:00/0000:00:02.0/i2c-9
lrwxrwxrwx 1 root root 0 Apr 28 17:42 i2c-MEX0000:00 -> ../../../devices/pci0000:00/0000:00:1f.4/i2c-1/i2c-MEX0000:00
lrwxrwxrwx 1 root root 0 Apr 28 17:42 i2c-MEX0008:00 -> ../../../devices/pci0000:00/0000:00:1f.4/i2c-1/i2c-MEX0008:00
lrwxrwxrwx 1 root root 0 Apr 28 17:42 i2c-MSFT8000:00 -> ../../../devices/pci0000:00/0000:00:19.0/i2c_designware.0/i2c-0/i2c-MSFT8000:00
I2C Tools#
Most of I2C devices are handled by kernel drivers, however there is a
userspace driver for I2C which can be accessed with tools provided by i2c-tools
package.
To acquire information about available I2C interfaces
$ i2cdetect -l
i2c-0 i2c Synopsys DesignWare I2C adapter I2C adapter
i2c-0 *link* I2C0 ID mapped
i2c-0 *link* USER ID mapped
i2c-1 smbus SMBus I801 adapter at efa0 SMBus adapter
i2c-1 *link* SMBUS ID mapped
i2c-2 i2c i915 gmbus dpa I2C adapter
i2c-2 *link* UNKNOWN_2 ID mapped
i2c-3 i2c i915 gmbus dpb I2C adapter
i2c-3 *link* UNKNOWN_3 ID mapped
i2c-4 i2c i915 gmbus dpc I2C adapter
i2c-4 *link* UNKNOWN_4 ID mapped
i2c-5 i2c i915 gmbus tc1 I2C adapter
i2c-5 *link* UNKNOWN_5 ID mapped
i2c-6 i2c i915 gmbus tc2 I2C adapter
i2c-6 *link* UNKNOWN_6 ID mapped
i2c-7 i2c i915 gmbus tc3 I2C adapter
i2c-7 *link* UNKNOWN_7 ID mapped
i2c-8 i2c i915 gmbus tc4 I2C adapter
i2c-8 *link* UNKNOWN_8 ID mapped
i2c-9 i2c i915 gmbus tc5 I2C adapter
i2c-9 *link* UNKNOWN_9 ID mapped
i2c-10 i2c i915 gmbus tc6 I2C adapter
i2c-10 *link* UNKNOWN_10 ID mapped
i2c-11 i2c AUX B/DDI B/PHY B I2C adapter
i2c-11 *link* UNKNOWN_11 ID mapped
i2c-12 i2c AUX C/DDI C (TC)/PHY C I2C adapter
i2c-12 *link* UNKNOWN_12 ID mapped
i2c-13 i2c Synopsys DesignWare I2C adapter I2C adapter
i2c-13 *link* UNKNOWN_13 ID mapped
To probe and detect which device addresses are available on the bus
$ i2cdetect -y -r SMBUS
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: 30 31 -- 33 34 35 -- 37 -- -- -- -- -- -- -- --
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --
50: 50 -- 52 -- UU UU -- -- -- -- -- -- -- -- -- --
60: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
UU
denotes a device claimed by kernel driver.
You can dump register content of a particular device using i2cdump
tool.
To dump registers from 0
to 0xf
on the device with address 0x27
.
$ i2cdump -r 0-0xf USER 0x27 b
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0, address 0x27, mode byte
Probe range limited to 0x00-0x0f.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 04 04 04 04 04 10 08 00 04 40 00 00 00 00 00 04 ???????.?@.....?
You can also read and write from/to device using i2cget
and i2cset
.
$ i2cget 0 0x27 4 b
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x27, data address
0x04, using read byte data.
Continue? [Y/n] y
0x04
$ i2cset 0 0x27 4 0x04 b
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will write to device file /dev/i2c-0, chip address 0x27,
data address 0x04, data 0x04, mode byte.
Continue? [Y/n] y