44714a12fcd86d2a7a4aa6e80fc6b020f29279e4
[linux-2.6-microblaze.git] / sound / soc / generic / audio-graph-card.c
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // ASoC audio graph sound card support
4 //
5 // Copyright (C) 2016 Renesas Solutions Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 //
8 // based on ${LINUX}/sound/soc/generic/simple-card.c
9
10 #include <linux/clk.h>
11 #include <linux/device.h>
12 #include <linux/gpio.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/module.h>
15 #include <linux/of.h>
16 #include <linux/of_device.h>
17 #include <linux/of_gpio.h>
18 #include <linux/of_graph.h>
19 #include <linux/platform_device.h>
20 #include <linux/string.h>
21 #include <sound/graph_card.h>
22
23 #define DPCM_SELECTABLE 1
24
25 static int graph_outdrv_event(struct snd_soc_dapm_widget *w,
26                               struct snd_kcontrol *kcontrol,
27                               int event)
28 {
29         struct snd_soc_dapm_context *dapm = w->dapm;
30         struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(dapm->card);
31
32         switch (event) {
33         case SND_SOC_DAPM_POST_PMU:
34                 gpiod_set_value_cansleep(priv->pa_gpio, 1);
35                 break;
36         case SND_SOC_DAPM_PRE_PMD:
37                 gpiod_set_value_cansleep(priv->pa_gpio, 0);
38                 break;
39         default:
40                 return -EINVAL;
41         }
42
43         return 0;
44 }
45
46 static const struct snd_soc_dapm_widget graph_dapm_widgets[] = {
47         SND_SOC_DAPM_OUT_DRV_E("Amplifier", SND_SOC_NOPM,
48                                0, 0, NULL, 0, graph_outdrv_event,
49                                SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
50 };
51
52 static const struct snd_soc_ops graph_ops = {
53         .startup        = asoc_simple_startup,
54         .shutdown       = asoc_simple_shutdown,
55         .hw_params      = asoc_simple_hw_params,
56 };
57
58 static 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         const u32 *reg;
65         int ret;
66
67         /* use driver specified DAI ID if exist */
68         ret = snd_soc_get_dai_id(ep);
69         if (ret != -ENOTSUPP)
70                 return ret;
71
72         /* use endpoint/port reg if exist */
73         ret = of_graph_parse_endpoint(ep, &info);
74         if (ret == 0) {
75                 /*
76                  * Because it will count port/endpoint if it doesn't have "reg".
77                  * But, we can't judge whether it has "no reg", or "reg = <0>"
78                  * only of_graph_parse_endpoint().
79                  * We need to check "reg" property
80                  */
81                 if (of_get_property(ep,   "reg", NULL))
82                         return info.id;
83
84                 node = of_get_parent(ep);
85                 reg = of_get_property(node, "reg", NULL);
86                 of_node_put(node);
87                 if (reg)
88                         return info.port;
89         }
90         node = of_graph_get_port_parent(ep);
91
92         /*
93          * Non HDMI sound case, counting port/endpoint on its DT
94          * is enough. Let's count it.
95          */
96         i = 0;
97         id = -1;
98         for_each_endpoint_of_node(node, endpoint) {
99                 if (endpoint == ep)
100                         id = i;
101                 i++;
102         }
103
104         of_node_put(node);
105
106         if (id < 0)
107                 return -ENODEV;
108
109         return id;
110 }
111
112 static bool soc_component_is_pcm(struct snd_soc_dai_link_component *dlc)
113 {
114         struct snd_soc_dai *dai = snd_soc_find_dai_with_mutex(dlc);
115
116         if (dai && (dai->component->driver->pcm_construct ||
117                     dai->driver->pcm_new))
118                 return true;
119
120         return false;
121 }
122
123 static int asoc_simple_parse_dai(struct device_node *ep,
124                                  struct snd_soc_dai_link_component *dlc,
125                                  int *is_single_link)
126 {
127         struct device_node *node;
128         struct of_phandle_args args;
129         int ret;
130
131         if (!ep)
132                 return 0;
133
134         node = of_graph_get_port_parent(ep);
135
136         /* Get dai->name */
137         args.np         = node;
138         args.args[0]    = graph_get_dai_id(ep);
139         args.args_count = (of_graph_get_endpoint_count(node) > 1);
140
141         /*
142          * FIXME
143          *
144          * Here, dlc->dai_name is pointer to CPU/Codec DAI name.
145          * If user unbinded CPU or Codec driver, but not for Sound Card,
146          * dlc->dai_name is keeping unbinded CPU or Codec
147          * driver's pointer.
148          *
149          * If user re-bind CPU or Codec driver again, ALSA SoC will try
150          * to rebind Card via snd_soc_try_rebind_card(), but because of
151          * above reason, it might can't bind Sound Card.
152          * Because Sound Card is pointing to released dai_name pointer.
153          *
154          * To avoid this rebind Card issue,
155          * 1) It needs to alloc memory to keep dai_name eventhough
156          *    CPU or Codec driver was unbinded, or
157          * 2) user need to rebind Sound Card everytime
158          *    if he unbinded CPU or Codec.
159          */
160         ret = snd_soc_get_dai_name(&args, &dlc->dai_name);
161         if (ret < 0)
162                 return ret;
163
164         dlc->of_node = node;
165
166         if (is_single_link)
167                 *is_single_link = of_graph_get_endpoint_count(node) == 1;
168
169         return 0;
170 }
171
172 static void graph_parse_convert(struct device *dev,
173                                 struct device_node *ep,
174                                 struct asoc_simple_data *adata)
175 {
176         struct device_node *top = dev->of_node;
177         struct device_node *port = of_get_parent(ep);
178         struct device_node *ports = of_get_parent(port);
179         struct device_node *node = of_graph_get_port_parent(ep);
180
181         asoc_simple_parse_convert(top,   NULL,   adata);
182         if (of_node_name_eq(ports, "ports"))
183                 asoc_simple_parse_convert(ports, NULL, adata);
184         asoc_simple_parse_convert(port,  NULL,   adata);
185         asoc_simple_parse_convert(ep,    NULL,   adata);
186
187         of_node_put(port);
188         of_node_put(ports);
189         of_node_put(node);
190 }
191
192 static void graph_parse_mclk_fs(struct device_node *top,
193                                 struct device_node *ep,
194                                 struct simple_dai_props *props)
195 {
196         struct device_node *port        = of_get_parent(ep);
197         struct device_node *ports       = of_get_parent(port);
198
199         of_property_read_u32(top,       "mclk-fs", &props->mclk_fs);
200         if (of_node_name_eq(ports, "ports"))
201                 of_property_read_u32(ports, "mclk-fs", &props->mclk_fs);
202         of_property_read_u32(port,      "mclk-fs", &props->mclk_fs);
203         of_property_read_u32(ep,        "mclk-fs", &props->mclk_fs);
204
205         of_node_put(port);
206         of_node_put(ports);
207 }
208
209 static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
210                                   struct device_node *cpu_ep,
211                                   struct device_node *codec_ep,
212                                   struct link_info *li)
213 {
214         struct device *dev = simple_priv_to_dev(priv);
215         struct snd_soc_card *card = simple_priv_to_card(priv);
216         struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
217         struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
218         struct device_node *top = dev->of_node;
219         struct device_node *ep = li->cpu ? cpu_ep : codec_ep;
220         struct device_node *port;
221         struct device_node *ports;
222         struct device_node *node;
223         struct asoc_simple_dai *dai;
224         struct snd_soc_dai_link_component *cpus = asoc_link_to_cpu(dai_link, 0);
225         struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, 0);
226         int ret;
227
228         port    = of_get_parent(ep);
229         ports   = of_get_parent(port);
230         node    = of_graph_get_port_parent(ep);
231
232         li->link++;
233
234         dev_dbg(dev, "link_of DPCM (%pOF)\n", ep);
235
236         if (li->cpu) {
237                 int is_single_links = 0;
238
239                 /* Codec is dummy */
240
241                 /* FE settings */
242                 dai_link->dynamic               = 1;
243                 dai_link->dpcm_merged_format    = 1;
244
245                 dai = simple_props_to_dai_cpu(dai_props, 0);
246
247                 ret = asoc_simple_parse_dai(ep, cpus, &is_single_links);
248                 if (ret)
249                         goto out_put_node;
250
251                 ret = asoc_simple_parse_clk(dev, ep, dai, cpus);
252                 if (ret < 0)
253                         goto out_put_node;
254
255                 ret = asoc_simple_set_dailink_name(dev, dai_link,
256                                                    "fe.%pOFP.%s",
257                                                    cpus->of_node,
258                                                    cpus->dai_name);
259                 if (ret < 0)
260                         goto out_put_node;
261
262                 /*
263                  * In BE<->BE connections it is not required to create
264                  * PCM devices at CPU end of the dai link and thus 'no_pcm'
265                  * flag needs to be set. It is useful when there are many
266                  * BE components and some of these have to be connected to
267                  * form a valid audio path.
268                  *
269                  * For example: FE <-> BE1 <-> BE2 <-> ... <-> BEn where
270                  * there are 'n' BE components in the path.
271                  */
272                 if (card->component_chaining && !soc_component_is_pcm(cpus))
273                         dai_link->no_pcm = 1;
274
275                 /* card->num_links includes Codec */
276                 asoc_simple_canonicalize_cpu(cpus, is_single_links);
277         } else {
278                 struct snd_soc_codec_conf *cconf;
279
280                 /* CPU is dummy */
281
282                 /* BE settings */
283                 dai_link->no_pcm                = 1;
284                 dai_link->be_hw_params_fixup    = asoc_simple_be_hw_params_fixup;
285
286                 dai     = simple_props_to_dai_codec(dai_props, 0);
287                 cconf   = simple_props_to_codec_conf(dai_props, 0);
288
289                 ret = asoc_simple_parse_dai(ep, codecs, NULL);
290                 if (ret < 0)
291                         goto out_put_node;
292
293                 ret = asoc_simple_parse_clk(dev, ep, dai, codecs);
294                 if (ret < 0)
295                         goto out_put_node;
296
297                 ret = asoc_simple_set_dailink_name(dev, dai_link,
298                                                    "be.%pOFP.%s",
299                                                    codecs->of_node,
300                                                    codecs->dai_name);
301                 if (ret < 0)
302                         goto out_put_node;
303
304                 /* check "prefix" from top node */
305                 snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node,
306                                               "prefix");
307                 if (of_node_name_eq(ports, "ports"))
308                         snd_soc_of_parse_node_prefix(ports, cconf, codecs->of_node, "prefix");
309                 snd_soc_of_parse_node_prefix(port, cconf, codecs->of_node,
310                                              "prefix");
311         }
312
313         graph_parse_convert(dev, ep, &dai_props->adata);
314         graph_parse_mclk_fs(top, ep, dai_props);
315
316         ret = asoc_simple_parse_tdm(ep, dai);
317         if (ret)
318                 goto out_put_node;
319
320         ret = asoc_simple_parse_daifmt(dev, cpu_ep, codec_ep,
321                                        NULL, &dai_link->dai_fmt);
322         if (ret < 0)
323                 goto out_put_node;
324
325         snd_soc_dai_link_set_capabilities(dai_link);
326
327         dai_link->ops                   = &graph_ops;
328
329         /* Use custom snd_soc_ops callbacks if available */
330         if (priv->ops)
331                 dai_link->ops = priv->ops;
332
333         dai_link->init                  = asoc_simple_dai_init;
334
335 out_put_node:
336         of_node_put(ports);
337         of_node_put(port);
338         of_node_put(node);
339         return ret;
340 }
341
342 static int graph_dai_link_of(struct asoc_simple_priv *priv,
343                              struct device_node *cpu_ep,
344                              struct device_node *codec_ep,
345                              struct link_info *li)
346 {
347         struct device *dev = simple_priv_to_dev(priv);
348         struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
349         struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
350         struct device_node *top = dev->of_node;
351         struct asoc_simple_dai *cpu_dai = simple_props_to_dai_cpu(dai_props, 0);
352         struct asoc_simple_dai *codec_dai = simple_props_to_dai_codec(dai_props, 0);
353         struct snd_soc_dai_link_component *cpus = asoc_link_to_cpu(dai_link, 0);
354         struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, 0);
355         int ret, single_cpu = 0;
356
357         dev_dbg(dev, "link_of (%pOF)\n", cpu_ep);
358
359         li->link++;
360
361         /* Factor to mclk, used in hw_params() */
362         graph_parse_mclk_fs(top, cpu_ep,   dai_props);
363         graph_parse_mclk_fs(top, codec_ep, dai_props);
364
365         ret = asoc_simple_parse_daifmt(dev, cpu_ep, codec_ep,
366                                        NULL, &dai_link->dai_fmt);
367         if (ret < 0)
368                 return ret;
369
370         ret = asoc_simple_parse_dai(cpu_ep, cpus, &single_cpu);
371         if (ret < 0)
372                 return ret;
373
374         ret = asoc_simple_parse_dai(codec_ep, codecs, NULL);
375         if (ret < 0)
376                 return ret;
377
378         ret = asoc_simple_parse_tdm(cpu_ep, cpu_dai);
379         if (ret < 0)
380                 return ret;
381
382         ret = asoc_simple_parse_tdm(codec_ep, codec_dai);
383         if (ret < 0)
384                 return ret;
385
386         ret = asoc_simple_parse_clk(dev, cpu_ep, cpu_dai, cpus);
387         if (ret < 0)
388                 return ret;
389
390         ret = asoc_simple_parse_clk(dev, codec_ep, codec_dai, codecs);
391         if (ret < 0)
392                 return ret;
393
394         ret = asoc_simple_set_dailink_name(dev, dai_link,
395                                            "%s-%s",
396                                            cpus->dai_name,
397                                            codecs->dai_name);
398         if (ret < 0)
399                 return ret;
400
401         dai_link->ops = &graph_ops;
402         dai_link->init = asoc_simple_dai_init;
403
404         asoc_simple_canonicalize_cpu(cpus, single_cpu);
405
406         return 0;
407 }
408
409 static inline bool parse_as_dpcm_link(struct asoc_simple_priv *priv,
410                                       struct device_node *codec_port,
411                                       struct asoc_simple_data *adata)
412 {
413         if (priv->force_dpcm)
414                 return true;
415
416         if (!priv->dpcm_selectable)
417                 return false;
418
419         /*
420          * It is DPCM
421          * if Codec port has many endpoints,
422          * or has convert-xxx property
423          */
424         if ((of_get_child_count(codec_port) > 1) ||
425             (adata->convert_rate || adata->convert_channels))
426                 return true;
427
428         return false;
429 }
430
431 static int __graph_for_each_link(struct asoc_simple_priv *priv,
432                         struct link_info *li,
433                         int (*func_noml)(struct asoc_simple_priv *priv,
434                                          struct device_node *cpu_ep,
435                                          struct device_node *codec_ep,
436                                          struct link_info *li),
437                         int (*func_dpcm)(struct asoc_simple_priv *priv,
438                                          struct device_node *cpu_ep,
439                                          struct device_node *codec_ep,
440                                          struct link_info *li))
441 {
442         struct of_phandle_iterator it;
443         struct device *dev = simple_priv_to_dev(priv);
444         struct device_node *node = dev->of_node;
445         struct device_node *cpu_port;
446         struct device_node *cpu_ep;
447         struct device_node *codec_ep;
448         struct device_node *codec_port;
449         struct device_node *codec_port_old = NULL;
450         struct asoc_simple_data adata;
451         int rc, ret = 0;
452
453         /* loop for all listed CPU port */
454         of_for_each_phandle(&it, rc, node, "dais", NULL, 0) {
455                 cpu_port = it.node;
456                 cpu_ep   = NULL;
457
458                 /* loop for all CPU endpoint */
459                 while (1) {
460                         cpu_ep = of_get_next_child(cpu_port, cpu_ep);
461                         if (!cpu_ep)
462                                 break;
463
464                         /* get codec */
465                         codec_ep = of_graph_get_remote_endpoint(cpu_ep);
466                         codec_port = of_get_parent(codec_ep);
467
468                         /* get convert-xxx property */
469                         memset(&adata, 0, sizeof(adata));
470                         graph_parse_convert(dev, codec_ep, &adata);
471                         graph_parse_convert(dev, cpu_ep,   &adata);
472
473                         /* check if link requires DPCM parsing */
474                         if (parse_as_dpcm_link(priv, codec_port, &adata)) {
475                                 /*
476                                  * Codec endpoint can be NULL for pluggable audio HW.
477                                  * Platform DT can populate the Codec endpoint depending on the
478                                  * plugged HW.
479                                  */
480                                 /* Do it all CPU endpoint, and 1st Codec endpoint */
481                                 if (li->cpu ||
482                                     ((codec_port_old != codec_port) && codec_ep))
483                                         ret = func_dpcm(priv, cpu_ep, codec_ep, li);
484                         /* else normal sound */
485                         } else {
486                                 if (li->cpu)
487                                         ret = func_noml(priv, cpu_ep, codec_ep, li);
488                         }
489
490                         of_node_put(codec_ep);
491                         of_node_put(codec_port);
492
493                         if (ret < 0)
494                                 return ret;
495
496                         codec_port_old = codec_port;
497                 }
498         }
499
500         return 0;
501 }
502
503 static int graph_for_each_link(struct asoc_simple_priv *priv,
504                                struct link_info *li,
505                                int (*func_noml)(struct asoc_simple_priv *priv,
506                                                 struct device_node *cpu_ep,
507                                                 struct device_node *codec_ep,
508                                                 struct link_info *li),
509                                int (*func_dpcm)(struct asoc_simple_priv *priv,
510                                                 struct device_node *cpu_ep,
511                                                 struct device_node *codec_ep,
512                                                 struct link_info *li))
513 {
514         int ret;
515         /*
516          * Detect all CPU first, and Detect all Codec 2nd.
517          *
518          * In Normal sound case, all DAIs are detected
519          * as "CPU-Codec".
520          *
521          * In DPCM sound case,
522          * all CPUs   are detected as "CPU-dummy", and
523          * all Codecs are detected as "dummy-Codec".
524          * To avoid random sub-device numbering,
525          * detect "dummy-Codec" in last;
526          */
527         for (li->cpu = 1; li->cpu >= 0; li->cpu--) {
528                 ret = __graph_for_each_link(priv, li, func_noml, func_dpcm);
529                 if (ret < 0)
530                         break;
531         }
532
533         return ret;
534 }
535
536 static int graph_get_dais_count(struct asoc_simple_priv *priv,
537                                 struct link_info *li);
538
539 int audio_graph_parse_of(struct asoc_simple_priv *priv, struct device *dev)
540 {
541         struct snd_soc_card *card = simple_priv_to_card(priv);
542         struct link_info *li;
543         int ret;
544
545         li = devm_kzalloc(dev, sizeof(*li), GFP_KERNEL);
546         if (!li)
547                 return -ENOMEM;
548
549         card->owner = THIS_MODULE;
550         card->dev = dev;
551
552         ret = graph_get_dais_count(priv, li);
553         if (ret < 0)
554                 return ret;
555
556         if (!li->link)
557                 return -EINVAL;
558
559         ret = asoc_simple_init_priv(priv, li);
560         if (ret < 0)
561                 return ret;
562
563         priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW);
564         if (IS_ERR(priv->pa_gpio)) {
565                 ret = PTR_ERR(priv->pa_gpio);
566                 dev_err(dev, "failed to get amplifier gpio: %d\n", ret);
567                 return ret;
568         }
569
570         ret = asoc_simple_parse_widgets(card, NULL);
571         if (ret < 0)
572                 return ret;
573
574         ret = asoc_simple_parse_routing(card, NULL);
575         if (ret < 0)
576                 return ret;
577
578         memset(li, 0, sizeof(*li));
579         ret = graph_for_each_link(priv, li,
580                                   graph_dai_link_of,
581                                   graph_dai_link_of_dpcm);
582         if (ret < 0)
583                 goto err;
584
585         ret = asoc_simple_parse_card_name(card, NULL);
586         if (ret < 0)
587                 goto err;
588
589         snd_soc_card_set_drvdata(card, priv);
590
591         asoc_simple_debug_info(priv);
592
593         ret = devm_snd_soc_register_card(dev, card);
594         if (ret < 0)
595                 goto err;
596
597         devm_kfree(dev, li);
598         return 0;
599
600 err:
601         asoc_simple_clean_reference(card);
602
603         if (ret != -EPROBE_DEFER)
604                 dev_err(dev, "parse error %d\n", ret);
605
606         return ret;
607 }
608 EXPORT_SYMBOL_GPL(audio_graph_parse_of);
609
610 static int graph_count_noml(struct asoc_simple_priv *priv,
611                             struct device_node *cpu_ep,
612                             struct device_node *codec_ep,
613                             struct link_info *li)
614 {
615         struct device *dev = simple_priv_to_dev(priv);
616
617         if (li->link >= SNDRV_MAX_LINKS) {
618                 dev_err(dev, "too many links\n");
619                 return -EINVAL;
620         }
621
622         li->num[li->link].cpus          = 1;
623         li->num[li->link].codecs        = 1;
624
625         li->link += 1; /* 1xCPU-Codec */
626
627         dev_dbg(dev, "Count As Normal\n");
628
629         return 0;
630 }
631
632 static int graph_count_dpcm(struct asoc_simple_priv *priv,
633                             struct device_node *cpu_ep,
634                             struct device_node *codec_ep,
635                             struct link_info *li)
636 {
637         struct device *dev = simple_priv_to_dev(priv);
638
639         if (li->link >= SNDRV_MAX_LINKS) {
640                 dev_err(dev, "too many links\n");
641                 return -EINVAL;
642         }
643
644         if (li->cpu) {
645                 li->num[li->link].cpus          = 1;
646
647                 li->link++; /* 1xCPU-dummy */
648         } else {
649                 li->num[li->link].codecs        = 1;
650
651                 li->link++; /* 1xdummy-Codec */
652         }
653
654         dev_dbg(dev, "Count As DPCM\n");
655
656         return 0;
657 }
658
659 static int graph_get_dais_count(struct asoc_simple_priv *priv,
660                                 struct link_info *li)
661 {
662         /*
663          * link_num :   number of links.
664          *              CPU-Codec / CPU-dummy / dummy-Codec
665          * dais_num :   number of DAIs
666          * ccnf_num :   number of codec_conf
667          *              same number for "dummy-Codec"
668          *
669          * ex1)
670          * CPU0 --- Codec0      link : 5
671          * CPU1 --- Codec1      dais : 7
672          * CPU2 -/              ccnf : 1
673          * CPU3 --- Codec2
674          *
675          *      => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec
676          *      => 7 DAIs  = 4xCPU + 3xCodec
677          *      => 1 ccnf  = 1xdummy-Codec
678          *
679          * ex2)
680          * CPU0 --- Codec0      link : 5
681          * CPU1 --- Codec1      dais : 6
682          * CPU2 -/              ccnf : 1
683          * CPU3 -/
684          *
685          *      => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec
686          *      => 6 DAIs  = 4xCPU + 2xCodec
687          *      => 1 ccnf  = 1xdummy-Codec
688          *
689          * ex3)
690          * CPU0 --- Codec0      link : 6
691          * CPU1 -/              dais : 6
692          * CPU2 --- Codec1      ccnf : 2
693          * CPU3 -/
694          *
695          *      => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec
696          *      => 6 DAIs  = 4xCPU + 2xCodec
697          *      => 2 ccnf  = 2xdummy-Codec
698          *
699          * ex4)
700          * CPU0 --- Codec0 (convert-rate)       link : 3
701          * CPU1 --- Codec1                      dais : 4
702          *                                      ccnf : 1
703          *
704          *      => 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec
705          *      => 4 DAIs  = 2xCPU + 2xCodec
706          *      => 1 ccnf  = 1xdummy-Codec
707          */
708         return graph_for_each_link(priv, li,
709                                    graph_count_noml,
710                                    graph_count_dpcm);
711 }
712
713 static int graph_probe(struct platform_device *pdev)
714 {
715         struct asoc_simple_priv *priv;
716         struct device *dev = &pdev->dev;
717         struct snd_soc_card *card;
718
719         /* Allocate the private data and the DAI link array */
720         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
721         if (!priv)
722                 return -ENOMEM;
723
724         card = simple_priv_to_card(priv);
725         card->dapm_widgets      = graph_dapm_widgets;
726         card->num_dapm_widgets  = ARRAY_SIZE(graph_dapm_widgets);
727         card->probe             = asoc_graph_card_probe;
728
729         if (of_device_get_match_data(dev))
730                 priv->dpcm_selectable = 1;
731
732         return audio_graph_parse_of(priv, dev);
733 }
734
735 static const struct of_device_id graph_of_match[] = {
736         { .compatible = "audio-graph-card", },
737         { .compatible = "audio-graph-scu-card",
738           .data = (void *)DPCM_SELECTABLE },
739         {},
740 };
741 MODULE_DEVICE_TABLE(of, graph_of_match);
742
743 static struct platform_driver graph_card = {
744         .driver = {
745                 .name = "asoc-audio-graph-card",
746                 .pm = &snd_soc_pm_ops,
747                 .of_match_table = graph_of_match,
748         },
749         .probe = graph_probe,
750         .remove = asoc_simple_remove,
751 };
752 module_platform_driver(graph_card);
753
754 MODULE_ALIAS("platform:asoc-audio-graph-card");
755 MODULE_LICENSE("GPL v2");
756 MODULE_DESCRIPTION("ASoC Audio Graph Sound Card");
757 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");