I2S External Codecs Configuration

The JH7110 I2S module supports up to 8 channels. All the 8 channels can connect to the external codecs of WM8960 or AC108. This section describes how to configure the WM8960 and AC108 codecs through device tree overlays.

Prerequisites

Preparing for the following for connecting to external codecs:
Preparation Details
Hardware
  1. Make sure hardware connections are correct.
    1. Make sure all the hardware connections are correct, including I2C_SDA, I2C_SCK, I2S_MCLK, I2S_BCLK, I2S_LRCK, I2S_DIN, and I2S_DOUT, all the clock and data pins are confirmed as working properly.
    2. Make sure the I2S module of the SoC and the external codec modules are fed with the proper power supply.
  2. Make sure you have checked the hardware schematics. And by checking the schematics, all the following items are correct.
    1. Confirm that the target I2S and the corresponding pins and pin multiplexing are working properly.
    2. Confirm that the I2C used for communication between the external codec and SoC is working properly.
  3. Make sure you have checked the datasheet of the external codec. And by checking the datasheet, confirm all the following items are correct.
    1. Confirm the required work mode is master mode or slave mode.
    2. Confirm that the mclk, sysclk, bclk and lrclk are derived from sysclk.
    3. Confirm the supported sample rate range.
    4. Confirm the clock polarity.
    5. Confirm the data format. (For sample bit width, Left justified, Right justified, I2S, and DSP mode).
    6. Confirm the I2C address of the external codec.
Software
  1. Make sure you have the drivers for I2S and the external codec.
  2. Make sure you have enabled the driver modules in kernel.
    1. SoC I2S driver modules, including linux-menuconfig and jh7110.dtsi, jh7110-common.dtsi.
    2. External codec driver modules, including linux-menuconfig and sf_wm8960.dtsi, sf_ac108.dtsi.
  3. Build and pack your program correctly.
  4. Enable I2S Peripherals.

Configure WM8960 and AC108 Codecs

Add the following to the freelight-u-sdk/linux/arch/riscv/boot/dts/starfive/jh7110-visionfive-v2-wm8960.dts (for WM8960) or the freelight-u-sdk/linux/arch/riscv/boot/dts/starfive/jh7110-visionfive-v2-ac108.dts (for AC108):
&sound{
       	
        simple-audio-card,dai-link@1 {
                reg = <0>;
                status = "okay";
                format = "i2s";
                bitclock-master = <&sndcodec1>;
                frame-master = <&sndcodec1>;

                widgets =
                                "Microphone", "Mic Jack",
                                "Line", "Line In",
                                "Line", "Line Out",
                                "Speaker", "Speaker",
                                "Headphone", "Headphone Jack";
                routing =
                                "Headphone Jack", "HP_L",
                                "Headphone Jack", "HP_R",
                                "Speaker", "SPK_LP",
                                "Speaker", "SPK_LN",
                                "LINPUT1", "Mic Jack",
                                "LINPUT3", "Mic Jack",
                                "RINPUT1", "Mic Jack",
                                "RINPUT2", "Mic Jack";
                cpu0 {
                        sound-dai = <&i2srx_3ch>;
                };
                cpu1 {
                        sound-dai = <&i2stx_4ch1>;
                };

                sndcodec1:codec {
                        sound-dai = <&wm8960>;
                        clocks = <&wm8960_mclk>;
                        clock-names = "mclk";
                };
        };
};
Parameter explanations:
Property Value Notes
format "i2s" Uses I2S audio bus format
bitclock-master <&sndcodec1> Codec drives BCLK
frame-master <&sndcodec1> Codec drives LRCK
cpu0 <&i2srx_3ch> Capture CPU DAI — receives data from codec ADC
cpu1 <&i2stx_4ch1> Playback CPU DAI — sends data to codec DAC
sndcodec1 <&wm8960> Codec DAI reference defined in sf_wm8960.dtsi
clocks <&wm8960_mclk> Master clock for the codec

Verify External Codecs Connection

Verify the following for connection to external codecs:
  1. Make sure OS can boot and the audio card has been registered successfully.
    1. Use the command cat /proc/asound/cards to check the existing audio cards.
    2. Use aplay -l to check the audio playback device.
    3. Use arecord -l to check the audio record device.
  2. Make sure I2C is working properly.
    • Use the command i2cdetect to search codec device (wm8960’s address is 0x1a )
      Figure 1. I2C Detect
      Note: UU in the above screen indicates wm8960 is present.
    • Use the debug nodes of the external codec to read and write the registers for I2C communication debug.
      mount -t debugfs none /mnt
      cat /mnt/wm8960_reg
  3. Verify the playback and record functions.

    Usage:

    Playback:
    aplay -Dhw:0,1 -f S32_LE -r16000 -t wav sound_32b_16k.wav
    Record:
    arecord -Dhw:0,0 -f S32_LE -r16000 -c2 -d 10 -t wav sound_32b_16k.wav