HDA: use device labels

This is huge cleanup using new device labels in 'Syntax 8' to remove
a lot of conditions. The future extensions will be simplier.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2026-01-13 16:41:35 +01:00
commit d2d810a35f
6 changed files with 114 additions and 354 deletions

View file

@ -1,10 +1,10 @@
Syntax 6 Syntax 8
Define.Use "" # a non-empty string to use UCM configuration for HDA devices Define.Use "" # a non-empty string to use UCM configuration for HDA devices
Define.Done "" # a non-empty string to skip the end error Define.Done "" # a non-empty string to skip the end error
Define.AcpCardId "$${find-card:field=name,return=id,regex='^acp(|6[23x]|-pdm-mach)$'}" Define.AcpCardId "$${find-card:field=name,return=id,regex='^acp(|6[23x]|-pdm-mach)$'}"
Define.DeviceMic "Mic" Define.MicType "hda"
If.dualcodec { If.dualcodec {
Condition { Condition {
@ -26,7 +26,7 @@ If.acp {
} }
False { False {
Define.Use y Define.Use y
Define.DeviceMic "Mic2" Define.MicType "acp"
} }
} }

View file

@ -1,4 +1,4 @@
SectionDevice."Mic1" { SectionDevice."Mic:acp" {
Comment "Digital Microphone" Comment "Digital Microphone"
Value { Value {

View file

@ -1,6 +1,5 @@
# Generic HDA devices for analog I/O # Generic HDA devices for analog I/O
Define.LineDevice ""
Define.spkvol "Speaker" Define.spkvol "Speaker"
Define.hpvol "Headphone" Define.hpvol "Headphone"
Define.hpjack "Headphone Jack" Define.hpjack "Headphone Jack"
@ -44,16 +43,6 @@ If.lineout {
} }
} }
If.linefront {
Condition {
Type ControlExists
Control "name='Front Playback Volume'"
}
True.Define {
LineDevice "1"
}
}
If.hpvol { If.hpvol {
Condition { Condition {
Type ControlExists Type ControlExists
@ -188,7 +177,7 @@ If.line {
Type String Type String
Empty "${var:loctl}" Empty "${var:loctl}"
} }
False.SectionDevice."Line${var:LineDevice}" { False.SectionDevice."Line:main" {
Comment "Line Output" Comment "Line Output"
If.conflict { If.conflict {
@ -234,18 +223,12 @@ If.linefront {
Type ControlExists Type ControlExists
Control "name='Front Playback Switch'" Control "name='Front Playback Switch'"
} }
True.SectionDevice."Line2" { True.SectionDevice."Line:front" {
Comment "Second Line Output" Comment "Second Line Output"
If.line1exists { ConflictingDevice [
Condition { "Line:main"
Type String ]
Empty "${var:loctl}"
}
False.ConflictingDevice [
"Line${var:LineDevice}"
]
}
EnableSequence [ EnableSequence [
cset "name='Front Playback Switch' on" cset "name='Front Playback Switch' on"

View file

@ -1,12 +1,8 @@
# Generic handling of analog microphones on HDA devices # Generic handling of analog microphones on HDA devices
# Microphone related variables on entry # Microphone related variables on entry
# If DMIC is present: # MicType == "hda" # HDA microphone
# (DeviceDmic == "Mic1") # MicType != "hda" # other microphone type (AMD 'acp', Intel 'sof-dsp')
# DeviceMic == "Mic2"
#
# If DMIC is not present:
# DeviceMic == "Mic"
# Microphone related variables as used internally # Microphone related variables as used internally
# HDA codecs can offer input source selection (mux) via "Input Source" or # HDA codecs can offer input source selection (mux) via "Input Source" or
@ -21,31 +17,11 @@
# This leads to up to maximum of four possible input devices. # This leads to up to maximum of four possible input devices.
Define.SourceControl "" Define.SourceControl ""
Define.MicExtraPriority 0
Define.MicJackControl "" Define.MicJackControl ""
Define.MicHPJackControl "" Define.MicHPJackControl ""
Define.MicHSJackControl "" Define.MicHSJackControl ""
# DeviceMic is pre-configured
Define.DeviceMicName ""
Define.DeviceMicComment ""
Define.DeviceMicPriority ""
Define.DeviceMicJack ""
Define.DeviceMic2 ""
Define.DeviceMic2Name ""
Define.DeviceMic2Comment ""
Define.DeviceMic2Priority ""
Define.DeviceMic2Jack ""
Define.DeviceMic3 ""
Define.DeviceMic3Name ""
Define.DeviceMic3Comment ""
Define.DeviceMic3Priority ""
Define.DeviceMic3Jack ""
Define.DeviceMic4 ""
Define.DeviceMic4Name ""
Define.DeviceMic4Comment ""
Define.DeviceMic4Priority ""
Define.DeviceMic4Jack ""
# evaluate the microphone jack name # evaluate the microphone jack name
If.micjack { If.micjack {
Condition { Condition {
@ -119,39 +95,77 @@ If.inputsourcectl {
} }
} }
# Set initial names and priorities for the SectionDevices based on the presence # Extra priority for systems with DMIC presence (MicType != 'hda')
# of DMIC (DMIC is named as 'Mic1')
If.micdevs { If.micdevs {
# DeviceMic == "Mic2" indicates DMIC presence
Condition { Condition {
Type String Type String
String1 "${var:DeviceMic}" String1 "${var:MicType}"
String2 "Mic2" String2 "hda"
} }
True.Define { False.Define.MicExtraPriority 100
# DeviceMic "Mic2" - already set (Mic1 is DMIC) }
DeviceMicPriority 200
DeviceMic2 "Mic3" # Macro HDAMicEnum - Create the SectionDevice for HDA inputs
DeviceMic2Priority 300 #
DeviceMic3 "Mic4" # Arguments:
DeviceMic3Priority 400 # DevName - Name of the device (used as SectionDevice."${var:__DevName}"
DeviceMic4 "Mic5" # Enum - Name of the source/input enum
DeviceMic4Priority 500 # Comment - Long name of the SectionDevice
# Jack - Jack control if available
# Priority - CapturePriority
DefineMacro.HDAMicEnum.SectionDevice."${var:__DevName}" {
Comment "${var:__Comment}"
EnableSequence [
cset "name='${var:SourceControl}' '${var:__Enum}'"
]
Value {
CapturePriority "${eval:($__Priority+$MicExtraPriority)}"
CapturePCM "hw:${CardId}"
CaptureMixerElem "Capture"
CaptureVolume "Capture Volume"
CaptureSwitch "Capture Switch"
CaptureMasterElem "${var:__Enum} Boost"
} }
False.Define { If.jack {
DeviceMic "Mic1" Condition {
DeviceMicPriority 100 Type String
DeviceMic2 "Mic2" Empty "${var:-__Jack}"
DeviceMic2Priority 200 }
DeviceMic3 "Mic3" False.Value.JackControl "${var:__Jack}"
DeviceMic3Priority 300 }
DeviceMic4 "Mic4"
DeviceMic4Priority 400 ConflictingDevice [
"Mic:hda-int"
"Mic:hda-hp"
"Mic:hda"
"Headset:hda-mic"
]
}
# Macro HDAMicSwitch - Create the SectionDevice for HDA inputs (switches)
#
# Arguments:
# DevName - Name of the device (used as SectionDevice."${var:__DevName}"
# Name - Name of the controls
# Comment - Long name of the SectionDevice
# Jack - Jack control if available
# Priority - CapturePriority
DefineMacro.HDAMicSwitch.SectionDevice."${var:__DevName}" {
Comment "${var:__Comment}"
Value {
CapturePriority "${eval:($__Priority+$MicExtraPriority)}"
CapturePCM "hw:${CardId}"
CaptureMixerElem "${var:__Name}"
CaptureVolume "${var:__Name} Volume"
CaptureSwitch "${var:__Name} Switch"
CaptureMasterElem "${var:__Name} Boost"
JackControl "${var:__Jack}"
} }
} }
# Scan the Microphone configuration in the system and set the definitions for
# the SectionDevice creations for them.
If.micsetup { If.micsetup {
Condition { Condition {
Type String Type String
@ -160,292 +174,56 @@ If.micsetup {
False { False {
# the input selection is via ENUM, the possible types are # the input selection is via ENUM, the possible types are
# Internal, Headset, Headphone and just 'Mic' # Internal, Headset, Headphone and just 'Mic'
Macro.in.HDAMicEnum {
# Internal Mic DevName "Mic:hda-int"
If.internalmic { Comment "Internal Stereo Microphone"
Condition { Enum "Internal Mic"
Type ControlExists Priority 100
Control "name='${var:SourceControl}'"
ControlEnum "Internal Mic"
}
True.Define {
DeviceMicName "Internal Mic"
DeviceMicComment "Internal Stereo Microphone"
}
} }
Macro.hp.HDAMicEnum {
# Headphone Mic (Stereo Microphone in Headphone Jack) DevName "Mic:hda-hp"
If.hpmic { Comment "Headphones Stereo Microphone"
Condition { Enum "Headphone Mic"
Type ControlExists Priority 200
Control "name='${var:SourceControl}'" Jack "${var:MicHPJackControl}"
ControlEnum "Headphone Mic"
}
True.If.whichdev {
Condition {
Type String
Empty "${var:DeviceMicName}"
}
True.Define {
DeviceMicName "Headphone Mic"
DeviceMicComment "Headphones Stereo Microphone"
DeviceMicJack "${var:MicHPJackControl}"
}
False.Define {
DeviceMic2Name "Headphone Mic"
DeviceMic2Comment "Headphones Stereo Microphone"
DeviceMic2Jack "${var:MicHPJackControl}"
}
}
} }
Macro.mi.HDAMicEnum {
# Just 'Mic' DevName "Mic:hda"
If.justmic { Comment "Stereo Microphone"
Condition { Enum "Mic"
Type ControlExists Priority 300
Control "name='${var:SourceControl}'" Jack "${var:MicJackControl}"
ControlEnum "Mic"
}
True.If.whichdev {
Condition {
Type String
Empty "${var:DeviceMicName}"
}
True.Define {
DeviceMicName "Mic"
DeviceMicComment "Stereo Microphone"
DeviceMicJack "${var:MicJackControl}"
}
False.If.whichdev2 {
Condition {
Type String
Empty "${var:DeviceMic2Name}"
}
True.Define {
DeviceMic2Name "Mic"
DeviceMic2Comment "Stereo Microphone"
DeviceMic2Jack "${var:MicJackControl}"
}
False.Define {
DeviceMic3Name "Mic"
DeviceMic3Comment "Stereo Microphone"
DeviceMic3Jack "${var:MicJackControl}"
}
}
}
} }
Macro.hs.HDAMicEnum {
# Headset Mono Mic DevName "Headset:hda-mic"
If.hsmic { Comment "Headset Mono Microphone"
Condition { Enum "Headset Mic"
Type ControlExists Priority 400
Control "name='${var:SourceControl}'" Jack "${var:MicHSJackControl}"
ControlEnum "Headset Mic"
}
True.If.whichdev {
# Override the DeviceMicX (which is used as
# SectionDevice name) for headset mic as per
# UCM naming convention, reference:
# https://github.com/alsa-project/alsa-lib/blob/master/include/use-case.h
Condition {
Type String
Empty "${var:DeviceMicName}"
}
True.Define {
DeviceMic "Headset"
DeviceMicName "Headset Mic"
DeviceMicComment "Headset Mono Microphone"
DeviceMicJack "${var:MicHSJackControl}"
}
False.If.whichdev2 {
Condition {
Type String
Empty "${var:DeviceMic2Name}"
}
True.Define {
DeviceMic2 "Headset"
DeviceMic2Name "Headset Mic"
DeviceMic2Comment "Headset Mono Microphone"
DeviceMic2Jack "${var:MicHSJackControl}"
}
False.If.whichdev3 {
Condition {
Type String
Empty "${var:DeviceMic2Name}"
}
True.Define {
DeviceMic3 "Headset"
DeviceMic3Name "Headset Mic"
DeviceMic3Comment "Headset Mono Microphone"
DeviceMic3Jack "${var:MicHSJackControl}"
}
False.Define {
DeviceMic4 "Headset"
DeviceMic4Name "Headset Mic"
DeviceMic4Comment "Headset Mono Microphone"
DeviceMic4Jack "${var:MicHSJackControl}"
}
}
}
}
} }
} }
True { True {
# the input selection is via switches, the possible types are # the input selection is via switches, the possible types are
# Mic and Front Mic # Mic and Front Mic
Define { Macro.mic.HDAMicSwitch {
DeviceMicName "Mic" DevName "Mic:hda"
DeviceMicComment "Stereo Microphone" Comment "Stereo Microphone"
DeviceMicJack "${var:MicJackControl}" Name "Mic"
DeviceMicPriority 200 Priority 100
Jack "${var:MicJackControl}"
} }
If.fmic { If.fmic {
Condition { Condition {
Type ControlExists Type ControlExists
Control "name='Front Mic Playback Switch'" Control "name='Front Mic Playback Switch'"
} }
True.Define { True.Macro.fmic.HDAMicSwitch {
DeviceMic2Name "Front Mic" DevName "Mic:hda-front"
DeviceMic2Comment "Front Stereo Microphone" Comment "Front Stereo Microphone"
DeviceMic2Jack "Front Mic Jack" Name "Front Mic"
DeviceMic2Priority 300 Priority 200
Jack "Front Mic Jack"
} }
} }
} }
} }
# Macro HDACaptureDevice - Create the SectionDevice for HDA inputs
#
# Arguments:
# DevName - Name of the device (used as SectionDevice."${var:__DevName}"
# MicName - Name of the Microphone
# DevComment - Long name of the SectionDevice
# JackName - Jack control if available
# Priority - CapturePriority
# ConflictCondition1 - (string) if not empty, set ConflictingDevice 1
# ConflictDev1 - Name of the ConflictingDevice 1
# ConflictCondition2 - (string) if not empty, set ConflictingDevice 2
# ConflictDev2 - Name of the ConflictingDevice 2
# ConflictCondition3 - (string) if not empty, set ConflictingDevice 3
# ConflictDev3 - Name of the ConflictingDevice 3
DefineMacro.HDACaptureDevice.SectionDevice."${var:__DevName}" {
Comment "${var:__DevComment}"
If.micsetup {
Condition {
Type String
Empty "${var:SourceControl}"
}
False.EnableSequence [
cset "name='${var:SourceControl}' '${var:__MicName}'"
]
}
Value {
CapturePriority "${var:__Priority}"
CapturePCM "hw:${CardId}"
CaptureMixerElem "Capture"
CaptureVolume "Capture Volume"
CaptureSwitch "Capture Switch"
CaptureMasterElem "${var:__MicName} Boost"
}
If.jack {
Condition {
Type String
Empty "${var:__JackName}"
}
False.Value.JackControl "${var:__JackName}"
}
If.conflict1 {
Condition {
Type String
Empty "${var:-__ConflictCondition1}"
}
False.ConflictingDevice [
"${var:-__ConflictDev1}"
]
}
If.conflict2 {
Condition {
Type String
Empty "${var:-__ConflictCondition2}"
}
False.ConflictingDevice [
"${var:-__ConflictDev2}"
]
}
If.conflict3 {
Condition {
Type String
Empty "${var:-__ConflictCondition3}"
}
False.ConflictingDevice [
"${var:-__ConflictDev3}"
]
}
}
If.mic1 {
Condition {
Type String
Empty "${var:DeviceMicName}"
}
False.Macro.0.HDACaptureDevice {
DevName "${var:DeviceMic}"
MicName "${var:DeviceMicName}"
DevComment "${var:DeviceMicComment}"
JackName "${var:DeviceMicJack}"
Priority "${var:DeviceMicPriority}"
ConflictCondition1 "${var:DeviceMic2Name}" ConflictDev1 "${var:DeviceMic2}"
ConflictCondition2 "${var:DeviceMic3Name}" ConflictDev2 "${var:DeviceMic3}"
ConflictCondition3 "${var:DeviceMic4Name}" ConflictDev3 "${var:DeviceMic4}"
}
}
If.mic2 {
Condition {
Type String
Empty "${var:DeviceMic2Name}"
}
False.Macro.1.HDACaptureDevice {
DevName "${var:DeviceMic2}"
MicName "${var:DeviceMic2Name}"
DevComment "${var:DeviceMic2Comment}"
JackName "${var:DeviceMic2Jack}"
Priority "${var:DeviceMic2Priority}"
ConflictCondition1 "${var:DeviceMic3Name}" ConflictDev1 "${var:DeviceMic3}"
ConflictCondition2 "${var:DeviceMic4Name}" ConflictDev2 "${var:DeviceMic4}"
}
}
If.mic3 {
Condition {
Type String
Empty "${var:DeviceMic3Name}"
}
False.Macro.1.HDACaptureDevice {
DevName "${var:DeviceMic3}"
MicName "${var:DeviceMic3Name}"
DevComment "${var:DeviceMic3Comment}"
JackName "${var:DeviceMic3Jack}"
Priority "${var:DeviceMic3Priority}"
ConflictCondition1 "${var:DeviceMic4Name}" ConflictDev1 "${var:DeviceMic4}"
}
}
If.mic4 {
Condition {
Type String
Empty "${var:DeviceMic4Name}"
}
False.Macro.1.HDACaptureDevice {
DevName "${var:DeviceMic4}"
MicName "${var:DeviceMic4Name}"
DevComment "${var:DeviceMic4Comment}"
JackName "${var:DeviceMic4Jack}"
Priority "${var:DeviceMic4Priority}"
}
}

View file

@ -15,10 +15,10 @@ Include.sof-analog.File "HiFi-sof.conf"
If.dmic { If.dmic {
Condition { Condition {
Type String Type String
Empty "${var:DeviceDmic}" String1 "${var:MicType}"
String2 "sof-dsp"
} }
Before.SectionDevice "${var:DeviceMic}" True.SectionDevice."Mic:sof-dsp" {
False.SectionDevice."${var:DeviceDmic}" {
Comment "Digital Microphone" Comment "Digital Microphone"
Value { Value {

View file

@ -1,11 +1,11 @@
Syntax 7 Syntax 8
Include.led.File "/common/ctl/led.conf" Include.led.File "/common/ctl/led.conf"
Include.card-init.File "/lib/card-init.conf" Include.card-init.File "/lib/card-init.conf"
Include.dsp-variables.File "dsp.conf" Include.dsp-variables.File "dsp.conf"
Define { Define {
DeviceMic "Mic" MicType "hda"
DeviceDmic "" DeviceDmic ""
Iec61937Pcms1 "" Iec61937Pcms1 ""
} }
@ -24,8 +24,7 @@ If.devdmic {
Needle "cfg-dmics:" Needle "cfg-dmics:"
} }
True { True {
Define.DeviceDmic "Mic1" Define.MicType "sof-dsp"
Define.DeviceMic "Mic2"
# #
# users expect to turn the LED on when only internal # users expect to turn the LED on when only internal
# mic is off, but it makes sense to turn this LED # mic is off, but it makes sense to turn this LED