99
1010#include <linux/device.h>
1111#include <linux/errno.h>
12+ #include <linux/soundwire/sdw_type.h>
1213#include <sound/soc.h>
1314#include <sound/soc-acpi.h>
1415#include <sound/soc_sdw_utils.h>
16+ #include <sound/sdca_function.h>
17+
1518
1619int asoc_sdw_rt_dmic_rtd_init (struct snd_soc_pcm_runtime * rtd , struct snd_soc_dai * dai )
1720{
1821 struct snd_soc_card * card = rtd -> card ;
1922 struct snd_soc_component * component ;
23+ struct sdw_slave * sdw_peripheral ;
24+ struct asoc_sdw_codec_info * codec_info ;
2025 char * mic_name ;
26+ int rt1320_dmic_num = 0 , part_id , i ;
2127
2228 component = dai -> component ;
2329
@@ -32,9 +38,40 @@ int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_da
3238 if (!mic_name )
3339 return - ENOMEM ;
3440
35- card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
36- "%s mic:%s" , card -> components ,
37- mic_name );
41+ /*
42+ * If there is any rt1320 DMIC belonging to this card, try to count the `cfg-mics` to be
43+ * used in card->components.
44+ */
45+ if (!strcmp (dai -> name , "rt1320-aif2" )) {
46+ codec_info = asoc_sdw_find_codec_info_dai (dai -> name , & i );
47+ if (!codec_info )
48+ return - EINVAL ;
49+ part_id = codec_info -> part_id ;
50+
51+ /* count the rt1320 with SDCA function SmartMic type in this card */
52+ for_each_card_components (card , component ) {
53+ if (!is_sdw_slave (component -> dev ))
54+ continue ;
55+ sdw_peripheral = dev_to_sdw_dev (component -> dev );
56+ if (sdw_peripheral -> id .part_id != part_id )
57+ continue ;
58+ for (i = 0 ; i < sdw_peripheral -> sdca_data .num_functions ; i ++ ) {
59+ if (sdw_peripheral -> sdca_data .function [i ].type ==
60+ SDCA_FUNCTION_TYPE_SMART_MIC ) {
61+ rt1320_dmic_num ++ ;
62+ break ;
63+ }
64+ }
65+ }
66+ card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
67+ "%s mic:%s cfg-mics:%d" , card -> components ,
68+ mic_name , rt1320_dmic_num );
69+ } else {
70+ card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
71+ "%s mic:%s" , card -> components ,
72+ mic_name );
73+ }
74+
3875 if (!card -> components )
3976 return - ENOMEM ;
4077
0 commit comments