ASoC: cs42l43: Move headset bias sense enable earlier in process
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Tue, 19 Sep 2023 10:31:15 +0000 (11:31 +0100)
committerMark Brown <broonie@kernel.org>
Tue, 19 Sep 2023 12:49:01 +0000 (13:49 +0100)
Currently the bias sense is enabled along with the button detect, but
this has two problems. Firstly, the detections themselves arn't covered
by the bias sense, potentially resulting in pops and secondly, the
sequence of enabling/disabling looks like:

enable bias
enable bias sense
disable bias sense
disable bias

When the bias sense is disabled but the bias is still on the clamp is
removed and a pop results. Fix both of these issues by moving the bias
sense enable/disable to be along with the bias itself. With a resulting
sequence of:

enable bias sense
enable bias
disable bias
disable bias sense

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20230919103116.580305-5-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/cs42l43-jack.c

index 7bd7cc1779506b59c2175e41b9ffe32113fd8800..66923cf2fdaff0cdda639ebecb40810efcef4061 100644 (file)
@@ -250,6 +250,15 @@ static void cs42l43_start_hs_bias(struct cs42l43_codec *priv, bool force_high)
        if (!force_high && priv->bias_low)
                val = 0x2 << CS42L43_HSBIAS_MODE_SHIFT;
 
+       if (priv->bias_sense_ua) {
+               regmap_update_bits(cs42l43->regmap,
+                                  CS42L43_HS_BIAS_SENSE_AND_CLAMP_AUTOCONTROL,
+                                  CS42L43_HSBIAS_SENSE_EN_MASK |
+                                  CS42L43_AUTO_HSBIAS_CLAMP_EN_MASK,
+                                  CS42L43_HSBIAS_SENSE_EN_MASK |
+                                  CS42L43_AUTO_HSBIAS_CLAMP_EN_MASK);
+       }
+
        regmap_update_bits(cs42l43->regmap, CS42L43_MIC_DETECT_CONTROL_1,
                           CS42L43_HSBIAS_MODE_MASK, val);
 
@@ -267,6 +276,13 @@ static void cs42l43_stop_hs_bias(struct cs42l43_codec *priv)
 
        regmap_update_bits(cs42l43->regmap, CS42L43_HS2,
                           CS42L43_HS_CLAMP_DISABLE_MASK, 0);
+
+       if (priv->bias_sense_ua) {
+               regmap_update_bits(cs42l43->regmap,
+                                  CS42L43_HS_BIAS_SENSE_AND_CLAMP_AUTOCONTROL,
+                                  CS42L43_HSBIAS_SENSE_EN_MASK |
+                                  CS42L43_AUTO_HSBIAS_CLAMP_EN_MASK, 0);
+       }
 }
 
 irqreturn_t cs42l43_bias_detect_clamp(int irq, void *data)
@@ -318,15 +334,6 @@ static void cs42l43_start_button_detect(struct cs42l43_codec *priv)
        regmap_update_bits(cs42l43->regmap, CS42L43_MIC_DETECT_CONTROL_1,
                           CS42L43_BUTTON_DETECT_MODE_MASK |
                           CS42L43_MIC_LVL_DET_DISABLE_MASK, val);
-
-       if (priv->bias_sense_ua) {
-               regmap_update_bits(cs42l43->regmap,
-                                  CS42L43_HS_BIAS_SENSE_AND_CLAMP_AUTOCONTROL,
-                                  CS42L43_HSBIAS_SENSE_EN_MASK |
-                                  CS42L43_AUTO_HSBIAS_CLAMP_EN_MASK,
-                                  CS42L43_HSBIAS_SENSE_EN_MASK |
-                                  CS42L43_AUTO_HSBIAS_CLAMP_EN_MASK);
-       }
 }
 
 static void cs42l43_stop_button_detect(struct cs42l43_codec *priv)
@@ -335,13 +342,6 @@ static void cs42l43_stop_button_detect(struct cs42l43_codec *priv)
 
        dev_dbg(priv->dev, "Stop button detect\n");
 
-       if (priv->bias_sense_ua) {
-               regmap_update_bits(cs42l43->regmap,
-                                  CS42L43_HS_BIAS_SENSE_AND_CLAMP_AUTOCONTROL,
-                                  CS42L43_HSBIAS_SENSE_EN_MASK |
-                                  CS42L43_AUTO_HSBIAS_CLAMP_EN_MASK, 0);
-       }
-
        regmap_update_bits(cs42l43->regmap, CS42L43_MIC_DETECT_CONTROL_1,
                           CS42L43_BUTTON_DETECT_MODE_MASK |
                           CS42L43_MIC_LVL_DET_DISABLE_MASK,