jsorocil's post in I2S sound with RT5651 was marked as the answer
April 17, 2021
Success!
% 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 :)