Using I2C in Linux Print

 

The i.MX 6ULL provides 4 I2C interfaces (I2C1-4). The default Linux kernel configuration for the Emcraft i.MX 6ULL SOM makes only ports I2C1 and I2C2 accessible from Linux.

The following table shows allocation of the I2C interfaces on the i.MX 6ULL SOM and Starter Kit:

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

 

U14, RTC (0x68)
U10, Audio Codec (0x1A)
P4, LCD add-on connector
I2C2


P10, RPi header

The Linux kernel provides a device driver for the I2C controller of the i.MX 6ULL, 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/arm/boot/dts/imx6ull.dtsi file:

/ { ... i2c1: i2c@021a0000 { #address-cells = <1>; #size-cells = <0>; compatible = "fsl,imx6ul-i2c", "fsl,imx21-i2c"; reg = <0x021a0000 0x4000>; interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; clocks = <&clks IMX6UL_CLK_I2C1>; status = "disabled"; }; ... };

The above file is generic for the i.MX 6ULL processor so you won't have to modify it in order to configure the I2C controllers for your application. The above information is provided for your reference.

The i.MX 6ULL 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 projects/rootfs/rootfs.dts file:

&iomuxc { imx6ul-evk { ... pinctrl_i2c1: i2c1grp { fsl,pins = < MX6UL_PAD_CSI_MCLK__I2C1_SDA MX6UL_I2C_PAD_CTRL MX6UL_PAD_CSI_PIXCLK__I2C1_SCL MX6UL_I2C_PAD_CTRL >; }; ... }; };

Additionally, the projects/rootfs/rootfs.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"; ... wm8985_codec: wm8985@1a { #sound-dai-cells = <0>; compatible = "wm8985"; reg = <0x1a>; clocks = <&sound_osc 0>; }; };

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 audio codec is instantiated in the i2c1 bus node.

The projects/rootfs/rootfs.dts file is specific to the Emcraft i.MX 6ULL SOM. You will have to update it only in case you decide to route the I2C interfaces to alternate pads of the i.MX 6ULL, 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 6ULL 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 6ULL I2C controllers in Linux. Note that in this example 2 I2C controllers have been enabled in the Linux configuration:

~ # i2cdetect -list i2c-1 i2c 21a4000.i2c I2C adapter i2c-0 i2c 21a0000.i2c I2C adapter ~ #

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

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

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

  • LCD add-on board with LCD panel (4.3" 480x272 LCD with capacitive touch screen).