Merge existing fixes from spi/for-5.13
[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_parse_node(struct asoc_simple_priv *priv,
210                             struct device_node *ep,
211                             struct link_info *li,
212                             int is_cpu)
213 {
214         struct device *dev = simple_priv_to_dev(priv);
215         struct device_node *top = dev->of_node;
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 snd_soc_dai_link_component *dlc;
219         struct asoc_simple_dai *dai;
220         int ret, single = 0;
221
222         if (is_cpu) {
223                 dlc = asoc_link_to_cpu(dai_link, 0);
224                 dai = simple_props_to_dai_cpu(dai_props, 0);
225         } else {
226                 dlc = asoc_link_to_codec(dai_link, 0);
227                 dai = simple_props_to_dai_codec(dai_props, 0);
228         }
229
230         graph_parse_mclk_fs(top, ep, dai_props);
231
232         ret = asoc_simple_parse_dai(ep, dlc, &single);
233         if (ret < 0)
234                 return ret;
235
236         ret = asoc_simple_parse_tdm(ep, dai);
237         if (ret < 0)
238                 return ret;
239
240         ret = asoc_simple_parse_clk(dev, ep, dai, dlc);
241         if (ret < 0)
242                 return ret;
243
244         if (is_cpu)
245                 asoc_simple_canonicalize_cpu(dlc, single);
246
247         return 0;
248 }
249
250 static int graph_link_init(struct asoc_simple_priv *priv,
251                            struct device_node *cpu_ep,
252                            struct device_node *codec_ep,
253                            struct link_info *li,
254                            char *name)
255 {
256         struct device *dev = simple_priv_to_dev(priv);
257         struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
258         int ret;
259
260         ret = asoc_simple_parse_daifmt(dev, cpu_ep, codec_ep,
261                                        NULL, &dai_link->dai_fmt);
262         if (ret < 0)
263                 return ret;
264
265         dai_link->init          = asoc_simple_dai_init;
266         dai_link->ops           = &graph_ops;
267         if (priv->ops)
268                 dai_link->ops   = priv->ops;
269
270         return asoc_simple_set_dailink_name(dev, dai_link, name);
271 }
272
273 static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
274                                   struct device_node *cpu_ep,
275                                   struct device_node *codec_ep,
276                                   struct link_info *li)
277 {
278         struct device *dev = simple_priv_to_dev(priv);
279         struct snd_soc_card *card = simple_priv_to_card(priv);
280         struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
281         struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
282         struct device_node *top = dev->of_node;
283         struct device_node *ep = li->cpu ? cpu_ep : codec_ep;
284         struct device_node *port;
285         struct device_node *ports;
286         struct snd_soc_dai_link_component *cpus = asoc_link_to_cpu(dai_link, 0);
287         struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, 0);
288         char dai_name[64];
289         int ret;
290
291         port    = of_get_parent(ep);
292         ports   = of_get_parent(port);
293
294         dev_dbg(dev, "link_of DPCM (%pOF)\n", ep);
295
296         if (li->cpu) {
297                 /* Codec is dummy */
298
299                 /* FE settings */
300                 dai_link->dynamic               = 1;
301                 dai_link->dpcm_merged_format    = 1;
302
303                 ret = graph_parse_node(priv, cpu_ep, li, 1);
304                 if (ret)
305                         goto out_put_node;
306
307                 snprintf(dai_name, sizeof(dai_name),
308                          "fe.%pOFP.%s", cpus->of_node, cpus->dai_name);
309                 /*
310                  * In BE<->BE connections it is not required to create
311                  * PCM devices at CPU end of the dai link and thus 'no_pcm'
312                  * flag needs to be set. It is useful when there are many
313                  * BE components and some of these have to be connected to
314                  * form a valid audio path.
315                  *
316                  * For example: FE <-> BE1 <-> BE2 <-> ... <-> BEn where
317                  * there are 'n' BE components in the path.
318                  */
319                 if (card->component_chaining && !soc_component_is_pcm(cpus))
320                         dai_link->no_pcm = 1;
321         } else {
322                 struct snd_soc_codec_conf *cconf;
323
324                 /* CPU is dummy */
325
326                 /* BE settings */
327                 dai_link->no_pcm                = 1;
328                 dai_link->be_hw_params_fixup    = asoc_simple_be_hw_params_fixup;
329
330                 cconf   = simple_props_to_codec_conf(dai_props, 0);
331
332                 ret = graph_parse_node(priv, codec_ep, li, 0);
333                 if (ret < 0)
334                         goto out_put_node;
335
336                 snprintf(dai_name, sizeof(dai_name),
337                          "be.%pOFP.%s", codecs->of_node, codecs->dai_name);
338
339                 /* check "prefix" from top node */
340                 snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node,
341                                               "prefix");
342                 if (of_node_name_eq(ports, "ports"))
343                         snd_soc_of_parse_node_prefix(ports, cconf, codecs->of_node, "prefix");
344                 snd_soc_of_parse_node_prefix(port, cconf, codecs->of_node,
345                                              "prefix");
346         }
347
348         graph_parse_convert(dev, ep, &dai_props->adata);
349
350         snd_soc_dai_link_set_capabilities(dai_link);
351
352         ret = graph_link_init(priv, cpu_ep, codec_ep, li, dai_name);
353
354 out_put_node:
355         li->link++;
356
357         of_node_put(ports);
358         of_node_put(port);
359         return ret;
360 }
361
362 static int graph_dai_link_of(struct asoc_simple_priv *priv,
363                              struct device_node *cpu_ep,
364                              struct device_node *codec_ep,
365                              struct link_info *li)
366 {
367         struct device *dev = simple_priv_to_dev(priv);
368         struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
369         struct snd_soc_dai_link_component *cpus = asoc_link_to_cpu(dai_link, 0);
370         struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, 0);
371         char dai_name[64];
372         int ret;
373
374         dev_dbg(dev, "link_of (%pOF)\n", cpu_ep);
375
376         ret = graph_parse_node(priv, cpu_ep, li, 1);
377         if (ret < 0)
378                 return ret;
379
380         ret = graph_parse_node(priv, codec_ep, li, 0);
381         if (ret < 0)
382                 return ret;
383
384         snprintf(dai_name, sizeof(dai_name),
385                  "%s-%s", cpus->dai_name, codecs->dai_name);
386         ret = graph_link_init(priv, cpu_ep, codec_ep, li, dai_name);
387         if (ret < 0)
388                 return ret;
389
390         li->link++;
391
392         return 0;
393 }
394
395 static inline bool parse_as_dpcm_link(struct asoc_simple_priv *priv,
396                                       struct device_node *codec_port,
397                                       struct asoc_simple_data *adata)
398 {
399         if (priv->force_dpcm)
400                 return true;
401
402         if (!priv->dpcm_selectable)
403                 return false;
404
405         /*
406          * It is DPCM
407          * if Codec port has many endpoints,
408          * or has convert-xxx property
409          */
410         if ((of_get_child_count(codec_port) > 1) ||
411             (adata->convert_rate || adata->convert_channels))
412                 return true;
413
414         return false;
415 }
416
417 static int __graph_for_each_link(struct asoc_simple_priv *priv,
418                         struct link_info *li,
419                         int (*func_noml)(struct asoc_simple_priv *priv,
420                                          struct device_node *cpu_ep,
421                                          struct device_node *codec_ep,
422                                          struct link_info *li),
423                         int (*func_dpcm)(struct asoc_simple_priv *priv,
424                                          struct device_node *cpu_ep,
425                                          struct device_node *codec_ep,
426                                          struct link_info *li))
427 {
428         struct of_phandle_iterator it;
429         struct device *dev = simple_priv_to_dev(priv);
430         struct device_node *node = dev->of_node;
431         struct device_node *cpu_port;
432         struct device_node *cpu_ep;
433         struct device_node *codec_ep;
434         struct device_node *codec_port;
435         struct device_node *codec_port_old = NULL;
436         struct asoc_simple_data adata;
437         int rc, ret = 0;
438
439         /* loop for all listed CPU port */
440         of_for_each_phandle(&it, rc, node, "dais", NULL, 0) {
441                 cpu_port = it.node;
442                 cpu_ep   = NULL;
443
444                 /* loop for all CPU endpoint */
445                 while (1) {
446                         cpu_ep = of_get_next_child(cpu_port, cpu_ep);
447                         if (!cpu_ep)
448                                 break;
449
450                         /* get codec */
451                         codec_ep = of_graph_get_remote_endpoint(cpu_ep);
452                         codec_port = of_get_parent(codec_ep);
453
454                         /* get convert-xxx property */
455                         memset(&adata, 0, sizeof(adata));
456                         graph_parse_convert(dev, codec_ep, &adata);
457                         graph_parse_convert(dev, cpu_ep,   &adata);
458
459                         /* check if link requires DPCM parsing */
460                         if (parse_as_dpcm_link(priv, codec_port, &adata)) {
461                                 /*
462                                  * Codec endpoint can be NULL for pluggable audio HW.
463                                  * Platform DT can populate the Codec endpoint depending on the
464                                  * plugged HW.
465                                  */
466                                 /* Do it all CPU endpoint, and 1st Codec endpoint */
467                                 if (li->cpu ||
468                                     ((codec_port_old != codec_port) && codec_ep))
469                                         ret = func_dpcm(priv, cpu_ep, codec_ep, li);
470                         /* else normal sound */
471                         } else {
472                                 if (li->cpu)
473                                         ret = func_noml(priv, cpu_ep, codec_ep, li);
474                         }
475
476                         of_node_put(codec_ep);
477                         of_node_put(codec_port);
478
479                         if (ret < 0)
480                                 return ret;
481
482                         codec_port_old = codec_port;
483                 }
484         }
485
486         return 0;
487 }
488
489 static int graph_for_each_link(struct asoc_simple_priv *priv,
490                                struct link_info *li,
491                                int (*func_noml)(struct asoc_simple_priv *priv,
492                                                 struct device_node *cpu_ep,
493                                                 struct device_node *codec_ep,
494                                                 struct link_info *li),
495                                int (*func_dpcm)(struct asoc_simple_priv *priv,
496                                                 struct device_node *cpu_ep,
497                                                 struct device_node *codec_ep,
498                                                 struct link_info *li))
499 {
500         int ret;
501         /*
502          * Detect all CPU first, and Detect all Codec 2nd.
503          *
504          * In Normal sound case, all DAIs are detected
505          * as "CPU-Codec".
506          *
507          * In DPCM sound case,
508          * all CPUs   are detected as "CPU-dummy", and
509          * all Codecs are detected as "dummy-Codec".
510          * To avoid random sub-device numbering,
511          * detect "dummy-Codec" in last;
512          */
513         for (li->cpu = 1; li->cpu >= 0; li->cpu--) {
514                 ret = __graph_for_each_link(priv, li, func_noml, func_dpcm);
515                 if (ret < 0)
516                         break;
517         }
518
519         return ret;
520 }
521
522 static int graph_get_dais_count(struct asoc_simple_priv *priv,
523                                 struct link_info *li);
524
525 int audio_graph_parse_of(struct asoc_simple_priv *priv, struct device *dev)
526 {
527         struct snd_soc_card *card = simple_priv_to_card(priv);
528         struct link_info *li;
529         int ret;
530
531         li = devm_kzalloc(dev, sizeof(*li), GFP_KERNEL);
532         if (!li)
533                 return -ENOMEM;
534
535         card->owner = THIS_MODULE;
536         card->dev = dev;
537
538         ret = graph_get_dais_count(priv, li);
539         if (ret < 0)
540                 return ret;
541
542         if (!li->link)
543                 return -EINVAL;
544
545         ret = asoc_simple_init_priv(priv, li);
546         if (ret < 0)
547                 return ret;
548
549         priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW);
550         if (IS_ERR(priv->pa_gpio)) {
551                 ret = PTR_ERR(priv->pa_gpio);
552                 dev_err(dev, "failed to get amplifier gpio: %d\n", ret);
553                 return ret;
554         }
555
556         ret = asoc_simple_parse_widgets(card, NULL);
557         if (ret < 0)
558                 return ret;
559
560         ret = asoc_simple_parse_routing(card, NULL);
561         if (ret < 0)
562                 return ret;
563
564         memset(li, 0, sizeof(*li));
565         ret = graph_for_each_link(priv, li,
566                                   graph_dai_link_of,
567                                   graph_dai_link_of_dpcm);
568         if (ret < 0)
569                 goto err;
570
571         ret = asoc_simple_parse_card_name(card, NULL);
572         if (ret < 0)
573                 goto err;
574
575         snd_soc_card_set_drvdata(card, priv);
576
577         asoc_simple_debug_info(priv);
578
579         ret = devm_snd_soc_register_card(dev, card);
580         if (ret < 0)
581                 goto err;
582
583         devm_kfree(dev, li);
584         return 0;
585
586 err:
587         asoc_simple_clean_reference(card);
588
589         if (ret != -EPROBE_DEFER)
590                 dev_err(dev, "parse error %d\n", ret);
591
592         return ret;
593 }
594 EXPORT_SYMBOL_GPL(audio_graph_parse_of);
595
596 static int graph_count_noml(struct asoc_simple_priv *priv,
597                             struct device_node *cpu_ep,
598                             struct device_node *codec_ep,
599                             struct link_info *li)
600 {
601         struct device *dev = simple_priv_to_dev(priv);
602
603         if (li->link >= SNDRV_MAX_LINKS) {
604                 dev_err(dev, "too many links\n");
605                 return -EINVAL;
606         }
607
608         li->num[li->link].cpus          = 1;
609         li->num[li->link].codecs        = 1;
610
611         li->link += 1; /* 1xCPU-Codec */
612
613         dev_dbg(dev, "Count As Normal\n");
614
615         return 0;
616 }
617
618 static int graph_count_dpcm(struct asoc_simple_priv *priv,
619                             struct device_node *cpu_ep,
620                             struct device_node *codec_ep,
621                             struct link_info *li)
622 {
623         struct device *dev = simple_priv_to_dev(priv);
624
625         if (li->link >= SNDRV_MAX_LINKS) {
626                 dev_err(dev, "too many links\n");
627                 return -EINVAL;
628         }
629
630         if (li->cpu) {
631                 li->num[li->link].cpus          = 1;
632
633                 li->link++; /* 1xCPU-dummy */
634         } else {
635                 li->num[li->link].codecs        = 1;
636
637                 li->link++; /* 1xdummy-Codec */
638         }
639
640         dev_dbg(dev, "Count As DPCM\n");
641
642         return 0;
643 }
644
645 static int graph_get_dais_count(struct asoc_simple_priv *priv,
646                                 struct link_info *li)
647 {
648         /*
649          * link_num :   number of links.
650          *              CPU-Codec / CPU-dummy / dummy-Codec
651          * dais_num :   number of DAIs
652          * ccnf_num :   number of codec_conf
653          *              same number for "dummy-Codec"
654          *
655          * ex1)
656          * CPU0 --- Codec0      link : 5
657          * CPU1 --- Codec1      dais : 7
658          * CPU2 -/              ccnf : 1
659          * CPU3 --- Codec2
660          *
661          *      => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec
662          *      => 7 DAIs  = 4xCPU + 3xCodec
663          *      => 1 ccnf  = 1xdummy-Codec
664          *
665          * ex2)
666          * CPU0 --- Codec0      link : 5
667          * CPU1 --- Codec1      dais : 6
668          * CPU2 -/              ccnf : 1
669          * CPU3 -/
670          *
671          *      => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec
672          *      => 6 DAIs  = 4xCPU + 2xCodec
673          *      => 1 ccnf  = 1xdummy-Codec
674          *
675          * ex3)
676          * CPU0 --- Codec0      link : 6
677          * CPU1 -/              dais : 6
678          * CPU2 --- Codec1      ccnf : 2
679          * CPU3 -/
680          *
681          *      => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec
682          *      => 6 DAIs  = 4xCPU + 2xCodec
683          *      => 2 ccnf  = 2xdummy-Codec
684          *
685          * ex4)
686          * CPU0 --- Codec0 (convert-rate)       link : 3
687          * CPU1 --- Codec1                      dais : 4
688          *                                      ccnf : 1
689          *
690          *      => 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec
691          *      => 4 DAIs  = 2xCPU + 2xCodec
692          *      => 1 ccnf  = 1xdummy-Codec
693          */
694         return graph_for_each_link(priv, li,
695                                    graph_count_noml,
696                                    graph_count_dpcm);
697 }
698
699 static int graph_probe(struct platform_device *pdev)
700 {
701         struct asoc_simple_priv *priv;
702         struct device *dev = &pdev->dev;
703         struct snd_soc_card *card;
704
705         /* Allocate the private data and the DAI link array */
706         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
707         if (!priv)
708                 return -ENOMEM;
709
710         card = simple_priv_to_card(priv);
711         card->dapm_widgets      = graph_dapm_widgets;
712         card->num_dapm_widgets  = ARRAY_SIZE(graph_dapm_widgets);
713         card->probe             = asoc_graph_card_probe;
714
715         if (of_device_get_match_data(dev))
716                 priv->dpcm_selectable = 1;
717
718         return audio_graph_parse_of(priv, dev);
719 }
720
721 static const struct of_device_id graph_of_match[] = {
722         { .compatible = "audio-graph-card", },
723         { .compatible = "audio-graph-scu-card",
724           .data = (void *)DPCM_SELECTABLE },
725         {},
726 };
727 MODULE_DEVICE_TABLE(of, graph_of_match);
728
729 static struct platform_driver graph_card = {
730         .driver = {
731                 .name = "asoc-audio-graph-card",
732                 .pm = &snd_soc_pm_ops,
733                 .of_match_table = graph_of_match,
734         },
735         .probe = graph_probe,
736         .remove = asoc_simple_remove,
737 };
738 module_platform_driver(graph_card);
739
740 MODULE_ALIAS("platform:asoc-audio-graph-card");
741 MODULE_LICENSE("GPL v2");
742 MODULE_DESCRIPTION("ASoC Audio Graph Sound Card");
743 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");