Skip to content

Commit

Permalink
Add new tools/topo2_list_vol_kcontrols.py
Browse files Browse the repository at this point in the history
Will be used in next commit to fix thesofproject#1068. See also discussion in earlier
attempt thesofproject#1068.
  • Loading branch information
marc-hb committed May 14, 2024
1 parent 3eaebc6 commit 51d3d3f
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tools/topo2_list_vol_kcontrols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/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") or gb.widget.name.startswith("Dmic")
else "" # topology v2: no prefix
)

for vkc in volume_kcontrols:
print(pga_prefix + vkc.hdr.name)


if __name__ == "__main__":
main()

0 comments on commit 51d3d3f

Please sign in to comment.