Skip to content

Commit 5ee283b

Browse files
hli25plbossart
authored andcommitted
SoC: Intel: sof_es8336: Add the support of PCH dmic on TGL device
On TGL with es8336 codec, usually it uses PCH dmic. This patch enabled the support of PCH dmic. Signed-off-by: Huajun Li <huajun.li@intel.com>
1 parent d87192c commit 5ee283b

File tree

1 file changed

+81
-3
lines changed

1 file changed

+81
-3
lines changed

sound/soc/intel/boards/sof_es8336.c

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define SOF_ES8336_SSP_CODEC_MASK (GENMASK(3, 0))
2525

2626
#define SOF_ES8336_TGL_GPIO_QUIRK BIT(4)
27+
#define SOF_ES8336_ENABLE_DMIC BIT(5)
2728

2829
static unsigned long quirk;
2930

@@ -84,6 +85,10 @@ static const struct snd_soc_dapm_widget sof_es8316_widgets[] = {
8485
SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
8586
};
8687

88+
static const struct snd_soc_dapm_widget dmic_widgets[] = {
89+
SND_SOC_DAPM_MIC("SoC DMIC", NULL),
90+
};
91+
8792
static const struct snd_soc_dapm_route sof_es8316_audio_map[] = {
8893
{"Headphone", NULL, "HPOL"},
8994
{"Headphone", NULL, "HPOR"},
@@ -102,6 +107,11 @@ static const struct snd_soc_dapm_route sof_es8316_intmic_in1_map[] = {
102107
{"MIC2", NULL, "Headset Mic"},
103108
};
104109

110+
static const struct snd_soc_dapm_route dmic_map[] = {
111+
/* digital mics */
112+
{"DMic", NULL, "SoC DMIC"},
113+
};
114+
105115
static const struct snd_kcontrol_new sof_es8316_controls[] = {
106116
SOC_DAPM_PIN_SWITCH("Speaker"),
107117
SOC_DAPM_PIN_SWITCH("Headphone"),
@@ -120,6 +130,26 @@ static struct snd_soc_jack_pin sof_es8316_jack_pins[] = {
120130
},
121131
};
122132

133+
static int dmic_init(struct snd_soc_pcm_runtime *runtime)
134+
{
135+
struct snd_soc_card *card = runtime->card;
136+
int ret;
137+
138+
ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
139+
ARRAY_SIZE(dmic_widgets));
140+
if (ret) {
141+
dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
142+
return ret;
143+
}
144+
145+
ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
146+
ARRAY_SIZE(dmic_map));
147+
if (ret)
148+
dev_err(card->dev, "DMic map addition failed: %d\n", ret);
149+
150+
return ret;
151+
}
152+
123153
static int sof_es8316_init(struct snd_soc_pcm_runtime *runtime)
124154
{
125155
struct snd_soc_component *codec = asoc_rtd_to_codec(runtime, 0)->component;
@@ -187,7 +217,8 @@ static const struct dmi_system_id sof_es8336_quirk_table[] = {
187217
DMI_MATCH(DMI_BOARD_NAME, "WN1"),
188218
},
189219
.driver_data = (void *)(SOF_ES8336_SSP_CODEC(0) |
190-
SOF_ES8336_TGL_GPIO_QUIRK)
220+
SOF_ES8336_TGL_GPIO_QUIRK |
221+
SOF_ES8336_ENABLE_DMIC)
191222
},
192223
{}
193224
};
@@ -231,6 +262,13 @@ static struct snd_soc_dai_link_component platform_component[] = {
231262
SND_SOC_DAILINK_DEF(ssp1_codec,
232263
DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8336:00", "ES8316 HiFi")));
233264

265+
static struct snd_soc_dai_link_component dmic_component[] = {
266+
{
267+
.name = "dmic-codec",
268+
.dai_name = "dmic-hifi",
269+
}
270+
};
271+
234272
/* SoC card */
235273
static struct snd_soc_card sof_es8336_card = {
236274
.name = "essx8336", /* sof- prefix added automatically */
@@ -245,11 +283,14 @@ static struct snd_soc_card sof_es8336_card = {
245283
.num_links = 1,
246284
};
247285

248-
static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, int ssp_codec)
286+
static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
287+
int ssp_codec,
288+
int dmic_be_num)
249289
{
250290
struct snd_soc_dai_link_component *cpus;
251291
struct snd_soc_dai_link *links;
252292
int id = 0;
293+
int i;
253294

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

288329
id++;
289330

331+
/* dmic */
332+
if (dmic_be_num > 0) {
333+
/* at least we have dmic01 */
334+
links[id].name = "dmic01";
335+
links[id].cpus = &cpus[id];
336+
links[id].cpus->dai_name = "DMIC01 Pin";
337+
links[id].init = dmic_init;
338+
if (dmic_be_num > 1) {
339+
/* set up 2 BE links at most */
340+
links[id + 1].name = "dmic16k";
341+
links[id + 1].cpus = &cpus[id + 1];
342+
links[id + 1].cpus->dai_name = "DMIC16k Pin";
343+
dmic_be_num = 2;
344+
}
345+
}
346+
347+
for (i = 0; i < dmic_be_num; i++) {
348+
links[id].id = id;
349+
links[id].num_cpus = 1;
350+
links[id].codecs = dmic_component;
351+
links[id].num_codecs = ARRAY_SIZE(dmic_component);
352+
links[id].platforms = platform_component;
353+
links[id].num_platforms = ARRAY_SIZE(platform_component);
354+
links[id].ignore_suspend = 1;
355+
links[id].dpcm_capture = 1;
356+
links[id].no_pcm = 1;
357+
358+
id++;
359+
}
360+
290361
return links;
362+
291363
devm_err:
292364
return NULL;
293365
}
@@ -304,6 +376,7 @@ static int sof_es8336_probe(struct platform_device *pdev)
304376
struct acpi_device *adev;
305377
struct snd_soc_dai_link *dai_links;
306378
struct device *codec_dev;
379+
int dmic_be_num;
307380
int ret;
308381

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

394+
if (quirk & SOF_ES8336_ENABLE_DMIC)
395+
dmic_be_num = 2;
396+
321397
if (quirk_override != -1) {
322398
dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",
323399
quirk, quirk_override);
324400
quirk = quirk_override;
325401
}
326402
log_quirks(dev);
327403

404+
sof_es8336_card.num_links += dmic_be_num;
328405
dai_links = sof_card_dai_links_create(dev,
329-
SOF_ES8336_SSP_CODEC(quirk));
406+
SOF_ES8336_SSP_CODEC(quirk),
407+
dmic_be_num);
330408
if (!dai_links)
331409
return -ENOMEM;
332410

0 commit comments

Comments
 (0)