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/of_device.h>
13 #include <linux/platform_device.h>
14 #include <linux/string.h>
15 #include <sound/simple_card.h>
16 #include <sound/soc-dai.h>
17 #include <sound/soc.h>
18
19 #define DPCM_SELECTABLE 1
20
21 #define DAI "sound-dai"
22 #define CELL "#sound-dai-cells"
23 #define PREFIX "simple-audio-card,"
24
25 static const struct snd_soc_ops simple_ops = {
26 .startup = asoc_simple_startup,
27 .shutdown = asoc_simple_shutdown,
28 .hw_params = asoc_simple_hw_params,
29 };
30
asoc_simple_parse_dai(struct device_node * node,struct snd_soc_dai_link_component * dlc,int * is_single_link)31 static int asoc_simple_parse_dai(struct device_node *node,
32 struct snd_soc_dai_link_component *dlc,
33 int *is_single_link)
34 {
35 struct of_phandle_args args;
36 int ret;
37
38 if (!node)
39 return 0;
40
41 /*
42 * Get node via "sound-dai = <&phandle port>"
43 * it will be used as xxx_of_node on soc_bind_dai_link()
44 */
45 ret = of_parse_phandle_with_args(node, DAI, CELL, 0, &args);
46 if (ret)
47 return ret;
48
49 /*
50 * FIXME
51 *
52 * Here, dlc->dai_name is pointer to CPU/Codec DAI name.
53 * If user unbinded CPU or Codec driver, but not for Sound Card,
54 * dlc->dai_name is keeping unbinded CPU or Codec
55 * driver's pointer.
56 *
57 * If user re-bind CPU or Codec driver again, ALSA SoC will try
58 * to rebind Card via snd_soc_try_rebind_card(), but because of
59 * above reason, it might can't bind Sound Card.
60 * Because Sound Card is pointing to released dai_name pointer.
61 *
62 * To avoid this rebind Card issue,
63 * 1) It needs to alloc memory to keep dai_name eventhough
64 * CPU or Codec driver was unbinded, or
65 * 2) user need to rebind Sound Card everytime
66 * if he unbinded CPU or Codec.
67 */
68 ret = snd_soc_of_get_dai_name(node, &dlc->dai_name);
69 if (ret < 0)
70 return ret;
71
72 dlc->of_node = args.np;
73
74 if (is_single_link)
75 *is_single_link = !args.args_count;
76
77 return 0;
78 }
79
simple_parse_convert(struct device * dev,struct device_node * np,struct asoc_simple_data * adata)80 static void simple_parse_convert(struct device *dev,
81 struct device_node *np,
82 struct asoc_simple_data *adata)
83 {
84 struct device_node *top = dev->of_node;
85 struct device_node *node = of_get_parent(np);
86
87 asoc_simple_parse_convert(top, PREFIX, adata);
88 asoc_simple_parse_convert(node, PREFIX, adata);
89 asoc_simple_parse_convert(node, NULL, adata);
90 asoc_simple_parse_convert(np, NULL, adata);
91
92 of_node_put(node);
93 }
94
simple_parse_mclk_fs(struct device_node * top,struct device_node * cpu,struct device_node * codec,struct simple_dai_props * props,char * prefix)95 static void simple_parse_mclk_fs(struct device_node *top,
96 struct device_node *cpu,
97 struct device_node *codec,
98 struct simple_dai_props *props,
99 char *prefix)
100 {
101 struct device_node *node = of_get_parent(cpu);
102 char prop[128];
103
104 snprintf(prop, sizeof(prop), "%smclk-fs", PREFIX);
105 of_property_read_u32(top, prop, &props->mclk_fs);
106
107 snprintf(prop, sizeof(prop), "%smclk-fs", prefix);
108 of_property_read_u32(node, prop, &props->mclk_fs);
109 of_property_read_u32(cpu, prop, &props->mclk_fs);
110 of_property_read_u32(codec, prop, &props->mclk_fs);
111
112 of_node_put(node);
113 }
114
simple_dai_link_of_dpcm(struct asoc_simple_priv * priv,struct device_node * np,struct device_node * codec,struct link_info * li,bool is_top)115 static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
116 struct device_node *np,
117 struct device_node *codec,
118 struct link_info *li,
119 bool is_top)
120 {
121 struct device *dev = simple_priv_to_dev(priv);
122 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
123 struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
124 struct asoc_simple_dai *dai;
125 struct snd_soc_dai_link_component *cpus = asoc_link_to_cpu(dai_link, 0);
126 struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, 0);
127 struct snd_soc_dai_link_component *platforms = asoc_link_to_platform(dai_link, 0);
128 struct device_node *top = dev->of_node;
129 struct device_node *node = of_get_parent(np);
130 char *prefix = "";
131 int ret;
132
133 dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
134
135 li->link++;
136
137 /* For single DAI link & old style of DT node */
138 if (is_top)
139 prefix = PREFIX;
140
141 if (li->cpu) {
142 int is_single_links = 0;
143
144 /* Codec is dummy */
145
146 /* FE settings */
147 dai_link->dynamic = 1;
148 dai_link->dpcm_merged_format = 1;
149
150 dai = simple_props_to_dai_cpu(dai_props, 0);
151
152 ret = asoc_simple_parse_dai(np, cpus, &is_single_links);
153 if (ret)
154 goto out_put_node;
155
156 ret = asoc_simple_parse_clk(dev, np, dai, cpus);
157 if (ret < 0)
158 goto out_put_node;
159
160 ret = asoc_simple_set_dailink_name(dev, dai_link,
161 "fe.%s",
162 cpus->dai_name);
163 if (ret < 0)
164 goto out_put_node;
165
166 asoc_simple_canonicalize_cpu(cpus, is_single_links);
167 asoc_simple_canonicalize_platform(platforms, cpus);
168 } else {
169 struct snd_soc_codec_conf *cconf;
170
171 /* CPU is dummy */
172
173 /* BE settings */
174 dai_link->no_pcm = 1;
175 dai_link->be_hw_params_fixup = asoc_simple_be_hw_params_fixup;
176
177 dai = simple_props_to_dai_codec(dai_props, 0);
178 cconf = simple_props_to_codec_conf(dai_props, 0);
179
180 ret = asoc_simple_parse_dai(np, codecs, NULL);
181 if (ret < 0)
182 goto out_put_node;
183
184 ret = asoc_simple_parse_clk(dev, np, dai, codecs);
185 if (ret < 0)
186 goto out_put_node;
187
188 ret = asoc_simple_set_dailink_name(dev, dai_link,
189 "be.%s",
190 codecs->dai_name);
191 if (ret < 0)
192 goto out_put_node;
193
194 /* check "prefix" from top node */
195 snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node,
196 PREFIX "prefix");
197 snd_soc_of_parse_node_prefix(node, cconf, codecs->of_node,
198 "prefix");
199 snd_soc_of_parse_node_prefix(np, cconf, codecs->of_node,
200 "prefix");
201 }
202
203 simple_parse_convert(dev, np, &dai_props->adata);
204 simple_parse_mclk_fs(top, np, codec, dai_props, prefix);
205
206 ret = asoc_simple_parse_tdm(np, dai);
207 if (ret)
208 goto out_put_node;
209
210 ret = asoc_simple_parse_daifmt(dev, node, codec,
211 prefix, &dai_link->dai_fmt);
212 if (ret < 0)
213 goto out_put_node;
214
215 snd_soc_dai_link_set_capabilities(dai_link);
216
217 dai_link->ops = &simple_ops;
218 dai_link->init = asoc_simple_dai_init;
219
220 out_put_node:
221 of_node_put(node);
222 return ret;
223 }
224
simple_dai_link_of(struct asoc_simple_priv * priv,struct device_node * np,struct device_node * codec,struct link_info * li,bool is_top)225 static int simple_dai_link_of(struct asoc_simple_priv *priv,
226 struct device_node *np,
227 struct device_node *codec,
228 struct link_info *li,
229 bool is_top)
230 {
231 struct device *dev = simple_priv_to_dev(priv);
232 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
233 struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
234 struct asoc_simple_dai *cpu_dai = simple_props_to_dai_cpu(dai_props, 0);
235 struct asoc_simple_dai *codec_dai = simple_props_to_dai_codec(dai_props, 0);
236 struct snd_soc_dai_link_component *cpus = asoc_link_to_cpu(dai_link, 0);
237 struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, 0);
238 struct snd_soc_dai_link_component *platforms = asoc_link_to_platform(dai_link, 0);
239 struct device_node *top = dev->of_node;
240 struct device_node *cpu = NULL;
241 struct device_node *node = NULL;
242 struct device_node *plat = NULL;
243 char prop[128];
244 char *prefix = "";
245 int ret, single_cpu = 0;
246
247 cpu = np;
248 node = of_get_parent(np);
249 li->link++;
250
251 dev_dbg(dev, "link_of (%pOF)\n", node);
252
253 /* For single DAI link & old style of DT node */
254 if (is_top)
255 prefix = PREFIX;
256
257 snprintf(prop, sizeof(prop), "%splat", prefix);
258 plat = of_get_child_by_name(node, prop);
259
260 ret = asoc_simple_parse_daifmt(dev, node, codec,
261 prefix, &dai_link->dai_fmt);
262 if (ret < 0)
263 goto dai_link_of_err;
264
265 simple_parse_mclk_fs(top, cpu, codec, dai_props, prefix);
266
267 ret = asoc_simple_parse_dai(cpu, cpus, &single_cpu);
268 if (ret < 0)
269 goto dai_link_of_err;
270
271 ret = asoc_simple_parse_dai(codec, codecs, NULL);
272 if (ret < 0)
273 goto dai_link_of_err;
274
275 ret = asoc_simple_parse_dai(plat, platforms, NULL);
276 if (ret < 0)
277 goto dai_link_of_err;
278
279 ret = asoc_simple_parse_tdm(cpu, cpu_dai);
280 if (ret < 0)
281 goto dai_link_of_err;
282
283 ret = asoc_simple_parse_tdm(codec, codec_dai);
284 if (ret < 0)
285 goto dai_link_of_err;
286
287 ret = asoc_simple_parse_clk(dev, cpu, cpu_dai, cpus);
288 if (ret < 0)
289 goto dai_link_of_err;
290
291 ret = asoc_simple_parse_clk(dev, codec, codec_dai, codecs);
292 if (ret < 0)
293 goto dai_link_of_err;
294
295 ret = asoc_simple_set_dailink_name(dev, dai_link,
296 "%s-%s",
297 cpus->dai_name,
298 codecs->dai_name);
299 if (ret < 0)
300 goto dai_link_of_err;
301
302 dai_link->ops = &simple_ops;
303 dai_link->init = asoc_simple_dai_init;
304
305 asoc_simple_canonicalize_cpu(cpus, single_cpu);
306 asoc_simple_canonicalize_platform(platforms, cpus);
307
308 dai_link_of_err:
309 of_node_put(plat);
310 of_node_put(node);
311
312 return ret;
313 }
314
__simple_for_each_link(struct asoc_simple_priv * priv,struct link_info * li,int (* func_noml)(struct asoc_simple_priv * priv,struct device_node * np,struct device_node * codec,struct link_info * li,bool is_top),int (* func_dpcm)(struct asoc_simple_priv * priv,struct device_node * np,struct device_node * codec,struct link_info * li,bool is_top))315 static int __simple_for_each_link(struct asoc_simple_priv *priv,
316 struct link_info *li,
317 int (*func_noml)(struct asoc_simple_priv *priv,
318 struct device_node *np,
319 struct device_node *codec,
320 struct link_info *li, bool is_top),
321 int (*func_dpcm)(struct asoc_simple_priv *priv,
322 struct device_node *np,
323 struct device_node *codec,
324 struct link_info *li, bool is_top))
325 {
326 struct device *dev = simple_priv_to_dev(priv);
327 struct device_node *top = dev->of_node;
328 struct device_node *node;
329 uintptr_t dpcm_selectable = (uintptr_t)of_device_get_match_data(dev);
330 bool is_top = 0;
331 int ret = 0;
332
333 /* Check if it has dai-link */
334 node = of_get_child_by_name(top, PREFIX "dai-link");
335 if (!node) {
336 node = of_node_get(top);
337 is_top = 1;
338 }
339
340 /* loop for all dai-link */
341 do {
342 struct asoc_simple_data adata;
343 struct device_node *codec;
344 struct device_node *plat;
345 struct device_node *np;
346 int num = of_get_child_count(node);
347
348 /* get codec */
349 codec = of_get_child_by_name(node, is_top ?
350 PREFIX "codec" : "codec");
351 if (!codec) {
352 ret = -ENODEV;
353 goto error;
354 }
355 /* get platform */
356 plat = of_get_child_by_name(node, is_top ?
357 PREFIX "plat" : "plat");
358
359 /* get convert-xxx property */
360 memset(&adata, 0, sizeof(adata));
361 for_each_child_of_node(node, np)
362 simple_parse_convert(dev, np, &adata);
363
364 /* loop for all CPU/Codec node */
365 for_each_child_of_node(node, np) {
366 if (plat == np)
367 continue;
368 /*
369 * It is DPCM
370 * if it has many CPUs,
371 * or has convert-xxx property
372 */
373 if (dpcm_selectable &&
374 (num > 2 ||
375 adata.convert_rate || adata.convert_channels)) {
376 /*
377 * np
378 * |1(CPU)|0(Codec) li->cpu
379 * CPU |Pass |return
380 * Codec |return|Pass
381 */
382 if (li->cpu != (np == codec))
383 ret = func_dpcm(priv, np, codec, li, is_top);
384 /* else normal sound */
385 } else {
386 /*
387 * np
388 * |1(CPU)|0(Codec) li->cpu
389 * CPU |Pass |return
390 * Codec |return|return
391 */
392 if (li->cpu && (np != codec))
393 ret = func_noml(priv, np, codec, li, is_top);
394 }
395
396 if (ret < 0) {
397 of_node_put(codec);
398 of_node_put(np);
399 goto error;
400 }
401 }
402
403 of_node_put(codec);
404 node = of_get_next_child(top, node);
405 } while (!is_top && node);
406
407 error:
408 of_node_put(node);
409 return ret;
410 }
411
simple_for_each_link(struct asoc_simple_priv * priv,struct link_info * li,int (* func_noml)(struct asoc_simple_priv * priv,struct device_node * np,struct device_node * codec,struct link_info * li,bool is_top),int (* func_dpcm)(struct asoc_simple_priv * priv,struct device_node * np,struct device_node * codec,struct link_info * li,bool is_top))412 static int simple_for_each_link(struct asoc_simple_priv *priv,
413 struct link_info *li,
414 int (*func_noml)(struct asoc_simple_priv *priv,
415 struct device_node *np,
416 struct device_node *codec,
417 struct link_info *li, bool is_top),
418 int (*func_dpcm)(struct asoc_simple_priv *priv,
419 struct device_node *np,
420 struct device_node *codec,
421 struct link_info *li, bool is_top))
422 {
423 int ret;
424 /*
425 * Detect all CPU first, and Detect all Codec 2nd.
426 *
427 * In Normal sound case, all DAIs are detected
428 * as "CPU-Codec".
429 *
430 * In DPCM sound case,
431 * all CPUs are detected as "CPU-dummy", and
432 * all Codecs are detected as "dummy-Codec".
433 * To avoid random sub-device numbering,
434 * detect "dummy-Codec" in last;
435 */
436 for (li->cpu = 1; li->cpu >= 0; li->cpu--) {
437 ret = __simple_for_each_link(priv, li, func_noml, func_dpcm);
438 if (ret < 0)
439 break;
440 }
441
442 return ret;
443 }
444
simple_parse_of(struct asoc_simple_priv * priv,struct link_info * li)445 static int simple_parse_of(struct asoc_simple_priv *priv, struct link_info *li)
446 {
447 struct snd_soc_card *card = simple_priv_to_card(priv);
448 int ret;
449
450 ret = asoc_simple_parse_widgets(card, PREFIX);
451 if (ret < 0)
452 return ret;
453
454 ret = asoc_simple_parse_routing(card, PREFIX);
455 if (ret < 0)
456 return ret;
457
458 ret = asoc_simple_parse_pin_switches(card, PREFIX);
459 if (ret < 0)
460 return ret;
461
462 /* Single/Muti DAI link(s) & New style of DT node */
463 memset(li, 0, sizeof(*li));
464 ret = simple_for_each_link(priv, li,
465 simple_dai_link_of,
466 simple_dai_link_of_dpcm);
467 if (ret < 0)
468 return ret;
469
470 ret = asoc_simple_parse_card_name(card, PREFIX);
471 if (ret < 0)
472 return ret;
473
474 ret = snd_soc_of_parse_aux_devs(card, PREFIX "aux-devs");
475
476 return ret;
477 }
478
simple_count_noml(struct asoc_simple_priv * priv,struct device_node * np,struct device_node * codec,struct link_info * li,bool is_top)479 static int simple_count_noml(struct asoc_simple_priv *priv,
480 struct device_node *np,
481 struct device_node *codec,
482 struct link_info *li, bool is_top)
483 {
484 if (li->link >= SNDRV_MAX_LINKS) {
485 struct device *dev = simple_priv_to_dev(priv);
486
487 dev_err(dev, "too many links\n");
488 return -EINVAL;
489 }
490
491 li->num[li->link].cpus = 1;
492 li->num[li->link].codecs = 1;
493 li->num[li->link].platforms = 1;
494
495 li->link += 1;
496
497 return 0;
498 }
499
simple_count_dpcm(struct asoc_simple_priv * priv,struct device_node * np,struct device_node * codec,struct link_info * li,bool is_top)500 static int simple_count_dpcm(struct asoc_simple_priv *priv,
501 struct device_node *np,
502 struct device_node *codec,
503 struct link_info *li, bool is_top)
504 {
505 if (li->link >= SNDRV_MAX_LINKS) {
506 struct device *dev = simple_priv_to_dev(priv);
507
508 dev_err(dev, "too many links\n");
509 return -EINVAL;
510 }
511
512 if (li->cpu) {
513 li->num[li->link].cpus = 1;
514 li->num[li->link].platforms = 1;
515
516 li->link++; /* CPU-dummy */
517 } else {
518 li->num[li->link].codecs = 1;
519
520 li->link++; /* dummy-Codec */
521 }
522
523 return 0;
524 }
525
simple_get_dais_count(struct asoc_simple_priv * priv,struct link_info * li)526 static int simple_get_dais_count(struct asoc_simple_priv *priv,
527 struct link_info *li)
528 {
529 struct device *dev = simple_priv_to_dev(priv);
530 struct device_node *top = dev->of_node;
531
532 /*
533 * link_num : number of links.
534 * CPU-Codec / CPU-dummy / dummy-Codec
535 * dais_num : number of DAIs
536 * ccnf_num : number of codec_conf
537 * same number for "dummy-Codec"
538 *
539 * ex1)
540 * CPU0 --- Codec0 link : 5
541 * CPU1 --- Codec1 dais : 7
542 * CPU2 -/ ccnf : 1
543 * CPU3 --- Codec2
544 *
545 * => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec
546 * => 7 DAIs = 4xCPU + 3xCodec
547 * => 1 ccnf = 1xdummy-Codec
548 *
549 * ex2)
550 * CPU0 --- Codec0 link : 5
551 * CPU1 --- Codec1 dais : 6
552 * CPU2 -/ ccnf : 1
553 * CPU3 -/
554 *
555 * => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec
556 * => 6 DAIs = 4xCPU + 2xCodec
557 * => 1 ccnf = 1xdummy-Codec
558 *
559 * ex3)
560 * CPU0 --- Codec0 link : 6
561 * CPU1 -/ dais : 6
562 * CPU2 --- Codec1 ccnf : 2
563 * CPU3 -/
564 *
565 * => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec
566 * => 6 DAIs = 4xCPU + 2xCodec
567 * => 2 ccnf = 2xdummy-Codec
568 *
569 * ex4)
570 * CPU0 --- Codec0 (convert-rate) link : 3
571 * CPU1 --- Codec1 dais : 4
572 * ccnf : 1
573 *
574 * => 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec
575 * => 4 DAIs = 2xCPU + 2xCodec
576 * => 1 ccnf = 1xdummy-Codec
577 */
578 if (!top) {
579 li->num[0].cpus = 1;
580 li->num[0].codecs = 1;
581 li->num[0].platforms = 1;
582
583 li->link = 1;
584 return 0;
585 }
586
587 return simple_for_each_link(priv, li,
588 simple_count_noml,
589 simple_count_dpcm);
590 }
591
simple_soc_probe(struct snd_soc_card * card)592 static int simple_soc_probe(struct snd_soc_card *card)
593 {
594 struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(card);
595 int ret;
596
597 ret = asoc_simple_init_hp(card, &priv->hp_jack, PREFIX);
598 if (ret < 0)
599 return ret;
600
601 ret = asoc_simple_init_mic(card, &priv->mic_jack, PREFIX);
602 if (ret < 0)
603 return ret;
604
605 return 0;
606 }
607
asoc_simple_probe(struct platform_device * pdev)608 static int asoc_simple_probe(struct platform_device *pdev)
609 {
610 struct asoc_simple_priv *priv;
611 struct device *dev = &pdev->dev;
612 struct device_node *np = dev->of_node;
613 struct snd_soc_card *card;
614 struct link_info *li;
615 int ret;
616
617 /* Allocate the private data and the DAI link array */
618 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
619 if (!priv)
620 return -ENOMEM;
621
622 card = simple_priv_to_card(priv);
623 card->owner = THIS_MODULE;
624 card->dev = dev;
625 card->probe = simple_soc_probe;
626
627 li = devm_kzalloc(dev, sizeof(*li), GFP_KERNEL);
628 if (!li)
629 return -ENOMEM;
630
631 ret = simple_get_dais_count(priv, li);
632 if (ret < 0)
633 return ret;
634
635 if (!li->link)
636 return -EINVAL;
637
638 ret = asoc_simple_init_priv(priv, li);
639 if (ret < 0)
640 return ret;
641
642 if (np && of_device_is_available(np)) {
643
644 ret = simple_parse_of(priv, li);
645 if (ret < 0) {
646 if (ret != -EPROBE_DEFER)
647 dev_err(dev, "parse error %d\n", ret);
648 goto err;
649 }
650
651 } else {
652 struct asoc_simple_card_info *cinfo;
653 struct snd_soc_dai_link_component *cpus;
654 struct snd_soc_dai_link_component *codecs;
655 struct snd_soc_dai_link_component *platform;
656 struct snd_soc_dai_link *dai_link = priv->dai_link;
657 struct simple_dai_props *dai_props = priv->dai_props;
658
659 cinfo = dev->platform_data;
660 if (!cinfo) {
661 dev_err(dev, "no info for asoc-simple-card\n");
662 return -EINVAL;
663 }
664
665 if (!cinfo->name ||
666 !cinfo->codec_dai.name ||
667 !cinfo->codec ||
668 !cinfo->platform ||
669 !cinfo->cpu_dai.name) {
670 dev_err(dev, "insufficient asoc_simple_card_info settings\n");
671 return -EINVAL;
672 }
673
674 cpus = dai_link->cpus;
675 cpus->dai_name = cinfo->cpu_dai.name;
676
677 codecs = dai_link->codecs;
678 codecs->name = cinfo->codec;
679 codecs->dai_name = cinfo->codec_dai.name;
680
681 platform = dai_link->platforms;
682 platform->name = cinfo->platform;
683
684 card->name = (cinfo->card) ? cinfo->card : cinfo->name;
685 dai_link->name = cinfo->name;
686 dai_link->stream_name = cinfo->name;
687 dai_link->dai_fmt = cinfo->daifmt;
688 dai_link->init = asoc_simple_dai_init;
689 memcpy(dai_props->cpu_dai, &cinfo->cpu_dai,
690 sizeof(*dai_props->cpu_dai));
691 memcpy(dai_props->codec_dai, &cinfo->codec_dai,
692 sizeof(*dai_props->codec_dai));
693 }
694
695 snd_soc_card_set_drvdata(card, priv);
696
697 asoc_simple_debug_info(priv);
698
699 ret = devm_snd_soc_register_card(dev, card);
700 if (ret < 0)
701 goto err;
702
703 devm_kfree(dev, li);
704 return 0;
705 err:
706 asoc_simple_clean_reference(card);
707
708 return ret;
709 }
710
711 static const struct of_device_id simple_of_match[] = {
712 { .compatible = "simple-audio-card", },
713 { .compatible = "simple-scu-audio-card",
714 .data = (void *)DPCM_SELECTABLE },
715 {},
716 };
717 MODULE_DEVICE_TABLE(of, simple_of_match);
718
719 static struct platform_driver asoc_simple_card = {
720 .driver = {
721 .name = "asoc-simple-card",
722 .pm = &snd_soc_pm_ops,
723 .of_match_table = simple_of_match,
724 },
725 .probe = asoc_simple_probe,
726 .remove = asoc_simple_remove,
727 };
728
729 module_platform_driver(asoc_simple_card);
730
731 MODULE_ALIAS("platform:asoc-simple-card");
732 MODULE_LICENSE("GPL v2");
733 MODULE_DESCRIPTION("ASoC Simple Sound Card");
734 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
735