99
1010#include <linux/device.h>
1111#include <linux/errno.h>
12+ #include <linux/soundwire/sdw.h>
13+ #include <linux/soundwire/sdw_type.h>
1214#include <sound/soc.h>
1315#include <sound/soc-acpi.h>
1416#include <sound/soc_sdw_utils.h>
17+ #include <sound/sdca_function.h>
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 = NULL ;
2024 char * mic_name ;
25+ int rt1320_dmic_num = 0 , part_id , i ;
2126
2227 component = dai -> component ;
2328
@@ -32,9 +37,44 @@ int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_da
3237 if (!mic_name )
3338 return - ENOMEM ;
3439
35- card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
36- "%s mic:%s" , card -> components ,
37- mic_name );
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+ * Note: The rt1320 drivers register the peripheral dev to component->dev, so get the
44+ * sdw_peripheral from component->dev.
45+ */
46+ if (is_sdw_slave (component -> dev ))
47+ sdw_peripheral = dev_to_sdw_dev (component -> dev );
48+ if (sdw_peripheral &&
49+ (sdw_peripheral -> id .part_id == 0x1320 || sdw_peripheral -> id .part_id == 0x1321 )) {
50+ part_id = sdw_peripheral -> id .part_id ;
51+ /*
52+ * This rtd init callback is called once, so count the rt1320/rt1321 with SDCA
53+ * function SmartMic type in this card.
54+ */
55+ for_each_card_components (card , component ) {
56+ if (!is_sdw_slave (component -> dev ))
57+ continue ;
58+ sdw_peripheral = dev_to_sdw_dev (component -> dev );
59+ if (sdw_peripheral -> id .part_id != part_id )
60+ continue ;
61+ for (i = 0 ; i < sdw_peripheral -> sdca_data .num_functions ; i ++ ) {
62+ if (sdw_peripheral -> sdca_data .function [i ].type ==
63+ SDCA_FUNCTION_TYPE_SMART_MIC ) {
64+ rt1320_dmic_num ++ ;
65+ break ;
66+ }
67+ }
68+ }
69+ card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
70+ "%s mic:%s cfg-mics:%d" , card -> components ,
71+ mic_name , rt1320_dmic_num );
72+ } else {
73+ card -> components = devm_kasprintf (card -> dev , GFP_KERNEL ,
74+ "%s mic:%s" , card -> components ,
75+ mic_name );
76+ }
77+
3878 if (!card -> components )
3979 return - ENOMEM ;
4080
0 commit comments