Skip to content

Commit

Permalink
ASoC: es8336: autodetect analog microphone ports
Browse files Browse the repository at this point in the history
Use the _DSM data to fill the analog microphone ports,
removing another quirk.

Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
mchehab committed Dec 30, 2023
1 parent 035abff commit 5662ff9
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions sound/soc/intel/boards/sof_es8336.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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");
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 5662ff9

Please sign in to comment.