ASoC: tegra: Support coupled mic-hp detection
authorSvyatoslav Ryhel <clamor95@gmail.com>
Wed, 8 Mar 2023 07:34:56 +0000 (09:34 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 20 Mar 2023 13:06:39 +0000 (13:06 +0000)
This quirk is used for cases when there is GPIO which detects
any type of 3.5 Jack insertion and actual type of jack is defined
by other GPIO. 3.5 Jack GPIO generates interrupt and MIC GPIO
indicates type of Jack only if 3.5 Jack GPIO is active.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
Link: https://lore.kernel.org/r/20230308073502.5421-3-clamor95@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/tegra/tegra_asoc_machine.c

index 2dc1f44..84a719e 100644 (file)
@@ -51,6 +51,17 @@ static struct snd_soc_jack_gpio tegra_machine_headset_jack_gpio = {
 };
 
 /* Mic Jack */
+static int coupled_mic_hp_check(void *data)
+{
+       struct tegra_machine *machine = (struct tegra_machine *)data;
+
+       /* Detect mic insertion only if 3.5 jack is in */
+       if (gpiod_get_value_cansleep(machine->gpiod_hp_det) &&
+           gpiod_get_value_cansleep(machine->gpiod_mic_det))
+               return SND_JACK_MICROPHONE;
+
+       return 0;
+}
 
 static struct snd_soc_jack tegra_machine_mic_jack;
 
@@ -183,8 +194,15 @@ int tegra_asoc_machine_init(struct snd_soc_pcm_runtime *rtd)
                        return err;
                }
 
+               tegra_machine_mic_jack_gpio.data = machine;
                tegra_machine_mic_jack_gpio.desc = machine->gpiod_mic_det;
 
+               if (of_property_read_bool(card->dev->of_node,
+                                         "nvidia,coupled-mic-hp-det")) {
+                       tegra_machine_mic_jack_gpio.desc = machine->gpiod_hp_det;
+                       tegra_machine_mic_jack_gpio.jack_status_check = coupled_mic_hp_check;
+               };
+
                err = snd_soc_jack_add_gpios(&tegra_machine_mic_jack, 1,
                                             &tegra_machine_mic_jack_gpio);
                if (err)