From 430933d74718d58d69980b16bff587a30aa8b1f8 Mon Sep 17 00:00:00 2001 From: lindongping Date: Wed, 22 Jan 2025 10:18:52 +0800 Subject: [PATCH] improve the function of headset hot plug detection and automatic switching of sound output device Signed-off-by: lindongping --- board/phytium/common/debian-package-installer | 4 ++-- configs/phytiumpi_desktop_defconfig | 2 +- configs/phytiumpi_linux_4.19.config | 2 +- .../phytium-desktop-tools.mk | 7 +++--- .../src/{Phytium => }/PMDK-I2S/HiFi.conf | 0 .../src/{Phytium => }/PMDK-I2S/PMDK-I2S.conf | 0 .../es8336 => phytium_pe220x-}/HiFi.conf | 0 .../phytium_pe220x-.conf} | 0 .../src/switch_to_headphone.sh | 22 ++++++++++++++----- 9 files changed, 23 insertions(+), 14 deletions(-) rename package/phytium-desktop-tools/src/{Phytium => }/PMDK-I2S/HiFi.conf (100%) rename package/phytium-desktop-tools/src/{Phytium => }/PMDK-I2S/PMDK-I2S.conf (100%) rename package/phytium-desktop-tools/src/{Phytium/es8336 => phytium_pe220x-}/HiFi.conf (100%) rename package/phytium-desktop-tools/src/{Phytium/es8336/es8336.conf => phytium_pe220x-/phytium_pe220x-.conf} (100%) diff --git a/board/phytium/common/debian-package-installer b/board/phytium/common/debian-package-installer index cd1c540d..49d1cde1 100755 --- a/board/phytium/common/debian-package-installer +++ b/board/phytium/common/debian-package-installer @@ -73,9 +73,9 @@ do_distrorfs_second_stage() { echo 'auth required pam_listfile.so onerr=succeed item=user sense=deny file=/etc/deniedusers' >> /etc/pam.d/lightdm # set the name of the sound output devices - echo 'update-sink-proplist 1 device.description=Headphone' >> /etc/pulse/default.pa + #echo 'update-sink-proplist 1 device.description=Headphone' >> /etc/pulse/default.pa echo 'update-sink-proplist 0 device.description=HDMI' >> /etc/pulse/default.pa - echo 'set-default-sink 1' >> /etc/pulse/default.pa + #echo 'set-default-sink 1' >> /etc/pulse/default.pa echo 'load-module module-switch-on-connect' >> /etc/pulse/default.pa # touch .desktop_firstrun diff --git a/configs/phytiumpi_desktop_defconfig b/configs/phytiumpi_desktop_defconfig index c2a564fd..8e59894b 100644 --- a/configs/phytiumpi_desktop_defconfig +++ b/configs/phytiumpi_desktop_defconfig @@ -36,7 +36,7 @@ BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_GIT=y BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://gitee.com/phytium_embedded/phytium-linux-kernel.git" # kernel 5.10 -BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="kernel-5.10_v2.2" +BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="7b787a8c53e522e122d35912c830849321aa9ae4" BR2_LINUX_KERNEL_INTREE_DTS_NAME="phytium/phytiumpi_firefly" BR2_LINUX_KERNEL_DTS_SUPPORT=y BR2_LINUX_KERNEL_DEFCONFIG="phytium" diff --git a/configs/phytiumpi_linux_4.19.config b/configs/phytiumpi_linux_4.19.config index 037455b3..2c556ccc 100644 --- a/configs/phytiumpi_linux_4.19.config +++ b/configs/phytiumpi_linux_4.19.config @@ -1,2 +1,2 @@ # kernel 4.19 -BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="kernel-4.19_v2.2" +BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="b96cb86c663b65a684cb5aed3a379a0598f775f7" diff --git a/package/phytium-desktop-tools/phytium-desktop-tools.mk b/package/phytium-desktop-tools/phytium-desktop-tools.mk index cac55ef2..01bfa5d2 100644 --- a/package/phytium-desktop-tools/phytium-desktop-tools.mk +++ b/package/phytium-desktop-tools/phytium-desktop-tools.mk @@ -16,14 +16,13 @@ define PHYTIUM_DESKTOP_TOOLS_INSTALL_TARGET_CMDS mkdir -p $(TARGET_DIR)/usr/share/desktop-base/profiles/xdg-config/xfce4/xfconf/xfce-perchannel-xml/ mkdir -p $(TARGET_DIR)/var/lib/alsa/ mkdir -p $(TARGET_DIR)/usr/share/alsa/ucm2/ - mkdir -p $(TARGET_DIR)/usr/share/alsa/ucm2/conf.d/simple-card/ - mkdir -p $(TARGET_DIR)/usr/share/alsa/ucm2/conf.d/PMDK-I2S/ $(INSTALL) -m 777 -D $(@D)/dark.jpg $(TARGET_DIR)/usr/share/images/desktop-base/ $(INSTALL) -m 755 -D $(@D)/01_debian.conf $(TARGET_DIR)/usr/share/lightdm/lightdm-gtk-greeter.conf.d/ $(INSTALL) -m 755 -D $(@D)/xfce4-desktop.xml $(TARGET_DIR)/usr/share/desktop-base/profiles/xdg-config/xfce4/xfconf/xfce-perchannel-xml/ $(INSTALL) -m 644 -D $(@D)/asound.state $(TARGET_DIR)/var/lib/alsa/ - cp -rf $(@D)/Phytium/ $(TARGET_DIR)/usr/share/alsa/ucm2/ - $(INSTALL) -m 644 -D $(@D)/switch_to_headphone.sh $(TARGET_DIR)/usr/bin/ + cp -rf $(@D)/PMDK-I2S/ $(TARGET_DIR)/usr/share/alsa/ucm2/ + cp -rf $(@D)/phytium_pe220x-/ $(TARGET_DIR)/usr/share/alsa/ucm2/ + $(INSTALL) -m 755 -D $(@D)/switch_to_headphone.sh $(TARGET_DIR)/usr/bin/ $(INSTALL) -m 644 -D $(@D)/sound_output_device_switching.desktop $(TARGET_DIR)/usr/share/alsa/ucm2/ endef diff --git a/package/phytium-desktop-tools/src/Phytium/PMDK-I2S/HiFi.conf b/package/phytium-desktop-tools/src/PMDK-I2S/HiFi.conf similarity index 100% rename from package/phytium-desktop-tools/src/Phytium/PMDK-I2S/HiFi.conf rename to package/phytium-desktop-tools/src/PMDK-I2S/HiFi.conf diff --git a/package/phytium-desktop-tools/src/Phytium/PMDK-I2S/PMDK-I2S.conf b/package/phytium-desktop-tools/src/PMDK-I2S/PMDK-I2S.conf similarity index 100% rename from package/phytium-desktop-tools/src/Phytium/PMDK-I2S/PMDK-I2S.conf rename to package/phytium-desktop-tools/src/PMDK-I2S/PMDK-I2S.conf diff --git a/package/phytium-desktop-tools/src/Phytium/es8336/HiFi.conf b/package/phytium-desktop-tools/src/phytium_pe220x-/HiFi.conf similarity index 100% rename from package/phytium-desktop-tools/src/Phytium/es8336/HiFi.conf rename to package/phytium-desktop-tools/src/phytium_pe220x-/HiFi.conf diff --git a/package/phytium-desktop-tools/src/Phytium/es8336/es8336.conf b/package/phytium-desktop-tools/src/phytium_pe220x-/phytium_pe220x-.conf similarity index 100% rename from package/phytium-desktop-tools/src/Phytium/es8336/es8336.conf rename to package/phytium-desktop-tools/src/phytium_pe220x-/phytium_pe220x-.conf diff --git a/package/phytium-desktop-tools/src/switch_to_headphone.sh b/package/phytium-desktop-tools/src/switch_to_headphone.sh index 6b690270..166e0d9e 100755 --- a/package/phytium-desktop-tools/src/switch_to_headphone.sh +++ b/package/phytium-desktop-tools/src/switch_to_headphone.sh @@ -5,15 +5,25 @@ # Copyright (c) 2024 Phytium Technology Co., Ltd. +FLAG=true + while true; do - FLAG="$(pactl list sinks | grep -oP '\[Out\] Headphones:.*?\bnot available\b' | grep -o 'not available')" - if pgrep -x pulseaudio > /dev/null - then - if [ -z "$FLAG" ]; then - pacmd set-default-sink 1 + HEADPHONE_AVAILABLE="$(pactl list cards | grep -oP '\[Out\] Headphones:.*?\b available\b' | grep -o 'not')" + if pgrep -x pulseaudio > /dev/null; then + if [ -z "$HEADPHONE_AVAILABLE" ]; then + pactl set-card-profile 1 HiFi + if [ "$FLAG" == true ]; then + pacmd update-sink-proplist alsa_output.platform-sound.HiFi__hw_phytiumpe220xi2_0__sink device.description=Headphone + pacmd set-default-sink alsa_output.platform-sound.HiFi__hw_phytiumpe220xi2_0__sink + + FLAG=false + fi + + elif [ -n "$HEADPHONE_AVAILABLE" ] && [ "$FLAG" == false ]; then + FLAG=true fi fi - sleep 2 + sleep 1 done -- Gitee