forked from thesofproject/sof-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new tools/topo2_list_vol_kcontrols.py
Will be used in next commit to fix thesofproject#1068. See also discussion in earlier attempt thesofproject#1068.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/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 | ||
|
||
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}") | ||
|
||
# Either 1 volume kcontrol, or 1 volume + 1 switch | ||
assert gb.widget.num_kcontrols > 0 | ||
|
||
# A switch is either a DapmType.SWITCH, or DapmType.MIXER | ||
# with a max = 1. Exclude switches. | ||
volume_kcontrols = [ | ||
kc | ||
for kc in gb.kcontrols | ||
if kc.hdr.type == DapmType.MIXER.name and kc.body.max != 1 | ||
] | ||
|
||
assert len(volume_kcontrols) == 1 | ||
|
||
# TODO: find how the kernel makes this "topology v1 versus v2" | ||
# decision and mimic it here. | ||
pga_prefix = f"{gb.widget.name} " if gb.widget.name.startswith("PGA") else "" | ||
|
||
for vkc in volume_kcontrols: | ||
print(pga_prefix + vkc.hdr.name) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |