Skip to contentSkip to conversation

codecs/rt5640: Cleanup + HW volume control support

PATCH In review Hans de Goede 2 participants 11 messages Mar 8, 2021 – Mar 13, 2021

lore
Share & tools
lore
#0 lore raw

v2 cover codecs/rt5640: Cleanup + HW volume control support

Hi All,

Here is v2 of my patch series consisting of some codecs/rt5640 cleanups and addition of HW volume control support to the rt5640 .conf snippets.

This new version has been updated to deal with the
"[PATCH 3/5] ASoC: rt5640: Add emulated 'DAC1 Playback Switch' control" kernel-patch being dropped.

Note patch 7 depends on a new "aif:%d" part being added to the components string, the kernel patches for this are pending upstream in the "[PATCH resend 0/2] AsoC: rt5640/rt5651: Volume control fixes" patch-series.

As such patch 7 should probably not be merged until the kernel patches have landed, because theoretically the new component string part could change as part of the review of the kernel patches.

Patches 1-6 are ready to be merged now.

Regards,

Hans

Hans de Goede (7):
codecs/rt5640: Cleanup: unify Stereo / Mono ADC handling codecs/rt5640: Cleanup: Initially disable all inputs and outputs codecs/rt5640: Cleanup: Move 'SPK MIX' setup to main EnableSequene codecs/rt5640: Drop bogus 'DIG MIXL DAC L2 Switch' setting codecs/rt5640: Unify capture volume for AIF1 and AIF2 recording paths codecs/rt5640: Add hardware volume-control support codecs/rt5640: Specify Playback/CaptureMasterElem for HW
volume-control

 ucm2/bytcr-rt5640/HiFi.conf             | 21 +++++++++++
 ucm2/codecs/rt5640/DigitalMics.conf     | 18 ++++++++-
 ucm2/codecs/rt5640/EnableSeq.conf       | 50 ++++++++++++++++++++-----
 ucm2/codecs/rt5640/HeadPhones.conf      | 15 +++++++-
 ucm2/codecs/rt5640/HeadsetMic.conf      | 24 ++++++++----
 ucm2/codecs/rt5640/IN1-InternalMic.conf | 27 +++++++------
 ucm2/codecs/rt5640/IN3-InternalMic.conf | 27 +++++++------
 ucm2/codecs/rt5640/MonoSpeaker.conf     | 17 +++++++--
 ucm2/codecs/rt5640/Speaker.conf         | 17 +++++++--
 9 files changed, 167 insertions(+), 49 deletions(-)
Signature · 1 line
2.30.1
#1 lore raw

PATCH v2 1/7 codecs/rt5640: Cleanup: unify Stereo / Mono ADC handling

Cleanup: no functional changes intended.

The rt5640 codec is sometimes used with AIF1 connected to the SoC and sometimes with AIF2 connected to the SoC.

The rt5640 UCM configuration deals with this by accepting input from and sending output to both AIFs, relying on the kernels DAPM framework to disable parts of the graph which are connected to the unconnected AIF.

On the output side we solve this by enabling both the IF1_DAC and IF2_DAC data inputs to the digital 'Stereo DAC MIX' mixer.

On the input side handling this is somewhat more complicated, the "Digital Mixer Path" leading to the IF1_ADC and IF2_ADC outputs are entirely separate paths. To solve this we enable the active input (DMIC or ADC) in both the Stereo ADC (connected to IF1_ADC) and the Mono ADC (IF2_ADC) paths.

So far we've not been entirely consistent in our handling of the Stereo ADC vs Mono ADC paths, this commit cleans this up:

1. Set the 'Mono ADC Capture Switch' to on once from EnableSeq.conf, like we do for the 'ADC Capture Switch' instead of toggling it on/off from the individual input Enable/Disable sequences.

2. Group all the 'Mono ADC ...' mixer cset calls together with their stereo ADC counterparts.

3. Explicitly select DMIC L/R 1 for the Mono ADC L/R 2 Mux input, instead of relying on this being the default.

---
 ucm2/codecs/rt5640/DigitalMics.conf     |  2 --
 ucm2/codecs/rt5640/EnableSeq.conf       | 10 +++++++---
 ucm2/codecs/rt5640/HeadsetMic.conf      | 10 ++--------
 ucm2/codecs/rt5640/IN1-InternalMic.conf | 11 ++---------
 ucm2/codecs/rt5640/IN3-InternalMic.conf | 11 ++---------
 5 files changed, 13 insertions(+), 31 deletions(-)
ucm2/codecs/rt5640/DigitalMics.conf +0 -2
index fdd412f..157c544 100644
@@ -8,7 +8,6 @@ SectionDevice."Mic" {
 	EnableSequence [
 		cset "name='Mono ADC MIXL ADC2 Switch' on"
 		cset "name='Mono ADC MIXR ADC2 Switch' on"
-		cset "name='Mono ADC Capture Switch' on"
 		cset "name='Stereo ADC MIXL ADC2 Switch' on"
 		cset "name='Stereo ADC MIXR ADC2 Switch' on"
 		cset "name='Internal Mic Switch' on"
@@ -18,7 +17,6 @@ SectionDevice."Mic" {
 	DisableSequence [
 		cset "name='Mono ADC MIXL ADC2 Switch' off"
 		cset "name='Mono ADC MIXR ADC2 Switch' off"
-		cset "name='Mono ADC Capture Switch' off"
 		cset "name='Stereo ADC MIXL ADC2 Switch' off"
 		cset "name='Stereo ADC MIXR ADC2 Switch' off"
 		cset "name='Internal Mic Switch' off"
ucm2/codecs/rt5640/EnableSeq.conf +7 -3
index 145a23b..4754df7 100644
@@ -30,8 +30,13 @@ EnableSequence [
 	# Input Configuration
 	cset "name='Stereo ADC1 Mux' ADC"
 	cset "name='Stereo ADC2 Mux' DMIC1"
-	cset "name='Mono ADC L1 Mux' 1"
-	cset "name='Mono ADC R1 Mux' 1"
+	cset "name='ADC Capture Switch' on"
+
+	cset "name='Mono ADC L1 Mux' ADCL"
+	cset "name='Mono ADC R1 Mux' ADCR"
+	cset "name='Mono ADC L2 Mux' DMIC L1"
+	cset "name='Mono ADC R2 Mux' DMIC R1"
+	cset "name='Mono ADC Capture Switch' on"
 
 	# 47=0dB, 0.375 dB/step, set it to 6 dB to help with soft mics
 	cset "name='ADC Capture Volume' 63"
@@ -45,5 +50,4 @@ EnableSequence [
 
 	cset "name='Internal Mic Switch' off"
 	cset "name='Headset Mic Switch' off"
-	cset "name='ADC Capture Switch' on"
 ]
ucm2/codecs/rt5640/HeadsetMic.conf +2 -8
index f88b611..829e4e6 100644
@@ -21,26 +21,20 @@ SectionDevice."Headset" {
 
 		cset "name='Stereo ADC MIXL ADC1 Switch' on"
 		cset "name='Stereo ADC MIXR ADC1 Switch' on"
-
 		cset "name='Mono ADC MIXL ADC1 Switch' on"
 		cset "name='Mono ADC MIXR ADC1 Switch' on"
-
-		cset "name='Mono ADC Capture Switch' on"
 	]
 
 	DisableSequence [
 		cset "name='Stereo ADC MIXL ADC1 Switch' off"
 		cset "name='Stereo ADC MIXR ADC1 Switch' off"
+		cset "name='Mono ADC MIXL ADC1 Switch' off"
+		cset "name='Mono ADC MIXR ADC1 Switch' off"
 
 		cset "name='RECMIXL BST2 Switch' off"
 		cset "name='RECMIXR BST2 Switch' off"
 
 		cset "name='Headset Mic Switch' off"
-
-		cset "name='Mono ADC MIXL ADC1 Switch' off"
-		cset "name='Mono ADC MIXR ADC1 Switch' off"
-
-		cset "name='Mono ADC Capture Switch' off"
 	]
 
 	Value {
ucm2/codecs/rt5640/IN1-InternalMic.conf +2 -9
index ebb5b6d..260df90 100644
@@ -15,27 +15,20 @@ SectionDevice."Mic" {
 
 		cset "name='Stereo ADC MIXL ADC1 Switch' on"
 		cset "name='Stereo ADC MIXR ADC1 Switch' on"
-
 		cset "name='Mono ADC MIXL ADC1 Switch' on"
 		cset "name='Mono ADC MIXR ADC1 Switch' on"
-
-		cset "name='Mono ADC Capture Switch' on"
 	]
 
 	DisableSequence [
 		cset "name='Stereo ADC MIXL ADC1 Switch' off"
 		cset "name='Stereo ADC MIXR ADC1 Switch' off"
+		cset "name='Mono ADC MIXL ADC1 Switch' off"
+		cset "name='Mono ADC MIXR ADC1 Switch' off"
 
 		cset "name='RECMIXL BST1 Switch' off"
 		cset "name='RECMIXR BST1 Switch' off"
 
 		cset "name='Internal Mic Switch' off"
-
-		cset "name='Mono ADC MIXL ADC1 Switch' off"
-		cset "name='Mono ADC MIXR ADC1 Switch' off"
-
-		cset "name='Mono ADC Capture Switch' off"
-
 	]
 
 	Value {
ucm2/codecs/rt5640/IN3-InternalMic.conf +2 -9
index 172d909..ebd2b9c 100644
@@ -15,27 +15,20 @@ SectionDevice."Mic" {
 
 		cset "name='Stereo ADC MIXL ADC1 Switch' on"
 		cset "name='Stereo ADC MIXR ADC1 Switch' on"
-
 		cset "name='Mono ADC MIXL ADC1 Switch' on"
 		cset "name='Mono ADC MIXR ADC1 Switch' on"
-
-		cset "name='Mono ADC Capture Switch' on"
-
 	]
 
 	DisableSequence [
 		cset "name='Stereo ADC MIXL ADC1 Switch' off"
 		cset "name='Stereo ADC MIXR ADC1 Switch' off"
+		cset "name='Mono ADC MIXL ADC1 Switch' off"
+		cset "name='Mono ADC MIXR ADC1 Switch' off"
 
 		cset "name='RECMIXL BST3 Switch' off"
 		cset "name='RECMIXR BST3 Switch' off"
 
 		cset "name='Internal Mic Switch' off"
-
-		cset "name='Mono ADC MIXL ADC1 Switch' off"
-		cset "name='Mono ADC MIXR ADC1 Switch' off"
-
-		cset "name='Mono ADC Capture Switch' off"
 	]
 
 	Value {
Signature · 1 line
2.30.1
#2 lore raw

PATCH v2 2/7 codecs/rt5640: Cleanup: Initially disable all inputs and outputs

In reply to Hans de Goede

Cleanup: no functional changes intended.

Disable all inputs and outputs from the main EnableSequence.

This allows removing some weirdness from the individual input/output EnableSequences where they were turning controls for other inputs/outputs then themselves off.

---
 ucm2/codecs/rt5640/EnableSeq.conf       | 21 +++++++++++++++++++++
 ucm2/codecs/rt5640/HeadPhones.conf      |  1 -
 ucm2/codecs/rt5640/IN1-InternalMic.conf |  2 --
 ucm2/codecs/rt5640/IN3-InternalMic.conf |  2 --
 ucm2/codecs/rt5640/MonoSpeaker.conf     |  1 -
 ucm2/codecs/rt5640/Speaker.conf         |  1 -
 6 files changed, 21 insertions(+), 7 deletions(-)
ucm2/codecs/rt5640/EnableSeq.conf +21 -0
index 4754df7..5dc7092 100644
@@ -48,6 +48,27 @@ EnableSequence [
 	cset "name='IN2 Boost' 1"
 	cset "name='IN3 Boost' 8"
 
+	# Start with all controls which are used by the individual
+	# input/output Enable/DisableSequences off
+
+	cset "name='RECMIXL BST1 Switch' off"
+	cset "name='RECMIXR BST1 Switch' off"
+	cset "name='RECMIXL BST2 Switch' off"
+	cset "name='RECMIXR BST2 Switch' off"
+	cset "name='RECMIXL BST3 Switch' off"
+	cset "name='RECMIXR BST3 Switch' off"
+
+	cset "name='Stereo ADC MIXL ADC1 Switch' off"
+	cset "name='Stereo ADC MIXR ADC1 Switch' off"
+	cset "name='Stereo ADC MIXL ADC2 Switch' off"
+	cset "name='Stereo ADC MIXR ADC2 Switch' off"
+	cset "name='Mono ADC MIXL ADC1 Switch' off"
+	cset "name='Mono ADC MIXR ADC1 Switch' off"
+	cset "name='Mono ADC MIXL ADC2 Switch' off"
+	cset "name='Mono ADC MIXR ADC2 Switch' off"
+
+	cset "name='Speaker Switch' off"
+	cset "name='Headphone Switch' off"
 	cset "name='Internal Mic Switch' off"
 	cset "name='Headset Mic Switch' off"
 ]
ucm2/codecs/rt5640/HeadPhones.conf +0 -1
index a9e4d20..1f4316d 100644
@@ -17,7 +17,6 @@ SectionDevice."Headphones" {
  		cset "name='HPO MIX HPVOL Switch'  on"
  		cset "name='Headphone Switch'  on"
 		cset "name='HP Channel Switch' on"
- 		cset "name='Speaker Switch' off"
 		cset "name='HP L Playback Switch' on"
 		cset "name='HP R Playback Switch' on"
 		cset "name='HP Playback Volume' 29"
ucm2/codecs/rt5640/IN1-InternalMic.conf +0 -2
index 260df90..d7c419e 100644
@@ -10,8 +10,6 @@ SectionDevice."Mic" {
 
 		cset "name='RECMIXL BST1 Switch' on"
 		cset "name='RECMIXR BST1 Switch' on"
-		cset "name='RECMIXL BST3 Switch' off"
-		cset "name='RECMIXR BST3 Switch' off"
 
 		cset "name='Stereo ADC MIXL ADC1 Switch' on"
 		cset "name='Stereo ADC MIXR ADC1 Switch' on"
ucm2/codecs/rt5640/IN3-InternalMic.conf +0 -2
index ebd2b9c..3e330e6 100644
@@ -8,8 +8,6 @@ SectionDevice."Mic" {
 	EnableSequence [
 		cset "name='Internal Mic Switch' on"
 
-		cset "name='RECMIXL BST1 Switch' off"
-		cset "name='RECMIXR BST1 Switch' off"
 		cset "name='RECMIXL BST3 Switch' on"
 		cset "name='RECMIXR BST3 Switch' on"
 
ucm2/codecs/rt5640/MonoSpeaker.conf +0 -1
index 23cf34c..5035c8d 100644
@@ -14,7 +14,6 @@ SectionDevice."Speaker" {
 		cset "name='SPOL MIX SPKVOL R Switch' on"
 		cset "name='Speaker Switch' on"
 		cset "name='Speaker Channel Switch' on"
-		cset "name='Headphone Switch' off"
 		cset "name='Speaker L Playback Switch' on"
 		cset "name='Speaker R Playback Switch' on"
 		cset "name='Speaker Playback Volume' 35"
ucm2/codecs/rt5640/Speaker.conf +0 -1
index 422cfdf..fd74994 100644
@@ -14,7 +14,6 @@ SectionDevice."Speaker" {
 		cset "name='SPOL MIX SPKVOL R Switch' off"
 		cset "name='Speaker Switch' on"
 		cset "name='Speaker Channel Switch' on"
-		cset "name='Headphone Switch' off"
 		cset "name='Speaker L Playback Switch' on"
 		cset "name='Speaker R Playback Switch' on"
 		cset "name='Speaker Playback Volume' 35"
Signature · 1 line
2.30.1
#3 lore raw

PATCH v2 3/7 codecs/rt5640: Cleanup: Move 'SPK MIX' setup to main EnableSequene

In reply to Hans de Goede

Cleanup: no functional changes intended.

Do the 'SPK MIXL' / 'SPK MIXR' setup only once from the main EnableSequene, like we do for the 'OUT MIXL' / 'OUT MIXR' setup used by the headphones already.

---
 ucm2/codecs/rt5640/EnableSeq.conf   | 6 ++++--
 ucm2/codecs/rt5640/MonoSpeaker.conf | 2 --
 ucm2/codecs/rt5640/Speaker.conf     | 2 --
 3 files changed, 4 insertions(+), 6 deletions(-)
ucm2/codecs/rt5640/EnableSeq.conf +4 -2
index 5dc7092..4a355a5 100644
@@ -6,8 +6,10 @@ EnableSequence [
 	cset "name='Stereo DAC MIXR DAC R1 Switch' on"
 	cset "name='Stereo DAC MIXL DAC L2 Switch' on"
 	cset "name='Stereo DAC MIXR DAC R2 Switch' on"
-	cset "name='OUT MIXL DAC L1 Switch'  on"
-	cset "name='OUT MIXR DAC R1 Switch'  on"
+	cset "name='OUT MIXL DAC L1 Switch' on"
+	cset "name='OUT MIXR DAC R1 Switch' on"
+	cset "name='SPK MIXL DAC L1 Switch' on"
+	cset "name='SPK MIXR DAC R1 Switch' on"
 
 	# uncomment for loopback mic->speakers
 	# cset "name='SPOL MIX BST1 Switch' on"
ucm2/codecs/rt5640/MonoSpeaker.conf +0 -2
index 5035c8d..654edc3 100644
@@ -6,8 +6,6 @@ SectionDevice."Speaker" {
 	]
 
 	EnableSequence [
-		cset "name='SPK MIXL DAC L1 Switch' on"
-		cset "name='SPK MIXR DAC R1 Switch' on"
 		cset "name='SPOL MIX SPKVOL L Switch' on"
 # for mono speaker we apply left on right
 #		cset "name='SPOR MIX SPKVOL R Switch' on"
ucm2/codecs/rt5640/Speaker.conf +0 -2
index fd74994..3264cc3 100644
@@ -6,8 +6,6 @@ SectionDevice."Speaker" {
 	]
 
 	EnableSequence [
-		cset "name='SPK MIXL DAC L1 Switch' on"
-		cset "name='SPK MIXR DAC R1 Switch' on"
 		cset "name='SPOL MIX SPKVOL L Switch' on"
 		cset "name='SPOR MIX SPKVOL R Switch' on"
 		# undo MonoSpeaker mixing of right channel to left speaker
Signature · 1 line
2.30.1
#4 lore raw

PATCH v2 4/7 codecs/rt5640: Drop bogus 'DIG MIXL DAC L2 Switch' setting

In reply to Hans de Goede

The 'DIG MIXL DAC L2 Switch' path is only used for Digital Mixer Path loopback, which we don't use. Drop it.

---
 ucm2/codecs/rt5640/EnableSeq.conf | 1 -
 1 file changed, 1 deletion(-)
ucm2/codecs/rt5640/EnableSeq.conf +0 -1
index 4a355a5..223cceb 100644
@@ -27,7 +27,6 @@ EnableSequence [
 	#cset "name='DAI select' 1"
 
 	cset "name='DAC2 Playback Switch' on"
-	cset "name='DIG MIXL DAC L2 Switch' on"
 
 	# Input Configuration
 	cset "name='Stereo ADC1 Mux' ADC"
Signature · 1 line
2.30.1
#5 lore raw

PATCH v2 5/7 codecs/rt5640: Unify capture volume for AIF1 and AIF2 recording paths

In reply to Hans de Goede

The rt5640 codec is sometimes used with AIF1 connected to the SoC and sometimes with AIF2 connected to the SoC.

The rt5640 UCM configuration deals with this by accepting input from and sending output to both AIFs, relying on the kernels DAPM framework to disable parts of the graph which are connected to the unconnected AIF.

Before this commit codecs/rt5640/EnableSeq.conf was adding a +9dB (digital) boost to recording going through the 'ADC' path to AIF1, while not touching the 'Mono ADC' path to AIF2.

This was causing recordings on devices using AIF2 to be somewhat soft.

This commit unifies the record volume control settings for both paths by only using the '[Mono ]ADC Capture Volume' control, which is present in both paths and setting it to +9dB on both paths.

---
 ucm2/codecs/rt5640/EnableSeq.conf | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
ucm2/codecs/rt5640/EnableSeq.conf +8 -4
index 223cceb..49703ae 100644
@@ -39,10 +39,14 @@ EnableSequence [
 	cset "name='Mono ADC R2 Mux' DMIC R1"
 	cset "name='Mono ADC Capture Switch' on"
 
-	# 47=0dB, 0.375 dB/step, set it to 6 dB to help with soft mics
-	cset "name='ADC Capture Volume' 63"
-	# Set ADC Boost Gain to 3dB higher vals result in too much noise
-	cset "name='ADC Boost Gain' 1"
+	# 47=0dB, 0.375 dB/step, set it to 9 dB to help with soft mics
+	cset "name='ADC Capture Volume' 71"
+	cset "name='Mono ADC Capture Volume' 71"
+
+	# The second 'Mono ADC' path does not have a 'Boost Gain',
+	# set this to 0dB so that the volume of the AIF1 and AIF2 paths is equal.
+	cset "name='ADC Boost Gain' 0"
+
 	# Set IN1/IN3 internal mic boost to 8 (max)
 	# Set IN2 headset-mic boost to 1, headset mics are quite loud
 	cset "name='IN1 Boost' 8"
Signature · 1 line
2.30.1
#6 lore raw

PATCH v2 6/7 codecs/rt5640: Add hardware volume-control support

In reply to Hans de Goede

Add hardware volume-control support for the rt5640 codec.

Note this commit does not add support for the (digital) master ADC/DAC Volume / Mute controls. There are 2 of each, and which one should be used depends on which AIF is being used.

---
 ucm2/codecs/rt5640/HeadPhones.conf      | 2 ++
 ucm2/codecs/rt5640/HeadsetMic.conf      | 2 ++
 ucm2/codecs/rt5640/IN1-InternalMic.conf | 2 ++
 ucm2/codecs/rt5640/IN3-InternalMic.conf | 2 ++
 ucm2/codecs/rt5640/MonoSpeaker.conf     | 2 ++
 ucm2/codecs/rt5640/Speaker.conf         | 2 ++
 6 files changed, 12 insertions(+)
ucm2/codecs/rt5640/HeadPhones.conf +2 -0
index 1f4316d..5535111 100644
@@ -35,5 +35,7 @@ SectionDevice."Headphones" {
 		PlaybackPriority 300
 		PlaybackPCM "hw:${CardId}"
 		JackControl "Headphone Jack"
+		PlaybackMixerElem "HP"
+		PlaybackVolume "HP Playback Volume"
 	}
 }
ucm2/codecs/rt5640/HeadsetMic.conf +2 -0
index 829e4e6..8479672 100644
@@ -41,5 +41,7 @@ SectionDevice."Headset" {
 		CapturePriority 200
 		CapturePCM "hw:${CardId}"
 		JackControl "Headset Mic Jack"
+		CaptureMixerElem "IN2 Boost"
+		CaptureVolume "IN2 Boost"
 	}
 }
ucm2/codecs/rt5640/IN1-InternalMic.conf +2 -0
index d7c419e..a317388 100644
@@ -32,5 +32,7 @@ SectionDevice."Mic" {
 	Value {
 		CapturePriority 100
 		CapturePCM "hw:${CardId}"
+		CaptureMixerElem "IN1 Boost"
+		CaptureVolume "IN1 Boost"
 	}
 }
ucm2/codecs/rt5640/IN3-InternalMic.conf +2 -0
index 3e330e6..ef4eaba 100644
@@ -32,5 +32,7 @@ SectionDevice."Mic" {
 	Value {
 		CapturePriority 100
 		CapturePCM "hw:${CardId}"
+		CaptureMixerElem "IN3 Boost"
+		CaptureVolume "IN3 Boost"
 	}
 }
ucm2/codecs/rt5640/MonoSpeaker.conf +2 -0
index 654edc3..3cbeafd 100644
@@ -29,5 +29,7 @@ SectionDevice."Speaker" {
 	Value {
 		PlaybackPriority 100
 		PlaybackPCM "hw:${CardId}"
+		PlaybackMixerElem "Speaker"
+		PlaybackVolume "Speaker Playback Volume"
 	}
 }
ucm2/codecs/rt5640/Speaker.conf +2 -0
index 3264cc3..0924f9c 100644
@@ -29,5 +29,7 @@ SectionDevice."Speaker" {
 	Value {
 		PlaybackPriority 100
 		PlaybackPCM "hw:${CardId}"
+		PlaybackMixerElem "Speaker"
+		PlaybackVolume "Speaker Playback Volume"
 	}
 }
Signature · 1 line
2.30.1
#7 lore raw

PATCH v2 7/7 codecs/rt5640: Specify Playback/CaptureMasterElem for HW volume-control

In reply to Hans de Goede

Newer kernels add "aif:1" or "aif:2" to the components string to let us know which AIF is being used.

Use this to specify the correct Playback/CaptureMasterElem for HW volume-control, based on which AIF is being used.

On older kernels, where there is no "aif:%d" string in the components string, no Playback/CaptureMasterElem is specified.

In DigitalMics.conf the master mixer is used as regular CaptureMixerElem instead of as CaptureMasterElem since the DMICs don't have any analog volume control.

---
 ucm2/bytcr-rt5640/HiFi.conf             | 21 +++++++++++++++++++++
 ucm2/codecs/rt5640/DigitalMics.conf     | 16 ++++++++++++++++
 ucm2/codecs/rt5640/HeadPhones.conf      | 12 ++++++++++++
 ucm2/codecs/rt5640/HeadsetMic.conf      | 12 ++++++++++++
 ucm2/codecs/rt5640/IN1-InternalMic.conf | 12 ++++++++++++
 ucm2/codecs/rt5640/IN3-InternalMic.conf | 12 ++++++++++++
 ucm2/codecs/rt5640/MonoSpeaker.conf     | 12 ++++++++++++
 ucm2/codecs/rt5640/Speaker.conf         | 12 ++++++++++++
 8 files changed, 109 insertions(+)
ucm2/bytcr-rt5640/HiFi.conf +21 -0
index a5c05ba..7d504d1 100644
@@ -1,5 +1,26 @@
 # Use case Configuration for bytcr-rt5640
 
+Define.HaveAif1 ""
+Define.HaveAif2 ""
+
+If.DefineAif1 {
+	Condition {
+		Type String
+		Haystack "${CardComponents}"
+		Needle "aif:1"
+	}
+	True.Define.HaveAif1 "yes"
+}
+
+If.DefineAif2 {
+	Condition {
+		Type String
+		Haystack "${CardComponents}"
+		Needle "aif:2"
+	}
+	True.Define.HaveAif2 "yes"
+}
+
 SectionVerb {
 	Include.e.File "/codecs/rt5640/EnableSeq.conf"
 
ucm2/codecs/rt5640/DigitalMics.conf +16 -0
index 157c544..032d954 100644
@@ -26,5 +26,21 @@ SectionDevice."Mic" {
 	Value {
 		CapturePriority 100
 		CapturePCM "hw:${CardId}"
+		If.DmicAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				CaptureMixerElem "ADC"
+				CaptureVolume "ADC Capture Volume"
+				CaptureSwitch "ADC Capture Switch"
+			}
+		}
+		If.DmicAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				CaptureMixerElem "Mono ADC"
+				CaptureVolume "Mono ADC Capture Volume"
+				CaptureSwitch "Mono ADC Capture Switch"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/HeadPhones.conf +12 -0
index 5535111..4fbe95d 100644
@@ -37,5 +37,17 @@ SectionDevice."Headphones" {
 		JackControl "Headphone Jack"
 		PlaybackMixerElem "HP"
 		PlaybackVolume "HP Playback Volume"
+		If.HpAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				PlaybackMasterElem "DAC1"
+			}
+		}
+		If.HpAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				PlaybackMasterElem "DAC2"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/HeadsetMic.conf +12 -0
index 8479672..b49dad4 100644
@@ -43,5 +43,17 @@ SectionDevice."Headset" {
 		JackControl "Headset Mic Jack"
 		CaptureMixerElem "IN2 Boost"
 		CaptureVolume "IN2 Boost"
+		If.HSmicAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				CaptureMasterElem "ADC"
+			}
+		}
+		If.HSmicAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				CaptureMasterElem "Mono ADC"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/IN1-InternalMic.conf +12 -0
index a317388..d670484 100644
@@ -34,5 +34,17 @@ SectionDevice."Mic" {
 		CapturePCM "hw:${CardId}"
 		CaptureMixerElem "IN1 Boost"
 		CaptureVolume "IN1 Boost"
+		If.In1Aif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				CaptureMasterElem "ADC"
+			}
+		}
+		If.In1Aif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				CaptureMasterElem "Mono ADC"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/IN3-InternalMic.conf +12 -0
index ef4eaba..345db1e 100644
@@ -34,5 +34,17 @@ SectionDevice."Mic" {
 		CapturePCM "hw:${CardId}"
 		CaptureMixerElem "IN3 Boost"
 		CaptureVolume "IN3 Boost"
+		If.In3Aif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				CaptureMasterElem "ADC"
+			}
+		}
+		If.In3Aif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				CaptureMasterElem "Mono ADC"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/MonoSpeaker.conf +12 -0
index 3cbeafd..addaddd 100644
@@ -31,5 +31,17 @@ SectionDevice."Speaker" {
 		PlaybackPCM "hw:${CardId}"
 		PlaybackMixerElem "Speaker"
 		PlaybackVolume "Speaker Playback Volume"
+		If.MonoSpkAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				PlaybackMasterElem "DAC1"
+			}
+		}
+		If.MonoSpkAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				PlaybackMasterElem "DAC2"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/Speaker.conf +12 -0
index 0924f9c..e7ff673 100644
@@ -31,5 +31,17 @@ SectionDevice."Speaker" {
 		PlaybackPCM "hw:${CardId}"
 		PlaybackMixerElem "Speaker"
 		PlaybackVolume "Speaker Playback Volume"
+		If.SpkAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				PlaybackMasterElem "DAC1"
+			}
+		}
+		If.SpkAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				PlaybackMasterElem "DAC2"
+			}
+		}
 	}
 }
Signature · 1 line
2.30.1
#8 lore raw

Re: [PATCH alsa-ucm-conf v2 7/7] codecs/rt5640: Specify Playback/CaptureMasterElem for HW volume-control

Hi,

Quoted 6 lines · Hans de Goede

Newer kernels add "aif:1" or "aif:2" to the components string to let us know which AIF is being used.

Use this to specify the correct Playback/CaptureMasterElem for HW volume-control, based on which AIF is being used.

Quoted 8 lines

On older kernels, where there is no "aif:%d" string in the components string, no Playback/CaptureMasterElem is specified.

In DigitalMics.conf the master mixer is used as regular CaptureMixerElem instead of as CaptureMasterElem since the DMICs don't have any analog volume control.

The kernel side of this patch has landed now, so this patch can be merged now.

Thanks & Regards,

Hans

Quoted 201 lines
---
 ucm2/bytcr-rt5640/HiFi.conf             | 21 +++++++++++++++++++++
 ucm2/codecs/rt5640/DigitalMics.conf     | 16 ++++++++++++++++
 ucm2/codecs/rt5640/HeadPhones.conf      | 12 ++++++++++++
 ucm2/codecs/rt5640/HeadsetMic.conf      | 12 ++++++++++++
 ucm2/codecs/rt5640/IN1-InternalMic.conf | 12 ++++++++++++
 ucm2/codecs/rt5640/IN3-InternalMic.conf | 12 ++++++++++++
 ucm2/codecs/rt5640/MonoSpeaker.conf     | 12 ++++++++++++
 ucm2/codecs/rt5640/Speaker.conf         | 12 ++++++++++++
 8 files changed, 109 insertions(+)
ucm2/bytcr-rt5640/HiFi.conf +21 -0
index a5c05ba..7d504d1 100644
@@ -1,5 +1,26 @@
 # Use case Configuration for bytcr-rt5640
 
+Define.HaveAif1 ""
+Define.HaveAif2 ""
+
+If.DefineAif1 {
+	Condition {
+		Type String
+		Haystack "${CardComponents}"
+		Needle "aif:1"
+	}
+	True.Define.HaveAif1 "yes"
+}
+
+If.DefineAif2 {
+	Condition {
+		Type String
+		Haystack "${CardComponents}"
+		Needle "aif:2"
+	}
+	True.Define.HaveAif2 "yes"
+}
+
 SectionVerb {
 	Include.e.File "/codecs/rt5640/EnableSeq.conf"
 
ucm2/codecs/rt5640/DigitalMics.conf +16 -0
index 157c544..032d954 100644
@@ -26,5 +26,21 @@ SectionDevice."Mic" {
 	Value {
 		CapturePriority 100
 		CapturePCM "hw:${CardId}"
+		If.DmicAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				CaptureMixerElem "ADC"
+				CaptureVolume "ADC Capture Volume"
+				CaptureSwitch "ADC Capture Switch"
+			}
+		}
+		If.DmicAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				CaptureMixerElem "Mono ADC"
+				CaptureVolume "Mono ADC Capture Volume"
+				CaptureSwitch "Mono ADC Capture Switch"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/HeadPhones.conf +12 -0
index 5535111..4fbe95d 100644
@@ -37,5 +37,17 @@ SectionDevice."Headphones" {
 		JackControl "Headphone Jack"
 		PlaybackMixerElem "HP"
 		PlaybackVolume "HP Playback Volume"
+		If.HpAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				PlaybackMasterElem "DAC1"
+			}
+		}
+		If.HpAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				PlaybackMasterElem "DAC2"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/HeadsetMic.conf +12 -0
index 8479672..b49dad4 100644
@@ -43,5 +43,17 @@ SectionDevice."Headset" {
 		JackControl "Headset Mic Jack"
 		CaptureMixerElem "IN2 Boost"
 		CaptureVolume "IN2 Boost"
+		If.HSmicAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				CaptureMasterElem "ADC"
+			}
+		}
+		If.HSmicAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				CaptureMasterElem "Mono ADC"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/IN1-InternalMic.conf +12 -0
index a317388..d670484 100644
@@ -34,5 +34,17 @@ SectionDevice."Mic" {
 		CapturePCM "hw:${CardId}"
 		CaptureMixerElem "IN1 Boost"
 		CaptureVolume "IN1 Boost"
+		If.In1Aif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				CaptureMasterElem "ADC"
+			}
+		}
+		If.In1Aif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				CaptureMasterElem "Mono ADC"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/IN3-InternalMic.conf +12 -0
index ef4eaba..345db1e 100644
@@ -34,5 +34,17 @@ SectionDevice."Mic" {
 		CapturePCM "hw:${CardId}"
 		CaptureMixerElem "IN3 Boost"
 		CaptureVolume "IN3 Boost"
+		If.In3Aif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				CaptureMasterElem "ADC"
+			}
+		}
+		If.In3Aif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				CaptureMasterElem "Mono ADC"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/MonoSpeaker.conf +12 -0
index 3cbeafd..addaddd 100644
@@ -31,5 +31,17 @@ SectionDevice."Speaker" {
 		PlaybackPCM "hw:${CardId}"
 		PlaybackMixerElem "Speaker"
 		PlaybackVolume "Speaker Playback Volume"
+		If.MonoSpkAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				PlaybackMasterElem "DAC1"
+			}
+		}
+		If.MonoSpkAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				PlaybackMasterElem "DAC2"
+			}
+		}
 	}
 }
ucm2/codecs/rt5640/Speaker.conf +12 -0
index 0924f9c..e7ff673 100644
@@ -31,5 +31,17 @@ SectionDevice."Speaker" {
 		PlaybackPCM "hw:${CardId}"
 		PlaybackMixerElem "Speaker"
 		PlaybackVolume "Speaker Playback Volume"
+		If.SpkAif1 {
+			Condition { Type String Empty "${var:HaveAif1}" }
+			False {
+				PlaybackMasterElem "DAC1"
+			}
+		}
+		If.SpkAif2 {
+			Condition { Type String Empty "${var:HaveAif2}" }
+			False {
+				PlaybackMasterElem "DAC2"
+			}
+		}
 	}
 }
#9 lore raw

Re: [PATCH alsa-ucm-conf v2 7/7] codecs/rt5640: Specify Playback/CaptureMasterElem for HW volume-control

Dne 13. 03. 21 v 13:10 Hans de Goede napsal(a):

Quoted 12 lines

Hi,

Quoted 9 lines · Hans de Goede

Newer kernels add "aif:1" or "aif:2" to the components string to let us know which AIF is being used.

Use this to specify the correct Playback/CaptureMasterElem for HW volume-control, based on which AIF is being used.

On older kernels, where there is no "aif:%d" string in the components string, no Playback/CaptureMasterElem is specified.

Quoted 8 lines
Quoted 5 lines

In DigitalMics.conf the master mixer is used as regular CaptureMixerElem instead of as CaptureMasterElem since the DMICs don't have any analog volume control.

The kernel side of this patch has landed now, so this patch can be merged now.

Merged. Thank you.

Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#10 lore raw
In reply to Hans de Goede

Dne 08. 03. 21 v 23:05 Hans de Goede napsal(a):

Quoted 5 lines

Hi All,

Here is v2 of my patch series consisting of some codecs/rt5640 cleanups and addition of HW volume control support to the rt5640 .conf snippets.

Quoted 8 lines

This new version has been updated to deal with the
"[PATCH 3/5] ASoC: rt5640: Add emulated 'DAC1 Playback Switch' control" kernel-patch being dropped.

Note patch 7 depends on a new "aif:%d" part being added to the components string, the kernel patches for this are pending upstream in the "[PATCH resend 0/2] AsoC: rt5640/rt5651: Volume control fixes" patch-series.

Applied all except the 7th patch.

Thank you.

Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.