@@ -511,6 +511,8 @@ static int check_dmic_num(struct snd_sof_dev *sdev)
511511 if (nhlt )
512512 dmic_num = intel_nhlt_get_dmic_geo (sdev -> dev , nhlt );
513513
514+ dev_info (sdev -> dev , "DMICs detected in NHLT tables: %d\n" , dmic_num );
515+
514516 /* allow for module parameter override */
515517 if (dmic_num_override != -1 ) {
516518 dev_dbg (sdev -> dev ,
@@ -558,82 +560,6 @@ static int check_nhlt_ssp_mclk_mask(struct snd_sof_dev *sdev, int ssp_num)
558560 return intel_nhlt_ssp_mclk_mask (nhlt , ssp_num );
559561}
560562
561- #if IS_ENABLED (CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE )
562-
563- static const char * fixup_tplg_name (struct snd_sof_dev * sdev ,
564- const char * sof_tplg_filename ,
565- const char * idisp_str ,
566- const char * dmic_str )
567- {
568- const char * tplg_filename = NULL ;
569- char * filename , * tmp ;
570- const char * split_ext ;
571-
572- filename = kstrdup (sof_tplg_filename , GFP_KERNEL );
573- if (!filename )
574- return NULL ;
575-
576- /* this assumes a .tplg extension */
577- tmp = filename ;
578- split_ext = strsep (& tmp , "." );
579- if (split_ext )
580- tplg_filename = devm_kasprintf (sdev -> dev , GFP_KERNEL ,
581- "%s%s%s.tplg" ,
582- split_ext , idisp_str , dmic_str );
583- kfree (filename );
584-
585- return tplg_filename ;
586- }
587-
588- static int dmic_detect_topology_fixup (struct snd_sof_dev * sdev ,
589- const char * * tplg_filename ,
590- const char * idisp_str ,
591- int * dmic_found ,
592- bool tplg_fixup )
593- {
594- const char * dmic_str ;
595- int dmic_num ;
596-
597- /* first check for DMICs (using NHLT or module parameter) */
598- dmic_num = check_dmic_num (sdev );
599-
600- switch (dmic_num ) {
601- case 1 :
602- dmic_str = "-1ch" ;
603- break ;
604- case 2 :
605- dmic_str = "-2ch" ;
606- break ;
607- case 3 :
608- dmic_str = "-3ch" ;
609- break ;
610- case 4 :
611- dmic_str = "-4ch" ;
612- break ;
613- default :
614- dmic_num = 0 ;
615- dmic_str = "" ;
616- break ;
617- }
618-
619- if (tplg_fixup ) {
620- const char * default_tplg_filename = * tplg_filename ;
621- const char * fixed_tplg_filename ;
622-
623- fixed_tplg_filename = fixup_tplg_name (sdev , default_tplg_filename ,
624- idisp_str , dmic_str );
625- if (!fixed_tplg_filename )
626- return - ENOMEM ;
627- * tplg_filename = fixed_tplg_filename ;
628- }
629-
630- dev_info (sdev -> dev , "DMICs detected in NHLT tables: %d\n" , dmic_num );
631- * dmic_found = dmic_num ;
632-
633- return 0 ;
634- }
635- #endif
636-
637563static int hda_init_caps (struct snd_sof_dev * sdev )
638564{
639565 u32 interface_mask = hda_get_interface_mask (sdev );
@@ -1199,45 +1125,10 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
11991125 break ;
12001126 }
12011127 if (mach && mach -> link_mask ) {
1202- int dmic_num = 0 ;
1203- bool tplg_fixup ;
1204- const char * tplg_filename ;
1205-
12061128 mach -> mach_params .links = mach -> links ;
12071129 mach -> mach_params .link_mask = mach -> link_mask ;
12081130 mach -> mach_params .platform = dev_name (sdev -> dev );
12091131
1210- if (pdata -> tplg_filename ) {
1211- tplg_fixup = false;
1212- } else {
1213- tplg_fixup = true;
1214- tplg_filename = mach -> sof_tplg_filename ;
1215- }
1216-
1217- /*
1218- * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1219- * link 2 and 3, or link 1 and 2, thus we only try to enable dmics
1220- * if all conditions are true:
1221- * a) 2 or fewer links are used by SoundWire
1222- * b) the NHLT table reports the presence of microphones
1223- */
1224- if (hweight_long (mach -> link_mask ) <= 2 ) {
1225- int ret ;
1226-
1227- ret = dmic_detect_topology_fixup (sdev , & tplg_filename , "" ,
1228- & dmic_num , tplg_fixup );
1229- if (ret < 0 )
1230- return NULL ;
1231- }
1232- if (tplg_fixup )
1233- pdata -> tplg_filename = tplg_filename ;
1234- mach -> mach_params .dmic_num = dmic_num ;
1235-
1236- dev_dbg (sdev -> dev ,
1237- "SoundWire machine driver %s topology %s\n" ,
1238- mach -> drv_name ,
1239- pdata -> tplg_filename );
1240-
12411132 return mach ;
12421133 }
12431134
@@ -1294,6 +1185,19 @@ static int check_tplg_quirk_mask(struct snd_soc_acpi_mach *mach)
12941185 return 0 ;
12951186}
12961187
1188+ static char * remove_file_ext (const char * tplg_filename )
1189+ {
1190+ char * filename , * tmp ;
1191+
1192+ filename = kstrdup (tplg_filename , GFP_KERNEL );
1193+ if (!filename )
1194+ return NULL ;
1195+
1196+ /* remove file extension if exist */
1197+ tmp = filename ;
1198+ return strsep (& tmp , "." );
1199+ }
1200+
12971201struct snd_soc_acpi_mach * hda_machine_select (struct snd_sof_dev * sdev )
12981202{
12991203 u32 interface_mask = hda_get_interface_mask (sdev );
@@ -1305,6 +1209,7 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
13051209 const char * tplg_filename ;
13061210 const char * tplg_suffix ;
13071211 bool i2s_mach_found = false;
1212+ bool sdw_mach_found = false;
13081213
13091214 /* Try I2S or DMIC if it is supported */
13101215 if (interface_mask & (BIT (SOF_DAI_INTEL_SSP ) | BIT (SOF_DAI_INTEL_DMIC ))) {
@@ -1318,8 +1223,11 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
13181223 * try SoundWire if it is supported
13191224 */
13201225 if (!mach && !HDA_EXT_CODEC (bus -> codec_mask ) &&
1321- (interface_mask & BIT (SOF_DAI_INTEL_ALH )))
1226+ (interface_mask & BIT (SOF_DAI_INTEL_ALH ))) {
13221227 mach = hda_sdw_machine_select (sdev );
1228+ if (mach )
1229+ sdw_mach_found = true;
1230+ }
13231231
13241232 /*
13251233 * Choose HDA generic machine driver if mach is NULL.
@@ -1334,15 +1242,20 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
13341242 * name string if quirk flag is set.
13351243 */
13361244 if (mach ) {
1337- bool add_extension = false;
13381245 bool tplg_fixup = false;
1246+ bool dmic_fixup = false;
13391247
13401248 /*
13411249 * If tplg file name is overridden, use it instead of
13421250 * the one set in mach table
13431251 */
13441252 if (!sof_pdata -> tplg_filename ) {
1345- sof_pdata -> tplg_filename = mach -> sof_tplg_filename ;
1253+ /* remove file extension if exist */
1254+ tplg_filename = remove_file_ext (mach -> sof_tplg_filename );
1255+ if (!tplg_filename )
1256+ return NULL ;
1257+
1258+ sof_pdata -> tplg_filename = tplg_filename ;
13461259 tplg_fixup = true;
13471260 }
13481261
@@ -1360,8 +1273,24 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
13601273 /* report to machine driver if any DMICs are found */
13611274 mach -> mach_params .dmic_num = check_dmic_num (sdev );
13621275
1276+ /* SDW mach does not use DMIC quirk flag. */
1277+ if (sdw_mach_found ) {
1278+ /*
1279+ * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1280+ * link 2 and 3, or link 1 and 2, thus we only try to enable dmics
1281+ * if all conditions are true:
1282+ * a) 2 or fewer links are used by SoundWire
1283+ * b) the NHLT table reports the presence of microphones
1284+ */
1285+ if (hweight_long (mach -> link_mask ) <= 2 )
1286+ dmic_fixup = true;
1287+ } else {
1288+ if (mach -> tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER )
1289+ dmic_fixup = true;
1290+ }
1291+
13631292 if (tplg_fixup &&
1364- mach -> tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER &&
1293+ dmic_fixup &&
13651294 mach -> mach_params .dmic_num ) {
13661295 tplg_filename = devm_kasprintf (sdev -> dev , GFP_KERNEL ,
13671296 "%s%s%d%s" ,
@@ -1373,7 +1302,6 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
13731302 return NULL ;
13741303
13751304 sof_pdata -> tplg_filename = tplg_filename ;
1376- add_extension = true;
13771305 }
13781306
13791307 if (mach -> link_mask ) {
@@ -1413,7 +1341,6 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
14131341 return NULL ;
14141342
14151343 sof_pdata -> tplg_filename = tplg_filename ;
1416- add_extension = true;
14171344
14181345 mclk_mask = check_nhlt_ssp_mclk_mask (sdev , ssp_num );
14191346
@@ -1451,7 +1378,6 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
14511378 return NULL ;
14521379
14531380 sof_pdata -> tplg_filename = tplg_filename ;
1454- add_extension = true;
14551381 }
14561382
14571383 codec_type = snd_soc_acpi_intel_detect_codec_type (sdev -> dev );
@@ -1474,10 +1400,9 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
14741400 return NULL ;
14751401
14761402 sof_pdata -> tplg_filename = tplg_filename ;
1477- add_extension = true;
14781403 }
14791404
1480- if (tplg_fixup && add_extension ) {
1405+ if (tplg_fixup ) {
14811406 tplg_filename = devm_kasprintf (sdev -> dev , GFP_KERNEL ,
14821407 "%s%s" ,
14831408 sof_pdata -> tplg_filename ,
0 commit comments