ASoC: rt5640: Add rt5640_set_ovcd_params() helper
authorHans de Goede <hdegoede@redhat.com>
Thu, 19 Aug 2021 19:05:41 +0000 (21:05 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 19 Aug 2021 22:27:58 +0000 (23:27 +0100)
Some devices don't use the builtin jack-detect but can still benefit
from the mic-bias-current over-current-detection to differentiate
between headphones vs a headset.

Move the ovcd init code from rt5640_enable_jack_detect() into a new
rt5640_set_ovcd_params() helper and export this helper as well
as a couple of related ovcd functions.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20210819190543.784415-5-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/rt5640.c
sound/soc/codecs/rt5640.h

index 04820af03ae8449c0321b70e2f27191b9943f7aa..cd1db5caabad2a51b7525eab00379901ce053f60 100644 (file)
@@ -2093,7 +2093,7 @@ int rt5640_sel_asrc_clk_src(struct snd_soc_component *component,
 }
 EXPORT_SYMBOL_GPL(rt5640_sel_asrc_clk_src);
 
-static void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component)
+void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component)
 {
        struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
 
@@ -2105,8 +2105,9 @@ static void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component)
        snd_soc_dapm_sync_unlocked(dapm);
        snd_soc_dapm_mutex_unlock(dapm);
 }
+EXPORT_SYMBOL_GPL(rt5640_enable_micbias1_for_ovcd);
 
-static void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component)
+void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component)
 {
        struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
 
@@ -2117,6 +2118,7 @@ static void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component
        snd_soc_dapm_sync_unlocked(dapm);
        snd_soc_dapm_mutex_unlock(dapm);
 }
+EXPORT_SYMBOL_GPL(rt5640_disable_micbias1_for_ovcd);
 
 static void rt5640_enable_micbias1_ovcd_irq(struct snd_soc_component *component)
 {
@@ -2368,6 +2370,31 @@ static void rt5640_cancel_work(void *data)
        cancel_delayed_work_sync(&rt5640->bp_work);
 }
 
+void rt5640_set_ovcd_params(struct snd_soc_component *component)
+{
+       struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
+
+       snd_soc_component_write(component, RT5640_PR_BASE + RT5640_BIAS_CUR4,
+               0xa800 | rt5640->ovcd_sf);
+
+       snd_soc_component_update_bits(component, RT5640_MICBIAS,
+               RT5640_MIC1_OVTH_MASK | RT5640_MIC1_OVCD_MASK,
+               rt5640->ovcd_th | RT5640_MIC1_OVCD_EN);
+
+       /*
+        * The over-current-detect is only reliable in detecting the absence
+        * of over-current, when the mic-contact in the jack is short-circuited,
+        * the hardware periodically retries if it can apply the bias-current
+        * leading to the ovcd status flip-flopping 1-0-1 with it being 0 about
+        * 10% of the time, as we poll the ovcd status bit we might hit that
+        * 10%, so we enable sticky mode and when checking OVCD we clear the
+        * status, msleep() a bit and then check to get a reliable reading.
+        */
+       snd_soc_component_update_bits(component, RT5640_IRQ_CTRL2,
+               RT5640_MB1_OC_STKY_MASK, RT5640_MB1_OC_STKY_EN);
+}
+EXPORT_SYMBOL_GPL(rt5640_set_ovcd_params);
+
 static void rt5640_disable_jack_detect(struct snd_soc_component *component)
 {
        struct rt5640_priv *rt5640 = snd_soc_component_get_drvdata(component);
@@ -2415,24 +2442,7 @@ static void rt5640_enable_jack_detect(struct snd_soc_component *component,
        /* Enabling jd2 in general control 2 */
        snd_soc_component_write(component, RT5640_DUMMY2, 0x4001);
 
-       snd_soc_component_write(component, RT5640_PR_BASE + RT5640_BIAS_CUR4,
-               0xa800 | rt5640->ovcd_sf);
-
-       snd_soc_component_update_bits(component, RT5640_MICBIAS,
-               RT5640_MIC1_OVTH_MASK | RT5640_MIC1_OVCD_MASK,
-               rt5640->ovcd_th | RT5640_MIC1_OVCD_EN);
-
-       /*
-        * The over-current-detect is only reliable in detecting the absence
-        * of over-current, when the mic-contact in the jack is short-circuited,
-        * the hardware periodically retries if it can apply the bias-current
-        * leading to the ovcd status flip-flopping 1-0-1 with it being 0 about
-        * 10% of the time, as we poll the ovcd status bit we might hit that
-        * 10%, so we enable sticky mode and when checking OVCD we clear the
-        * status, msleep() a bit and then check to get a reliable reading.
-        */
-       snd_soc_component_update_bits(component, RT5640_IRQ_CTRL2,
-               RT5640_MB1_OC_STKY_MASK, RT5640_MB1_OC_STKY_EN);
+       rt5640_set_ovcd_params(component);
 
        /*
         * All IRQs get or-ed together, so we need the jack IRQ to report 0
index 4d19997dd68479f5fdf31a3f619cf8ebc908ee4d..2c28f83e338adb8c6efda8f39553ab08d1ffe763 100644 (file)
@@ -2157,6 +2157,10 @@ int rt5640_dmic_enable(struct snd_soc_component *component,
                       bool dmic1_data_pin, bool dmic2_data_pin);
 int rt5640_sel_asrc_clk_src(struct snd_soc_component *component,
                unsigned int filter_mask, unsigned int clk_src);
+
+void rt5640_set_ovcd_params(struct snd_soc_component *component);
+void rt5640_enable_micbias1_for_ovcd(struct snd_soc_component *component);
+void rt5640_disable_micbias1_for_ovcd(struct snd_soc_component *component);
 int rt5640_detect_headset(struct snd_soc_component *component, struct gpio_desc *hp_det_gpio);
 
 #endif