Using I2C in Linux |
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:
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:
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
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:
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:
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 8M SOM and the IMX8M-SOM-BSB development baseboard, the following I2C devices have been added to the i.MX 8M Starter Kit:
|