From b07462e361bf9b7bf4246c7f1ff9ba71180e7025 Mon Sep 17 00:00:00 2001
From: qiangsong <neon@linux.do>
Date: Tue, 17 Mar 2026 19:29:36 +0800
Subject: [PATCH] fix(audio): resolve PCM communication issues for Bluetooth
 sound cards

---
 buildroot/configs/rockchip_rv1126b_defconfig  |  2 +
 ...Broadcom-specific-connection-dispatc.patch | 26 ++++++++
 buildroot/package/bluez-alsa/bluez-alsa.mk    |  1 +
 external/rkwifibt/scripts/wifibt-init.sh      | 12 ++--
 .../arm64/boot/dts/rockchip/rp-audio-dsm.dtsi |  1 +
 .../dts/rockchip/rp-wifibt-ap6xxx-sdio.dtsi   | 60 ++++++++++++-------
 kernel-6.1/net/bluetooth/hci_conn.c           |  2 +-
 kernel-6.1/net/bluetooth/sco.c                |  4 +-
 8 files changed, 79 insertions(+), 29 deletions(-)
 create mode 100644 buildroot/package/bluez-alsa/0002-fix-sco-disable-Broadcom-specific-connection-dispatc.patch

diff --git a/buildroot/configs/rockchip_rv1126b_defconfig b/buildroot/configs/rockchip_rv1126b_defconfig
index ddcca768b..b9b799074 100644
--- a/buildroot/configs/rockchip_rv1126b_defconfig
+++ b/buildroot/configs/rockchip_rv1126b_defconfig
@@ -21,6 +21,8 @@
 #include "gpu/mesa3d.config"
 #include "gui/weston.config"
 #include "rp_buildroot.config"
+BR2_PACKAGE_BLUEZ5_UTILS_TEST=y
+BR2_PACKAGE_BLUEZ_TOOLS=y
 BR2_PACKAGE_DROPBEAR_DISABLE_REVERSEDNS=y
 # BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_PULSE is reset to default
 BR2_PACKAGE_LIBSNDFILE=y
diff --git a/buildroot/package/bluez-alsa/0002-fix-sco-disable-Broadcom-specific-connection-dispatc.patch b/buildroot/package/bluez-alsa/0002-fix-sco-disable-Broadcom-specific-connection-dispatc.patch
new file mode 100644
index 000000000..53a2727bf
--- /dev/null
+++ b/buildroot/package/bluez-alsa/0002-fix-sco-disable-Broadcom-specific-connection-dispatc.patch
@@ -0,0 +1,26 @@
+From d7eb65709ec58adc93ecccf13dc5348a5bb064d4 Mon Sep 17 00:00:00 2001
+From: qiangsong <neon@linux.do>
+Date: Tue, 17 Mar 2026 16:40:38 +0800
+Subject: [PATCH 1/1] fix(sco): disable Broadcom-specific connection dispatcher
+ logic
+
+---
+ src/sco.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/sco.c b/src/sco.c
+index 857a28e..145631f 100644
+--- a/src/sco.c
++++ b/src/sco.c
+@@ -177,7 +177,7 @@ int sco_setup_connection_dispatcher(struct ba_adapter *a) {
+ 	/* XXX: It is a known issue with Broadcom chips, that by default, the SCO
+ 	 *      packets are routed via the chip's PCM interface. However, the IO
+ 	 *      thread expects data to be available via the transport interface. */
+-	if (a->chip.manufacturer == BT_COMPID_BROADCOM) {
++	if (0) {
+ 
+ 		int dd;
+ 		uint8_t routing, clock, frame, sync, clk;
+-- 
+2.25.1
+
diff --git a/buildroot/package/bluez-alsa/bluez-alsa.mk b/buildroot/package/bluez-alsa/bluez-alsa.mk
index 0d39f6bc4..4937805c6 100644
--- a/buildroot/package/bluez-alsa/bluez-alsa.mk
+++ b/buildroot/package/bluez-alsa/bluez-alsa.mk
@@ -18,6 +18,7 @@ BLUEZ_ALSA_CONF_OPTS = \
 	--enable-aplay \
 	--enable-debug \
 	--enable-msbc \
+	--enable-sco2pcm \
 	--disable-debug-time \
 	--with-alsaplugindir=/usr/lib/alsa-lib \
 	--with-alsaconfdir=/etc/alsa/conf.d
diff --git a/external/rkwifibt/scripts/wifibt-init.sh b/external/rkwifibt/scripts/wifibt-init.sh
index c8ac83a8a..c9e26e2c5 100755
--- a/external/rkwifibt/scripts/wifibt-init.sh
+++ b/external/rkwifibt/scripts/wifibt-init.sh
@@ -112,16 +112,18 @@ wait_bt()
 }
 
 # Blocked init for Broadcom uart BT
+
 init_bt_brcm()
 {
-	which brcm_patchram_plus1 >/dev/null
+    which brcm_patchram_plus1 >/dev/null
 
-	brcm_patchram_plus1 --enable_hci --no2bytes \
-		--use_baudrate_for_download --tosleep 200000 \
-		--baudrate 1500000 \
-		--patchram ${WIFIBT_FIRMWARE_DIR:-/lib/firmware}/ $WIFIBT_TTY
+    brcm_patchram_plus1 -scopcm=0,2,0,0,0,0,0,3,0,0 --enable_hci --no2bytes \
+        --use_baudrate_for_download --tosleep 200000 \
+        --baudrate 1500000 \
+        --patchram ${WIFIBT_FIRMWARE_DIR:-/lib/firmware}/ $WIFIBT_TTY
 }
 
+
 # Blocked init for Rockchip uart BT
 init_bt_rk_uart()
 {
diff --git a/kernel-6.1/arch/arm64/boot/dts/rockchip/rp-audio-dsm.dtsi b/kernel-6.1/arch/arm64/boot/dts/rockchip/rp-audio-dsm.dtsi
index f9d04dad7..50e22976e 100755
--- a/kernel-6.1/arch/arm64/boot/dts/rockchip/rp-audio-dsm.dtsi
+++ b/kernel-6.1/arch/arm64/boot/dts/rockchip/rp-audio-dsm.dtsi
@@ -34,6 +34,7 @@ simple-audio-card,codec {
 &sai2 {
     status = "okay";
     // rockchip,sai-rx-route = <0 1 2 3>;
+    /delete-property/ rockchip,bclk-fs;
     /delete-property/ pinctrl-names;
     /delete-property/ pinctrl-0;
 };
diff --git a/kernel-6.1/arch/arm64/boot/dts/rockchip/rp-wifibt-ap6xxx-sdio.dtsi b/kernel-6.1/arch/arm64/boot/dts/rockchip/rp-wifibt-ap6xxx-sdio.dtsi
index 48c0700c2..e4973c106 100755
--- a/kernel-6.1/arch/arm64/boot/dts/rockchip/rp-wifibt-ap6xxx-sdio.dtsi
+++ b/kernel-6.1/arch/arm64/boot/dts/rockchip/rp-wifibt-ap6xxx-sdio.dtsi
@@ -56,31 +56,46 @@ wireless-wlan {
 	};
     
     /*
-     * 蓝牙声卡使用了 SAI2, SAI2 在RV1126B的SOC内部已经连接到了内部声卡，如果需要用蓝牙声卡，需要关闭内部声卡配置，一个SAI接口无法同时注册两个声卡
+     * 蓝牙声卡使用了 SAI2, SAI2 在RV1126B的SOC内部已经连接到了内部声卡，
+	 * 如果需要用蓝牙声卡，需要关闭内部声卡配置，一个SAI接口无法同时注册两个声卡
+	 * RV1126B 启用蓝牙声卡需将 rp-audio-dsm.dtsi 里的 &sai2 {} 整块注释掉
      */
-    bt_sound: bt-sound {
-        status = "disabled";
-        compatible = "simple-audio-card";
-        simple-audio-card,format = "dsp_a";
-        simple-audio-card,bitclock-inversion = <1>;
-        simple-audio-card,mclk-fs = <256>;
-        simple-audio-card,name = "rockchip,bt";
-        simple-audio-card,cpu {
-            sound-dai = <&sai2>;
-        };
-
-        simple-audio-card,codec {
-            sound-dai = <&bt_sco 1>;
-        };
-    };
-
-    bt_sco: bt-sco {
-        compatible = "linux,bt-sco";
-        #sound-dai-cells = <1>;
-        status = "okay";
-    };
+
+
+	bt_sound: bt-sound {
+		status = "disabled";
+		compatible = "simple-audio-card";
+		simple-audio-card,format = "dsp_a";
+		simple-audio-card,bitclock-inversion;
+		simple-audio-card,mclk-fs = <256>;
+		simple-audio-card,name = "rockchip,bt";
+
+		simple-audio-card,cpu {
+			sound-dai = <&sai2>;
+		};
+
+		simple-audio-card,codec {
+			sound-dai = <&bt_sco 1>;
+		};
+	};
+	bt_sco: bt-sco {
+		status = "disabled";
+		compatible = "delta,dfbmcs320";
+		#sound-dai-cells = <1>;
+	};
+
 };
 
+&sai2 {
+	status = "okay";
+	rockchip,bclk-fs = <32>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&sai2m0_lrck_pins
+		     &sai2m0_sclk_pins
+		     &sai2m0_sdi0_pins
+		     &sai2m0_sdo_pins>;
+};
+ 
 #ifdef PRO_RV1126BP
 &bt_sound {
     status = "okay";
@@ -88,6 +103,7 @@ &bt_sound {
 
 &sai2 {
     status = "okay";
+
     pinctrl-names = "default";
     pinctrl-0 = <&sai2m0_lrck_pins
              &sai2m0_sclk_pins
diff --git a/kernel-6.1/net/bluetooth/hci_conn.c b/kernel-6.1/net/bluetooth/hci_conn.c
index 49b9dd21b..1b1436d0e 100644
--- a/kernel-6.1/net/bluetooth/hci_conn.c
+++ b/kernel-6.1/net/bluetooth/hci_conn.c
@@ -562,7 +562,7 @@ bool hci_setup_sync(struct hci_conn *conn, __u16 handle)
 	int result;
 	struct conn_handle_t *conn_handle;
 
-	if (enhanced_sync_conn_capable(conn->hdev)) {
+	if (false && enhanced_sync_conn_capable(conn->hdev)) {
 		conn_handle = kzalloc(sizeof(*conn_handle), GFP_KERNEL);
 
 		if (!conn_handle)
diff --git a/kernel-6.1/net/bluetooth/sco.c b/kernel-6.1/net/bluetooth/sco.c
index fe8728041..c12f1ac44 100644
--- a/kernel-6.1/net/bluetooth/sco.c
+++ b/kernel-6.1/net/bluetooth/sco.c
@@ -796,7 +796,9 @@ static void sco_conn_defer_accept(struct hci_conn *conn, u16 setting)
 
 		cp.tx_bandwidth   = cpu_to_le32(0x00001f40);
 		cp.rx_bandwidth   = cpu_to_le32(0x00001f40);
-		cp.content_format = cpu_to_le16(setting);
+		//cp.content_format = cpu_to_le16(setting);
+		cp.content_format = 0x63;
+
 
 		switch (setting & SCO_AIRMODE_MASK) {
 		case SCO_AIRMODE_TRANSP:
-- 
2.25.1

