I2S Configuration

Configure Kernel Menu for I2S

  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. Select the Sound Card Support option.

  4. Select the Advanced Linux Sound Architecture option.

  5. Select the ALAS for SoC audio support option.

  6. Select the Synopsys I2S Device Driver option and then select the I2S driver for JH-7110.
    Figure 1. Synopsys I2S Device Drivers
  7. Enter the CODEC Drivers menu.

  8. Select the AC108 option.

  9. Scroll down and select the WM8960 CODEC option.
    Figure 2. WM8960 Codec
  10. Save your change and exit the kernel configuration dialog.

Enable I2S Peripherals

The I2S RX and TX peripherals are disabled by default in the SoC DTSI. Enable them in the board-level DTS file before configuring any codec.

  1. Open the board DTS file:
    • For WM8960: freelight-u-sdk/linux/arch/riscv/boot/dts/starfive/jh7110-visionfive-v2-wm8960.dts
    • For AC108: freelight-u-sdk/linux/arch/riscv/boot/dts/starfive/jh7110-visionfive-v2-ac108.dts
  2. Add or modify the following nodes:
    &i2srx_3ch {
            status = "okay";
    };
    
    &i2stx_4ch1 {
            status = "okay";
    };
  3. Save the DTS files.

Verify I2S Audio Function

The examples below use WM8960

Action Command Output Example
Check sound card registration
cat /proc/asound/cards
0 [StarfiveMultiSo]: simple-card - Starfive-Multi-Sound-Card
                      Starfive-Multi-Sound-Card
Note: Before a physical codec is associated with the I2S audio card, all the registered audio cards are virtual, thus configuration is not needed.
List audio devices
arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: StarfiveMultiSo [Starfive-Multi-Sound-Card], device 0: 100e0000.i2srx_3ch-wm8960-hifi wm8960-hifi-0 [100e0000.i2srx_3ch-wm8960-hifi wm8960-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
List playback devices
aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: StarfiveMultiSo [Starfive-Multi-Sound-Card], device 1: 120c0000.i2stx_4ch1-wm8960-hifi wm8960-hifi-1 [120c0000.i2stx_4ch1-wm8960-hifi wm8960-hifi-1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
Check playback stream parameters
# Start playback in background (&)
aplay -Dhw:0,1 -f S32_LE -r48000 -t wav tdm_32bit_48k.wav &

# Check active parameters
cat /proc/asound/card0/pcm1p/sub0/hw_params
access: RW_INTERLEAVED
format: S32_LE
subformat: STD
channels: 2
rate: 48000 (48000/1)
period_size: 512
buffer_size: 24064
Check capture stream parameters
# Start capture in background: 32-bit, 16 kHz, 2 channels, 10 seconds
arecord -Dhw:0,0 -f S32_LE -r16000 -c2 -d 10 -t wav music_32b_16k.wav &

# Check active parameters
cat /proc/asound/card0/pcm0c/sub0/hw_params
access: RW_INTERLEAVED
format: S32_LE
subformat: STD
channels: 2
rate: 16000 (16000/1)
period_size: 512
buffer_size: 8192
List sound card controllers
# amixer -controls
numid=12,iface=MIXER,name='Headphone Playback ZC Switch'
numid=11,iface=MIXER,name='Headphone Playback Volume'
numid=17,iface=MIXER,name='PCM Playback -6dB Switch'
numid=57,iface=MIXER,name='Mono Output Mixer Left Switch'
numid=58,iface=MIXER,name='Mono Output Mixer Right Switch'
numid=41,iface=MIXER,name='ADC Data Output Select'
numid=19,iface=MIXER,name='ADC High Pass Filter Switch'
numid=36,iface=MIXER,name='ADC PCM Capture Volume'
numid=18,iface=MIXER,name='ADC Polarity'
numid=2,iface=MIXER,name='Capture Volume ZC Switch'
numid=3,iface=MIXER,name='Capture Switch'
numid=1,iface=MIXER,name='Capture Volume'
numid=10,iface=MIXER,name='Playback Volume'
numid=23,iface=MIXER,name='3D Filter Lower Cut-Off'
numid=22,iface=MIXER,name='3D Filter Upper Cut-Off'
numid=25,iface=MIXER,name='3D Switch'
numid=24,iface=MIXER,name='3D Volume'
numid=33,iface=MIXER,name='ALC Attack'
numid=32,iface=MIXER,name='ALC Decay'
numid=26,iface=MIXER,name='ALC Function'
numid=30,iface=MIXER,name='ALC Hold Time'
numid=27,iface=MIXER,name='ALC Max Gain'
numid=29,iface=MIXER,name='ALC Min Gain'
numid=31,iface=MIXER,name='ALC Mode'
numid=28,iface=MIXER,name='ALC Target'
numid=21,iface=MIXER,name='DAC Deemphasis Switch'
numid=42,iface=MIXER,name='DAC Mono Mix'
numid=20,iface=MIXER,name='DAC Polarity'
numid=45,iface=MIXER,name='Left Boost Mixer LINPUT1 Switch'
numid=43,iface=MIXER,name='Left Boost Mixer LINPUT2 Switch'
numid=44,iface=MIXER,name='Left Boost Mixer LINPUT3 Switch'
numid=9,iface=MIXER,name='Left Input Boost Mixer LINPUT1 Volume'
numid=5,iface=MIXER,name='Left Input Boost Mixer LINPUT2 Volume'
numid=4,iface=MIXER,name='Left Input Boost Mixer LINPUT3 Volume'
numid=49,iface=MIXER,name='Left Input Mixer Boost Switch'
numid=53,iface=MIXER,name='Left Output Mixer Boost Bypass Switch'
numid=37,iface=MIXER,name='Left Output Mixer Boost Bypass Volume'
numid=52,iface=MIXER,name='Left Output Mixer LINPUT3 Switch'
numid=38,iface=MIXER,name='Left Output Mixer LINPUT3 Volume'
numid=51,iface=MIXER,name='Left Output Mixer PCM Playback Switch'
numid=35,iface=MIXER,name='Noise Gate Switch'
numid=34,iface=MIXER,name='Noise Gate Threshold'
numid=48,iface=MIXER,name='Right Boost Mixer RINPUT1 Switch'
numid=46,iface=MIXER,name='Right Boost Mixer RINPUT2 Switch'
numid=47,iface=MIXER,name='Right Boost Mixer RINPUT3 Switch'
numid=8,iface=MIXER,name='Right Input Boost Mixer RINPUT1 Volume'
numid=7,iface=MIXER,name='Right Input Boost Mixer RINPUT2 Volume'
numid=6,iface=MIXER,name='Right Input Boost Mixer RINPUT3 Volume'
numid=50,iface=MIXER,name='Right Input Mixer Boost Switch'
numid=56,iface=MIXER,name='Right Output Mixer Boost Bypass Switch'
numid=39,iface=MIXER,name='Right Output Mixer Boost Bypass Volume'
numid=54,iface=MIXER,name='Right Output Mixer PCM Playback Switch'
numid=55,iface=MIXER,name='Right Output Mixer RINPUT3 Switch'
numid=40,iface=MIXER,name='Right Output Mixer RINPUT3 Volume'
numid=16,iface=MIXER,name='Speaker AC Volume'
numid=15,iface=MIXER,name='Speaker DC Volume'
numid=13,iface=MIXER,name='Speaker Playback Volume'
numid=14,iface=MIXER,name='Speaker Playback ZC Switch'
Verify recording
    • To record a 10-second sound track in the sample rate of 16 KHz:
      # arecord -Dhw:0,0 -f S32_LE -r16000 -c2 -d 10 -t wav sound_32b_16k.wav
    • To record a 10-second sound track in the sample rate of 44.1 KHz:
      # arecord -Dhw:0,0 -f S32_LE -r44100 -c2 -d 10 -t wav sound_32b_44100.wav
–
Verify playback
  • To play a 10-second sound track in the sample rate of 16 KHz:
    # aplay -Dhw:0,1 -f S32_LE -r16000 -t wav sound_32b_16k.wav
  • To play a 10-second sound track in the sample rate of 44.1 KHz:
    # arecord -Dhw:0,1 -f S32_LE -r44100 -t wav sound_32b_44100.wav
–
Verify loopback

Loopback is essentially the test channel between TXFIFO and RXFIFO in IC. No external pin connections are required. Once loopback has been enabled, if you can write data in I2S TX, you can read data from I2S RX. The function is usually used in audio data recording scenarios.

Use the commands below to validate the loopback function.
# arecord -D hw:0,0 -r 16000 -c 2 -f S32_LE -t raw | aplay -D hw:0,1 -t raw -r 16000 -c 2 -f S32_LE

Configure U-Boot

Follow the steps below to configure the U-boot parameters for Linux boot.
  1. Use the following command to switch IO voltage to 3.3 V.
    mw.l 0x1303000c 0x0 0x1
  2. Set IP address and gateway address according to actual application environments.
    The following code block provides an example based on the test environment.
    setenv bootfile vmlinuz; 
    setenv fdt_addr_r 0x48000000;
    setenv fdt_high 0xffffffffffffffff; 
    setenv fdtcontroladdr 0xffffffffffffffff; 
    setenv initrd_high 0xffffffffffffffff; 
    setenv kernel_addr_r 0x44000000; 
    setenv fileaddr a0000000; 
    setenv ipaddr 192.168.125.211; 
    setenv gatewayip 192.168.125.1; 
    setenv serverip 192.168.125.139;
    setenv kernel_comp_addr_r 0xb0000000;
    setenv kernel_comp_size 0x10000000
  3. Use the following command to boot Linux.
    tftpboot ${fdt_addr_r} jh7110-visionfive-v2-pcie-i2s-sd.dtb;
    tftpboot ${kernel_addr_r} Im-age.gz;
    tftpboot ${ramdisk_addr_r} initramfs.cpio.gz;
    booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};