@@ -505,7 +505,7 @@ static int hda_init(struct snd_sof_dev *sdev)
505505 return ret ;
506506}
507507
508- #if IS_ENABLED (CONFIG_SND_SOC_SOF_HDA )
508+ #if IS_ENABLED (CONFIG_SND_SOC_SOF_HDA ) || IS_ENABLED ( CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE )
509509
510510static int check_nhlt_dmic (struct snd_sof_dev * sdev )
511511{
@@ -548,6 +548,53 @@ static const char *fixup_tplg_name(struct snd_sof_dev *sdev,
548548 return tplg_filename ;
549549}
550550
551+ static int dmic_topology_fixup (struct snd_sof_dev * sdev ,
552+ const char * * tplg_filename ,
553+ const char * idisp_str ,
554+ int * dmic_found )
555+ {
556+ const char * dmic_str ;
557+ const char * default_tplg_filename = * tplg_filename ;
558+ const char * fixed_tplg_filename ;
559+ int dmic_num ;
560+
561+ /* first check NHLT for DMICs */
562+ dmic_num = check_nhlt_dmic (sdev );
563+
564+ /* allow for module parameter override */
565+ if (hda_dmic_num != -1 )
566+ dmic_num = hda_dmic_num ;
567+
568+ switch (dmic_num ) {
569+ case 1 :
570+ dmic_str = "-1ch" ;
571+ break ;
572+ case 2 :
573+ dmic_str = "-2ch" ;
574+ break ;
575+ case 3 :
576+ dmic_str = "-3ch" ;
577+ break ;
578+ case 4 :
579+ dmic_str = "-4ch" ;
580+ break ;
581+ default :
582+ dmic_num = 0 ;
583+ dmic_str = "" ;
584+ break ;
585+ }
586+
587+ fixed_tplg_filename = fixup_tplg_name (sdev , default_tplg_filename ,
588+ idisp_str , dmic_str );
589+ if (!fixed_tplg_filename )
590+ return - ENOMEM ;
591+
592+ dev_info (sdev -> dev , "DMICs detected in NHLT tables: %d\n" , dmic_num );
593+ * dmic_found = dmic_num ;
594+ * tplg_filename = fixed_tplg_filename ;
595+
596+ return 0 ;
597+ }
551598#endif
552599
553600static int hda_init_caps (struct snd_sof_dev * sdev )
@@ -913,9 +960,9 @@ static int hda_generic_machine_select(struct snd_sof_dev *sdev)
913960 struct snd_sof_pdata * pdata = sdev -> pdata ;
914961 const char * tplg_filename ;
915962 const char * idisp_str ;
916- const char * dmic_str ;
917963 int dmic_num = 0 ;
918964 int codec_num = 0 ;
965+ int ret ;
919966 int i ;
920967
921968 /* codec detection */
@@ -940,10 +987,6 @@ static int hda_generic_machine_select(struct snd_sof_dev *sdev)
940987 if (!pdata -> machine && codec_num <= 2 ) {
941988 hda_mach = snd_soc_acpi_intel_hda_machines ;
942989
943- /* topology: use the info from hda_machines */
944- pdata -> tplg_filename =
945- hda_mach -> sof_tplg_filename ;
946-
947990 dev_info (bus -> dev , "using HDA machine driver %s now\n" ,
948991 hda_mach -> drv_name );
949992
@@ -952,42 +995,13 @@ static int hda_generic_machine_select(struct snd_sof_dev *sdev)
952995 else
953996 idisp_str = "" ;
954997
955- /* first check NHLT for DMICs */
956- dmic_num = check_nhlt_dmic (sdev );
957-
958- /* allow for module parameter override */
959- if (hda_dmic_num != -1 )
960- dmic_num = hda_dmic_num ;
961-
962- switch (dmic_num ) {
963- case 1 :
964- dmic_str = "-1ch" ;
965- break ;
966- case 2 :
967- dmic_str = "-2ch" ;
968- break ;
969- case 3 :
970- dmic_str = "-3ch" ;
971- break ;
972- case 4 :
973- dmic_str = "-4ch" ;
974- break ;
975- default :
976- dmic_num = 0 ;
977- dmic_str = "" ;
978- break ;
979- }
980-
981- tplg_filename = pdata -> tplg_filename ;
982- tplg_filename = fixup_tplg_name (sdev , tplg_filename ,
983- idisp_str , dmic_str );
984- if (!tplg_filename )
985- return - EINVAL ;
986-
987- dev_info (bus -> dev ,
988- "DMICs detected in NHLT tables: %d\n" ,
989- dmic_num );
998+ /* topology: use the info from hda_machines */
999+ tplg_filename = hda_mach -> sof_tplg_filename ;
1000+ ret = dmic_topology_fixup (sdev , & tplg_filename , idisp_str , & dmic_num );
1001+ if (ret < 0 )
1002+ return ret ;
9901003
1004+ hda_mach -> mach_params .dmic_num = dmic_num ;
9911005 pdata -> machine = hda_mach ;
9921006 pdata -> tplg_filename = tplg_filename ;
9931007 }
@@ -999,7 +1013,6 @@ static int hda_generic_machine_select(struct snd_sof_dev *sdev)
9991013 & pdata -> machine -> mach_params ;
10001014 mach_params -> codec_mask = bus -> codec_mask ;
10011015 mach_params -> common_hdmi_codec_drv = hda_codec_use_common_hdmi ;
1002- mach_params -> dmic_num = dmic_num ;
10031016 }
10041017
10051018 return 0 ;
@@ -1063,7 +1076,6 @@ static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
10631076{
10641077 struct snd_sof_pdata * pdata = sdev -> pdata ;
10651078 const struct snd_soc_acpi_link_adr * link ;
1066- struct hdac_bus * bus = sof_to_bus (sdev );
10671079 struct snd_soc_acpi_mach * mach ;
10681080 struct sof_intel_hda_dev * hdev ;
10691081 u32 link_mask ;
@@ -1111,10 +1123,8 @@ static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
11111123 break ;
11121124 }
11131125 if (mach && mach -> link_mask ) {
1114- dev_dbg (bus -> dev ,
1115- "SoundWire machine driver %s topology %s\n" ,
1116- mach -> drv_name ,
1117- mach -> sof_tplg_filename );
1126+ int dmic_num = 0 ;
1127+
11181128 pdata -> machine = mach ;
11191129 mach -> mach_params .links = mach -> links ;
11201130 mach -> mach_params .link_mask = mach -> link_mask ;
@@ -1124,6 +1134,31 @@ static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
11241134 else
11251135 pdata -> fw_filename = pdata -> desc -> default_fw_filename ;
11261136 pdata -> tplg_filename = mach -> sof_tplg_filename ;
1137+
1138+ /*
1139+ * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1140+ * link 2 and 3, thus we only try to enable dmics if all conditions
1141+ * are true:
1142+ * a) link 2 and 3 are not used by SoundWire
1143+ * b) the NHLT table reports the presence of microphones
1144+ */
1145+ if (!(mach -> link_mask & GENMASK (3 , 2 ))) {
1146+ const char * tplg_filename = mach -> sof_tplg_filename ;
1147+ int ret ;
1148+
1149+ ret = dmic_topology_fixup (sdev , & tplg_filename , "" , & dmic_num );
1150+
1151+ if (ret < 0 )
1152+ return ret ;
1153+
1154+ pdata -> tplg_filename = tplg_filename ;
1155+ }
1156+ mach -> mach_params .dmic_num = dmic_num ;
1157+
1158+ dev_dbg (sdev -> dev ,
1159+ "SoundWire machine driver %s topology %s\n" ,
1160+ mach -> drv_name ,
1161+ pdata -> tplg_filename );
11271162 } else {
11281163 dev_info (sdev -> dev ,
11291164 "No SoundWire machine driver found\n" );
0 commit comments