Skip to content

Commit 6729e3a

Browse files
lib.sh: Set ALSA settings from a state file
set_alsa_settings() function now uses `alsactl restore` command, to change ALSA controls from a custom state filie first, if it is present, and next - execute a bash script with amixer commands if it is also present. The state file is expected as `./alsa_settings/${PLATFORM}.state` whereas the bash script remains as `./alsa_settings/${PLATFORM}.sh` The custom state should be compatible with the platform's default state, see set_alsa() function. Co-authored-by: Lukasz Mrugala <lukaszx.mrugala@intel.com> Co-authored-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
1 parent bf76a15 commit 6729e3a

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

case-lib/lib.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ set_alsa_settings()
12061206
{
12071207
# ZEPHYR platform shares same tplg, remove '_ZEPHYR' from platform name
12081208
local PNAME="${1%_ZEPHYR}"
1209-
dlogi "Run alsa setting for $PNAME"
1209+
dlogi "Apply ALSA settings for $PNAME"
12101210
case $PNAME in
12111211
APL_UP2_NOCODEC | CML_RVP_NOCODEC | JSL_RVP_NOCODEC | TGLU_RVP_NOCODEC | ADLP_RVP_NOCODEC | TGLH_RVP_NOCODEC | ADLP_RVP_NOCODEC-ipc3 | CML_RVP_NOCODEC-ipc3 | JSL_RVP_NOCODEC-ipc3)
12121212
# common nocodec alsa settings
@@ -1218,13 +1218,23 @@ set_alsa_settings()
12181218
;;
12191219
TGLU_RVP_NOCODEC_IPC4ZPH | ADLP_RVP_NOCODEC_IPC4ZPH | ADLP_RVP_NOCODEC-ipc4 | TGLU_RVP_NOCODEC-ipc4 | MTLP_RVP_NOCODEC | MTLP_RVP_NOCODEC-multicore-2cores | MTLP_RVP_NOCODEC-multicore-3cores | LNLM_RVP_NOCODEC)
12201220
dlogi "Use reset_sof_volume function to set amixer setting."
1221-
;;
1221+
;;
12221222
*)
12231223
# if script name is same as platform name, default case will handle all
1224-
if [ -f "$SCRIPT_HOME"/alsa_settings/"$PNAME".sh ]; then
1225-
"$SCRIPT_HOME"/alsa_settings/"$PNAME".sh
1226-
else
1227-
dlogw "alsa setting for $PNAME is not available"
1224+
local ALSA_SETTINGS_FILE="$SCRIPT_HOME"/alsa_settings/"$PNAME"
1225+
local rc=0
1226+
if [ -f "${ALSA_SETTINGS_FILE}.state" ]; then
1227+
dlogc "alsactl restore --file=${ALSA_SETTINGS_FILE}.state --pedantic --no-init-fallback --no-ucm"
1228+
alsactl restore --file="${ALSA_SETTINGS_FILE}".state --pedantic --no-init-fallback --no-ucm 2>&1 || rc=$?
1229+
[[ "${rc}" -ne 0 ]] && dloge "alsactl restore error=${rc}"
1230+
fi
1231+
if [ -f "${ALSA_SETTINGS_FILE}.sh" ]; then
1232+
dlogc "${ALSA_SETTINGS_FILE}.sh"
1233+
"${ALSA_SETTINGS_FILE}".sh 2>&1 || rc=$?
1234+
[[ "${rc}" -ne 0 ]] && dloge "ALSA settings error=${rc}"
1235+
fi
1236+
if [ ! -f "${ALSA_SETTINGS_FILE}.state" ] && [ ! -f "${ALSA_SETTINGS_FILE}.sh" ]; then
1237+
dlogw "ALSA settings for $PNAME are not available"
12281238
fi
12291239
;;
12301240
esac
@@ -1294,7 +1304,7 @@ set_alsa()
12941304

12951305
# If MODEL is defined, set proper gain for the platform
12961306
if [ -z "$MODEL" ]; then
1297-
dlogw "NO MODEL is defined. Please define MODEL to run alsa_settings/\${MODEL}.sh"
1307+
dlogw "NO MODEL is defined. Please define MODEL to apply additional settings from ./alsa_settings"
12981308
else
12991309
set_alsa_settings "$MODEL"
13001310
fi

0 commit comments

Comments
 (0)