]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
ASoC: rt5640: Add optional hp_det_gpio parameter to rt5640_detect_headset()
authorHans de Goede <hdegoede@redhat.com>
Thu, 19 Aug 2021 19:05:40 +0000 (21:05 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 19 Aug 2021 22:27:57 +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 headphones vs
headset detection done by rt5640_detect_headset().

In this case the jack-inserted check done by rt5640_detect_headset()
needs to be done through a GPIO rather then by using the codec's
builtin jack-detect. Add an optional hp_det_gpio parameter and export
rt5640_detect_headset() for use on machines where jack-detect is
handled outside of the codec.

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-4-hdegoede@redhat.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/rt5640.c
sound/soc/codecs/rt5640.h

index d32e9d69231c488a21f80287198a68ff6314b421..04820af03ae8449c0321b70e2f27191b9943f7aa 100644 (file)
@@ -2241,7 +2241,7 @@ static void rt5640_button_press_work(struct work_struct *work)
        schedule_delayed_work(&rt5640->bp_work, msecs_to_jiffies(BP_POLL_TIME));
 }
 
-static int rt5640_detect_headset(struct snd_soc_component *component)
+int rt5640_detect_headset(struct snd_soc_component *component, struct gpio_desc *hp_det_gpio)
 {
        int i, headset_count = 0, headphone_count = 0;
 
@@ -2259,8 +2259,13 @@ static int rt5640_detect_headset(struct snd_soc_component *component)
                msleep(JACK_SETTLE_TIME);
 
                /* Check the jack is still connected before checking ovcd */
-               if (!rt5640_jack_inserted(component))
-                       return 0;
+               if (hp_det_gpio) {
+                       if (gpiod_get_value_cansleep(hp_det_gpio))
+                               return 0;
+               } else {
+                       if (!rt5640_jack_inserted(component))
+                               return 0;
+               }
 
                if (rt5640_micbias1_ovcd(component)) {
                        /*
@@ -2285,6 +2290,7 @@ static int rt5640_detect_headset(struct snd_soc_component *component)
        dev_err(component->dev, "Error detecting headset vs headphones, bad contact?, assuming headphones\n");
        return SND_JACK_HEADPHONE;
 }
+EXPORT_SYMBOL_GPL(rt5640_detect_headset);
 
 static void rt5640_jack_work(struct work_struct *work)
 {
@@ -2309,7 +2315,7 @@ static void rt5640_jack_work(struct work_struct *work)
                /* Jack inserted */
                WARN_ON(rt5640->ovcd_irq_enabled);
                rt5640_enable_micbias1_for_ovcd(component);
-               status = rt5640_detect_headset(component);
+               status = rt5640_detect_headset(component, NULL);
                if (status == SND_JACK_HEADSET) {
                        /* Enable ovcd IRQ for button press detect. */
                        rt5640_enable_micbias1_ovcd_irq(component);
index 4fd47f2b936b6f969c911f3d5a70d45735414762..4d19997dd68479f5fdf31a3f619cf8ebc908ee4d 100644 (file)
@@ -10,6 +10,7 @@
 #define _RT5640_H
 
 #include <linux/clk.h>
+#include <linux/gpio/consumer.h>
 #include <linux/workqueue.h>
 #include <dt-bindings/sound/rt5640.h>
 
@@ -2156,5 +2157,6 @@ 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);
+int rt5640_detect_headset(struct snd_soc_component *component, struct gpio_desc *hp_det_gpio);
 
 #endif