3535#define DRV_NAME "rk-hdmi-dp-sound"
3636#define MAX_CODECS 2
3737
38+ static const struct snd_soc_dapm_widget rk_dapm_widgets [] = {
39+ SND_SOC_DAPM_LINE ("HDMI" , NULL ),
40+ };
41+
42+ static const struct snd_soc_dapm_route rk_dapm_routes [] = {
43+ {"HDMI" , NULL , "TX" },
44+ };
45+
46+ static const struct snd_kcontrol_new rk_mc_controls [] = {
47+ SOC_DAPM_PIN_SWITCH ("HDMI" ),
48+ };
49+
3850static int rk_hdmi_dp_hw_params (struct snd_pcm_substream * substream ,
3951 struct snd_pcm_hw_params * params )
4052{
@@ -142,32 +154,43 @@ static struct snd_soc_ops rockchip_sound_hdmidp_ops = {
142154 .hw_params = rk_hdmi_dp_hw_params ,
143155};
144156
157+ SND_SOC_DAILINK_DEFS (audio ,
158+ DAILINK_COMP_ARRAY (COMP_CPU (NULL )),
159+ DAILINK_COMP_ARRAY (COMP_CODEC (NULL , NULL ), COMP_CODEC (NULL , NULL )),
160+ DAILINK_COMP_ARRAY (COMP_PLATFORM (NULL )));
161+
145162static struct snd_soc_dai_link rk_dailink = {
146163 .name = "HDMI-DP" ,
147164 .stream_name = "HDMI-DP" ,
148165 .init = rockchip_sound_hdmi_dp_init ,
149166 .ops = & rockchip_sound_hdmidp_ops ,
150167 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
151168 SND_SOC_DAIFMT_CBS_CFS ,
169+ SND_SOC_DAILINK_REG (audio ),
152170};
153171
154172static struct snd_soc_card snd_soc_card_rk = {
155173 .name = "rk-hdmi-dp-sound" ,
156174 .dai_link = & rk_dailink ,
157175 .num_links = 1 ,
158176 .num_aux_devs = 0 ,
177+ .dapm_widgets = rk_dapm_widgets ,
178+ .num_dapm_widgets = ARRAY_SIZE (rk_dapm_widgets ),
179+ .dapm_routes = rk_dapm_routes ,
180+ .num_dapm_routes = ARRAY_SIZE (rk_dapm_routes ),
181+ .controls = rk_mc_controls ,
182+ .num_controls = ARRAY_SIZE (rk_mc_controls ),
159183};
160184
161185static int rk_hdmi_dp_probe (struct platform_device * pdev )
162186{
163187 struct snd_soc_card * card = & snd_soc_card_rk ;
164188 struct device_node * np = pdev -> dev .of_node ;
165189 struct snd_soc_dai_link * link = card -> dai_link ;
166- struct snd_soc_dai_link_component * codecs ;
190+ struct snd_soc_dai_link_component * codec ;
167191 struct of_phandle_args args ;
168- struct device_node * node ;
169192 int count ;
170- int ret = 0 , i = 0 , idx = 0 ;
193+ int ret = 0 , i = 0 ;
171194
172195 card -> dev = & pdev -> dev ;
173196
@@ -176,44 +199,51 @@ static int rk_hdmi_dp_probe(struct platform_device *pdev)
176199 return - EINVAL ;
177200
178201 /* refine codecs, remove unavailable node */
179- for (i = 0 ; i < count ; i ++ ) {
180- node = of_parse_phandle (np , "rockchip,codec" , i );
181- if (!node )
182- return - ENODEV ;
183- if (of_device_is_available (node ))
184- idx ++ ;
185- }
186-
187- if (!idx )
188- return - ENODEV ;
202+ link -> num_codecs = 0 ;
189203
190- codecs = devm_kcalloc (& pdev -> dev , idx ,
191- sizeof (* codecs ), GFP_KERNEL );
192- link -> codecs = codecs ;
193- link -> num_codecs = idx ;
194- idx = 0 ;
195204 for (i = 0 ; i < count ; i ++ ) {
196- node = of_parse_phandle (np , "rockchip,codec" , i );
197- if (!node )
198- return - ENODEV ;
199- if (!of_device_is_available (node ))
205+ codec = & link -> codecs [link -> num_codecs ];
206+
207+ codec -> of_node = of_parse_phandle (np , "rockchip,codec" , i );
208+ if (!codec -> of_node ) {
209+ dev_err (& pdev -> dev ,
210+ "Property 'rockchip,codec' missing or invalid\n" );
211+ return - EINVAL ;
212+ }
213+
214+ if (!of_device_is_available (codec -> of_node )) {
215+ dev_err (& pdev -> dev ,
216+ "Property 'rockchip,codec' is not available\n" );
200217 continue ;
218+ }
201219
202220 ret = of_parse_phandle_with_fixed_args (np , "rockchip,codec" ,
203221 0 , i , & args );
204- if (ret )
222+ if (ret ) {
223+ dev_err (& pdev -> dev ,
224+ "Unable to parse property 'rockchip,codec'\n" );
205225 return ret ;
226+ }
206227
207- codecs [idx ].of_node = node ;
208- ret = snd_soc_get_dai_name (& args , & codecs [idx ].dai_name );
228+ ret = snd_soc_get_dai_name (& args , & codec -> dai_name );
209229 if (ret )
210230 return ret ;
211- idx ++ ;
231+
232+ link -> num_codecs ++ ;
233+ }
234+
235+ if (!link -> num_codecs ) {
236+ dev_err (& pdev -> dev ,
237+ "Property 'rockchip,cpu' missing or invalid\n" );
238+ return - ENODEV ;
212239 }
213240
214241 link -> cpus -> of_node = of_parse_phandle (np , "rockchip,cpu" , 0 );
215- if (!link -> cpus -> of_node )
242+ if (!link -> cpus -> of_node ) {
243+ dev_err (& pdev -> dev ,
244+ "Property 'rockchip,cpu' missing or invalid\n" );
216245 return - ENODEV ;
246+ }
217247 link -> platforms -> of_node = link -> cpus -> of_node ;
218248
219249 ret = devm_snd_soc_register_card (& pdev -> dev , card );
0 commit comments