Using I2C in Linux Print

 

The i.MX 8M provides 4 I2C interfaces. The following table shows allocation of the I2C interfaces on the i.MX 8M SOM and Starter Kit:

I2C
Interface
Devices on SOM Devices on IMX8M-SOM-BSB Availablility on Extension Interfaces
I2C1

U1702, PMIC (0x4B)

U11, RTC (0x68)
U25, USB 3.0 TCPC (0x52)
U8, Audio Codec (0x1A)
P3, MIPI-DSI LCD add-on connector
J8, MIPI-CSI1 connector
J9, MIPI-CSI2 connector
I2C2
J10, PCIe.M2 (NGFF)
I2C3
P1, RPi header
I2C4
P1, RPi header

The Linux kernel provides a device driver for the I2C controller of the i.MX 8M, enabled in the kernel with the CONFIG_I2C_IMX build-time option. Another kernel configuration option that you will require is CONFIG_I2C_CHARDEV. This option enables the kernel API that allows accessing I2C devices from user-space application code. Both these kernel configuration options are enabled by default in the Linux configuration installed on the Starter Kit.

Parameters of each I2C bus controller (interrupt request numbers, clock source, etc.) are specified in the i2cx child nodes properties in the soc node in the arch/arm64/boot/dts/freescale/fsl-imx8mq.dtsi file:

/ { ... i2c1: i2c@30a20000 { #address-cells = <1>; #size-cells = <0>; compatible = "fsl,imx21-i2c"; reg = <0x0 0x30a20000 0x0 0x10000>; interrupts = <GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>; clocks = <&clk IMX8MQ_CLK_I2C1_ROOT>; status = "disabled"; }; ... };

The above file is generic for the i.MX 8M family and the i.MX 8M processor so you won't have to modify them in order to configure the I2C controllers for your application. The above information is provided for your reference.

The i.MX 8M allows different alternate pin selection for each I2C controller. Assignment of the I2C signals to specific pins is described in the pinctrl_i2cx child nodes of the iomuxc node in the
meta-emcraft/recipes-kernel/linux/linux-imx/imx8m-som.dts file:

&iomuxc { pinctrl-names = "default"; ... imx8m-som { ... pinctrl_i2c1: i2c1grp { fsl,pins = < MX8MQ_IOMUXC_I2C1_SCL_I2C1_SCL 0x4000007f MX8MQ_IOMUXC_I2C1_SDA_I2C1_SDA 0x4000007f >; }; ... }; };

Additionally, the meta-emcraft/recipes-kernel/linux/linux-imx/imx8m-som.dts file defines the I2C interface reference with other properties, which enable the appropriate I2C bus controller, connect it to the pins specified, select the bus speed, and define I2C devices, located on the corresponding bus:

&i2c1 { clock-frequency = <100000>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_i2c1>; status = "okay"; ... typec_ptn5100: ptn5110@50 { compatible = "usb,tcpci"; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_typec>; reg = <0x52>; interrupt-parent = <&gpio3>; interrupts = <1 IRQ_TYPE_LEVEL_LOW>; ss-sel-gpios = <&gpio3 12 GPIO_ACTIVE_HIGH>; src-pdos = <0x380190c8>; snk-pdos = <0x380190c8 0x3802d0c8>; max-snk-mv = <9000>; max-snk-ma = <1000>; op-snk-mw = <9000>; port-type = "drp"; default-role = "sink"; }; };

Note that any devices added to an I2C device node should be properly supported by the Linux kernel and enabled in the kernel configuration file. In the above example, an USB Type-C controller is instantiated in the i2c1 bus node.

The meta-emcraft/recipes-kernel/linux/linux-imx/imx8m-som.dts file is specific to the Emcraft i.MX 8M SOM. You will have to update it only in case you decide to route the I2C interfaces to alternate pads of the i.MX 8M, or change population of I2C devices. Use caution when updating this file to avoid conflict in allocation of various I/O interfaces to i.MX 8M pads.

The i.MX Yocto Linux distribution includes the Linux run-time tools that can be used to access I2C devices from user space.

The following Linux command shows configuration of the i.MX 8M I2C controllers in Linux. Note that in this example all 4 I2C contollers have been enabled in the Linux configuration:

root@imx8m-som:~# i2cdetect -list i2c-3 i2c 30a50000.i2c I2C adapter i2c-1 i2c 30a30000.i2c I2C adapter i2c-2 i2c 30a40000.i2c I2C adapter i2c-0 i2c 30a20000.i2c I2C adapter

The following Linux command lists I2C devices available on the first I2C controller (i2c-0):

root@imx8m-som:~# i2cdetect y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- 14 -- -- -- -- -- UU -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- UU -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- 4b -- -- -- -- 50: -- -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --

In the above example, in addition to the I2C devices available on the i.MX 8M SOM and the IMX8M-SOM-BSB development baseboard, the following I2C devices have been added to the i.MX 8M Starter Kit:

  • The FRD-55 LCD Add-on Board plugged into the LCD add-on connector;
  • The OV5647 Camera Board connected to the MIPI-CSI1 connector.