1717#include <linux/pm_runtime.h>
1818#include <linux/iopoll.h>
1919#include <linux/soundwire/sdw_amd.h>
20+ #include "../mach-config.h"
2021
2122#include "acp63.h"
2223
@@ -281,6 +282,42 @@ static int amd_sdw_exit(struct acp63_dev_data *acp_data)
281282
282283 return 0 ;
283284}
285+
286+ static struct snd_soc_acpi_mach * acp63_sdw_machine_select (struct device * dev )
287+ {
288+ struct snd_soc_acpi_mach * mach ;
289+ const struct snd_soc_acpi_link_adr * link ;
290+ struct acp63_dev_data * acp_data = dev_get_drvdata (dev );
291+ int ret , i ;
292+
293+ if (acp_data -> info .count ) {
294+ ret = sdw_amd_get_slave_info (acp_data -> sdw );
295+ if (ret ) {
296+ dev_dbg (dev , "failed to read slave information\n" );
297+ return NULL ;
298+ }
299+ for (mach = acp_data -> machines ; mach ; mach ++ ) {
300+ if (!mach -> links )
301+ break ;
302+ link = mach -> links ;
303+ for (i = 0 ; i < acp_data -> info .count && link -> num_adr ; link ++ , i ++ ) {
304+ if (!snd_soc_acpi_sdw_link_slaves_found (dev , link ,
305+ acp_data -> sdw -> ids ,
306+ acp_data -> sdw -> num_slaves ))
307+ break ;
308+ }
309+ if (i == acp_data -> info .count || !link -> num_adr )
310+ break ;
311+ }
312+ if (mach && mach -> link_mask ) {
313+ mach -> mach_params .links = mach -> links ;
314+ mach -> mach_params .link_mask = mach -> link_mask ;
315+ return mach ;
316+ }
317+ }
318+ dev_dbg (dev , "No SoundWire machine driver found\n" );
319+ return NULL ;
320+ }
284321#else
285322static int acp_scan_sdw_devices (struct device * dev , u64 addr )
286323{
@@ -296,8 +333,44 @@ static int amd_sdw_exit(struct acp63_dev_data *acp_data)
296333{
297334 return 0 ;
298335}
336+
337+ static struct snd_soc_acpi_mach * acp63_sdw_machine_select (struct device * dev )
338+ {
339+ return NULL ;
340+ }
299341#endif
300342
343+ static int acp63_machine_register (struct device * dev )
344+ {
345+ struct snd_soc_acpi_mach * mach ;
346+ struct acp63_dev_data * adata = dev_get_drvdata (dev );
347+ int size ;
348+
349+ if (adata -> is_sdw_dev && adata -> is_sdw_config ) {
350+ size = sizeof (* adata -> machines );
351+ mach = acp63_sdw_machine_select (dev );
352+ if (mach ) {
353+ adata -> mach_dev = platform_device_register_data (dev , mach -> drv_name ,
354+ PLATFORM_DEVID_NONE , mach ,
355+ size );
356+ if (IS_ERR (adata -> mach_dev )) {
357+ dev_err (dev ,
358+ "cannot register Machine device for SoundWire Interface\n" );
359+ return PTR_ERR (adata -> mach_dev );
360+ }
361+ }
362+
363+ } else if (adata -> is_pdm_dev && !adata -> is_sdw_dev && adata -> is_pdm_config ) {
364+ adata -> mach_dev = platform_device_register_data (dev , "acp_ps_mach" ,
365+ PLATFORM_DEVID_NONE , NULL , 0 );
366+ if (IS_ERR (adata -> mach_dev )) {
367+ dev_err (dev , "cannot register amd_ps_mach device\n" );
368+ return PTR_ERR (adata -> mach_dev );
369+ }
370+ }
371+ return 0 ;
372+ }
373+
301374static int get_acp63_device_config (struct pci_dev * pci , struct acp63_dev_data * acp_data )
302375{
303376 struct acpi_device * pdm_dev ;
@@ -526,7 +599,11 @@ static int snd_acp63_probe(struct pci_dev *pci,
526599 dev_err (& pci -> dev , "ACP platform devices creation failed\n" );
527600 goto de_init ;
528601 }
529-
602+ ret = acp63_machine_register (& pci -> dev );
603+ if (ret ) {
604+ dev_err (& pci -> dev , "ACP machine register failed\n" );
605+ goto de_init ;
606+ }
530607skip_pdev_creation :
531608 device_set_wakeup_enable (& pci -> dev , true);
532609 pm_runtime_set_autosuspend_delay (& pci -> dev , ACP_SUSPEND_DELAY_MS );
@@ -640,6 +717,8 @@ static void snd_acp63_remove(struct pci_dev *pci)
640717 platform_device_unregister (adata -> pdm_dev );
641718 platform_device_unregister (adata -> dmic_codec_dev );
642719 }
720+ if (adata -> mach_dev )
721+ platform_device_unregister (adata -> mach_dev );
643722 ret = acp63_deinit (adata -> acp63_base , & pci -> dev );
644723 if (ret )
645724 dev_err (& pci -> dev , "ACP de-init failed\n" );
0 commit comments