From 5662ff91467ba6ef6140683081cc42997016c994 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Tue, 20 Dec 2022 13:40:19 +0000 Subject: [PATCH] ASoC: es8336: autodetect analog microphone ports Use the _DSM data to fill the analog microphone ports, removing another quirk. Signed-off-by: Mauro Carvalho Chehab --- sound/soc/intel/boards/sof_es8336.c | 58 +++++++++++++++++------------ 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/sound/soc/intel/boards/sof_es8336.c b/sound/soc/intel/boards/sof_es8336.c index d5b8662fbef64e..a85e23a04867ec 100644 --- a/sound/soc/intel/boards/sof_es8336.c +++ b/sound/soc/intel/boards/sof_es8336.c @@ -49,7 +49,6 @@ #define SOF_ES8336_ENABLE_DMIC BIT(5) #define SOF_ES8336_JD_INVERTED BIT(6) -#define SOC_ES8336_HEADSET_MIC1 BIT(8) #define SOF_ES8336_OVERRIDE_DSM_LOW_HIGH BIT(9) #define SOF_ES8336_SPK_EN_LOW BIT(10) #define SOF_ES8336_HP_EN_LOW BIT(11) @@ -70,6 +69,7 @@ struct sof_es8336_private { struct acpi_gpio_params enable_spk_gpio, enable_hp_gpio; struct acpi_gpio_mapping gpio_mapping[3]; + struct snd_soc_dapm_route mic_map[2]; }; struct sof_hdmi_pcm { @@ -88,8 +88,6 @@ static void log_quirks(struct device *dev) dev_info(dev, "Speakers GPIO1 quirk 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"); if (quirk & SOF_ES8336_OVERRIDE_DSM_LOW_HIGH) { dev_info(dev, "quirk speaker enabled on %s\n", quirk & SOF_ES8336_SPK_EN_LOW ? "low" : "high"); @@ -179,16 +177,6 @@ static const struct snd_soc_dapm_route sof_es8316_audio_map[] = { {"Speaker", NULL, "Speaker Power"}, }; -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"}, @@ -256,21 +244,44 @@ static int sof_es8316_init(struct snd_soc_pcm_runtime *runtime) struct snd_soc_component *codec = snd_soc_rtd_to_codec(runtime, 0)->component; struct snd_soc_card *card = runtime->card; struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card); - const struct snd_soc_dapm_route *custom_map; - int num_routes; - int ret; + int num_routes = 0; + int i, ret; card->dapm.idle_bias_off = true; - 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); + /* + * Need to check if DMIC is not enabled, as the _DSM table may be + * reporting a non-existent AMIC. + */ + if (!(quirk & SOF_ES8336_ENABLE_DMIC)) { + ret = es83xx_dsm_mic_type(priv->codec_dev, true); + if (ret == PLATFORM_MIC_AMIC_LIN1RIN1) { + priv->mic_map[num_routes].sink = "MIC1"; + priv->mic_map[num_routes].source = "Internal Mic"; + num_routes++; + } else if (ret == PLATFORM_MIC_AMIC_LIN2RIN2) { + priv->mic_map[num_routes].sink = "MIC2"; + priv->mic_map[num_routes].source = "Internal Mic"; + num_routes++; + } } - ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes); + ret = es83xx_dsm_mic_type(priv->codec_dev, false); + if (ret == PLATFORM_MIC_AMIC_LIN1RIN1) { + priv->mic_map[num_routes].sink = "MIC1"; + priv->mic_map[num_routes].source = "Headset Mic"; + num_routes++; + } else if (ret == PLATFORM_MIC_AMIC_LIN2RIN2) { + priv->mic_map[num_routes].sink = "MIC2"; + priv->mic_map[num_routes].source = "Headset Mic"; + num_routes++; + } + + for (i = 0; i < num_routes; i++) + dev_info(card->dev, "%s is %s\n", + priv->mic_map[i].source, priv->mic_map[i].sink); + + ret = snd_soc_dapm_add_routes(&card->dapm, priv->mic_map, num_routes); if (ret) return ret; @@ -331,7 +342,6 @@ static const struct dmi_system_id sof_es8336_quirk_table[] = { DMI_MATCH(DMI_BOARD_NAME, "BOHB-WAX9-PCB-B2"), }, .driver_data = (void *)(SOF_ES8336_SPEAKERS_EN_GPIO1_QUIRK | - SOC_ES8336_HEADSET_MIC1 | SOF_ES8336_OVERRIDE_DSM_LOW_HIGH | SOF_ES8336_HP_EN_LOW)