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>
1517
1618int asoc_sdw_rt_dmic_rtd_init (struct snd_soc_pcm_runtime * rtd , struct snd_soc_dai * dai )
1719{
1820 struct snd_soc_card * card = rtd -> card ;
1921 struct snd_soc_component * component ;
22+ struct sdw_slave * sdw_peripheral ;
2023 char * mic_name ;
24+ int rt1320_dmic_num = 0 , part_id , i ;
2125
2226 component = dai -> component ;
2327
@@ -32,9 +36,37 @@ int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_da
3236 if (!mic_name )
3337 return - ENOMEM ;
3438
35- card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
36- "%s mic:%s" , card -> components ,
37- mic_name );
39+ sdw_peripheral = dev_to_sdw_dev (component -> dev );
40+ /*
41+ * If there is any rt1320/rt1321 DMIC belonging to this card, try to count the `cfg-mics`
42+ * to be used in card->components.
43+ */
44+ if (sdw_peripheral -> id .part_id == 0x1320 || sdw_peripheral -> id .part_id == 0x1321 ) {
45+ part_id = sdw_peripheral -> id .part_id ;
46+ /* count the rt1320/rt1321 with SDCA function SmartMic type in this card */
47+ for_each_card_components (card , component ) {
48+ if (!is_sdw_slave (component -> dev ))
49+ continue ;
50+ sdw_peripheral = dev_to_sdw_dev (component -> dev );
51+ if (sdw_peripheral -> id .part_id != part_id )
52+ continue ;
53+ for (i = 0 ; i < sdw_peripheral -> sdca_data .num_functions ; i ++ ) {
54+ if (sdw_peripheral -> sdca_data .function [i ].type ==
55+ SDCA_FUNCTION_TYPE_SMART_MIC ) {
56+ rt1320_dmic_num ++ ;
57+ break ;
58+ }
59+ }
60+ }
61+ card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
62+ "%s mic:%s cfg-mics:%d" , card -> components ,
63+ mic_name , rt1320_dmic_num );
64+ } else {
65+ card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
66+ "%s mic:%s" , card -> components ,
67+ mic_name );
68+ }
69+
3870 if (!card -> components )
3971 return - ENOMEM ;
4072
0 commit comments