24
24
#define SOF_ES8336_SSP_CODEC_MASK (GENMASK(3, 0))
25
25
26
26
#define SOF_ES8336_TGL_GPIO_QUIRK BIT(4)
27
+ #define SOF_ES8336_ENABLE_DMIC BIT(5)
27
28
28
29
static unsigned long quirk ;
29
30
@@ -84,6 +85,10 @@ static const struct snd_soc_dapm_widget sof_es8316_widgets[] = {
84
85
SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU ),
85
86
};
86
87
88
+ static const struct snd_soc_dapm_widget dmic_widgets [] = {
89
+ SND_SOC_DAPM_MIC ("SoC DMIC" , NULL ),
90
+ };
91
+
87
92
static const struct snd_soc_dapm_route sof_es8316_audio_map [] = {
88
93
{"Headphone" , NULL , "HPOL" },
89
94
{"Headphone" , NULL , "HPOR" },
@@ -102,6 +107,11 @@ static const struct snd_soc_dapm_route sof_es8316_intmic_in1_map[] = {
102
107
{"MIC2" , NULL , "Headset Mic" },
103
108
};
104
109
110
+ static const struct snd_soc_dapm_route dmic_map [] = {
111
+ /* digital mics */
112
+ {"DMic" , NULL , "SoC DMIC" },
113
+ };
114
+
105
115
static const struct snd_kcontrol_new sof_es8316_controls [] = {
106
116
SOC_DAPM_PIN_SWITCH ("Speaker" ),
107
117
SOC_DAPM_PIN_SWITCH ("Headphone" ),
@@ -120,6 +130,26 @@ static struct snd_soc_jack_pin sof_es8316_jack_pins[] = {
120
130
},
121
131
};
122
132
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
+
123
153
static int sof_es8316_init (struct snd_soc_pcm_runtime * runtime )
124
154
{
125
155
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[] = {
187
217
DMI_MATCH (DMI_BOARD_NAME , "WN1" ),
188
218
},
189
219
.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 )
191
222
},
192
223
{}
193
224
};
@@ -231,6 +262,13 @@ static struct snd_soc_dai_link_component platform_component[] = {
231
262
SND_SOC_DAILINK_DEF (ssp1_codec ,
232
263
DAILINK_COMP_ARRAY (COMP_CODEC ("i2c-ESSX8336:00" , "ES8316 HiFi" )));
233
264
265
+ static struct snd_soc_dai_link_component dmic_component [] = {
266
+ {
267
+ .name = "dmic-codec" ,
268
+ .dai_name = "dmic-hifi" ,
269
+ }
270
+ };
271
+
234
272
/* SoC card */
235
273
static struct snd_soc_card sof_es8336_card = {
236
274
.name = "essx8336" , /* sof- prefix added automatically */
@@ -245,11 +283,14 @@ static struct snd_soc_card sof_es8336_card = {
245
283
.num_links = 1 ,
246
284
};
247
285
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 )
249
289
{
250
290
struct snd_soc_dai_link_component * cpus ;
251
291
struct snd_soc_dai_link * links ;
252
292
int id = 0 ;
293
+ int i ;
253
294
254
295
links = devm_kcalloc (dev , sof_es8336_card .num_links ,
255
296
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
287
328
288
329
id ++ ;
289
330
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
+
290
361
return links ;
362
+
291
363
devm_err :
292
364
return NULL ;
293
365
}
@@ -304,6 +376,7 @@ static int sof_es8336_probe(struct platform_device *pdev)
304
376
struct acpi_device * adev ;
305
377
struct snd_soc_dai_link * dai_links ;
306
378
struct device * codec_dev ;
379
+ int dmic_be_num ;
307
380
int ret ;
308
381
309
382
priv = devm_kzalloc (dev , sizeof (* priv ), GFP_KERNEL );
@@ -318,15 +391,20 @@ static int sof_es8336_probe(struct platform_device *pdev)
318
391
if (!dmi_check_system (sof_es8336_quirk_table ))
319
392
quirk = SOF_ES8336_SSP_CODEC (2 );
320
393
394
+ if (quirk & SOF_ES8336_ENABLE_DMIC )
395
+ dmic_be_num = 2 ;
396
+
321
397
if (quirk_override != -1 ) {
322
398
dev_info (dev , "Overriding quirk 0x%lx => 0x%x\n" ,
323
399
quirk , quirk_override );
324
400
quirk = quirk_override ;
325
401
}
326
402
log_quirks (dev );
327
403
404
+ sof_es8336_card .num_links += dmic_be_num ;
328
405
dai_links = sof_card_dai_links_create (dev ,
329
- SOF_ES8336_SSP_CODEC (quirk ));
406
+ SOF_ES8336_SSP_CODEC (quirk ),
407
+ dmic_be_num );
330
408
if (!dai_links )
331
409
return - ENOMEM ;
332
410
0 commit comments