diff mbox series

[v4,3/4] ASoC: Intel: sof_es8336: add a quirk for headset at mic1 port

Message ID baf412bc431650fc7f3a157c6ab96d08120940fc.1649275618.git.mchehab@kernel.org (mailing list archive)
State Superseded
Headers show
Series Make headphone work on Huawei Matebook D15 | expand

Commit Message

Mauro Carvalho Chehab April 6, 2022, 8:19 p.m. UTC
The headset/internal mic can either be routed as mic1/mic2
or vice-versa.

By default, the driver assumes that the headset is mapped as
mic2, but not all devices map this way.

So, add a quirk to support changing it to mic1, using mic2
for the internal analog mic (if any).

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
---

See [PATCH v4 0/4] at: https://lore.kernel.org/all/cover.1649275618.git.mchehab@kernel.org/

 sound/soc/intel/boards/sof_es8336.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Comments

Pierre-Louis Bossart April 7, 2022, 3:08 a.m. UTC | #1
>   static int sof_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,
> @@ -145,13 +148,23 @@ static const struct snd_soc_dapm_route sof_es8316_audio_map[] = {
>   	{"Speaker", NULL, "HPOL"},
>   	{"Speaker", NULL, "HPOR"},
>   	{"Speaker", NULL, "Speaker Power"},
> +
> +	{"Differential Mux", "lin1-rin1", "MIC1"},
> +	{"Differential Mux", "lin2-rin2", "MIC2"},
> +	{"Differential Mux", "lin1-rin1 with 20db Boost", "MIC1"},
> +	{"Differential Mux", "lin2-rin2 with 20db Boost", "MIC2"},

this is surprising, shouldn't this be part of the codec driver?

The part that should be machine-specific is really how MIC1 or MIC2 are 
connected (as done below), but the routes above seem machine-independent?

Or is this a work-around for a miss in the codec driver?

Confused...

>   };
>   
> -static const struct snd_soc_dapm_route sof_es8316_intmic_in1_map[] = {
> +static const struct snd_soc_dapm_route sof_es8316_headset_mic2_map[] = {
>   	{"MIC1", NULL, "Internal Mic"},
>   	{"MIC2", NULL, "Headset Mic"},
>   };
>   
> +static const struct snd_soc_dapm_route sof_es8316_headset_mic1_map[] = {
> +	{"MIC2", NULL, "Internal Mic"},
> +	{"MIC1", NULL, "Headset Mic"},
> +};
> +
Mauro Carvalho Chehab April 7, 2022, 6:47 p.m. UTC | #2
Em Wed, 6 Apr 2022 22:08:53 -0500
Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> escreveu:

> >   static int sof_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,
> > @@ -145,13 +148,23 @@ static const struct snd_soc_dapm_route sof_es8316_audio_map[] = {
> >   	{"Speaker", NULL, "HPOL"},
> >   	{"Speaker", NULL, "HPOR"},
> >   	{"Speaker", NULL, "Speaker Power"},
> > +
> > +	{"Differential Mux", "lin1-rin1", "MIC1"},
> > +	{"Differential Mux", "lin2-rin2", "MIC2"},
> > +	{"Differential Mux", "lin1-rin1 with 20db Boost", "MIC1"},
> > +	{"Differential Mux", "lin2-rin2 with 20db Boost", "MIC2"},  
> 
> this is surprising, shouldn't this be part of the codec driver?
> 
> The part that should be machine-specific is really how MIC1 or MIC2 are 
> connected (as done below), but the routes above seem machine-independent?

Yeah, this should be there... and it is there already ;-)

Tested without it and it still works.

So, I'll just drop the above.

Thanks,
Mauro
diff mbox series

Patch

diff --git a/sound/soc/intel/boards/sof_es8336.c b/sound/soc/intel/boards/sof_es8336.c
index d15a58666cc6..bc5bc6124223 100644
--- a/sound/soc/intel/boards/sof_es8336.c
+++ b/sound/soc/intel/boards/sof_es8336.c
@@ -31,6 +31,7 @@ 
 #define SOF_ES8336_ENABLE_DMIC			BIT(5)
 #define SOF_ES8336_JD_INVERTED			BIT(6)
 #define SOF_ES8336_HEADPHONE_GPIO		BIT(7)
+#define SOC_ES8336_HEADSET_MIC1			BIT(8)
 
 static unsigned long quirk;
 
@@ -90,6 +91,8 @@  static void log_quirks(struct device *dev)
 		dev_info(dev, "quirk headphone GPIO enabled\n");
 	if (quirk & SOF_ES8336_JD_INVERTED)
 		dev_info(dev, "quirk JD inverted enabled\n");
+	if (quirk & SOC_ES8336_HEADSET_MIC1)
+		dev_info(dev, "quirk headset at mic1 port enabled\n");
 }
 
 static int sof_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,
@@ -145,13 +148,23 @@  static const struct snd_soc_dapm_route sof_es8316_audio_map[] = {
 	{"Speaker", NULL, "HPOL"},
 	{"Speaker", NULL, "HPOR"},
 	{"Speaker", NULL, "Speaker Power"},
+
+	{"Differential Mux", "lin1-rin1", "MIC1"},
+	{"Differential Mux", "lin2-rin2", "MIC2"},
+	{"Differential Mux", "lin1-rin1 with 20db Boost", "MIC1"},
+	{"Differential Mux", "lin2-rin2 with 20db Boost", "MIC2"},
 };
 
-static const struct snd_soc_dapm_route sof_es8316_intmic_in1_map[] = {
+static const struct snd_soc_dapm_route sof_es8316_headset_mic2_map[] = {
 	{"MIC1", NULL, "Internal Mic"},
 	{"MIC2", NULL, "Headset Mic"},
 };
 
+static const struct snd_soc_dapm_route sof_es8316_headset_mic1_map[] = {
+	{"MIC2", NULL, "Internal Mic"},
+	{"MIC1", NULL, "Headset Mic"},
+};
+
 static const struct snd_soc_dapm_route dmic_map[] = {
 	/* digital mics */
 	{"DMic", NULL, "SoC DMIC"},
@@ -225,8 +238,13 @@  static int sof_es8316_init(struct snd_soc_pcm_runtime *runtime)
 
 	card->dapm.idle_bias_off = true;
 
-	custom_map = sof_es8316_intmic_in1_map;
-	num_routes = ARRAY_SIZE(sof_es8316_intmic_in1_map);
+	if (quirk & SOC_ES8336_HEADSET_MIC1) {
+		custom_map = sof_es8316_headset_mic1_map;
+		num_routes = ARRAY_SIZE(sof_es8316_headset_mic1_map);
+	} else {
+		custom_map = sof_es8316_headset_mic2_map;
+		num_routes = ARRAY_SIZE(sof_es8316_headset_mic2_map);
+	}
 
 	ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
 	if (ret)