Skip to content

Commit

Permalink
SoC: Intel: sof_es8336: Add the support of PCH dmic on TGL device
Browse files Browse the repository at this point in the history
On TGL with es8336 codec, usually it uses PCH dmic.
This patch enabled the support of PCH dmic.

Signed-off-by: Huajun Li <[email protected]>
  • Loading branch information
hli25 committed Aug 10, 2021
1 parent 7070ac5 commit 2159abc
Showing 1 changed file with 81 additions and 3 deletions.
84 changes: 81 additions & 3 deletions sound/soc/intel/boards/sof_es8336.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define SOF_ES8336_SSP_CODEC_MASK (GENMASK(3, 0))

#define SOF_ES8336_TGL_GPIO_QUIRK BIT(4)
#define SOF_ES8336_ENABLE_DMIC BIT(5)

static unsigned long quirk;

Expand Down Expand Up @@ -84,6 +85,10 @@ static const struct snd_soc_dapm_widget sof_es8316_widgets[] = {
SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
};

static const struct snd_soc_dapm_widget dmic_widgets[] = {
SND_SOC_DAPM_MIC("SoC DMIC", NULL),
};

static const struct snd_soc_dapm_route sof_es8316_audio_map[] = {
{"Headphone", NULL, "HPOL"},
{"Headphone", NULL, "HPOR"},
Expand All @@ -102,6 +107,11 @@ static const struct snd_soc_dapm_route sof_es8316_intmic_in1_map[] = {
{"MIC2", NULL, "Headset Mic"},
};

static const struct snd_soc_dapm_route dmic_map[] = {
/* digital mics */
{"DMic", NULL, "SoC DMIC"},
};

static const struct snd_kcontrol_new sof_es8316_controls[] = {
SOC_DAPM_PIN_SWITCH("Speaker"),
SOC_DAPM_PIN_SWITCH("Headphone"),
Expand All @@ -120,6 +130,26 @@ static struct snd_soc_jack_pin sof_es8316_jack_pins[] = {
},
};

static int dmic_init(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_card *card = runtime->card;
int ret;

ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
ARRAY_SIZE(dmic_widgets));
if (ret) {
dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
return ret;
}

ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
ARRAY_SIZE(dmic_map));
if (ret)
dev_err(card->dev, "DMic map addition failed: %d\n", ret);

return ret;
}

static int sof_es8316_init(struct snd_soc_pcm_runtime *runtime)
{
struct snd_soc_component *codec = asoc_rtd_to_codec(runtime, 0)->component;
Expand Down Expand Up @@ -187,7 +217,8 @@ static const struct dmi_system_id sof_es8336_quirk_table[] = {
DMI_MATCH(DMI_BOARD_NAME, "WN1"),
},
.driver_data = (void *)(SOF_ES8336_SSP_CODEC(0) |
SOF_ES8336_TGL_GPIO_QUIRK)
SOF_ES8336_TGL_GPIO_QUIRK |
SOF_ES8336_ENABLE_DMIC)
},
{}
};
Expand Down Expand Up @@ -231,6 +262,13 @@ static struct snd_soc_dai_link_component platform_component[] = {
SND_SOC_DAILINK_DEF(ssp1_codec,
DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8336:00", "ES8316 HiFi")));

static struct snd_soc_dai_link_component dmic_component[] = {
{
.name = "dmic-codec",
.dai_name = "dmic-hifi",
}
};

/* SoC card */
static struct snd_soc_card sof_es8336_card = {
.name = "essx8336", /* sof- prefix added automatically */
Expand All @@ -245,11 +283,14 @@ static struct snd_soc_card sof_es8336_card = {
.num_links = 1,
};

static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, int ssp_codec)
static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
int ssp_codec,
int dmic_be_num)
{
struct snd_soc_dai_link_component *cpus;
struct snd_soc_dai_link *links;
int id = 0;
int i;

links = devm_kcalloc(dev, sof_es8336_card.num_links,
sizeof(struct snd_soc_dai_link), GFP_KERNEL);
Expand Down Expand Up @@ -287,7 +328,38 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, in

id++;

/* dmic */
if (dmic_be_num > 0) {
/* at least we have dmic01 */
links[id].name = "dmic01";
links[id].cpus = &cpus[id];
links[id].cpus->dai_name = "DMIC01 Pin";
links[id].init = dmic_init;
if (dmic_be_num > 1) {
/* set up 2 BE links at most */
links[id + 1].name = "dmic16k";
links[id + 1].cpus = &cpus[id + 1];
links[id + 1].cpus->dai_name = "DMIC16k Pin";
dmic_be_num = 2;
}
}

for (i = 0; i < dmic_be_num; i++) {
links[id].id = id;
links[id].num_cpus = 1;
links[id].codecs = dmic_component;
links[id].num_codecs = ARRAY_SIZE(dmic_component);
links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].ignore_suspend = 1;
links[id].dpcm_capture = 1;
links[id].no_pcm = 1;

id++;
}

return links;

devm_err:
return NULL;
}
Expand All @@ -304,6 +376,7 @@ static int sof_es8336_probe(struct platform_device *pdev)
struct acpi_device *adev;
struct snd_soc_dai_link *dai_links;
struct device *codec_dev;
int dmic_be_num;
int ret;

priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
Expand All @@ -318,15 +391,20 @@ static int sof_es8336_probe(struct platform_device *pdev)
if (!dmi_check_system(sof_es8336_quirk_table))
quirk = SOF_ES8336_SSP_CODEC(2);

if (quirk & SOF_ES8336_ENABLE_DMIC)
dmic_be_num = 2;

if (quirk_override != -1) {
dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",
quirk, quirk_override);
quirk = quirk_override;
}
log_quirks(dev);

sof_es8336_card.num_links += dmic_be_num;
dai_links = sof_card_dai_links_create(dev,
SOF_ES8336_SSP_CODEC(quirk));
SOF_ES8336_SSP_CODEC(quirk),
dmic_be_num);
if (!dai_links)
return -ENOMEM;

Expand Down

0 comments on commit 2159abc

Please sign in to comment.