I2C Configuration

Configure Kernel Menu for I2C

  1. Under the root directory of freelight-u-sdk, run the following command to enter the kernel menu configuration GUI.
    make linux-menuconfig
  2. Enter the Device Drivers menu.

  3. Enter the I2C support > I2C Hardware Bus Support menu.

  4. In the I2C Hardware Bus Support menu, select the Synopsys DesignWare Platform option.

  5. In the Graphics support menu, select the HDMI2.0 option.

  6. Save your change and exit the kernel configuration dialog.

Board-level Configuration: Configure I2C Controllers

The following code example (in the jh7110-common.dtsi file) configures the I2C0 controller timing, bus speed, pin mapping, default status, and defines two onboard audio codec devices connected to the I2C bus:
&i2c0 {
	clock-frequency = <100000>;        
	i2c-sda-hold-time-ns = <300>;      
	i2c-sda-falling-time-ns = <510>;   
	i2c-scl-falling-time-ns = <510>;   
	auto_calc_scl_lhcnt;
	pinctrl-names = "default";
	pinctrl-0 = <&i2c0_pins>;
	status = "disabled";

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

	wm8960: codec@1a {
		compatible = "wlf,wm8960";
		reg = <0x1a>;
		#sound-dai-cells = <0>;
		wlf,shared-lrclk;
	};
};
Parameter explanations:
  • &i2c0: References the I2C0 controller node for board-level configuration override.
  • clock-frequency = <100000>: Sets I2C bus clock speed to 100 kHz (standard mode).
  • i2c-sda-hold-time-ns = <300>: Configures the SDA pin hold time in nanoseconds for stable communication.
  • i2c-sda-falling-time-ns = <510>: Defines the falling edge time of the SDA signal.
  • i2c-scl-falling-time-ns = <510>: Defines the falling edge time of the SCL signal.
  • auto_calc_scl_lhcnt: Enables automatic hardware calculation of SCL high/low cycle counts.
  • pinctrl-names = "default": Names the default pin configuration state.
  • pinctrl-0 = <&i2c0_pins>: Assigns the pre-defined I2C0 pin configuration to the controller.
  • status = "disabled": Sets the controller to disabled by default (can be set to "okay" to enable).
  • ac108_a: ac108@3b: Defines an AC108 audio codec device at I2C address 0x3b.
    • compatible: Driver matching string for the AC108 codec.
    • reg = <0x3b>: I2C slave address of the AC108.
    • #sound-dai-cells = <0>: Audio interface configuration parameter.
    • data-protocol = <0>: Audio data format selection.
  • wm8960: codec@1a: Defines a WM8960 audio codec device at I2C address 0x1a.
    • compatible: Driver matching string for the WM8960 codec.
    • reg = <0x1a>: I2C slave address of the WM8960.
    • #sound-dai-cells = <0>: Audio interface configuration parameter.
    • wlf,shared-lrclk: Enables shared LR clock for the audio codec (hardware-specific feature).

Board-level Configuration: Configure I2C Pins

The following code example (in the pinctrl.dtsi file under the jh7110-visionfive-v2.dts) defines the pin multiplexing, electrical settings, and signal paths for the I2C0 SCL and SDA pins at the board level:
i2c0_pins: i2c0-pins {
		i2c0-pins-scl {
			sf,pins = <PAD_GPIO57>;
			sf,pinmux = <PAD_GPIO57_FUNC_SEL 0>;
			sf,pin-ioconfig = <IO(GPIO_IE(1) | (GPIO_PU(1)))>;
			sf,pin-gpio-dout = <GPO_LOW>;
			sf,pin-gpio-doen = <OEN_I2C0_IC_CLK_OE>;
			sf,pin-gpio-din =  <GPI_I2C0_IC_CLK_IN_A>;
		};

		i2c0-pins-sda {
			sf,pins = <PAD_GPIO58>;
			sf,pinmux = <PAD_GPIO58_FUNC_SEL 0>;
			sf,pin-ioconfig = <IO(GPIO_IE(1) | (GPIO_PU(1)))>;
			sf,pin-gpio-dout = <GPO_LOW>;
			sf,pin-gpio-doen = <OEN_I2C0_IC_DATA_OE>;
			sf,pin-gpio-din =  <GPI_I2C0_IC_DATA_IN_A>;
		};
};
Parameter explanations:
  • i2c0_pins: i2c0-pins: Defines a named pin configuration node for I2C0.
  • i2c0-pins-scl: Sub-node configuring the I2C0 SCL (clock) pin.
    • sf,pins = <PAD_GPIO57>: Assigns the SCL function to GPIO57.
    • sf,pinmux = <PAD_GPIO57_FUNC_SEL 0>: Configures pin multiplexing for I2C0 SCL mode.
    • sf,pin-ioconfig: Sets electrical properties (input enable + internal pull-up resistor).
    • sf,pin-gpio-dout = <GPO_LOW>: Default output low level (GPIO mode only).
    • sf,pin-gpio-doen = <OEN_I2C0_IC_CLK_OE>: Enables hardware-controlled output enable for SCL.
    • sf,pin-gpio-din = <GPI_I2C0_IC_CLK_IN_A>: Configures the SCL input signal path.
  • i2c0-pins-sda: Sub-node configuring the I2C0 SDA (data) pin.
    • sf,pins = <PAD_GPIO58>: Assigns the SDA function to GPIO58.
    • sf,pinmux = <PAD_GPIO58_FUNC_SEL 0>: Configures pin multiplexing for I2C0 SDA mode.
    • sf,pin-ioconfig: Sets electrical properties (input enable + internal pull-up resistor).
    • sf,pin-gpio-dout = <GPO_LOW>: Default output low level (GPIO mode only).
    • sf,pin-gpio-doen = <OEN_I2C0_IC_DATA_OE>: Enables hardware-controlled output enable for SDA.
    • sf,pin-gpio-din = <GPI_I2C0_IC_DATA_IN_A>: Configures the SDA input signal path.