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