I2S sound with RT5651


jsorocil
 Share

1 1
Go to solution Solved by jsorocil,

Recommended Posts

I am trying to enable sound with RT5651 audio codec on SoM-RK3399v2. Hardware is integrated on the board (on i2c1 bus, address 0x1a), worked with official FriendlyElec Linux (4.4 kernel IIRC) and tests were run with powered speakers (which work when connected to PC).

I used this patch to patch my current device tree:
https://github.com/armbian/build/blob/master/patch/kernel/rockchip64-dev/board-nanopi-m4v2-dts-add-sound-card.patch

I did not use Kconfig file from the patch as it seems that my kernel have has built that modules.


page 19 of NanoPI M4V2 and page 7 of SoM-RK3399 schematic shows that same audio codec (rt5651 on the same busses (I2S1 and I2C1) is used on both boards):
https://wiki.friendlyarm.com/wiki/images/c/cc/NanoPi-M4V2_1908_Schematic.pdf
https://wiki.friendlyarm.com/wiki/images/d/de/SOM-RK3399_Dev_Kit_1904_Schematic.pdf

After reboot I can see card but it didn't play any sound on the speakers (except random quite noises - which also occures in u-boot)
 

# dmesg | grep rt5651
[    3.535527] rt5651 1-001a: Failed to reguest IRQ 0: -22

# uname -a
Linux miki 5.10.12-rockchip64 #21.02.1 SMP PREEMPT Wed Feb 3 20:55:02 CET 2021 aarch64 aarch64 aarch64 GNU/Linux

# grep -E  "SND_SOC_ROCKCHIP_I2S|SND_SOC_RT5651" /boot/config-5.10.12-rockchip64
CONFIG_SND_SOC_ROCKCHIP_I2S=m
CONFIG_SND_SOC_ROCKCHIP_I2S_TDM=m
CONFIG_SND_SOC_RT5651=m

# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

# cat /etc/modules
snd_soc_simple_card
snd_soc_rt5651

# lsmod | grep snd
snd_soc_hdmi_codec     20480  1
snd_soc_rockchip_spdif    16384  0
snd_soc_rockchip_i2s    24576  4
snd_soc_rt5651         98304  1
snd_soc_rl6231         20480  1 snd_soc_rt5651
snd_soc_simple_card    24576  0
snd_soc_simple_card_utils    28672  1 snd_soc_simple_card
snd_soc_core          237568  6 snd_soc_rt5651,snd_soc_hdmi_codec,snd_soc_rockchip_spdif,snd_soc_simple_card_utils,snd_soc_rockchip_i2s,snd_soc_simple_card
snd_pcm_dmaengine      20480  1 snd_soc_core
snd_pcm               118784  4 snd_soc_rt5651,snd_soc_hdmi_codec,snd_soc_core,snd_pcm_dmaengine
snd_seq_midi           20480  0
snd_seq_midi_event     16384  1 snd_seq_midi
snd_rawmidi            40960  1 snd_seq_midi
snd_seq                81920  2 snd_seq_midi,snd_seq_midi_event
snd_seq_device         20480  3 snd_seq,snd_seq_midi,snd_rawmidi
snd_timer              40960  2 snd_seq,snd_pcm
snd                    90112  7 snd_seq,snd_seq_device,snd_soc_hdmi_codec,snd_timer,snd_soc_core,snd_pcm,snd_rawmidi
soundcore              16384  1 snd

# aplay -l
**** List of PLAYBACK Hardware Devices ****
xcb_connection_has_error() returned true
card 0: realtekrt5651co [realtek,rt5651-codec], device 0: ff890000.i2s-rt5651-aif1 rt5651-aif1-0 [ff890000.i2s-rt5651-aif1 rt5651-aif1-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: hdmisound [hdmi-sound], device 0: ff8a0000.i2s-i2s-hifi i2s-hifi-0 [ff8a0000.i2s-i2s-hifi i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

# cat /etc/asound.conf
pcm.!default {
    type hw
    card 0
    device 0
}

ctl.!default {
    type hw
    card 0
}

# cat /proc/asound/pcm
00-00: ff890000.i2s-rt5651-aif1 rt5651-aif1-0 : ff890000.i2s-rt5651-aif1 rt5651-aif1-0 : playback 1 : capture 1
01-00: ff8a0000.i2s-i2s-hifi i2s-hifi-0 : ff8a0000.i2s-i2s-hifi i2s-hifi-0 : playback 1

 

mpv reports no errors, but there is no sound. There is a slight pop when mpv starts playing and around 5 seconds after mpv stops playing.
Same as with speakers-test

# mpv sound.wav
 (+) Audio --aid=1 (pcm_s16le 2ch 44100Hz)
xcb_connection_has_error() returned true
xcb_connection_has_error() returned true
AO: [alsa] 44100Hz stereo 2ch s16
A: 00:00:41 / 00:10:07 (6%)


Exiting... (Quit)


# speaker-test -c2

speaker-test 1.2.2

Playback device is default
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
xcb_connection_has_error() returned true
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 128 to 131072
Period size range from 64 to 65536
Using max buffer size 131072
Periods = 4
was set period_size = 32768
was set buffer_size = 131072
 0 - Front Left
 1 - Front Right
Time per period = 2.740121
 0 - Front Left
^C 1 - Front Right
Time per period = 1.390964


# dmesg | tail -2
[  326.479986] rockchip-i2s ff890000.i2s: Fail to set mclk -22
[  326.480598] rockchip-i2s ff890000.i2s: ASoC: error at snd_soc_dai_set_sysclk on ff890000.i2s: -22


Maybe I have invalid I2S clock?

# cat /sys/kernel/debug/clk/clk_i2sout_src/clk_parent
clk_i2s0
# echo clk_i2s1 >> /sys/kernel/debug/clk/clk_i2sout_src/clk_parent
echo: write error: invalid argument
zsh: exit 1

Tried various amixer set commands and alsactl files from other threads but still no sound.

 

Any ideas what might be the problem?

Link to post
Share on other sites

Donate and support the project!

This may be related to issues going on in a different thread: https://forum.armbian.com/topic/16401-77666669616-rockchip-i2s-ff890000i2s-fail-to-set-mclk-22/

 

Basically, it looks like the I2S devices &i2s1 and &i2s2 aren't being initialized with the correct clock.

 

At a glance, I don't see anything glaring in the DTB for the I2S devices @ ff89000 and ff8a0000, but something is definitely off.

 

Link to post
Share on other sites

So, been poking at this, not really making any progress, but did have some thoughts.

 

First, I realized later that you're missing the output of "armbianmonitor -u". Recommend you upload and put at the top of your post. You'll probably get more interest if folks know more about your environment.

 

Second, there are some substantial differences between the FriendlyElec and Armbian DTB's. The FriendlyElec DTB provides a "status = okay" on both "/rt5651-sound" and "&rt5651". It also provides a number of "assigned-clocks" and "reset" definitions as well. None of those are in the Armbian DTB. The Armbian DTB does define "&i2s1" as having 8 playback and capture channels, which I doesn't look like it's correct. However, attempts as using an overlay to tweak the DTB to look more like the FriendlyElec version has not resulted in a working audio channel.

Link to post
Share on other sites

More digging.

 

Looks like folks have gotten the M4 (v1) headphone jack working in the past. At minimum, you may have to fiddle with ALSA settings a bit before it does much: https://forum.armbian.com/topic/9605-sound-problems-with-nanopi-m4/?do=findComment&comment=72701

 

I was not able to get the headphone jack working, but HDMI is working for me. So at least most of the audio subsystem is intact. Had to set the default audio device to HDMI via pactl before I got anything out of it though.

 

Both I2S controllers on ff890000 and ff8a0000 are still screaming into the system log though. Guess it's not a fatal error though?

Link to post
Share on other sites

Armbianmonitor uploaded

Booted into FriendlyElec distribution and gather some logs:


Linux SOM-RK3399v2 4.4.179 #2 SMP Tue Sep 15 15:59:49 CST 2020 aarch64 aarch64 aarch64 GNU/Linux

 

root@SOM-RK3399v2:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: realtekrt5651co [realtek,rt5651-codec], device 0: ff890000.i2s-rt5651-aif1 rt5651-aif1-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: rockchiphdmi [rockchip,hdmi], device 0: ff8a0000.i2s-i2s-hifi i2s-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0

 

root@SOM-RK3399v2:~# dmesg | grep -i i2s
[    1.858450] asoc-simple-card rt5651-sound: rt5651-aif1 <-> ff890000.i2s mapping ok
[    1.875441] asoc-simple-card hdmi-sound: i2s-hifi <-> ff8a0000.i2s mapping ok

root@SOM-RK3399v2:~# dmesg | grep rt5651
[    1.838498] of_get_named_gpiod_flags: parsed 'simple-audio-card,hp-det-gpio' property of node '/rt5651-sound[0]' - status (0)
[    1.838522] of_get_named_gpiod_flags: can't parse 'simple-audio-card,mic-det-gpio' property of node '/rt5651-sound[0]'
[    1.856077] asoc-simple-card rt5651-sound: ASoC: DAPM unknown pin Headphones
[    1.858450] asoc-simple-card rt5651-sound: rt5651-aif1 <-> ff890000.i2s mapping ok
[    1.859230] asoc-simple-card rt5651-sound: ASoC: no source widget found for MICBIAS1
[    1.859959] asoc-simple-card rt5651-sound: ASoC: Failed to add route MICBIAS1 -> direct -> Mic Jack
[    1.861239] rt5651 1-001a: ASoC: mux INL1 Mux has no paths
[    1.861783] rt5651 1-001a: ASoC: mux INR1 Mux has no paths
[    1.862294] rt5651 1-001a: ASoC: mux INL2 Mux has no paths
[    1.862830] rt5651 1-001a: ASoC: mux INR2 Mux has no paths
[    1.870625] input: realtek,rt5651-codec Headphones as /devices/platform/rt5651-sound/sound/card0/input3
[    2.006432] asoc-simple-card rt5651-sound: ASoC: DAPM unknown pin Headphones
[    2.023786]   #0: realtek,rt5651-codec

 

root@SOM-RK3399v2:~# cat /etc/modules
<nothing specified>

 

root@SOM-RK3399v2:~# lsmod | grep snd
<nothing>

 

root@SOM-RK3399v2:~# cat /etc/asound.conf
cat: /etc/asound.conf: No such file or directory


root@SOM-RK3399v2:~# amixer
Simple mixer control 'Mono ADC',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 127
  Front Left: Capture 47 [37%] [0.00dB]
  Front Right: Capture 47 [37%] [0.00dB]
Simple mixer control 'Mono DAC',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 175
  Mono:
  Front Left: Playback 170 [97%] [-18.75dB]
  Front Right: Playback 170 [97%] [-18.75dB]
Simple mixer control 'ADC',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 127
  Front Left: Capture 47 [37%] [0.00dB] [on]
  Front Right: Capture 47 [37%] [0.00dB] [on]
Simple mixer control 'ADC Boost Gain',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%]
  Front Right: 0 [0%]
Simple mixer control 'ADC IF2 Data',0
  Capabilities: enum
  Items: 'Normal' 'Swap' 'left copy to right' 'right copy to left'
  Item0: 'Normal'
Simple mixer control 'DAC IF2 Data',0
  Capabilities: enum
  Items: 'Normal' 'Swap' 'left copy to right' 'right copy to left'
  Item0: 'Normal'
Simple mixer control 'DAC L2 Mux',0
  Capabilities: enum
  Items: 'IF1' 'IF2'
  Item0: 'IF2'
Simple mixer control 'DAC MIXL INF1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'DAC MIXL Stereo ADC',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DAC MIXR INF1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'DAC MIXR Stereo ADC',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DAC R2 Mux',0
  Capabilities: enum
  Items: 'IF1' 'IF2'
  Item0: 'IF2'
Simple mixer control 'DAC1',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 175
  Mono:
  Front Left: Playback 169 [97%] [-22.50dB]
  Front Right: Playback 169 [97%] [-22.50dB]
Simple mixer control 'DAC2',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [on]
  Front Right: Playback [on]
Simple mixer control 'DD MIXL DAC L1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DD MIXL DAC L2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DD MIXL DAC R2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DD MIXR DAC L2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DD MIXR DAC R1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DD MIXR DAC R2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'DMIC ASRC',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'HP',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 39
  Mono:
  Front Left: Playback 16 [41%] [-22.50dB]
  Front Right: Playback 16 [41%] [-22.50dB]
Simple mixer control 'HPO L',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'HPO MIX DAC1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'HPO MIX HPVOL',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'HPO R',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'HPOVOL L',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'HPOVOL R',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IF1 ASRC',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'IF2 ADC',0
  Capabilities: enum
  Items: 'IF1 ADC1' 'IF1 ADC2'
  Item0: 'IF1 ADC1'
Simple mixer control 'IF2 ASRC',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'IN',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 31
  Front Left: Capture 23 [74%] [0.00dB]
  Front Right: Capture 23 [74%] [0.00dB]
Simple mixer control 'IN1 Boost',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 8
  Mono: 0 [0%]
Simple mixer control 'IN2 Boost',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 8
  Mono: 2 [25%]
Simple mixer control 'LOUT L',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'LOUT MIX DAC L1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'LOUT MIX DAC R1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'LOUT MIX OUTVOL L',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'LOUT MIX OUTVOL R',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'LOUT R',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUT',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 39
  Mono:
  Front Left: Playback 31 [79%] [0.00dB]
  Front Right: Playback 31 [79%] [0.00dB]
Simple mixer control 'OUT MIXL BST1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUT MIXL BST2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUT MIXL DAC L1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'OUT MIXL INL1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUT MIXL REC MIXL',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUT MIXR BST1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUT MIXR BST2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUT MIXR DAC R1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'OUT MIXR INR1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUT MIXR REC MIXR',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUTVOL L',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'OUTVOL R',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'PDM L Mux',0
  Capabilities: enum
  Items: 'DD MIX' 'Stereo DAC MIX'
  Item0: 'DD MIX'
Simple mixer control 'PDM R Mux',0
  Capabilities: enum
  Items: 'DD MIX' 'Stereo DAC MIX'
  Item0: 'DD MIX'
Simple mixer control 'RECMIXL BST1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'RECMIXL BST2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'RECMIXL BST3',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'RECMIXL INL1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'RECMIXR BST1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'RECMIXR BST2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'RECMIXR BST3',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'RECMIXR INR1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'RT5651 ASRC',0
  Capabilities: enum
  Items: 'Disable' 'Enable'
  Item0: 'Disable'
Simple mixer control 'Stereo DAC MIXL DAC L1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Stereo DAC MIXL DAC L2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo DAC MIXL DAC R1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo DAC MIXR DAC L1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo DAC MIXR DAC R1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Stereo DAC MIXR DAC R2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo1 ADC L1 Mux',0
  Capabilities: enum
  Items: 'DD MIX' 'ADC'
  Item0: 'ADC'
Simple mixer control 'Stereo1 ADC L2 Mux',0
  Capabilities: enum
  Items: 'DMIC' 'DD MIX'
  Item0: 'DD MIX'
Simple mixer control 'Stereo1 ADC MIXL ADC1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Stereo1 ADC MIXL ADC2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo1 ADC MIXR ADC1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Stereo1 ADC MIXR ADC2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo1 ADC R1 Mux',0
  Capabilities: enum
  Items: 'DD MIX' 'ADC'
  Item0: 'ADC'
Simple mixer control 'Stereo1 ADC R2 Mux',0
  Capabilities: enum
  Items: 'DMIC' 'DD MIX'
  Item0: 'DD MIX'
Simple mixer control 'Stereo2 ADC L1 Mux',0
  Capabilities: enum
  Items: 'DD MIXL' 'ADCL'
  Item0: 'ADCL'
Simple mixer control 'Stereo2 ADC L2 Mux',0
  Capabilities: enum
  Items: 'DMIC L' 'DD MIXL'
  Item0: 'DD MIXL'
Simple mixer control 'Stereo2 ADC MIXL ADC1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo2 ADC MIXL ADC2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo2 ADC MIXR ADC1',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo2 ADC MIXR ADC2',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Stereo2 ADC R1 Mux',0
  Capabilities: enum
  Items: 'DD MIXR' 'ADCR'
  Item0: 'DD MIXR'
Simple mixer control 'Stereo2 ADC R2 Mux',0
  Capabilities: enum
  Items: 'DMIC R' 'DD MIXR'
  Item0: 'DMIC R'


root@SOM-RK3399v2:~# cat /sys/kernel/debug/clk/clk_i2sout_src/clk_parent
clk_i2s1

 

I2S clock is indeed I2S1 (mine under Armbian is I2S0).

Tried various alsamixer commands (from your link and from others on the forum) without success.

Link to post
Share on other sites

Managed to get sound working on 4.4 Armbian legacy kernel with stock rk3399-nanopi-m4v2.dtb from linux-dtb-legacy package.

 


% uname -a

Linux miki 4.4.213-rk3399 #1 SMP Tue Apr 6 02:35:05 CDT 2021 aarch64 aarch64 aarch64 GNU/Linux

 

% dpkg -l | grep -v ^rc | grep -E "linux-dtb-legacy|linux-image-legacy"

ii  linux-dtb-legacy-rk3399                 21.05.0-trunk                        arm64        Linux DTB, version 4.4.213-rk3399
ii  linux-image-legacy-rk3399            21.05.0-trunk                        arm64        Linux kernel, version 4.4.213-rk3399

 

% aplay -l
**** List of PLAYBACK Hardware Devices ****
xcb_connection_has_error() returned true
card 0: Dummy [Dummy], device 0: Dummy PCM [Dummy PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 2: realtekrt5651co [realtek,rt5651-codec], device 0: ff890000.i2s-rt5651-aif1 rt5651-aif1-0 [ff890000.i2s-rt5651-aif1 rt5651-aif1-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: rockchiphdmi [rockchip,hdmi], device 0: ff8a0000.i2s-i2s-hifi i2s-hifi-0 [ff8a0000.i2s-i2s-hifi i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

 

% cat /etc/asound.conf
pcm.!default {
    type hw
    card 2
    device 0
}

ctl.!default {
    type hw
    card 2
}

 

% cat /sys/kernel/debug/clk/clk_i2sout_src/clk_parent

clk_i2s1

Link to post
Share on other sites

  • Solution

Success! :beer:

 

% uname -a
Linux miki 5.10.21-rockchip64 #21.02.3 SMP PREEMPT Mon Mar 8 01:05:08 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

% dpkg -l | grep -v ^rc | grep -E "linux-dtb-current|linux-image-current"
ii  linux-dtb-current-rockchip64            21.02.3                              arm64        Linux DTB, version 5.10.21-rockchip64
ii  linux-image-current-rockchip64          21.02.3                              arm64        Linux kernel, version 5.10.21-rockchip64

 

% aplay -l
**** List of PLAYBACK Hardware Devices ****
xcb_connection_has_error() returned true
card 0: realtekrt5651co [realtek,rt5651-codec], device 0: ff890000.i2s-rt5651-aif1 rt5651-aif1-0 [ff890000.i2s-rt5651-aif1 rt5651-aif1-0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: hdmisound [hdmi-sound], device 0: ff8a0000.i2s-i2s-hifi i2s-hifi-0 [ff8a0000.i2s-i2s-hifi i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

 

% grep -iE "name|linux|version" /etc/armbian-release
BOARD_NAME="NanoPi M4V2"
DISTRIBUTION_CODENAME=focal
VERSION=21.02.3
LINUXFAMILY=rockchip64

 

Patched .dts:

--- a/dt-bindings/clock/rk3399-cru.h
+++ b/dt-bindings/clock/rk3399-cru.h
@@ -19,6 +19,7 @@
 #define ARMCLKB                9

 /* sclk gates (special clocks) */
+#define SCLK_I2SOUT_SRC        64
 #define SCLK_I2C1            65
 #define SCLK_I2C2            66
 #define SCLK_I2C3            67
diff --git a/rk3399-som-rk3399v2.dts b/rk3399-som-rk3399v2.dts
index 2626e27..6c708f8 100644
--- a/rk3399-som-rk3399v2.dts
+++ b/rk3399-som-rk3399v2.dts
@@ -75,6 +75,35 @@
             };
         };
     };
+
+    rt5651_card: rt5651-sound {
+        status = "okay";
+        compatible = "simple-audio-card";
+        pinctrl-names = "default";
+        pinctrl-0 = <&hp_det>;
+
+        simple-audio-card,name = "realtek,rt5651-codec";
+        simple-audio-card,format = "i2s";
+        simple-audio-card,mclk-fs = <256>;
+        simple-audio-card,hp-det-gpio = <&gpio4 28 GPIO_ACTIVE_HIGH>;
+
+        simple-audio-card,widgets =
+            "Microphone", "Mic Jack",
+            "Headphone", "Headphone Jack";
+        simple-audio-card,routing =
+            "Mic Jack", "micbias1",
+            "IN2P", "Mic Jack",
+            "IN3P", "Mic Jack",
+            "Headphone Jack", "HPOL",
+            "Headphone Jack", "HPOR";
+
+        simple-audio-card,cpu {
+            sound-dai = <&i2s1>;
+        };
+        simple-audio-card,codec {
+            sound-dai = <&rt5651>;
+        };
+    };
 };    // root/ node

 &vcc3v3_sys {
@@ -114,3 +143,44 @@
         };
     };
 };
+
+&i2c1 {
+    status = "okay";
+    i2c-scl-rising-time-ns = <300>;
+    i2c-scl-falling-time-ns = <15>;
+    clock-frequency = <200000>;
+
+    rt5651: rt5651@1a {
+        #sound-dai-cells = <0>;
+        compatible = "realtek,rt5651";
+        reg = <0x1a>;
+        clocks = <&cru SCLK_I2S_8CH_OUT>;
+        clock-names = "mclk";
+        status = "okay";
+    };
+};
+
+&i2s1 {
+    assigned-clocks = <&cru SCLK_I2SOUT_SRC>;
+    assigned-clock-parents = <&cru SCLK_I2S1_8CH>;
+    pinctrl-names = "default";
+    pinctrl-0 = <&i2s_8ch_mclk>,<&i2s1_2ch_bus>;
+    rockchip,playback-channels = <2>;
+    rockchip,capture-channels = <2>;
+    #sound-dai-cells = <0>;
+    status = "okay";
+};
+
+&pinctrl {
+    i2s1 {
+        i2s_8ch_mclk: i2s-8ch-mclk {
+            rockchip,pins = <4 RK_PA0 1 &pcfg_pull_none>;
+        };
+    };
+
+    headphone {
+        hp_det: hp-det {
+            rockchip,pins = <4 28 RK_FUNC_GPIO &pcfg_pull_up>;
+        };
+    };
+};

 

Funny thing is that clk_parent will change after audio player is started:

% cat /sys/kernel/debug/clk/clk_i2sout_src/clk_parent
clk_i2s1
% mpv <audiofile>
% cat /sys/kernel/debug/clk/clk_i2sout_src/clk_parent
clk_i2s0


But in both cases sound works on my SoM-RK3399v2 SBC :)
Link to post
Share on other sites

There appears to be a lot of good looking information in this post, though do have some questions on what you did, while I'm unpacking everything in this post ...

 

On 4/17/2021 at 6:31 AM, jsorocil said:

Patched .dts

 

Your post references "rk3399-som-rk3399v2", but the Armbian default u-boot setup uses "rk3399-nanopi-m4v2". There's also a number of duplicate sections. Your "rt5651_card:  " already exists on the Armbian DTS as "/rt5651-sound" and shouldn't need to be added. I'm curious what file you started with, and a little puzzled what needs to be fixed in the existing builds.

 

Also your edits appear to edit the top level RK3399 DTS, where I'm uncertain whether those changes are appropriate to all boards that use it.

Link to post
Share on other sites

On 4/24/2021 at 7:11 PM, thc013 said:

so i dont know wich  distro he is using but he just could copy the patches from armbian

 

ony thig he had to do is choose a dtb or adjust it nothing more

I not sure about this. On NanoPC-T4 (which also equipped with rt5651) there is same issue, which same errors messages in dmesg. So maybe something else (besides rk3399-add-sclk-i2sout-src-clock.patch) is missing in Armbian?

 

Actually, can you check if 3.5mm jack output works for you on RK3399 boards with rt5651?

Link to post
Share on other sites

2 hours ago, RussianNeuroMancer said:

On NanoPC-T4 (which also equipped with rt5651) there is same issue, which same errors messages in dmesg. So maybe something else (besides rk3399-add-sclk-i2sout-src-clock.patch) is missing in Armbian?

I use since long time pure mainline kernel for rt5651 support. The kernel hack that Armbian is still applying is not really required. If you like, I can upload a kernel for a quick test to see if it is also working for you. Or even easier, try this image for your NanoPC-T4, it should already have everything in place.

Link to post
Share on other sites

On 4/20/2021 at 2:57 AM, tparys said:

Your post references "rk3399-som-rk3399v2", but the Armbian default u-boot setup uses "rk3399-nanopi-m4v2". There's also a number of duplicate sections. Your "rt5651_card:  " already exists on the Armbian DTS as "/rt5651-sound" and shouldn't need to be added. I'm curious what file you started with, and a little puzzled what needs to be fixed in the existing builds.

 

I was using Linux 5.11 vanilla dts (from Torvalds' github) for NanoPi M4V2 and using that as base for my custom dts without overlays.
Also u-boot was built (and patched) by me - learning new things and so on :)
My idea was to share my experience in hope if someone decided to do something similar, but this is Armbian forum where people are using Armbian stuff without compiling their own so...

 

Now I have reinstalled fresh Armbian for NanoPC T4 (u-boot, kernel and ramdisk are on SD card, rootfs is on NVMe but it shouldn't matter).

Image I dd-ed to SD card (from 12.06.2021.): https://mirrors.netix.net/armbian/dl/nanopct4/archive/Armbian_21.05.1_Nanopct4_focal_current_5.10.35_xfce_desktop.img.xz
NVMe doesn't work in u-boot (works in Linux) for my board but that's another topic

 

I am using Armbian u-boot with /boot/dtb/rockchip/rk3399-nanopc-t4.dtb.
After dts overlay I have sound on my SoM-RK3399v2 (which should be pretty similar to T4).

 

# dmesg | grep rt5651
[    5.727048] rt5651 1-001a: Failed to reguest IRQ 0: -22

 

# uname -a
Linux miki 5.10.35-rockchip64 #21.05.1 SMP PREEMPT Fri May 7 13:53:11 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

 

# grep -E  "SND_SOC_ROCKCHIP_I2S|SND_SOC_RT5651" /boot/config-5*
CONFIG_SND_SOC_ROCKCHIP_I2S=m
CONFIG_SND_SOC_ROCKCHIP_I2S_TDM=m
CONFIG_SND_SOC_RT5651=m

 

# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

 

# cat /etc/modules
<empty>

 

# lsmod | grep snd
snd_soc_hdmi_codec     20480  1
snd_soc_simple_card    24576  3
snd_soc_simple_card_utils    28672  1 snd_soc_simple_card
snd_soc_rt5651         98304  1
snd_soc_rl6231         20480  1 snd_soc_rt5651
snd_soc_rockchip_spdif    16384  0
snd_soc_rockchip_i2s    24576  4
snd_soc_core          237568  6 snd_soc_rt5651,snd_soc_hdmi_codec,snd_soc_rockchip_spdif,snd_soc_simple_card_utils,snd_soc_rockchip_i2s,snd_soc_simple_card
snd_pcm_dmaengine      20480  1 snd_soc_core
snd_pcm               118784  4 snd_soc_rt5651,snd_soc_hdmi_codec,snd_soc_core,snd_pcm_dmaengine
snd_timer              40960  1 snd_pcm
snd                    90112  10 snd_soc_hdmi_codec,snd_timer,snd_soc_core,snd_pcm
soundcore              16384  1 snd

 

# aplay -l
**** List of PLAYBACK Hardware Devices ****
Invalid MIT-MAGIC-COOKIE-1 keyxcb_connection_has_error() returned true
card 0: realtekrt5651co [realtek,rt5651-codec], device 0: ff890000.i2s-rt5651-aif1 rt5651-aif1-0 [ff890000.i2s-rt5651-aif1 rt5651-aif1-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: hdmisound [hdmi-sound], device 0: ff8a0000.i2s-i2s-hifi i2s-hifi-0 [ff8a0000.i2s-i2s-hifi i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

 

# cat /etc/asound.conf
<empty>

 

# cat /proc/asound/pcm
00-00: ff890000.i2s-rt5651-aif1 rt5651-aif1-0 : ff890000.i2s-rt5651-aif1 rt5651-aif1-0 : playback 1 : capture 1
01-00: ff8a0000.i2s-i2s-hifi i2s-hifi-0 : ff8a0000.i2s-i2s-hifi i2s-hifi-0 : playback 1

# cat /sys/kernel/debug/clk/clk_i2sout_src/clk_parent
clk_i2s1

 

# dpkg -l | grep -v ^rc | grep -E "linux-dtb-|linux-image-"
ii  linux-dtb-current-rockchip64          21.05.1                              arm64        Linux DTB, version 5.10.35-rockchip64
ii  linux-image-current-rockchip64        21.05.1                              arm64        Linux kernel, version 5.10.35-rockchip64

 

# grep -iE "name|linux|version" /etc/armbian-release
BOARD_NAME="NanoPC T4"
DISTRIBUTION_CODENAME=focal
VERSION=21.05.2
LINUXFAMILY=rockchip64

 

I still have these messages in syslog but sound works nonetheless:

Jun 13 21:28:31 miki kernel: [   28.822975] rockchip-i2s ff8a0000.i2s: Fail to set mclk -22
Jun 13 21:28:31 miki kernel: [   28.823485] rockchip-i2s ff8a0000.i2s: ASoC: error at snd_soc_dai_set_sysclk on ff8a0000.i2s: -22
Jun 13 21:39:50 miki kernel: [  708.376058] rockchip-i2s ff890000.i2s: Fail to set mclk -22
Jun 13 21:39:50 miki kernel: [  708.376576] rockchip-i2s ff890000.i2s: ASoC: error at snd_soc_dai_set_sysclk on ff890000.i2s: -22

 

This is overlay which I have used:

#include <dt-bindings/pinctrl/rockchip.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/clock/rk3399-cru.h>

/dts-v1/;
/plugin/;

/ {
    compatible = "rockchip,rk3399";

    fragment@0 {
        target = <&rt5651>;
        __overlay__ {
            status = "okay";
        };
    };

    fragment@1 {
        target = <&i2s1>;
        __overlay__ {
            assigned-clocks = <&cru SCLK_I2SOUT_SRC>;
            assigned-clock-parents = <&cru SCLK_I2S1_8CH>;
            pinctrl-0 = <&i2s_8ch_mclk>,<&i2s1_2ch_bus>;
            status = "okay";
        };
    };

    fragment@2 {
        target = <&pinctrl>;
        __overlay__ {
            i2s1 {
                i2s_8ch_mclk: i2s-8ch-mclk {
                    // GPIO4_A0 - RK3399 I2S_CLK
                    rockchip,pins = <4 RK_PA0 1 &pcfg_pull_none>;
                };
            };

            headphone {
                hp_det: hp-det {
                    // GPIO4_D4 - HP_DET_H pin on SoM-RK3399v2
                    rockchip,pins = <4 RK_PD4 RK_FUNC_GPIO &pcfg_pull_up>;
                };
            };
        };
    };
};

Link to post
Share on other sites

25.05.2021 в 01:32, usual user сказал:

I use since long time pure mainline kernel for rt5651 support. The kernel hack that Armbian is still applying is not really required. If you like, I can upload a kernel for a quick test to see if it is also working for you. Or even easier, try this image for your NanoPC-T4, it should already have everything in place.

 

Unfortunately, this image does not load on my T4, get stuck here.

Link to post
Share on other sites

On 7/1/2021 at 3:52 PM, RussianNeuroMancer said:

Unfortunately, this image does not load on my T4, get stuck here.

Looks like the clocking set up by uboot for HDMI is not suitable for setting up the native video mode that the monitor wants to set through the kernel. Either drop in an uboot without HDMI support and lose the uboot display support or set up a native HDMI mode for linux. It is known that manline rockchip is limited in selecting video modes, only native HDMI modes are suported for sure. There are several patches floating around to enable more modes for a particular clocking, but nothing finaly decided.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

1 1