Skip to contentSkip to conversation

ASoC: cs42l43: Fix headphone output by properly disabling HP clamp

PATCH In review Cole Leavitt 2 participants 2 messages Jan 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 ASoC: cs42l43: Fix headphone output by properly disabling HP clamp

The CS42L43 codec requires proper configuration of the headphone amplifier clamp circuitry for audio output to work. Two issues were preventing headphone audio:

1. The STEREO_MIC_CLAMP_CTRL register (0x100c4) requires both bit 0 (SMIC_HPAMP_CLAMP_DIS_FRC) AND bit 1 (SMIC_HPAMP_CLAMP_DIS_FRC_VAL) to be set to properly disable the HP amp clamp. The driver was only setting bit 0, which enables force mode but leaves the clamp enabled.

2. When switching to headphone or line-out mode via the Jack Override control, the HS_CLAMP_DISABLE bit (bit 28) in the HS2 register must be set to disable the headset clamp circuitry.

Without these fixes, the headphone amplifier output is clamped to ground and no audio is heard despite correct DAPM routing.

Tested on Lenovo ThinkPad P16 Gen 3 with CS42L43 codec.

---
 sound/soc/codecs/cs42l43-jack.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
sound/soc/codecs/cs42l43-jack.c +14 -7
index b719d6263..7d6a93eec 100644
@@ -698,7 +698,7 @@ void cs42l43_clear_jack(struct cs42l43_codec *priv)
 	regmap_update_bits(cs42l43->regmap, CS42L43_STEREO_MIC_CTRL,
 			   CS42L43_JACK_STEREO_CONFIG_MASK, 0);
 	regmap_update_bits(cs42l43->regmap, CS42L43_STEREO_MIC_CLAMP_CTRL,
-			   CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK,
+			   CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK | CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_VAL_MASK,
 			   CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK);
 	regmap_update_bits(cs42l43->regmap, CS42L43_HS2,
 			   CS42L43_HSDET_MODE_MASK | CS42L43_HSDET_MANUAL_MODE_MASK,
@@ -814,7 +814,7 @@ static const struct cs42l43_jack_override_mode {
 			      CS42L43_HSBIAS_GNDREF_HS3_SEL_MASK |
 			      CS42L43_HSBIAS_OUT_HS4_SEL_MASK |
 			      CS42L43_HSGND_HS3_SEL_MASK,
-		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK,
+		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK | CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_VAL_MASK,
 		.report = CS42L43_JACK_HEADSET,
 	},
 	[CS42L43_JACK_RAW_OMTP] = {
@@ -823,17 +823,17 @@ static const struct cs42l43_jack_override_mode {
 			       CS42L43_HSBIAS_GNDREF_HS4_SEL_MASK |
 			       CS42L43_HSBIAS_OUT_HS3_SEL_MASK |
 			       CS42L43_HSGND_HS4_SEL_MASK,
-		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK,
+		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK | CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_VAL_MASK,
 		.report = CS42L43_JACK_HEADSET,
 	},
 	[CS42L43_JACK_RAW_HEADPHONE] = {
 		.hsdet_mode = CS42L43_JACK_3_POLE_SWITCHES,
-		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK,
+		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK | CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_VAL_MASK,
 		.report = CS42L43_JACK_HEADPHONE,
 	},
 	[CS42L43_JACK_RAW_LINE_OUT] = {
 		.hsdet_mode = CS42L43_JACK_3_POLE_SWITCHES,
-		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK,
+		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK | CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_VAL_MASK,
 		.report = CS42L43_JACK_LINEOUT,
 	},
 	[CS42L43_JACK_RAW_LINE_IN] = {
@@ -849,7 +849,7 @@ static const struct cs42l43_jack_override_mode {
 	},
 	[CS42L43_JACK_RAW_OPTICAL] = {
 		.hsdet_mode = CS42L43_JACK_3_POLE_SWITCHES,
-		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK,
+		.clamp_ctrl = CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK | CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_VAL_MASK,
 		.report = CS42L43_JACK_OPTICAL,
 	},
 };
@@ -927,7 +927,7 @@ int cs42l43_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u
 				   CS42L43_JACK_STEREO_CONFIG_MASK,
 				   cs42l43_jack_override_modes[override].mic_ctrl);
 		regmap_update_bits(cs42l43->regmap, CS42L43_STEREO_MIC_CLAMP_CTRL,
-				   CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK,
+				   CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_MASK | CS42L43_SMIC_HPAMP_CLAMP_DIS_FRC_VAL_MASK,
 				   cs42l43_jack_override_modes[override].clamp_ctrl);
 
 		switch (override) {
@@ -947,6 +947,13 @@ int cs42l43_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u
 		case CS42L43_JACK_RAW_MICROPHONE:
 			cs42l43_start_hs_bias(priv, false);
 			break;
+		case CS42L43_JACK_RAW_HEADPHONE:
+		case CS42L43_JACK_RAW_LINE_OUT:
+			/* Disable HS clamp for headphone/line-out playback */
+			regmap_update_bits(cs42l43->regmap, CS42L43_HS2,
+					   CS42L43_HS_CLAMP_DISABLE_MASK,
+					   CS42L43_HS_CLAMP_DISABLE_MASK);
+			break;
 		default:
 			break;
 		}
Signature · 1 line
2.52.0
#1 lore raw
Quoted 8 lines · Cole Leavitt

The CS42L43 codec requires proper configuration of the headphone amplifier clamp circuitry for audio output to work. Two issues were preventing headphone audio:

1. The STEREO_MIC_CLAMP_CTRL register (0x100c4) requires both bit 0 (SMIC_HPAMP_CLAMP_DIS_FRC) AND bit 1 (SMIC_HPAMP_CLAMP_DIS_FRC_VAL) to be set to properly disable the HP amp clamp. The driver was only setting bit 0, which enables force mode but leaves the clamp enabled.

This bit isn't a general clamp it moves the clamp under control of the stereo mic logic. The normal playback paths should override these settings when brought up.

Quoted 3 lines

2. When switching to headphone or line-out mode via the Jack Override control, the HS_CLAMP_DISABLE bit (bit 28) in the HS2 register must be set to disable the headset clamp circuitry.

This clamps pins 3/4 to ground (gnd/mic), not the signal pins, as such the clamp should be active for both headphone and line-out cases.

Quoted 2 lines

Without these fixes, the headphone amplifier output is clamped to ground and no audio is heard despite correct DAPM routing.

Are you really having no sound without this patch and sound with this patch? Could you confirm that is the case, making sure reverting this one change is the difference between your two tests. Could you also describe a little more about how you get into the failing state? Is it a simple case of plug in headphones no sound? cs42l43 is a pretty well tested device it seems unlikely something is fundamentally wrong with the clamping.

Thanks,
Charles