2222#include <sound/soc-dai.h>
2323#include <sound/simple_card_utils.h>
2424
25- struct asoc_simple_card_priv {
25+ struct simple_card_data {
2626 struct snd_soc_card snd_card ;
2727 struct snd_soc_codec_conf codec_conf ;
2828 struct asoc_simple_dai * dai_props ;
@@ -42,7 +42,7 @@ struct asoc_simple_card_priv {
4242static int asoc_simple_card_startup (struct snd_pcm_substream * substream )
4343{
4444 struct snd_soc_pcm_runtime * rtd = substream -> private_data ;
45- struct asoc_simple_card_priv * priv = snd_soc_card_get_drvdata (rtd -> card );
45+ struct simple_card_data * priv = snd_soc_card_get_drvdata (rtd -> card );
4646 struct asoc_simple_dai * dai_props =
4747 simple_priv_to_props (priv , rtd -> num );
4848
@@ -52,7 +52,7 @@ static int asoc_simple_card_startup(struct snd_pcm_substream *substream)
5252static void asoc_simple_card_shutdown (struct snd_pcm_substream * substream )
5353{
5454 struct snd_soc_pcm_runtime * rtd = substream -> private_data ;
55- struct asoc_simple_card_priv * priv = snd_soc_card_get_drvdata (rtd -> card );
55+ struct simple_card_data * priv = snd_soc_card_get_drvdata (rtd -> card );
5656 struct asoc_simple_dai * dai_props =
5757 simple_priv_to_props (priv , rtd -> num );
5858
@@ -66,7 +66,7 @@ static const struct snd_soc_ops asoc_simple_card_ops = {
6666
6767static int asoc_simple_card_dai_init (struct snd_soc_pcm_runtime * rtd )
6868{
69- struct asoc_simple_card_priv * priv = snd_soc_card_get_drvdata (rtd -> card );
69+ struct simple_card_data * priv = snd_soc_card_get_drvdata (rtd -> card );
7070 struct snd_soc_dai * dai ;
7171 struct snd_soc_dai_link * dai_link ;
7272 struct asoc_simple_dai * dai_props ;
@@ -84,7 +84,7 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
8484static int asoc_simple_card_be_hw_params_fixup (struct snd_soc_pcm_runtime * rtd ,
8585 struct snd_pcm_hw_params * params )
8686{
87- struct asoc_simple_card_priv * priv = snd_soc_card_get_drvdata (rtd -> card );
87+ struct simple_card_data * priv = snd_soc_card_get_drvdata (rtd -> card );
8888 struct snd_interval * rate = hw_param_interval (params ,
8989 SNDRV_PCM_HW_PARAM_RATE );
9090 struct snd_interval * channels = hw_param_interval (params ,
@@ -101,8 +101,8 @@ static int asoc_simple_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
101101 return 0 ;
102102}
103103
104- static int asoc_simple_card_parse_links (struct device_node * np ,
105- struct asoc_simple_card_priv * priv ,
104+ static int asoc_simple_card_dai_link_of (struct device_node * np ,
105+ struct simple_card_data * priv ,
106106 unsigned int daifmt ,
107107 int idx , bool is_fe )
108108{
@@ -195,22 +195,35 @@ static int asoc_simple_card_parse_links(struct device_node *np,
195195 return 0 ;
196196}
197197
198- static int asoc_simple_card_dai_link_of (struct device_node * node ,
199- struct asoc_simple_card_priv * priv )
198+ static int asoc_simple_card_parse_of (struct device_node * node ,
199+ struct simple_card_data * priv )
200+
200201{
201202 struct device * dev = simple_priv_to_dev (priv );
202203 struct device_node * np ;
203204 unsigned int daifmt = 0 ;
204- int ret , i ;
205205 bool is_fe ;
206+ int ret , i ;
207+
208+ if (!node )
209+ return - EINVAL ;
210+
211+ ret = snd_soc_of_parse_audio_routing (& priv -> snd_card , PREFIX "routing" );
212+ if (ret < 0 )
213+ return ret ;
214+
215+ /* sampling rate convert */
216+ of_property_read_u32 (node , PREFIX "convert-rate" , & priv -> convert_rate );
217+
218+ /* channels transfer */
219+ of_property_read_u32 (node , PREFIX "convert-channels" , & priv -> convert_channels );
206220
207221 /* find 1st codec */
208222 np = of_get_child_by_name (node , PREFIX "codec" );
209223 if (!np )
210224 return - ENODEV ;
211225
212- ret = asoc_simple_card_parse_daifmt (dev , node , np ,
213- PREFIX , & daifmt );
226+ ret = asoc_simple_card_parse_daifmt (dev , node , np , PREFIX , & daifmt );
214227 if (ret < 0 )
215228 return ret ;
216229
@@ -220,58 +233,12 @@ static int asoc_simple_card_dai_link_of(struct device_node *node,
220233 if (strcmp (np -> name , PREFIX "cpu" ) == 0 )
221234 is_fe = true;
222235
223- ret = asoc_simple_card_parse_links (np , priv , daifmt , i , is_fe );
236+ ret = asoc_simple_card_dai_link_of (np , priv , daifmt , i , is_fe );
224237 if (ret < 0 )
225238 return ret ;
226239 i ++ ;
227240 }
228241
229- return 0 ;
230- }
231-
232- static int asoc_simple_card_parse_of (struct device_node * node ,
233- struct asoc_simple_card_priv * priv ,
234- struct device * dev )
235- {
236- struct asoc_simple_dai * props ;
237- struct snd_soc_dai_link * links ;
238- int ret ;
239- int num ;
240-
241- if (!node )
242- return - EINVAL ;
243-
244- num = of_get_child_count (node );
245- props = devm_kzalloc (dev , sizeof (* props ) * num , GFP_KERNEL );
246- links = devm_kzalloc (dev , sizeof (* links ) * num , GFP_KERNEL );
247- if (!props || !links )
248- return - ENOMEM ;
249-
250- priv -> dai_props = props ;
251- priv -> dai_link = links ;
252-
253- /* Init snd_soc_card */
254- priv -> snd_card .owner = THIS_MODULE ;
255- priv -> snd_card .dev = dev ;
256- priv -> snd_card .dai_link = priv -> dai_link ;
257- priv -> snd_card .num_links = num ;
258- priv -> snd_card .codec_conf = & priv -> codec_conf ;
259- priv -> snd_card .num_configs = 1 ;
260-
261- ret = snd_soc_of_parse_audio_routing (& priv -> snd_card , PREFIX "routing" );
262- if (ret < 0 )
263- return ret ;
264-
265- /* sampling rate convert */
266- of_property_read_u32 (node , PREFIX "convert-rate" , & priv -> convert_rate );
267-
268- /* channels transfer */
269- of_property_read_u32 (node , PREFIX "convert-channels" , & priv -> convert_channels );
270-
271- ret = asoc_simple_card_dai_link_of (node , priv );
272- if (ret < 0 )
273- return ret ;
274-
275242 ret = asoc_simple_card_parse_card_name (& priv -> snd_card , PREFIX );
276243 if (ret < 0 )
277244 return ret ;
@@ -286,17 +253,37 @@ static int asoc_simple_card_parse_of(struct device_node *node,
286253
287254static int asoc_simple_card_probe (struct platform_device * pdev )
288255{
289- struct asoc_simple_card_priv * priv ;
290- struct device_node * np = pdev -> dev .of_node ;
256+ struct simple_card_data * priv ;
257+ struct snd_soc_dai_link * dai_link ;
258+ struct asoc_simple_dai * dai_props ;
291259 struct device * dev = & pdev -> dev ;
292- int ret ;
260+ struct device_node * np = pdev -> dev .of_node ;
261+ int num , ret ;
293262
294263 /* Allocate the private data */
295264 priv = devm_kzalloc (dev , sizeof (* priv ), GFP_KERNEL );
296265 if (!priv )
297266 return - ENOMEM ;
298267
299- ret = asoc_simple_card_parse_of (np , priv , dev );
268+ num = of_get_child_count (np );
269+
270+ dai_props = devm_kzalloc (dev , sizeof (* dai_props ) * num , GFP_KERNEL );
271+ dai_link = devm_kzalloc (dev , sizeof (* dai_link ) * num , GFP_KERNEL );
272+ if (!dai_props || !dai_link )
273+ return - ENOMEM ;
274+
275+ priv -> dai_props = dai_props ;
276+ priv -> dai_link = dai_link ;
277+
278+ /* Init snd_soc_card */
279+ priv -> snd_card .owner = THIS_MODULE ;
280+ priv -> snd_card .dev = dev ;
281+ priv -> snd_card .dai_link = priv -> dai_link ;
282+ priv -> snd_card .num_links = num ;
283+ priv -> snd_card .codec_conf = & priv -> codec_conf ;
284+ priv -> snd_card .num_configs = 1 ;
285+
286+ ret = asoc_simple_card_parse_of (np , priv );
300287 if (ret < 0 ) {
301288 if (ret != - EPROBE_DEFER )
302289 dev_err (dev , "parse error %d\n" , ret );
0 commit comments