]> asedeno.scripts.mit.edu Git - linux.git/blob - sound/soc/generic/simple-card.c
ASoC: simple-card-utils: share asoc_simple_shutdown()
[linux.git] / sound / soc / generic / simple-card.c
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // ASoC simple sound card support
4 //
5 // Copyright (C) 2012 Renesas Solutions Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7
8 #include <linux/clk.h>
9 #include <linux/device.h>
10 #include <linux/module.h>
11 #include <linux/of.h>
12 #include <linux/platform_device.h>
13 #include <linux/string.h>
14 #include <sound/simple_card.h>
15 #include <sound/soc-dai.h>
16 #include <sound/soc.h>
17
18 struct link_info {
19         int dais; /* number of dai  */
20         int link; /* number of link */
21         int conf; /* number of codec_conf */
22         int cpu;  /* turn for CPU / Codec */
23 };
24
25 #define DAI     "sound-dai"
26 #define CELL    "#sound-dai-cells"
27 #define PREFIX  "simple-audio-card,"
28
29 static int simple_set_clk_rate(struct asoc_simple_dai *simple_dai,
30                                unsigned long rate)
31 {
32         if (!simple_dai)
33                 return 0;
34
35         if (!simple_dai->clk)
36                 return 0;
37
38         if (clk_get_rate(simple_dai->clk) == rate)
39                 return 0;
40
41         return clk_set_rate(simple_dai->clk, rate);
42 }
43
44 static int simple_hw_params(struct snd_pcm_substream *substream,
45                             struct snd_pcm_hw_params *params)
46 {
47         struct snd_soc_pcm_runtime *rtd = substream->private_data;
48         struct snd_soc_dai *codec_dai = rtd->codec_dai;
49         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
50         struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
51         struct simple_dai_props *dai_props =
52                 simple_priv_to_props(priv, rtd->num);
53         unsigned int mclk, mclk_fs = 0;
54         int ret = 0;
55
56         if (dai_props->mclk_fs)
57                 mclk_fs = dai_props->mclk_fs;
58
59         if (mclk_fs) {
60                 mclk = params_rate(params) * mclk_fs;
61
62                 ret = simple_set_clk_rate(dai_props->codec_dai, mclk);
63                 if (ret < 0)
64                         return ret;
65
66                 ret = simple_set_clk_rate(dai_props->cpu_dai, mclk);
67                 if (ret < 0)
68                         return ret;
69
70                 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
71                                              SND_SOC_CLOCK_IN);
72                 if (ret && ret != -ENOTSUPP)
73                         goto err;
74
75                 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
76                                              SND_SOC_CLOCK_OUT);
77                 if (ret && ret != -ENOTSUPP)
78                         goto err;
79         }
80         return 0;
81 err:
82         return ret;
83 }
84
85 static const struct snd_soc_ops simple_ops = {
86         .startup        = asoc_simple_startup,
87         .shutdown       = asoc_simple_shutdown,
88         .hw_params      = simple_hw_params,
89 };
90
91 static int simple_dai_init(struct snd_soc_pcm_runtime *rtd)
92 {
93         struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
94         struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num);
95         int ret;
96
97         ret = asoc_simple_card_init_dai(rtd->codec_dai,
98                                         dai_props->codec_dai);
99         if (ret < 0)
100                 return ret;
101
102         ret = asoc_simple_card_init_dai(rtd->cpu_dai,
103                                         dai_props->cpu_dai);
104         if (ret < 0)
105                 return ret;
106
107         return 0;
108 }
109
110 static int simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
111                                      struct snd_pcm_hw_params *params)
112 {
113         struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
114         struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num);
115
116         asoc_simple_card_convert_fixup(&dai_props->adata, params);
117
118         return 0;
119 }
120
121 static void simple_parse_convert(struct device *dev,
122                                  struct device_node *np,
123                                  struct asoc_simple_card_data *adata)
124 {
125         struct device_node *top = dev->of_node;
126         struct device_node *node = of_get_parent(np);
127
128         asoc_simple_card_parse_convert(dev, top,  PREFIX, adata);
129         asoc_simple_card_parse_convert(dev, node, PREFIX, adata);
130         asoc_simple_card_parse_convert(dev, node, NULL,   adata);
131         asoc_simple_card_parse_convert(dev, np,   NULL,   adata);
132
133         of_node_put(node);
134 }
135
136 static void simple_parse_mclk_fs(struct device_node *top,
137                                  struct device_node *cpu,
138                                  struct device_node *codec,
139                                  struct simple_dai_props *props,
140                                  char *prefix)
141 {
142         struct device_node *node = of_get_parent(cpu);
143         char prop[128];
144
145         snprintf(prop, sizeof(prop), "%smclk-fs", PREFIX);
146         of_property_read_u32(top,       prop, &props->mclk_fs);
147
148         snprintf(prop, sizeof(prop), "%smclk-fs", prefix);
149         of_property_read_u32(node,      prop, &props->mclk_fs);
150         of_property_read_u32(cpu,       prop, &props->mclk_fs);
151         of_property_read_u32(codec,     prop, &props->mclk_fs);
152
153         of_node_put(node);
154 }
155
156 static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
157                                    struct device_node *np,
158                                    struct device_node *codec,
159                                    struct link_info *li,
160                                    bool is_top)
161 {
162         struct device *dev = simple_priv_to_dev(priv);
163         struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
164         struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
165         struct asoc_simple_dai *dai;
166         struct snd_soc_dai_link_component *codecs = dai_link->codecs;
167         struct device_node *top = dev->of_node;
168         struct device_node *node = of_get_parent(np);
169         char *prefix = "";
170         int ret;
171
172         /*
173          *       |CPU   |Codec   : turn
174          * CPU   |Pass  |return
175          * Codec |return|Pass
176          * np
177          */
178         if (li->cpu == (np == codec))
179                 return 0;
180
181         dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
182
183         li->link++;
184
185         of_node_put(node);
186
187         /* For single DAI link & old style of DT node */
188         if (is_top)
189                 prefix = PREFIX;
190
191         if (li->cpu) {
192                 int is_single_links = 0;
193
194                 /* BE is dummy */
195                 codecs->of_node         = NULL;
196                 codecs->dai_name        = "snd-soc-dummy-dai";
197                 codecs->name            = "snd-soc-dummy";
198
199                 /* FE settings */
200                 dai_link->dynamic               = 1;
201                 dai_link->dpcm_merged_format    = 1;
202
203                 dai =
204                 dai_props->cpu_dai      = &priv->dais[li->dais++];
205
206                 ret = asoc_simple_card_parse_cpu(np, dai_link, DAI, CELL,
207                                                  &is_single_links);
208                 if (ret)
209                         return ret;
210
211                 ret = asoc_simple_card_parse_clk_cpu(dev, np, dai_link, dai);
212                 if (ret < 0)
213                         return ret;
214
215                 ret = asoc_simple_card_set_dailink_name(dev, dai_link,
216                                                         "fe.%s",
217                                                         dai_link->cpu_dai_name);
218                 if (ret < 0)
219                         return ret;
220
221                 asoc_simple_card_canonicalize_cpu(dai_link, is_single_links);
222         } else {
223                 struct snd_soc_codec_conf *cconf;
224
225                 /* FE is dummy */
226                 dai_link->cpu_of_node           = NULL;
227                 dai_link->cpu_dai_name          = "snd-soc-dummy-dai";
228                 dai_link->cpu_name              = "snd-soc-dummy";
229
230                 /* BE settings */
231                 dai_link->no_pcm                = 1;
232                 dai_link->be_hw_params_fixup    = simple_be_hw_params_fixup;
233
234                 dai =
235                 dai_props->codec_dai    = &priv->dais[li->dais++];
236
237                 cconf =
238                 dai_props->codec_conf   = &priv->codec_conf[li->conf++];
239
240                 ret = asoc_simple_card_parse_codec(np, dai_link, DAI, CELL);
241                 if (ret < 0)
242                         return ret;
243
244                 ret = asoc_simple_card_parse_clk_codec(dev, np, dai_link, dai);
245                 if (ret < 0)
246                         return ret;
247
248                 ret = asoc_simple_card_set_dailink_name(dev, dai_link,
249                                                         "be.%s",
250                                                         codecs->dai_name);
251                 if (ret < 0)
252                         return ret;
253
254                 /* check "prefix" from top node */
255                 snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node,
256                                               PREFIX "prefix");
257                 snd_soc_of_parse_node_prefix(node, cconf, codecs->of_node,
258                                              "prefix");
259                 snd_soc_of_parse_node_prefix(np, cconf, codecs->of_node,
260                                              "prefix");
261         }
262
263         simple_parse_convert(dev, np, &dai_props->adata);
264         simple_parse_mclk_fs(top, np, codec, dai_props, prefix);
265
266         asoc_simple_card_canonicalize_platform(dai_link);
267
268         ret = asoc_simple_card_of_parse_tdm(np, dai);
269         if (ret)
270                 return ret;
271
272         ret = asoc_simple_card_parse_daifmt(dev, node, codec,
273                                             prefix, &dai_link->dai_fmt);
274         if (ret < 0)
275                 return ret;
276
277         dai_link->dpcm_playback         = 1;
278         dai_link->dpcm_capture          = 1;
279         dai_link->ops                   = &simple_ops;
280         dai_link->init                  = simple_dai_init;
281
282         return 0;
283 }
284
285 static int simple_dai_link_of(struct asoc_simple_priv *priv,
286                               struct device_node *np,
287                               struct device_node *codec,
288                               struct link_info *li,
289                               bool is_top)
290 {
291         struct device *dev = simple_priv_to_dev(priv);
292         struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
293         struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
294         struct asoc_simple_dai *cpu_dai;
295         struct asoc_simple_dai *codec_dai;
296         struct device_node *top = dev->of_node;
297         struct device_node *cpu = NULL;
298         struct device_node *node = NULL;
299         struct device_node *plat = NULL;
300         char prop[128];
301         char *prefix = "";
302         int ret, single_cpu;
303
304         /*
305          *       |CPU   |Codec   : turn
306          * CPU   |Pass  |return
307          * Codec |return|return
308          * np
309          */
310         if (!li->cpu || np == codec)
311                 return 0;
312
313         cpu  = np;
314         node = of_get_parent(np);
315         li->link++;
316
317         dev_dbg(dev, "link_of (%pOF)\n", node);
318
319         /* For single DAI link & old style of DT node */
320         if (is_top)
321                 prefix = PREFIX;
322
323         snprintf(prop, sizeof(prop), "%splat", prefix);
324         plat = of_get_child_by_name(node, prop);
325
326         cpu_dai                 =
327         dai_props->cpu_dai      = &priv->dais[li->dais++];
328         codec_dai               =
329         dai_props->codec_dai    = &priv->dais[li->dais++];
330
331         ret = asoc_simple_card_parse_daifmt(dev, node, codec,
332                                             prefix, &dai_link->dai_fmt);
333         if (ret < 0)
334                 goto dai_link_of_err;
335
336         simple_parse_mclk_fs(top, cpu, codec, dai_props, prefix);
337
338         ret = asoc_simple_card_parse_cpu(cpu, dai_link,
339                                          DAI, CELL, &single_cpu);
340         if (ret < 0)
341                 goto dai_link_of_err;
342
343         ret = asoc_simple_card_parse_codec(codec, dai_link, DAI, CELL);
344         if (ret < 0)
345                 goto dai_link_of_err;
346
347         ret = asoc_simple_card_parse_platform(plat, dai_link, DAI, CELL);
348         if (ret < 0)
349                 goto dai_link_of_err;
350
351         ret = asoc_simple_card_of_parse_tdm(cpu, cpu_dai);
352         if (ret < 0)
353                 goto dai_link_of_err;
354
355         ret = asoc_simple_card_of_parse_tdm(codec, codec_dai);
356         if (ret < 0)
357                 goto dai_link_of_err;
358
359         ret = asoc_simple_card_parse_clk_cpu(dev, cpu, dai_link, cpu_dai);
360         if (ret < 0)
361                 goto dai_link_of_err;
362
363         ret = asoc_simple_card_parse_clk_codec(dev, codec, dai_link, codec_dai);
364         if (ret < 0)
365                 goto dai_link_of_err;
366
367         ret = asoc_simple_card_set_dailink_name(dev, dai_link,
368                                                 "%s-%s",
369                                                 dai_link->cpu_dai_name,
370                                                 dai_link->codecs->dai_name);
371         if (ret < 0)
372                 goto dai_link_of_err;
373
374         dai_link->ops = &simple_ops;
375         dai_link->init = simple_dai_init;
376
377         asoc_simple_card_canonicalize_cpu(dai_link, single_cpu);
378         asoc_simple_card_canonicalize_platform(dai_link);
379
380 dai_link_of_err:
381         of_node_put(plat);
382         of_node_put(node);
383
384         return ret;
385 }
386
387 static int simple_for_each_link(struct asoc_simple_priv *priv,
388                         struct link_info *li,
389                         int (*func_noml)(struct asoc_simple_priv *priv,
390                                          struct device_node *np,
391                                          struct device_node *codec,
392                                          struct link_info *li, bool is_top),
393                         int (*func_dpcm)(struct asoc_simple_priv *priv,
394                                          struct device_node *np,
395                                          struct device_node *codec,
396                                          struct link_info *li, bool is_top))
397 {
398         struct device *dev = simple_priv_to_dev(priv);
399         struct device_node *top = dev->of_node;
400         struct device_node *node;
401         bool is_top = 0;
402         int ret = 0;
403
404         /* Check if it has dai-link */
405         node = of_get_child_by_name(top, PREFIX "dai-link");
406         if (!node) {
407                 node = of_node_get(top);
408                 is_top = 1;
409         }
410
411         /* loop for all dai-link */
412         do {
413                 struct asoc_simple_card_data adata;
414                 struct device_node *codec;
415                 struct device_node *np;
416                 int num = of_get_child_count(node);
417
418                 /* get codec */
419                 codec = of_get_child_by_name(node, is_top ?
420                                              PREFIX "codec" : "codec");
421                 if (!codec) {
422                         ret = -ENODEV;
423                         goto error;
424                 }
425
426                 of_node_put(codec);
427
428                 /* get convert-xxx property */
429                 memset(&adata, 0, sizeof(adata));
430                 for_each_child_of_node(node, np)
431                         simple_parse_convert(dev, np, &adata);
432
433                 /* loop for all CPU/Codec node */
434                 for_each_child_of_node(node, np) {
435                         /*
436                          * It is DPCM
437                          * if it has many CPUs,
438                          * or has convert-xxx property
439                          */
440                         if (num > 2 ||
441                             adata.convert_rate || adata.convert_channels)
442                                 ret = func_dpcm(priv, np, codec, li, is_top);
443                         /* else normal sound */
444                         else
445                                 ret = func_noml(priv, np, codec, li, is_top);
446
447                         if (ret < 0) {
448                                 of_node_put(np);
449                                 goto error;
450                         }
451                 }
452
453                 node = of_get_next_child(top, node);
454         } while (!is_top && node);
455
456  error:
457         of_node_put(node);
458         return ret;
459 }
460
461 static int simple_parse_aux_devs(struct device_node *node,
462                                  struct asoc_simple_priv *priv)
463 {
464         struct device *dev = simple_priv_to_dev(priv);
465         struct device_node *aux_node;
466         struct snd_soc_card *card = simple_priv_to_card(priv);
467         int i, n, len;
468
469         if (!of_find_property(node, PREFIX "aux-devs", &len))
470                 return 0;               /* Ok to have no aux-devs */
471
472         n = len / sizeof(__be32);
473         if (n <= 0)
474                 return -EINVAL;
475
476         card->aux_dev = devm_kcalloc(dev,
477                         n, sizeof(*card->aux_dev), GFP_KERNEL);
478         if (!card->aux_dev)
479                 return -ENOMEM;
480
481         for (i = 0; i < n; i++) {
482                 aux_node = of_parse_phandle(node, PREFIX "aux-devs", i);
483                 if (!aux_node)
484                         return -EINVAL;
485                 card->aux_dev[i].codec_of_node = aux_node;
486         }
487
488         card->num_aux_devs = n;
489         return 0;
490 }
491
492 static int simple_parse_of(struct asoc_simple_priv *priv)
493 {
494         struct device *dev = simple_priv_to_dev(priv);
495         struct device_node *top = dev->of_node;
496         struct snd_soc_card *card = simple_priv_to_card(priv);
497         struct link_info li;
498         int ret;
499
500         if (!top)
501                 return -EINVAL;
502
503         ret = asoc_simple_card_of_parse_widgets(card, PREFIX);
504         if (ret < 0)
505                 return ret;
506
507         ret = asoc_simple_card_of_parse_routing(card, PREFIX);
508         if (ret < 0)
509                 return ret;
510
511         /* Single/Muti DAI link(s) & New style of DT node */
512         memset(&li, 0, sizeof(li));
513         for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
514                 /*
515                  * Detect all CPU first, and Detect all Codec 2nd.
516                  *
517                  * In Normal sound case, all DAIs are detected
518                  * as "CPU-Codec".
519                  *
520                  * In DPCM sound case,
521                  * all CPUs   are detected as "CPU-dummy", and
522                  * all Codecs are detected as "dummy-Codec".
523                  * To avoid random sub-device numbering,
524                  * detect "dummy-Codec" in last;
525                  */
526                 ret = simple_for_each_link(priv, &li,
527                                            simple_dai_link_of,
528                                            simple_dai_link_of_dpcm);
529                 if (ret < 0)
530                         return ret;
531         }
532
533         ret = asoc_simple_card_parse_card_name(card, PREFIX);
534         if (ret < 0)
535                 return ret;
536
537         ret = simple_parse_aux_devs(top, priv);
538
539         return ret;
540 }
541
542 static int simple_count_noml(struct asoc_simple_priv *priv,
543                              struct device_node *np,
544                              struct device_node *codec,
545                              struct link_info *li, bool is_top)
546 {
547         li->dais++; /* CPU or Codec */
548         if (np != codec)
549                 li->link++; /* CPU-Codec */
550
551         return 0;
552 }
553
554 static int simple_count_dpcm(struct asoc_simple_priv *priv,
555                              struct device_node *np,
556                              struct device_node *codec,
557                              struct link_info *li, bool is_top)
558 {
559         li->dais++; /* CPU or Codec */
560         li->link++; /* CPU-dummy or dummy-Codec */
561         if (np == codec)
562                 li->conf++;
563
564         return 0;
565 }
566
567 static void simple_get_dais_count(struct asoc_simple_priv *priv,
568                                   struct link_info *li)
569 {
570         struct device *dev = simple_priv_to_dev(priv);
571         struct device_node *top = dev->of_node;
572
573         /*
574          * link_num :   number of links.
575          *              CPU-Codec / CPU-dummy / dummy-Codec
576          * dais_num :   number of DAIs
577          * ccnf_num :   number of codec_conf
578          *              same number for "dummy-Codec"
579          *
580          * ex1)
581          * CPU0 --- Codec0      link : 5
582          * CPU1 --- Codec1      dais : 7
583          * CPU2 -/              ccnf : 1
584          * CPU3 --- Codec2
585          *
586          *      => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec
587          *      => 7 DAIs  = 4xCPU + 3xCodec
588          *      => 1 ccnf  = 1xdummy-Codec
589          *
590          * ex2)
591          * CPU0 --- Codec0      link : 5
592          * CPU1 --- Codec1      dais : 6
593          * CPU2 -/              ccnf : 1
594          * CPU3 -/
595          *
596          *      => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec
597          *      => 6 DAIs  = 4xCPU + 2xCodec
598          *      => 1 ccnf  = 1xdummy-Codec
599          *
600          * ex3)
601          * CPU0 --- Codec0      link : 6
602          * CPU1 -/              dais : 6
603          * CPU2 --- Codec1      ccnf : 2
604          * CPU3 -/
605          *
606          *      => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec
607          *      => 6 DAIs  = 4xCPU + 2xCodec
608          *      => 2 ccnf  = 2xdummy-Codec
609          *
610          * ex4)
611          * CPU0 --- Codec0 (convert-rate)       link : 3
612          * CPU1 --- Codec1                      dais : 4
613          *                                      ccnf : 1
614          *
615          *      => 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec
616          *      => 4 DAIs  = 2xCPU + 2xCodec
617          *      => 1 ccnf  = 1xdummy-Codec
618          */
619         if (!top) {
620                 li->link = 1;
621                 li->dais = 2;
622                 li->conf = 0;
623                 return;
624         }
625
626         simple_for_each_link(priv, li,
627                              simple_count_noml,
628                              simple_count_dpcm);
629
630         dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
631                 li->link, li->dais, li->conf);
632 }
633
634 static int simple_soc_probe(struct snd_soc_card *card)
635 {
636         struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(card);
637         int ret;
638
639         ret = asoc_simple_card_init_hp(card, &priv->hp_jack, PREFIX);
640         if (ret < 0)
641                 return ret;
642
643         ret = asoc_simple_card_init_mic(card, &priv->mic_jack, PREFIX);
644         if (ret < 0)
645                 return ret;
646
647         return 0;
648 }
649
650 static int simple_probe(struct platform_device *pdev)
651 {
652         struct asoc_simple_priv *priv;
653         struct snd_soc_dai_link *dai_link;
654         struct simple_dai_props *dai_props;
655         struct asoc_simple_dai *dais;
656         struct device *dev = &pdev->dev;
657         struct device_node *np = dev->of_node;
658         struct snd_soc_card *card;
659         struct snd_soc_codec_conf *cconf;
660         struct link_info li;
661         int ret, i;
662
663         /* Allocate the private data and the DAI link array */
664         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
665         if (!priv)
666                 return -ENOMEM;
667
668         card = simple_priv_to_card(priv);
669         card->owner             = THIS_MODULE;
670         card->dev               = dev;
671         card->probe             = simple_soc_probe;
672
673         memset(&li, 0, sizeof(li));
674         simple_get_dais_count(priv, &li);
675         if (!li.link || !li.dais)
676                 return -EINVAL;
677
678         dai_props = devm_kcalloc(dev, li.link, sizeof(*dai_props), GFP_KERNEL);
679         dai_link  = devm_kcalloc(dev, li.link, sizeof(*dai_link),  GFP_KERNEL);
680         dais      = devm_kcalloc(dev, li.dais, sizeof(*dais),      GFP_KERNEL);
681         cconf     = devm_kcalloc(dev, li.conf, sizeof(*cconf),     GFP_KERNEL);
682         if (!dai_props || !dai_link || !dais)
683                 return -ENOMEM;
684
685         /*
686          * Use snd_soc_dai_link_component instead of legacy style
687          * It is codec only. but cpu/platform will be supported in the future.
688          * see
689          *      soc-core.c :: snd_soc_init_multicodec()
690          */
691         for (i = 0; i < li.link; i++) {
692                 dai_link[i].codecs      = &dai_props[i].codecs;
693                 dai_link[i].num_codecs  = 1;
694                 dai_link[i].platforms   = &dai_props[i].platforms;
695                 dai_link[i].num_platforms = 1;
696         }
697
698         priv->dai_props         = dai_props;
699         priv->dai_link          = dai_link;
700         priv->dais              = dais;
701         priv->codec_conf        = cconf;
702
703         card->dai_link          = priv->dai_link;
704         card->num_links         = li.link;
705         card->codec_conf        = cconf;
706         card->num_configs       = li.conf;
707
708         if (np && of_device_is_available(np)) {
709
710                 ret = simple_parse_of(priv);
711                 if (ret < 0) {
712                         if (ret != -EPROBE_DEFER)
713                                 dev_err(dev, "parse error %d\n", ret);
714                         goto err;
715                 }
716
717         } else {
718                 struct asoc_simple_card_info *cinfo;
719                 struct snd_soc_dai_link_component *codecs;
720                 struct snd_soc_dai_link_component *platform;
721                 int dai_idx = 0;
722
723                 cinfo = dev->platform_data;
724                 if (!cinfo) {
725                         dev_err(dev, "no info for asoc-simple-card\n");
726                         return -EINVAL;
727                 }
728
729                 if (!cinfo->name ||
730                     !cinfo->codec_dai.name ||
731                     !cinfo->codec ||
732                     !cinfo->platform ||
733                     !cinfo->cpu_dai.name) {
734                         dev_err(dev, "insufficient asoc_simple_card_info settings\n");
735                         return -EINVAL;
736                 }
737
738                 dai_props->cpu_dai      = &priv->dais[dai_idx++];
739                 dai_props->codec_dai    = &priv->dais[dai_idx++];
740
741                 codecs                  = dai_link->codecs;
742                 codecs->name            = cinfo->codec;
743                 codecs->dai_name        = cinfo->codec_dai.name;
744
745                 platform                = dai_link->platforms;
746                 platform->name          = cinfo->platform;
747
748                 card->name              = (cinfo->card) ? cinfo->card : cinfo->name;
749                 dai_link->name          = cinfo->name;
750                 dai_link->stream_name   = cinfo->name;
751                 dai_link->cpu_dai_name  = cinfo->cpu_dai.name;
752                 dai_link->dai_fmt       = cinfo->daifmt;
753                 dai_link->init          = simple_dai_init;
754                 memcpy(priv->dai_props->cpu_dai, &cinfo->cpu_dai,
755                                         sizeof(*priv->dai_props->cpu_dai));
756                 memcpy(priv->dai_props->codec_dai, &cinfo->codec_dai,
757                                         sizeof(*priv->dai_props->codec_dai));
758         }
759
760         snd_soc_card_set_drvdata(card, priv);
761
762         asoc_simple_debug_info(priv);
763
764         ret = devm_snd_soc_register_card(dev, card);
765         if (ret < 0)
766                 goto err;
767
768         return 0;
769 err:
770         asoc_simple_card_clean_reference(card);
771
772         return ret;
773 }
774
775 static int simple_remove(struct platform_device *pdev)
776 {
777         struct snd_soc_card *card = platform_get_drvdata(pdev);
778
779         return asoc_simple_card_clean_reference(card);
780 }
781
782 static const struct of_device_id simple_of_match[] = {
783         { .compatible = "simple-audio-card", },
784         { .compatible = "simple-scu-audio-card", },
785         {},
786 };
787 MODULE_DEVICE_TABLE(of, simple_of_match);
788
789 static struct platform_driver asoc_simple_card = {
790         .driver = {
791                 .name = "asoc-simple-card",
792                 .pm = &snd_soc_pm_ops,
793                 .of_match_table = simple_of_match,
794         },
795         .probe = simple_probe,
796         .remove = simple_remove,
797 };
798
799 module_platform_driver(asoc_simple_card);
800
801 MODULE_ALIAS("platform:asoc-simple-card");
802 MODULE_LICENSE("GPL v2");
803 MODULE_DESCRIPTION("ASoC Simple Sound Card");
804 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");