The NXP i.MX91 CPU has six I2C buses that operate at up to 400 Kbps. The CPU facilitates the functionality of both I2C master and slave according to the I2C Bus Specification v2.1, but the Linux kernel only contains an I2C bus master driver.
On the ConnectCore 91:
-
LPI2C1 connects internally to the power management IC (PMIC) at the following address:
Interface Address (7-bit) PMIC
0x25
On the ConnectCore 93 Development Kit:
-
LPI2C3 is connected to the Goodix touch, an external RTC, to the USB Type-C and routed to the MIPI camera.
Interface Address (7-bit) Goodix touch controller
0x14
OmniVision CSI camera
0x3C
External RTC
0x52
USB Type C
0x53
-
LPI2C4 is connected to the on-board audio chip and to the on-board LT8912 MIPI-to-HDMI.
Interface Address (7-bit) Maxim MAX98089 sound chip
0x10
LT8912 MIPI-to-HDMI bridge
0x48
-
LPI2C4 is also available on the HDMI connector, so it connects with HDMI monitors.
Kernel configuration
You can manage the I2C driver support through the kernel configuration:
-
IMX I2C interface (
CONFIG_I2C_IMX
)
This kernel configuration option is enabled as built-in on the default ConnectCore 91 kernel configuration file.
Kernel driver
The driver for the I2C interface is located at:
File | Description |
---|---|
i.MX I2C controller driver |
Device tree bindings and customization
The i.MX91 I2C interface device tree binding is documented at Documentation/devicetree/bindings/i2c/i2c-imx.yaml
.
The I2C interfaces are defined in the CPU, system-on-module, and carrier board device tree files.
Example: LPI2C3
Define the bus
lpi2c3: i2c@42530000 {
compatible = "fsl,imx93-lpi2c", "fsl,imx7ulp-lpi2c";
reg = <0x42530000 0x10000>;
#address-cells = <1>;
#size-cells = <0>;
interrupts = <GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clk IMX93_CLK_LPI2C3_GATE>,
<&clk IMX93_CLK_BUS_WAKEUP>;
clock-names = "per", "ipg";
dmas = <&edma2 8 0 0>, <&edma2 9 0 1>;
dma-names = "tx","rx";
status = "disabled";
};
Configure IOMUX
&iomuxc {
[...]
/* LPI2C3 */
pinctrl_lpi2c3: lpi2c3grp {
fsl,pins = <
{short-cpu-prefix-ucase}_PAD_GPIO_IO00__LPI2C3_SDA 0x40000b9e
{short-cpu-prefix-ucase}_PAD_GPIO_IO01__LPI2C3_SCL 0x40000b9e
>;
};
Enable the bus and define attached client devices
&lpi2c3 {
#address-cells = <1>;
#size-cells = <0>;
clock-frequency = <400000>;
pinctrl-names = "default", "sleep";
pinctrl-0 = <&pinctrl_lpi2c3>;
pinctrl-1 = <&pinctrl_lpi2c3>;
status = "okay";
goodix_touch: gt9271@14 {
[...]
};
ext_rtc: ext_rtc@52 {
[...]
};
ptn5110: tcpc@53 {
[...]
};
ov5640_mipi: ov5640_mipi@3c {
[...]
};
};
Use the I2C bus
The I2C bus driver exposes device data through the sysfs at /sys/class/i2c-dev/
.
The correct way to access an I2C device is through a kernel driver. Accessing the I2C bus from the file system can confuse your I2C bus and cause data loss on devices like EEPROMs. The following tools are recommended for debugging purposes only. |
I2C device interface
You can access I2C devices on an adapter from user space, through the /dev
interface.
This support requires that you enable the kernel configuration option I2C device interface (CONFIG_I2C_CHARDEV
).
Once you have enabled the option, you can use the /dev/i2c-N
device node where N corresponds to the adapter number, starting at zero.
i2c-tools
You can install the i2c-tools package to access the I2C devices from user space. The package contains the following tools:
Tool | Description |
---|---|
i2cdetect |
Bus scanning |
i2cdump |
Device register dumping |
i2cget |
Device register reading |
i2cset |
Device register setting |
All I2C tools operate on a specific I2C bus which is identified by number.
To obtain a formatted list of all I2C adapters on your system, run:
# i2cdetect -l
i2c-3 i2c 42540000.i2c I2C adapter
i2c-2 i2c 42530000.i2c I2C adapter
i2c-0 i2c 44340000.i2c I2C adapter
Query the I2C bus using the I2C bus number to find devices connected to that bus:
# i2cdetect 3
i2cdetect: WARNING! This program can confuse your I2C bus
Continue? [y/N] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- UU 49 4a 4b -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
The example above shows several devices on the bus at addresses 0x10, 0x48, 0x49, 0x4a, and 0x4b. The ones showing UU denote this address is currently in use by a driver, while devices without a registered driver show the address (in the example 0x49, 0x4a, and 0x4b).
You can dump the registers of any of these devices using the i2cdump
command with the I2C bus number as the first argument and the chip address as the second argument:
# i2cdump 3 0x49
i2cdump: WARNING! This program can confuse your I2C bus
Continue? [y/N] y
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 01 97 08 95 00 00 16 2d 00 5d 02 01 be 1b d3 00 ????..?-.]?????.
10: 01 0a 04 00 00 00 00 00 2c 05 03 03 80 07 4f 5e ???.....,?????O^
20: 01 2c 01 fa 00 c8 00 5e 01 2c 01 fa 00 c8 00 0c ?,??.?.^?,??.?.?
30: 00 00 00 00 98 08 65 04 04 00 24 00 94 00 58 00 ....??e??.$.?.X.
40: 00 00 64 00 04 00 59 00 f2 06 00 72 45 00 6a ad ..d.?.Y.??.rE.j?
50: f3 00 08 00 b2 00 e4 0d 00 e4 8a 00 34 00 00 00 ?.?.?.??.??.4...
60: c8 00 01 00 ff ff ff ff ff ff ff ff ff ff ff ff ?.?.............
70: 00 07 12 7a 00 24 d0 e0 12 5a 0d 23 3e 06 06 06 .??z.$???Z?#>???
80: 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 ????????????????
90: 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 ????????????????
a0: 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 ????????????????
b0: 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 ????????????????
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Accessing the I2C bus using Digi APIx
An example application called apix-i2c-example
is included in the dey-examples-digiapix recipe (part of dey-examples package) of the meta-digi layer.
This application is an example of how to write data to an external EEPROM (24FC1026) and read it back using Digi APIx library on the ConnectCore 91 platform.
Go to GitHub to see the application instructions and source code.
See I2C API for more information about the I2C APIx.