I2C
Introduction to the Functions and Usage Methods of I2C. A total of 9 I2C buses are provided, which support DMA transmission, 7-bit address mode, and the bus supports three speed modes: 100k / 400k / 1.5M. The I2C bus configuration is as follows:
Configuration | Description |
---|---|
spacemit, i2c - fast - mode | 400K speed mode |
spacemit, i2c - high - mode | 1.5M speed mode |
spacemit, dma - disable | Disable DMA transmission |
The default rate of the bus is 100K. If you need to switch the speed mode, just add the corresponding configuration in the dts;
For example, to switch to the fast mode, the configuration is as follows:
i2c6: i2c@d4018800 {
spacemit, i2c - fast - mode;
};
The "spacemit, dma - disable" configuration means that DMA transmission is not used. To enable DMA transmission, just remove this configuration in the dts; Taking i2c6 as an example, to disable DMA transmission, the configuration in k1 - x.dtsi is as follows:
i2c6: i2c@d4018800 {
spacemit, dma - disable;
};
pinctrl
Check the schematic diagram of the development board to find the pin group used by the I2C controller. Taking i2c6 as an example, suppose the schematic diagram uses gpio56/57 as SCL/SDA respectively, and the configuration can use the pinctrl_i2c6_2 group defined in k1 - x_pinctrl.dtsi, then the configuration in the solution dts is as follows.
&i2c6 {
pinctrl - names = "default";
pinctrl - 0 = <&pinctrl_i2c6_2>;
};
I2C Device Configuration
Take the touchscreen device as an example to analyze how to configure the dts of the I2C device.
Device Type
Confirm the device type and the driver used. Select the compatible configuration of the touchscreen device as "goodix, gt9xx".
Device Address
Confirm the I2C communication address (7 bits) of the device. Query the schematic diagram to get the address of the touchscreen device as 0x5d, and the configuration is as follows.
gt9xx@5d {
compatible = "goodix, gt9xx";
reg = <0x5d>;
Communication Frequency
Confirm the communication frequency of the device. The touchscreen communication frequency supports 100K. Choose to mount it under the i2c bus6, remove the "spacemit, i2c - fast - mode" and "spacemit, i2c - high - mode" configurations, and use the default rate of 100K.
Device Control Signals
Query the control signals used by the device in the schematic diagram of the solution. The reset / irq signals of the touchscreen are gpio 114/58 respectively, and the irq - flags is configured to the required interrupt trigger mode (2 is triggered by a falling edge), and the configuration is as follows.
gt9xx@5d {
reset - gpios = <&gpio 114 GPIO_ACTIVE_HIGH>;
irq - gpios = <&gpio 58 GPIO_ACTIVE_HIGH>;
irq - flags = <2>;
};
Device DTS
The touchscreen device address is 0x5d, gpio 114/58 are the reset/irq signals respectively, the interrupt is triggered by a falling edge, and the communication frequency is 100K. Configure the corresponding parameters of the touchscreen. The device dts configuration is as follows:
gt9xx@5d {
compatible = "goodix, gt9xx";
reg = <0x5d>;
reset - gpios = <&gpio 114 GPIO_ACTIVE_HIGH>;
irq - gpios = <&gpio 58 GPIO_ACTIVE_HIGH>;
irq - flags = <2>;
touchscreen - max - id = <11>;
touchscreen - size - x = <1200>;
touchscreen - size - y = <1920>;
touchscreen - max - w = <512>;
touchscreen - max - p = <512>;
};
DTS
Based on the above information, i2c6 is connected to the i2c touchscreen device, and the configuration of the solution dts is as follows.
&i2c6 {
pinctrl - names = "default";
pinctrl - 0 = <&pinctrl_i2c6_2>;
status = "okay";
gt9xx@5d {
compatible = "goodix, gt9xx";
reg = <0x5d>;
reset - gpios = <&gpio 114 GPIO_ACTIVE_HIGH>;
irq - gpios = <&gpio 58 GPIO_ACTIVE_HIGH>;
irq - flags = <2>;
touchscreen - max - id = <11>;
touchscreen - size - x = <1200>;
touchscreen - size - y = <1920>;
touchscreen - max - w = <512>;
touchscreen - max - p = <512>;
};
};