From 3eaebc682824c6ccba869d4a1a1dae12e4e8eb5d Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 9 May 2024 23:17:58 +0000 Subject: [PATCH 1/4] tplgtool2.py: do not silently ignore unsupported "dump type" args No typo left behind. Signed-off-by: Marc Herbert --- tools/tplgtool2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/tplgtool2.py b/tools/tplgtool2.py index b72915b4..f7791a28 100755 --- a/tools/tplgtool2.py +++ b/tools/tplgtool2.py @@ -1330,6 +1330,7 @@ def main(): errors = 0 for f in files: tplg = GroupedTplg(tplgFormat.parse_file(f)) + assert set(dump_types) <= set(supported_dump), f"unsupported type in {dump_types}" if 'pcm' in dump_types: tplg.print_pcm_info() if 'graph' in dump_types: From ac8d62a4d4050ebc25de67bc841703b270c1f140 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Tue, 14 May 2024 22:11:49 +0000 Subject: [PATCH 2/4] tplgtool2.py: add missing SOF_TKN_COMP_NO_WNAME_IN_KCONTROL_NAME Synchronize with Linux commit 246b5b77fc74 ("ASoC: SOF: topology: Add a token for dropping widget name in kcontrol name") Signed-off-by: Marc Herbert --- tools/tplgtool2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/tplgtool2.py b/tools/tplgtool2.py index f7791a28..698f9e8b 100755 --- a/tools/tplgtool2.py +++ b/tools/tplgtool2.py @@ -198,7 +198,7 @@ class PcmFormatsFlag(enum.IntFlag): class SofVendorToken(enum.IntEnum): r"""SOF vendor tokens - See `tools/topology1/sof/tokens.m4` in SOF. + Duplicates Linux' `include/uapi/sound/sof/tokens.h` """ # sof_buffer_tokens SOF_TKN_BUF_SIZE = 100 @@ -235,6 +235,7 @@ class SofVendorToken(enum.IntEnum): SOF_TKN_COMP_CORE_ID = 404 SOF_TKN_COMP_UUID = 405 SOF_TKN_COMP_CPC = 406 + SOF_TKN_COMP_NO_WNAME_IN_KCONTROL_NAME = 417 # sof_ssp_tokens SOF_TKN_INTEL_SSP_CLKS_CONTROL = 500 SOF_TKN_INTEL_SSP_MCLK_ID = 501 From 09df37165c1a1f148b71c6bba1067b95a24f98c3 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 10 May 2024 23:35:23 +0000 Subject: [PATCH 3/4] Add new tools/topo_vol_kcontrols.py Will be used in next commit to fix #1068. See also discussion in earlier attempt #1068. --- tools/topo_vol_kcontrols.py | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 tools/topo_vol_kcontrols.py diff --git a/tools/topo_vol_kcontrols.py b/tools/topo_vol_kcontrols.py new file mode 100755 index 00000000..1f1c5cc5 --- /dev/null +++ b/tools/topo_vol_kcontrols.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 + +"""Parses the .tplg file argument and returns a list of volume +kcontrols, one per line. + +Pro tip: try using these commands _interactively_ with ipython3 +""" + +# Keep this script short and simple. If you want to get something else +# from .tplg files, create another script. + +import sys +from tplgtool2 import TplgBinaryFormat, TplgType, DapmType, SofVendorToken + +TPLG_FORMAT = TplgBinaryFormat() + + +def main(): + "Main" + + parsed_tplg = TPLG_FORMAT.parse_file(sys.argv[1]) + + # pylint: disable=invalid-name + DAPMs = [ + item for item in parsed_tplg if item.header.type == TplgType.DAPM_WIDGET.name + ] + + for dapm in DAPMs: + gain_blocks = [b for b in dapm.blocks if b.widget.id == DapmType.PGA.name] + + for gb in gain_blocks: + # debug + # print(f"{gb.widget.id}: {gb.widget.name}") + print_volume_kcontrols(gb) + + +def print_volume_kcontrols(gain_block): + "Print volume kcontrols" + + # Either 1 volume kcontrol, or 1 volume + 1 switch + assert gain_block.widget.num_kcontrols in (1, 2) + + # A switch is either a DapmType.SWITCH, or DapmType.MIXER + # with a max "volume" = 1. Don't include switches here. + volume_kcontrols = [ + kc + for kc in gain_block.kcontrols + if kc.hdr.type == DapmType.MIXER.name and kc.body.max != 1 + ] + + assert len(volume_kcontrols) == 1 + + wname_prefix = ( + f"{gain_block.widget.name} " if has_wname_prefix(gain_block.widget) else "" + ) + + for vkc in volume_kcontrols: + print(wname_prefix + vkc.hdr.name) + + +# This could probably be moved to tplgtool2.py? +def has_wname_prefix(widget): + """Is the kcontrol name prefixed with the widget name? ("PGAxx" or "Dmicxx") + Check SOF_TKN_COMP_NO_WNAME_IN_KCONTROL_NAME""" + + wname_elems = [ + prv.elems + for prv in widget.priv + if prv.elems[0].token + == SofVendorToken.SOF_TKN_COMP_NO_WNAME_IN_KCONTROL_NAME.name + ] + + if len(wname_elems) == 0: # typically: topo v1 + no_wname_prefix = 0 + elif len(wname_elems) == 1: # typically: topo v2 + assert len(wname_elems[0]) == 1 + no_wname_prefix = wname_elems[0][0].value + else: + assert False, f"Unexpected len of wname_elems={wname_elems}" + + assert no_wname_prefix in (0, 1) + + # Double-negation: "no_wname false" => prefix + return not no_wname_prefix + + +if __name__ == "__main__": + main() From 1dce3d7ba2c077847f9e29885dd16836249a41f5 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Mon, 13 May 2024 21:04:40 +0000 Subject: [PATCH 4/4] volume-basic-test.sh: switch to .tplg parsing to test topologies v2 Until now this test was "screen-scraping" amixer output. This was not compatible with v2 topologies which means the test was always SKIP for everything developped on the main branch. Switch to parsing topologies to extract volume kcontrols. Fixes: #1069, see also discussion in earlier attempt #1068. Signed-off-by: Marc Herbert --- test-case/volume-basic-test.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test-case/volume-basic-test.sh b/test-case/volume-basic-test.sh index 79e29043..1f013b2c 100755 --- a/test-case/volume-basic-test.sh +++ b/test-case/volume-basic-test.sh @@ -16,7 +16,9 @@ # source from the relative path of current folder # shellcheck source=case-lib/lib.sh -source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh +TOPDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd) +source "$TOPDIR/case-lib/lib.sh" + volume_array=("0%" "10%" "20%" "30%" "40%" "50%" "60%" "70%" "80%" "90%" "100%") OPT_NAME['t']='tplg' OPT_DESC['t']="tplg file, default value is env TPLG: $TPLG" @@ -62,7 +64,10 @@ sleep 1 [[ ! $(pidof aplay) ]] && die "aplay process is terminated too early" sofcard=${SOFCARD:-0} -readarray -t pgalist < <(amixer -c"$sofcard" controls | awk -Fname= 'toupper($2) ~ /PGA/ { print $2 }') + +# https://mywiki.wooledge.org/BashFAQ/024 why cant I pipe data to read? +readarray -t pgalist < <("$TOPDIR"/tools/topo_vol_kcontrols.py "$tplg") + # This (1) provides some logging (2) avoids skip_test if amixer fails amixer -c"$sofcard" controls dlogi "pgalist number = ${#pgalist[@]}"