Using I2C in Linux |
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:
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:
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:
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:
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:
The following Linux command lists I2C devices available on the first I2C controller (i2c-0):
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:
|