summaryrefslogtreecommitdiffstats
path: root/sound/soc/generic
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2019-03-20 00:56:36 -0400
committerMark Brown <broonie@kernel.org>2019-03-21 10:52:37 -0400
commit8f7f298a333761a528e103cda3b42f3a416ad1ee (patch)
treee5b79636bc0a7e7aa859e6791512aa1103db5ba2 /sound/soc/generic
parent65a5056b21202eff7f54243e587183f4bb6ed352 (diff)
ASoC: simple-card-utils: separate asoc_simple_card_parse_dai()
The difference between simple-card / audio-graph are just using OF graph style, or not. In other words, other things should be same. This means, simple-card/audio-graph common functions should be implemented at simple-card-utils, and its own functions should be implemented at each files. Current simple-card / audio-graph are using asoc_simple_card_parse_dai() which is different implementation. But, these are implemanted at simple-card-utils. It should be implemanted at each files. This patch separate these into each files. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/generic')
-rw-r--r--sound/soc/generic/audio-graph-card.c114
-rw-r--r--sound/soc/generic/simple-card-utils.c143
-rw-r--r--sound/soc/generic/simple-card.c58
3 files changed, 156 insertions, 159 deletions
diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index b9a93379098d..3370b6fc6da2 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -55,6 +55,103 @@ static const struct snd_soc_ops graph_ops = {
55 .hw_params = asoc_simple_hw_params, 55 .hw_params = asoc_simple_hw_params,
56}; 56};
57 57
58static int graph_get_dai_id(struct device_node *ep)
59{
60 struct device_node *node;
61 struct device_node *endpoint;
62 struct of_endpoint info;
63 int i, id;
64 int ret;
65
66 /* use driver specified DAI ID if exist */
67 ret = snd_soc_get_dai_id(ep);
68 if (ret != -ENOTSUPP)
69 return ret;
70
71 /* use endpoint/port reg if exist */
72 ret = of_graph_parse_endpoint(ep, &info);
73 if (ret == 0) {
74 /*
75 * Because it will count port/endpoint if it doesn't have "reg".
76 * But, we can't judge whether it has "no reg", or "reg = <0>"
77 * only of_graph_parse_endpoint().
78 * We need to check "reg" property
79 */
80 if (of_get_property(ep, "reg", NULL))
81 return info.id;
82
83 node = of_get_parent(ep);
84 of_node_put(node);
85 if (of_get_property(node, "reg", NULL))
86 return info.port;
87 }
88 node = of_graph_get_port_parent(ep);
89
90 /*
91 * Non HDMI sound case, counting port/endpoint on its DT
92 * is enough. Let's count it.
93 */
94 i = 0;
95 id = -1;
96 for_each_endpoint_of_node(node, endpoint) {
97 if (endpoint == ep)
98 id = i;
99 i++;
100 }
101
102 of_node_put(node);
103
104 if (id < 0)
105 return -ENODEV;
106
107 return id;
108}
109
110static int asoc_simple_card_parse_dai(struct device_node *ep,
111 struct snd_soc_dai_link_component *dlc,
112 struct device_node **dai_of_node,
113 const char **dai_name,
114 int *is_single_link)
115{
116 struct device_node *node;
117 struct of_phandle_args args;
118 int ret;
119
120 /*
121 * Use snd_soc_dai_link_component instead of legacy style.
122 * It is only for codec, but cpu will be supported in the future.
123 * see
124 * soc-core.c :: snd_soc_init_multicodec()
125 */
126 if (dlc) {
127 dai_name = &dlc->dai_name;
128 dai_of_node = &dlc->of_node;
129 }
130
131 if (!ep)
132 return 0;
133 if (!dai_name)
134 return 0;
135
136 node = of_graph_get_port_parent(ep);
137
138 /* Get dai->name */
139 args.np = node;
140 args.args[0] = graph_get_dai_id(ep);
141 args.args_count = (of_graph_get_endpoint_count(node) > 1);
142
143 ret = snd_soc_get_dai_name(&args, dai_name);
144 if (ret < 0)
145 return ret;
146
147 *dai_of_node = node;
148
149 if (is_single_link)
150 *is_single_link = of_graph_get_endpoint_count(node) == 1;
151
152 return 0;
153}
154
58static void graph_parse_convert(struct device *dev, 155static void graph_parse_convert(struct device *dev,
59 struct device_node *ep, 156 struct device_node *ep,
60 struct asoc_simple_card_data *adata) 157 struct asoc_simple_card_data *adata)
@@ -128,6 +225,7 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
128 of_node_put(node); 225 of_node_put(node);
129 226
130 if (li->cpu) { 227 if (li->cpu) {
228 int is_single_links = 0;
131 229
132 /* BE is dummy */ 230 /* BE is dummy */
133 codecs->of_node = NULL; 231 codecs->of_node = NULL;
@@ -141,7 +239,7 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
141 dai = 239 dai =
142 dai_props->cpu_dai = &priv->dais[li->dais++]; 240 dai_props->cpu_dai = &priv->dais[li->dais++];
143 241
144 ret = asoc_simple_card_parse_graph_cpu(ep, dai_link); 242 ret = asoc_simple_card_parse_cpu(ep, dai_link, &is_single_links);
145 if (ret) 243 if (ret)
146 return ret; 244 return ret;
147 245
@@ -156,8 +254,7 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
156 return ret; 254 return ret;
157 255
158 /* card->num_links includes Codec */ 256 /* card->num_links includes Codec */
159 asoc_simple_card_canonicalize_cpu(dai_link, 257 asoc_simple_card_canonicalize_cpu(dai_link, is_single_links);
160 of_graph_get_endpoint_count(dai_link->cpu_of_node) == 1);
161 } else { 258 } else {
162 struct snd_soc_codec_conf *cconf; 259 struct snd_soc_codec_conf *cconf;
163 260
@@ -176,7 +273,7 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
176 cconf = 273 cconf =
177 dai_props->codec_conf = &priv->codec_conf[li->conf++]; 274 dai_props->codec_conf = &priv->codec_conf[li->conf++];
178 275
179 ret = asoc_simple_card_parse_graph_codec(ep, dai_link); 276 ret = asoc_simple_card_parse_codec(ep, dai_link);
180 if (ret < 0) 277 if (ret < 0)
181 return ret; 278 return ret;
182 279
@@ -234,7 +331,7 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
234 struct device_node *top = dev->of_node; 331 struct device_node *top = dev->of_node;
235 struct asoc_simple_dai *cpu_dai; 332 struct asoc_simple_dai *cpu_dai;
236 struct asoc_simple_dai *codec_dai; 333 struct asoc_simple_dai *codec_dai;
237 int ret; 334 int ret, single_cpu;
238 335
239 /* Do it only CPU turn */ 336 /* Do it only CPU turn */
240 if (!li->cpu) 337 if (!li->cpu)
@@ -258,11 +355,11 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
258 if (ret < 0) 355 if (ret < 0)
259 return ret; 356 return ret;
260 357
261 ret = asoc_simple_card_parse_graph_cpu(cpu_ep, dai_link); 358 ret = asoc_simple_card_parse_cpu(cpu_ep, dai_link, &single_cpu);
262 if (ret < 0) 359 if (ret < 0)
263 return ret; 360 return ret;
264 361
265 ret = asoc_simple_card_parse_graph_codec(codec_ep, dai_link); 362 ret = asoc_simple_card_parse_codec(codec_ep, dai_link);
266 if (ret < 0) 363 if (ret < 0)
267 return ret; 364 return ret;
268 365
@@ -293,8 +390,7 @@ static int graph_dai_link_of(struct asoc_simple_priv *priv,
293 dai_link->init = asoc_simple_dai_init; 390 dai_link->init = asoc_simple_dai_init;
294 391
295 asoc_simple_card_canonicalize_platform(dai_link); 392 asoc_simple_card_canonicalize_platform(dai_link);
296 asoc_simple_card_canonicalize_cpu(dai_link, 393 asoc_simple_card_canonicalize_cpu(dai_link, single_cpu);
297 of_graph_get_endpoint_count(dai_link->cpu_of_node) == 1);
298 394
299 return 0; 395 return 0;
300} 396}
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 697e820bee18..40cefbde6d9b 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -305,149 +305,6 @@ int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
305} 305}
306EXPORT_SYMBOL_GPL(asoc_simple_be_hw_params_fixup); 306EXPORT_SYMBOL_GPL(asoc_simple_be_hw_params_fixup);
307 307
308int asoc_simple_card_parse_dai(struct device_node *node,
309 struct snd_soc_dai_link_component *dlc,
310 struct device_node **dai_of_node,
311 const char **dai_name,
312 const char *list_name,
313 const char *cells_name,
314 int *is_single_link)
315{
316 struct of_phandle_args args;
317 int ret;
318
319 if (!node)
320 return 0;
321
322 /*
323 * Use snd_soc_dai_link_component instead of legacy style.
324 * It is only for codec, but cpu will be supported in the future.
325 * see
326 * soc-core.c :: snd_soc_init_multicodec()
327 */
328 if (dlc) {
329 dai_name = &dlc->dai_name;
330 dai_of_node = &dlc->of_node;
331 }
332
333 /*
334 * Get node via "sound-dai = <&phandle port>"
335 * it will be used as xxx_of_node on soc_bind_dai_link()
336 */
337 ret = of_parse_phandle_with_args(node, list_name, cells_name, 0, &args);
338 if (ret)
339 return ret;
340
341 /* Get dai->name */
342 if (dai_name) {
343 ret = snd_soc_of_get_dai_name(node, dai_name);
344 if (ret < 0)
345 return ret;
346 }
347
348 *dai_of_node = args.np;
349
350 if (is_single_link)
351 *is_single_link = !args.args_count;
352
353 return 0;
354}
355EXPORT_SYMBOL_GPL(asoc_simple_card_parse_dai);
356
357static int asoc_simple_card_get_dai_id(struct device_node *ep)
358{
359 struct device_node *node;
360 struct device_node *endpoint;
361 struct of_endpoint info;
362 int i, id;
363 int ret;
364
365 /* use driver specified DAI ID if exist */
366 ret = snd_soc_get_dai_id(ep);
367 if (ret != -ENOTSUPP)
368 return ret;
369
370 /* use endpoint/port reg if exist */
371 ret = of_graph_parse_endpoint(ep, &info);
372 if (ret == 0) {
373 /*
374 * Because it will count port/endpoint if it doesn't have "reg".
375 * But, we can't judge whether it has "no reg", or "reg = <0>"
376 * only of_graph_parse_endpoint().
377 * We need to check "reg" property
378 */
379 if (of_get_property(ep, "reg", NULL))
380 return info.id;
381
382 node = of_get_parent(ep);
383 of_node_put(node);
384 if (of_get_property(node, "reg", NULL))
385 return info.port;
386 }
387 node = of_graph_get_port_parent(ep);
388
389 /*
390 * Non HDMI sound case, counting port/endpoint on its DT
391 * is enough. Let's count it.
392 */
393 i = 0;
394 id = -1;
395 for_each_endpoint_of_node(node, endpoint) {
396 if (endpoint == ep)
397 id = i;
398 i++;
399 }
400
401 of_node_put(node);
402
403 if (id < 0)
404 return -ENODEV;
405
406 return id;
407}
408
409int asoc_simple_card_parse_graph_dai(struct device_node *ep,
410 struct snd_soc_dai_link_component *dlc,
411 struct device_node **dai_of_node,
412 const char **dai_name)
413{
414 struct device_node *node;
415 struct of_phandle_args args;
416 int ret;
417
418 /*
419 * Use snd_soc_dai_link_component instead of legacy style.
420 * It is only for codec, but cpu will be supported in the future.
421 * see
422 * soc-core.c :: snd_soc_init_multicodec()
423 */
424 if (dlc) {
425 dai_name = &dlc->dai_name;
426 dai_of_node = &dlc->of_node;
427 }
428
429 if (!ep)
430 return 0;
431 if (!dai_name)
432 return 0;
433
434 node = of_graph_get_port_parent(ep);
435
436 /* Get dai->name */
437 args.np = node;
438 args.args[0] = asoc_simple_card_get_dai_id(ep);
439 args.args_count = (of_graph_get_endpoint_count(node) > 1);
440
441 ret = snd_soc_get_dai_name(&args, dai_name);
442 if (ret < 0)
443 return ret;
444
445 *dai_of_node = node;
446
447 return 0;
448}
449EXPORT_SYMBOL_GPL(asoc_simple_card_parse_graph_dai);
450
451static int asoc_simple_card_init_dai(struct snd_soc_dai *dai, 308static int asoc_simple_card_init_dai(struct snd_soc_dai *dai,
452 struct asoc_simple_dai *simple_dai) 309 struct asoc_simple_dai *simple_dai)
453{ 310{
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 4e3e6b34593c..d8560fb1f5de 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -25,6 +25,52 @@ static const struct snd_soc_ops simple_ops = {
25 .hw_params = asoc_simple_hw_params, 25 .hw_params = asoc_simple_hw_params,
26}; 26};
27 27
28static int asoc_simple_card_parse_dai(struct device_node *node,
29 struct snd_soc_dai_link_component *dlc,
30 struct device_node **dai_of_node,
31 const char **dai_name,
32 int *is_single_link)
33{
34 struct of_phandle_args args;
35 int ret;
36
37 if (!node)
38 return 0;
39
40 /*
41 * Use snd_soc_dai_link_component instead of legacy style.
42 * It is only for codec, but cpu will be supported in the future.
43 * see
44 * soc-core.c :: snd_soc_init_multicodec()
45 */
46 if (dlc) {
47 dai_name = &dlc->dai_name;
48 dai_of_node = &dlc->of_node;
49 }
50
51 /*
52 * Get node via "sound-dai = <&phandle port>"
53 * it will be used as xxx_of_node on soc_bind_dai_link()
54 */
55 ret = of_parse_phandle_with_args(node, DAI, CELL, 0, &args);
56 if (ret)
57 return ret;
58
59 /* Get dai->name */
60 if (dai_name) {
61 ret = snd_soc_of_get_dai_name(node, dai_name);
62 if (ret < 0)
63 return ret;
64 }
65
66 *dai_of_node = args.np;
67
68 if (is_single_link)
69 *is_single_link = !args.args_count;
70
71 return 0;
72}
73
28static void simple_parse_convert(struct device *dev, 74static void simple_parse_convert(struct device *dev,
29 struct device_node *np, 75 struct device_node *np,
30 struct asoc_simple_card_data *adata) 76 struct asoc_simple_card_data *adata)
@@ -110,8 +156,7 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
110 dai = 156 dai =
111 dai_props->cpu_dai = &priv->dais[li->dais++]; 157 dai_props->cpu_dai = &priv->dais[li->dais++];
112 158
113 ret = asoc_simple_card_parse_cpu(np, dai_link, DAI, CELL, 159 ret = asoc_simple_card_parse_cpu(np, dai_link, &is_single_links);
114 &is_single_links);
115 if (ret) 160 if (ret)
116 return ret; 161 return ret;
117 162
@@ -144,7 +189,7 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
144 cconf = 189 cconf =
145 dai_props->codec_conf = &priv->codec_conf[li->conf++]; 190 dai_props->codec_conf = &priv->codec_conf[li->conf++];
146 191
147 ret = asoc_simple_card_parse_codec(np, dai_link, DAI, CELL); 192 ret = asoc_simple_card_parse_codec(np, dai_link);
148 if (ret < 0) 193 if (ret < 0)
149 return ret; 194 return ret;
150 195
@@ -242,16 +287,15 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
242 287
243 simple_parse_mclk_fs(top, cpu, codec, dai_props, prefix); 288 simple_parse_mclk_fs(top, cpu, codec, dai_props, prefix);
244 289
245 ret = asoc_simple_card_parse_cpu(cpu, dai_link, 290 ret = asoc_simple_card_parse_cpu(cpu, dai_link, &single_cpu);
246 DAI, CELL, &single_cpu);
247 if (ret < 0) 291 if (ret < 0)
248 goto dai_link_of_err; 292 goto dai_link_of_err;
249 293
250 ret = asoc_simple_card_parse_codec(codec, dai_link, DAI, CELL); 294 ret = asoc_simple_card_parse_codec(codec, dai_link);
251 if (ret < 0) 295 if (ret < 0)
252 goto dai_link_of_err; 296 goto dai_link_of_err;
253 297
254 ret = asoc_simple_card_parse_platform(plat, dai_link, DAI, CELL); 298 ret = asoc_simple_card_parse_platform(plat, dai_link);
255 if (ret < 0) 299 if (ret < 0)
256 goto dai_link_of_err; 300 goto dai_link_of_err;
257 301