xref: /linux/sound/soc/generic/audio-graph-card.c (revision 6e7fd890f1d6ac83805409e9c346240de2705584)
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/cleanup.h>
11 #include <linux/clk.h>
12 #include <linux/device.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/module.h>
15 #include <linux/of.h>
16 #include <linux/of_graph.h>
17 #include <linux/platform_device.h>
18 #include <linux/string.h>
19 #include <sound/graph_card.h>
20 
21 #define DPCM_SELECTABLE 1
22 
23 #define ep_to_port(ep)	of_get_parent(ep)
24 static struct device_node *port_to_ports(struct device_node *port)
25 {
26 	struct device_node *ports = of_get_parent(port);
27 
28 	if (!of_node_name_eq(ports, "ports")) {
29 		of_node_put(ports);
30 		return NULL;
31 	}
32 	return ports;
33 }
34 
35 static int graph_outdrv_event(struct snd_soc_dapm_widget *w,
36 			      struct snd_kcontrol *kcontrol,
37 			      int event)
38 {
39 	struct snd_soc_dapm_context *dapm = w->dapm;
40 	struct simple_util_priv *priv = snd_soc_card_get_drvdata(dapm->card);
41 
42 	switch (event) {
43 	case SND_SOC_DAPM_POST_PMU:
44 		gpiod_set_value_cansleep(priv->pa_gpio, 1);
45 		break;
46 	case SND_SOC_DAPM_PRE_PMD:
47 		gpiod_set_value_cansleep(priv->pa_gpio, 0);
48 		break;
49 	default:
50 		return -EINVAL;
51 	}
52 
53 	return 0;
54 }
55 
56 static const struct snd_soc_dapm_widget graph_dapm_widgets[] = {
57 	SND_SOC_DAPM_OUT_DRV_E("Amplifier", SND_SOC_NOPM,
58 			       0, 0, NULL, 0, graph_outdrv_event,
59 			       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
60 };
61 
62 static const struct snd_soc_ops graph_ops = {
63 	.startup	= simple_util_startup,
64 	.shutdown	= simple_util_shutdown,
65 	.hw_params	= simple_util_hw_params,
66 };
67 
68 static bool soc_component_is_pcm(struct snd_soc_dai_link_component *dlc)
69 {
70 	struct snd_soc_dai *dai = snd_soc_find_dai_with_mutex(dlc);
71 
72 	if (dai && (dai->component->driver->pcm_construct ||
73 		    (dai->driver->ops && dai->driver->ops->pcm_new)))
74 		return true;
75 
76 	return false;
77 }
78 
79 static void graph_parse_convert(struct device *dev,
80 				struct device_node *ep,
81 				struct simple_util_data *adata)
82 {
83 	struct device_node *top = dev->of_node;
84 	struct device_node *port = ep_to_port(ep);
85 	struct device_node *ports = port_to_ports(port);
86 	struct device_node *node = of_graph_get_port_parent(ep);
87 
88 	simple_util_parse_convert(top,   NULL,   adata);
89 	simple_util_parse_convert(ports, NULL,   adata);
90 	simple_util_parse_convert(port,  NULL,   adata);
91 	simple_util_parse_convert(ep,    NULL,   adata);
92 
93 	of_node_put(port);
94 	of_node_put(ports);
95 	of_node_put(node);
96 }
97 
98 static int graph_parse_node(struct simple_util_priv *priv,
99 			    struct device_node *ep,
100 			    struct link_info *li,
101 			    int *cpu)
102 {
103 	struct device *dev = simple_priv_to_dev(priv);
104 	struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
105 	struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
106 	struct snd_soc_dai_link_component *dlc;
107 	struct simple_util_dai *dai;
108 	int ret;
109 
110 	if (cpu) {
111 		dlc = snd_soc_link_to_cpu(dai_link, 0);
112 		dai = simple_props_to_dai_cpu(dai_props, 0);
113 	} else {
114 		dlc = snd_soc_link_to_codec(dai_link, 0);
115 		dai = simple_props_to_dai_codec(dai_props, 0);
116 	}
117 
118 	ret = graph_util_parse_dai(dev, ep, dlc, cpu);
119 	if (ret < 0)
120 		return ret;
121 
122 	ret = simple_util_parse_tdm(ep, dai);
123 	if (ret < 0)
124 		return ret;
125 
126 	ret = simple_util_parse_clk(dev, ep, dai, dlc);
127 	if (ret < 0)
128 		return ret;
129 
130 	return 0;
131 }
132 
133 static int graph_link_init(struct simple_util_priv *priv,
134 			   struct device_node *ep_cpu,
135 			   struct device_node *ep_codec,
136 			   struct link_info *li,
137 			   char *name)
138 {
139 	struct device *dev = simple_priv_to_dev(priv);
140 	struct device_node *top = dev->of_node;
141 	struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
142 	struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
143 	struct device_node *port_cpu = ep_to_port(ep_cpu);
144 	struct device_node *port_codec = ep_to_port(ep_codec);
145 	struct device_node *ports_cpu = port_to_ports(port_cpu);
146 	struct device_node *ports_codec = port_to_ports(port_codec);
147 	enum snd_soc_trigger_order trigger_start = SND_SOC_TRIGGER_ORDER_DEFAULT;
148 	enum snd_soc_trigger_order trigger_stop  = SND_SOC_TRIGGER_ORDER_DEFAULT;
149 	bool playback_only = 0, capture_only = 0;
150 	int ret;
151 
152 	ret = simple_util_parse_daifmt(dev, ep_cpu, ep_codec,
153 				       NULL, &dai_link->dai_fmt);
154 	if (ret < 0)
155 		goto init_end;
156 
157 	graph_util_parse_link_direction(top,		&playback_only, &capture_only);
158 	graph_util_parse_link_direction(port_cpu,	&playback_only, &capture_only);
159 	graph_util_parse_link_direction(port_codec,	&playback_only, &capture_only);
160 	graph_util_parse_link_direction(ep_cpu,		&playback_only, &capture_only);
161 	graph_util_parse_link_direction(ep_codec,	&playback_only, &capture_only);
162 
163 	of_property_read_u32(top,		"mclk-fs", &dai_props->mclk_fs);
164 	of_property_read_u32(ports_cpu,		"mclk-fs", &dai_props->mclk_fs);
165 	of_property_read_u32(ports_codec,	"mclk-fs", &dai_props->mclk_fs);
166 	of_property_read_u32(port_cpu,		"mclk-fs", &dai_props->mclk_fs);
167 	of_property_read_u32(port_codec,	"mclk-fs", &dai_props->mclk_fs);
168 	of_property_read_u32(ep_cpu,		"mclk-fs", &dai_props->mclk_fs);
169 	of_property_read_u32(ep_codec,		"mclk-fs", &dai_props->mclk_fs);
170 
171 	graph_util_parse_trigger_order(priv, top,		&trigger_start, &trigger_stop);
172 	graph_util_parse_trigger_order(priv, ports_cpu,		&trigger_start, &trigger_stop);
173 	graph_util_parse_trigger_order(priv, ports_codec,	&trigger_start, &trigger_stop);
174 	graph_util_parse_trigger_order(priv, port_cpu,		&trigger_start, &trigger_stop);
175 	graph_util_parse_trigger_order(priv, port_cpu,		&trigger_start, &trigger_stop);
176 	graph_util_parse_trigger_order(priv, ep_cpu,		&trigger_start, &trigger_stop);
177 	graph_util_parse_trigger_order(priv, ep_codec,		&trigger_start, &trigger_stop);
178 
179 	dai_link->playback_only	= playback_only;
180 	dai_link->capture_only	= capture_only;
181 
182 	dai_link->trigger_start	= trigger_start;
183 	dai_link->trigger_stop	= trigger_stop;
184 
185 	dai_link->init		= simple_util_dai_init;
186 	dai_link->ops		= &graph_ops;
187 	if (priv->ops)
188 		dai_link->ops	= priv->ops;
189 
190 	ret = simple_util_set_dailink_name(dev, dai_link, name);
191 init_end:
192 	of_node_put(ports_cpu);
193 	of_node_put(ports_codec);
194 	of_node_put(port_cpu);
195 	of_node_put(port_codec);
196 
197 	return ret;
198 }
199 
200 static int graph_dai_link_of_dpcm(struct simple_util_priv *priv,
201 				  struct device_node *cpu_ep,
202 				  struct device_node *codec_ep,
203 				  struct link_info *li)
204 {
205 	struct device *dev = simple_priv_to_dev(priv);
206 	struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
207 	struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
208 	struct device_node *top = dev->of_node;
209 	struct device_node *ep = li->cpu ? cpu_ep : codec_ep;
210 	char dai_name[64];
211 	int ret;
212 
213 	dev_dbg(dev, "link_of DPCM (%pOF)\n", ep);
214 
215 	if (li->cpu) {
216 		struct snd_soc_card *card = simple_priv_to_card(priv);
217 		struct snd_soc_dai_link_component *cpus = snd_soc_link_to_cpu(dai_link, 0);
218 		struct snd_soc_dai_link_component *platforms = snd_soc_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 = graph_parse_node(priv, cpu_ep, li, &is_single_links);
228 		if (ret)
229 			return ret;
230 
231 		snprintf(dai_name, sizeof(dai_name),
232 			 "fe.%pOFP.%s", cpus->of_node, cpus->dai_name);
233 		/*
234 		 * In BE<->BE connections it is not required to create
235 		 * PCM devices at CPU end of the dai link and thus 'no_pcm'
236 		 * flag needs to be set. It is useful when there are many
237 		 * BE components and some of these have to be connected to
238 		 * form a valid audio path.
239 		 *
240 		 * For example: FE <-> BE1 <-> BE2 <-> ... <-> BEn where
241 		 * there are 'n' BE components in the path.
242 		 */
243 		if (card->component_chaining && !soc_component_is_pcm(cpus)) {
244 			dai_link->no_pcm = 1;
245 			dai_link->be_hw_params_fixup = simple_util_be_hw_params_fixup;
246 		}
247 
248 		simple_util_canonicalize_cpu(cpus, is_single_links);
249 		simple_util_canonicalize_platform(platforms, cpus);
250 	} else {
251 		struct snd_soc_codec_conf *cconf = simple_props_to_codec_conf(dai_props, 0);
252 		struct snd_soc_dai_link_component *codecs = snd_soc_link_to_codec(dai_link, 0);
253 		struct device_node *port;
254 		struct device_node *ports;
255 
256 		/* CPU is dummy */
257 
258 		/* BE settings */
259 		dai_link->no_pcm		= 1;
260 		dai_link->be_hw_params_fixup	= simple_util_be_hw_params_fixup;
261 
262 		ret = graph_parse_node(priv, codec_ep, li, NULL);
263 		if (ret < 0)
264 			return ret;
265 
266 		snprintf(dai_name, sizeof(dai_name),
267 			 "be.%pOFP.%s", codecs->of_node, codecs->dai_name);
268 
269 		/* check "prefix" from top node */
270 		port  = ep_to_port(ep);
271 		ports = port_to_ports(port);
272 		snd_soc_of_parse_node_prefix(top,   cconf, codecs->of_node, "prefix");
273 		snd_soc_of_parse_node_prefix(ports, cconf, codecs->of_node, "prefix");
274 		snd_soc_of_parse_node_prefix(port,  cconf, codecs->of_node, "prefix");
275 
276 		of_node_put(ports);
277 		of_node_put(port);
278 	}
279 
280 	graph_parse_convert(dev, ep, &dai_props->adata);
281 
282 	snd_soc_dai_link_set_capabilities(dai_link);
283 
284 	ret = graph_link_init(priv, cpu_ep, codec_ep, li, dai_name);
285 
286 	li->link++;
287 
288 	return ret;
289 }
290 
291 static int graph_dai_link_of(struct simple_util_priv *priv,
292 			     struct device_node *cpu_ep,
293 			     struct device_node *codec_ep,
294 			     struct link_info *li)
295 {
296 	struct device *dev = simple_priv_to_dev(priv);
297 	struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
298 	struct snd_soc_dai_link_component *cpus = snd_soc_link_to_cpu(dai_link, 0);
299 	struct snd_soc_dai_link_component *codecs = snd_soc_link_to_codec(dai_link, 0);
300 	struct snd_soc_dai_link_component *platforms = snd_soc_link_to_platform(dai_link, 0);
301 	char dai_name[64];
302 	int ret, is_single_links = 0;
303 
304 	dev_dbg(dev, "link_of (%pOF)\n", cpu_ep);
305 
306 	ret = graph_parse_node(priv, cpu_ep, li, &is_single_links);
307 	if (ret < 0)
308 		return ret;
309 
310 	ret = graph_parse_node(priv, codec_ep, li, NULL);
311 	if (ret < 0)
312 		return ret;
313 
314 	snprintf(dai_name, sizeof(dai_name),
315 		 "%s-%s", cpus->dai_name, codecs->dai_name);
316 
317 	simple_util_canonicalize_cpu(cpus, is_single_links);
318 	simple_util_canonicalize_platform(platforms, cpus);
319 
320 	ret = graph_link_init(priv, cpu_ep, codec_ep, li, dai_name);
321 	if (ret < 0)
322 		return ret;
323 
324 	li->link++;
325 
326 	return 0;
327 }
328 
329 static inline bool parse_as_dpcm_link(struct simple_util_priv *priv,
330 				      struct device_node *codec_port,
331 				      struct simple_util_data *adata)
332 {
333 	if (priv->force_dpcm)
334 		return true;
335 
336 	if (!priv->dpcm_selectable)
337 		return false;
338 
339 	/*
340 	 * It is DPCM
341 	 * if Codec port has many endpoints,
342 	 * or has convert-xxx property
343 	 */
344 	if ((of_get_child_count(codec_port) > 1) ||
345 	    simple_util_is_convert_required(adata))
346 		return true;
347 
348 	return false;
349 }
350 
351 static int __graph_for_each_link(struct simple_util_priv *priv,
352 			struct link_info *li,
353 			int (*func_noml)(struct simple_util_priv *priv,
354 					 struct device_node *cpu_ep,
355 					 struct device_node *codec_ep,
356 					 struct link_info *li),
357 			int (*func_dpcm)(struct simple_util_priv *priv,
358 					 struct device_node *cpu_ep,
359 					 struct device_node *codec_ep,
360 					 struct link_info *li))
361 {
362 	struct of_phandle_iterator it;
363 	struct device *dev = simple_priv_to_dev(priv);
364 	struct device_node *node = dev->of_node;
365 	struct device_node *cpu_port;
366 	struct device_node *cpu_ep;
367 	struct device_node *codec_ep;
368 	struct device_node *codec_port;
369 	struct device_node *codec_port_old = NULL;
370 	struct simple_util_data adata;
371 	int rc, ret = 0;
372 
373 	/* loop for all listed CPU port */
374 	of_for_each_phandle(&it, rc, node, "dais", NULL, 0) {
375 		cpu_port = it.node;
376 		cpu_ep	 = NULL;
377 
378 		/* loop for all CPU endpoint */
379 		while (1) {
380 			cpu_ep = of_get_next_child(cpu_port, cpu_ep);
381 			if (!cpu_ep)
382 				break;
383 
384 			/* get codec */
385 			codec_ep = of_graph_get_remote_endpoint(cpu_ep);
386 			codec_port = ep_to_port(codec_ep);
387 
388 			/* get convert-xxx property */
389 			memset(&adata, 0, sizeof(adata));
390 			graph_parse_convert(dev, codec_ep, &adata);
391 			graph_parse_convert(dev, cpu_ep,   &adata);
392 
393 			/* check if link requires DPCM parsing */
394 			if (parse_as_dpcm_link(priv, codec_port, &adata)) {
395 				/*
396 				 * Codec endpoint can be NULL for pluggable audio HW.
397 				 * Platform DT can populate the Codec endpoint depending on the
398 				 * plugged HW.
399 				 */
400 				/* Do it all CPU endpoint, and 1st Codec endpoint */
401 				if (li->cpu ||
402 				    ((codec_port_old != codec_port) && codec_ep))
403 					ret = func_dpcm(priv, cpu_ep, codec_ep, li);
404 			/* else normal sound */
405 			} else {
406 				if (li->cpu)
407 					ret = func_noml(priv, cpu_ep, codec_ep, li);
408 			}
409 
410 			of_node_put(codec_ep);
411 			of_node_put(codec_port);
412 
413 			if (ret < 0) {
414 				of_node_put(cpu_ep);
415 				return ret;
416 			}
417 
418 			codec_port_old = codec_port;
419 		}
420 	}
421 
422 	return 0;
423 }
424 
425 static int graph_for_each_link(struct simple_util_priv *priv,
426 			       struct link_info *li,
427 			       int (*func_noml)(struct simple_util_priv *priv,
428 						struct device_node *cpu_ep,
429 						struct device_node *codec_ep,
430 						struct link_info *li),
431 			       int (*func_dpcm)(struct simple_util_priv *priv,
432 						struct device_node *cpu_ep,
433 						struct device_node *codec_ep,
434 						struct link_info *li))
435 {
436 	int ret;
437 	/*
438 	 * Detect all CPU first, and Detect all Codec 2nd.
439 	 *
440 	 * In Normal sound case, all DAIs are detected
441 	 * as "CPU-Codec".
442 	 *
443 	 * In DPCM sound case,
444 	 * all CPUs   are detected as "CPU-dummy", and
445 	 * all Codecs are detected as "dummy-Codec".
446 	 * To avoid random sub-device numbering,
447 	 * detect "dummy-Codec" in last;
448 	 */
449 	for (li->cpu = 1; li->cpu >= 0; li->cpu--) {
450 		ret = __graph_for_each_link(priv, li, func_noml, func_dpcm);
451 		if (ret < 0)
452 			break;
453 	}
454 
455 	return ret;
456 }
457 
458 static int graph_count_noml(struct simple_util_priv *priv,
459 			    struct device_node *cpu_ep,
460 			    struct device_node *codec_ep,
461 			    struct link_info *li)
462 {
463 	struct device *dev = simple_priv_to_dev(priv);
464 
465 	if (li->link >= SNDRV_MAX_LINKS) {
466 		dev_err(dev, "too many links\n");
467 		return -EINVAL;
468 	}
469 
470 	/*
471 	 * DON'T REMOVE platforms
472 	 * see
473 	 *	simple-card.c :: simple_count_noml()
474 	 */
475 	li->num[li->link].cpus		= 1;
476 	li->num[li->link].platforms     = 1;
477 
478 	li->num[li->link].codecs	= 1;
479 
480 	li->link += 1; /* 1xCPU-Codec */
481 
482 	dev_dbg(dev, "Count As Normal\n");
483 
484 	return 0;
485 }
486 
487 static int graph_count_dpcm(struct simple_util_priv *priv,
488 			    struct device_node *cpu_ep,
489 			    struct device_node *codec_ep,
490 			    struct link_info *li)
491 {
492 	struct device *dev = simple_priv_to_dev(priv);
493 
494 	if (li->link >= SNDRV_MAX_LINKS) {
495 		dev_err(dev, "too many links\n");
496 		return -EINVAL;
497 	}
498 
499 	if (li->cpu) {
500 		/*
501 		 * DON'T REMOVE platforms
502 		 * see
503 		 *	simple-card.c :: simple_count_noml()
504 		 */
505 		li->num[li->link].cpus		= 1;
506 		li->num[li->link].platforms     = 1;
507 
508 		li->link++; /* 1xCPU-dummy */
509 	} else {
510 		li->num[li->link].codecs	= 1;
511 
512 		li->link++; /* 1xdummy-Codec */
513 	}
514 
515 	dev_dbg(dev, "Count As DPCM\n");
516 
517 	return 0;
518 }
519 
520 static int graph_get_dais_count(struct simple_util_priv *priv,
521 				struct link_info *li)
522 {
523 	/*
524 	 * link_num :	number of links.
525 	 *		CPU-Codec / CPU-dummy / dummy-Codec
526 	 * dais_num :	number of DAIs
527 	 * ccnf_num :	number of codec_conf
528 	 *		same number for "dummy-Codec"
529 	 *
530 	 * ex1)
531 	 * CPU0 --- Codec0	link : 5
532 	 * CPU1 --- Codec1	dais : 7
533 	 * CPU2 -/		ccnf : 1
534 	 * CPU3 --- Codec2
535 	 *
536 	 *	=> 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec
537 	 *	=> 7 DAIs  = 4xCPU + 3xCodec
538 	 *	=> 1 ccnf  = 1xdummy-Codec
539 	 *
540 	 * ex2)
541 	 * CPU0 --- Codec0	link : 5
542 	 * CPU1 --- Codec1	dais : 6
543 	 * CPU2 -/		ccnf : 1
544 	 * CPU3 -/
545 	 *
546 	 *	=> 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec
547 	 *	=> 6 DAIs  = 4xCPU + 2xCodec
548 	 *	=> 1 ccnf  = 1xdummy-Codec
549 	 *
550 	 * ex3)
551 	 * CPU0 --- Codec0	link : 6
552 	 * CPU1 -/		dais : 6
553 	 * CPU2 --- Codec1	ccnf : 2
554 	 * CPU3 -/
555 	 *
556 	 *	=> 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec
557 	 *	=> 6 DAIs  = 4xCPU + 2xCodec
558 	 *	=> 2 ccnf  = 2xdummy-Codec
559 	 *
560 	 * ex4)
561 	 * CPU0 --- Codec0 (convert-rate)	link : 3
562 	 * CPU1 --- Codec1			dais : 4
563 	 *					ccnf : 1
564 	 *
565 	 *	=> 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec
566 	 *	=> 4 DAIs  = 2xCPU + 2xCodec
567 	 *	=> 1 ccnf  = 1xdummy-Codec
568 	 */
569 	return graph_for_each_link(priv, li,
570 				   graph_count_noml,
571 				   graph_count_dpcm);
572 }
573 
574 int audio_graph_parse_of(struct simple_util_priv *priv, struct device *dev)
575 {
576 	struct snd_soc_card *card = simple_priv_to_card(priv);
577 	int ret;
578 
579 	struct link_info *li __free(kfree) = kzalloc(sizeof(*li), GFP_KERNEL);
580 	if (!li)
581 		return -ENOMEM;
582 
583 	card->owner = THIS_MODULE;
584 	card->dev = dev;
585 
586 	ret = graph_get_dais_count(priv, li);
587 	if (ret < 0)
588 		return ret;
589 
590 	if (!li->link)
591 		return -EINVAL;
592 
593 	ret = simple_util_init_priv(priv, li);
594 	if (ret < 0)
595 		return ret;
596 
597 	priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW);
598 	if (IS_ERR(priv->pa_gpio)) {
599 		ret = PTR_ERR(priv->pa_gpio);
600 		dev_err(dev, "failed to get amplifier gpio: %d\n", ret);
601 		return ret;
602 	}
603 
604 	ret = simple_util_parse_widgets(card, NULL);
605 	if (ret < 0)
606 		return ret;
607 
608 	ret = simple_util_parse_routing(card, NULL);
609 	if (ret < 0)
610 		return ret;
611 
612 	memset(li, 0, sizeof(*li));
613 	ret = graph_for_each_link(priv, li,
614 				  graph_dai_link_of,
615 				  graph_dai_link_of_dpcm);
616 	if (ret < 0)
617 		goto err;
618 
619 	ret = simple_util_parse_card_name(card, NULL);
620 	if (ret < 0)
621 		goto err;
622 
623 	snd_soc_card_set_drvdata(card, priv);
624 
625 	simple_util_debug_info(priv);
626 
627 	ret = devm_snd_soc_register_card(dev, card);
628 	if (ret < 0)
629 		goto err;
630 
631 	return 0;
632 
633 err:
634 	simple_util_clean_reference(card);
635 
636 	return dev_err_probe(dev, ret, "parse error\n");
637 }
638 EXPORT_SYMBOL_GPL(audio_graph_parse_of);
639 
640 static int graph_probe(struct platform_device *pdev)
641 {
642 	struct simple_util_priv *priv;
643 	struct device *dev = &pdev->dev;
644 	struct snd_soc_card *card;
645 
646 	/* Allocate the private data and the DAI link array */
647 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
648 	if (!priv)
649 		return -ENOMEM;
650 
651 	card = simple_priv_to_card(priv);
652 	card->dapm_widgets	= graph_dapm_widgets;
653 	card->num_dapm_widgets	= ARRAY_SIZE(graph_dapm_widgets);
654 	card->probe		= graph_util_card_probe;
655 
656 	if (of_device_get_match_data(dev))
657 		priv->dpcm_selectable = 1;
658 
659 	return audio_graph_parse_of(priv, dev);
660 }
661 
662 static const struct of_device_id graph_of_match[] = {
663 	{ .compatible = "audio-graph-card", },
664 	{ .compatible = "audio-graph-scu-card",
665 	  .data = (void *)DPCM_SELECTABLE },
666 	{},
667 };
668 MODULE_DEVICE_TABLE(of, graph_of_match);
669 
670 static struct platform_driver graph_card = {
671 	.driver = {
672 		.name = "asoc-audio-graph-card",
673 		.pm = &snd_soc_pm_ops,
674 		.of_match_table = graph_of_match,
675 	},
676 	.probe = graph_probe,
677 	.remove_new = simple_util_remove,
678 };
679 module_platform_driver(graph_card);
680 
681 MODULE_ALIAS("platform:asoc-audio-graph-card");
682 MODULE_LICENSE("GPL v2");
683 MODULE_DESCRIPTION("ASoC Audio Graph Sound Card");
684 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
685