The NXP i.MX8M Nano CPU has four 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 8M Nano:

  • I2C1 connects internally to the power management IC (PMIC), the on-module Micro Controller Assist (MCA), and the Atmel Cryptochip at the following addresses:

    Interface Address (7-bit)

    PMIC

    0x4B

    Cryptochip

    0x60

    MCA

    0x63

On the ConnectCore 8M Nano Development Kit:

  • I2C2, I2C3 and I2C4 are available on the J48 expansion connector, where you can connect additional devices.

  • I2C2 is connected to the on-board audio chip, routed to the MIPI camera so it can connect to an image sensor and routed to the LVDS connector so it can connect to a touch controller.

    Interface Address (7-bit)

    Maxim MAX98089 sound chip

    0x10

    Goodix touch controller

    0x14

    OmniVision CSI camera

    0x3C

  • I2C2 is also available on the miniPCIe connector.

  • I2C3 (which operates at 1.8 V) is connected to the on-board LT8912 MIPI-to-HDMI and SN65DSI83 MIPI-to-LVDS display bridges.

    Interface Address (7-bit)

    SN65DSI83 MIPI-to-LVDS bridge

    0x2C

    LT8912 MIPI-to-HDMI bridge

    0x48

  • I2C3 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 8M Nano kernel configuration file.

Kernel driver

The driver for the I2C interface is located at:

File Description

drivers/i2c/busses/i2c-imx.c

i.MX I2C controller driver

Device tree bindings and customization

The i.MX8M Nano 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: I2C3

Define the bus

i.MX8M Nano device tree
i2c3: i2c@30a40000 {
	#address-cells = <1>;
	#size-cells = <0>;
	compatible = "fsl,imx8mn-i2c", "fsl,imx21-i2c";
	reg = <0x30a40000 0x10000>;
	interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&clk IMX8MN_CLK_I2C3_ROOT>;
	status = "disabled";
};

Configure IOMUX

ConnectCore 8M Nano Development Kit device tree
&iomuxc {
	pinctrl_i2c3: i2c3grp {
		fsl,pins = <
			MX8MN_IOMUXC_I2C3_SCL_I2C3_SCL			0x400001c3
			MX8MN_IOMUXC_I2C3_SDA_I2C3_SDA			0x400001c3
		>;
	};

	pinctrl_i2c3_gpio: i2c3grp-gpio {
		fsl,pins = <
			MX8MN_IOMUXC_I2C3_SCL_GPIO5_IO18		0x1c3
			MX8MN_IOMUXC_I2C3_SDA_GPIO5_IO19		0x1c3
		>;
	};
};

Enable the bus and define attached client devices

ConnectCore 8M Nano Development Kit device tree
&i2c3 {
	clock-frequency = <100000>;
	pinctrl-names = "default", "gpio";
	pinctrl-0 = <&pinctrl_i2c3>;
	pinctrl-1 = <&pinctrl_i2c3_gpio>;
	scl-gpios = <&gpio5 18 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
	sda-gpios = <&gpio5 19 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
	status = "okay";

	[...]

	dsi_lvds_bridge: sn65dsi84@2c {
		[...]
	};

	lt_bridge: lt8912@48 {
		[...]
	};

	[...]

};

Using 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             30a40000.i2c                            I2C adapter
i2c-4   i2c             30a50000.i2c                            I2C adapter
i2c-2   i2c             30a30000.i2c                            I2C adapter
i2c-0   i2c             30a20000.i2c                            I2C adapter

Query the I2C bus using the I2C bus number to find devices connected to that bus:

# i2cdetect 0
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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 -- -- UU -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

The example above shows several devices on the bus at addresses 0x4b, 0x60, and 0x63. 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 0x60).

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 0 0x60
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: XX XX XX 04 11 33 43 04 11 33 43 04 11 33 43 04    XXX??3C??3C??3C?
10: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
20: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
30: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
40: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
50: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
60: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
70: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
80: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
90: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
a0: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
b0: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
c0: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
d0: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
e0: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?
f0: 11 33 43 04 11 33 43 04 11 33 43 04 11 33 43 04    ?3C??3C??3C??3C?

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 8M Nano platform.

Go to GitHub to see the application instructions and source code.

See I2C API for more information about the I2C APIx.