@@ -1306,6 +1306,8 @@ static struct snd_soc_acpi_adr_device *find_acpi_adr_device(struct device *dev,
13061306 return adr_dev ;
13071307}
13081308
1309+ #define SDW_ENUM_TIMEOUT_MS 3000
1310+
13091311static struct snd_soc_acpi_mach * hda_sdw_machine_select (struct snd_sof_dev * sdev )
13101312{
13111313 struct snd_sof_pdata * pdata = sdev -> pdata ;
@@ -1315,7 +1317,9 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
13151317 struct sdw_peripherals * peripherals ;
13161318 struct snd_soc_acpi_mach * mach ;
13171319 struct sof_intel_hda_dev * hdev ;
1320+ struct sdw_slave * slave ;
13181321 int link_index , link_num ;
1322+ unsigned long time ;
13191323 int amp_index = 1 ;
13201324 u32 link_mask = 0 ;
13211325 int i ;
@@ -1416,14 +1420,32 @@ static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev
14161420 if (!links )
14171421 return NULL ;
14181422
1423+ /*
1424+ * Recalculate the link_mask as a link will be empty if all peripherals on the link are
1425+ * not enumerated
1426+ */
1427+ link_mask = 0 ;
14191428 /* Generate snd_soc_acpi_link_adr struct for each peripheral reported by the ACPI table */
14201429 for (i = 0 ; i < peripherals -> num_peripherals ; i ++ ) {
1430+ slave = peripherals -> array [i ];
1431+
1432+ /* Check if the SoundWire peripheral is present */
1433+ if (sof_debug_check_flag (SOF_DBG_CHECK_SDW_PERIPHERAL ) && !slave -> dev_num_sticky ) {
1434+ /* Wait for the peripheral to enumerate */
1435+ time = wait_for_completion_timeout (& slave -> enumeration_complete ,
1436+ msecs_to_jiffies (SDW_ENUM_TIMEOUT_MS ));
1437+ if (!time ) {
1438+ dev_warn (& slave -> dev , "SoundWire peripheral is not present\n" );
1439+ continue ;
1440+ }
1441+ }
14211442 /* link_index = the number of used links below the current link */
1422- link_index = hweight32 (link_mask & (BIT (peripherals -> array [ i ] -> bus -> link_id ) - 1 ));
1423- links [link_index ].adr_d = find_acpi_adr_device (sdev -> dev , peripherals -> array [ i ] ,
1443+ link_index = hweight32 (link_mask & (BIT (slave -> bus -> link_id ) - 1 ));
1444+ links [link_index ].adr_d = find_acpi_adr_device (sdev -> dev , slave ,
14241445 & links [link_index ], & amp_index );
14251446 if (!links [link_index ].adr_d )
14261447 return NULL ;
1448+ link_mask |= BIT (slave -> bus -> link_id );
14271449 }
14281450
14291451 mach -> drv_name = "sof_sdw" ;
0 commit comments