General Use Example

In most cases, the I2C adapter works in master mode. Before you start transferring data in your I2C driver, you need to finish some configuration.
  1. Set a suitable sample rate of I2C bus through the device tree according to your client device requirement.

    The following code blocks provide some commonly used configurations.

    To set the sample rate as 100 KHz.
    &i2c0 {
                    clock-frequency = <100000>;
                    i2c-sda-hold-time-ns = <300>;
                    i2c-sda-falling-time-ns = <510>;
                    i2c-scl-falling-time-ns = <510>;
            }
    
    To set the sample rate as 400 KHz.
    &i2c0 {
                    clock-frequency = <400000>;
                    i2c-sda-hold-time-ns = <300>;
                    i2c-sda-falling-time-ns = <150>;
                    i2c-scl-falling-time-ns = <150>;
            }
    
  2. Mount your I2C client device on a specified adapter through the device tree. The property compatible has to match your I2C driver and reg is set as the I2C slave address.

    The following code block shows a simple case of ac108 mounted on adapter i2c0.

    &i2c0 {
                            ac108_a: ac108@3b {
                                    compatible = "x-power,ac108_0";
                                    reg = <0x3b>;
                                    #sound-dai-cells = <0>;
                                    data-protocol = <0>;
                    };
            }