xref: /openbmc/linux/sound/soc/sh/rcar/src.c (revision c819e2cf)
1 /*
2  * Renesas R-Car SRC support
3  *
4  * Copyright (C) 2013 Renesas Solutions Corp.
5  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 #include "rsnd.h"
12 
13 #define SRC_NAME "src"
14 
15 struct rsnd_src {
16 	struct rsnd_src_platform_info *info; /* rcar_snd.h */
17 	struct rsnd_mod mod;
18 	struct clk *clk;
19 };
20 
21 #define RSND_SRC_NAME_SIZE 16
22 
23 #define rsnd_src_convert_rate(p) ((p)->info->convert_rate)
24 #define rsnd_mod_to_src(_mod)				\
25 	container_of((_mod), struct rsnd_src, mod)
26 #define rsnd_src_dma_available(src) \
27 	rsnd_dma_available(rsnd_mod_to_dma(&(src)->mod))
28 
29 #define for_each_rsnd_src(pos, priv, i)				\
30 	for ((i) = 0;						\
31 	     ((i) < rsnd_src_nr(priv)) &&			\
32 	     ((pos) = (struct rsnd_src *)(priv)->src + i);	\
33 	     i++)
34 
35 
36 /*
37  *		image of SRC (Sampling Rate Converter)
38  *
39  * 96kHz   <-> +-----+	48kHz	+-----+	 48kHz	+-------+
40  * 48kHz   <-> | SRC | <------>	| SSI |	<----->	| codec |
41  * 44.1kHz <-> +-----+		+-----+		+-------+
42  * ...
43  *
44  */
45 
46 /*
47  * src.c is caring...
48  *
49  * Gen1
50  *
51  * [mem] -> [SRU] -> [SSI]
52  *        |--------|
53  *
54  * Gen2
55  *
56  * [mem] -> [SRC] -> [SSIU] -> [SSI]
57  *        |-----------------|
58  */
59 
60 /*
61  *	How to use SRC bypass mode for debugging
62  *
63  * SRC has bypass mode, and it is useful for debugging.
64  * In Gen2 case,
65  * SRCm_MODE controls whether SRC is used or not
66  * SSI_MODE0 controls whether SSIU which receives SRC data
67  * is used or not.
68  * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC,
69  * but SRC bypass mode needs SSI_MODE0 only.
70  *
71  * This driver request
72  * struct rsnd_src_platform_info {
73  *	u32 convert_rate;
74  *	int dma_id;
75  * }
76  *
77  * rsnd_src_convert_rate() indicates
78  * above convert_rate, and it controls
79  * whether SRC is used or not.
80  *
81  * ex) doesn't use SRC
82  * static struct rsnd_dai_platform_info rsnd_dai = {
83  *	.playback = { .ssi = &rsnd_ssi[0], },
84  * };
85  *
86  * ex) uses SRC
87  * static struct rsnd_src_platform_info rsnd_src[] = {
88  *	RSND_SCU(48000, 0),
89  *	...
90  * };
91  * static struct rsnd_dai_platform_info rsnd_dai = {
92  *	.playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
93  * };
94  *
95  * ex) uses SRC bypass mode
96  * static struct rsnd_src_platform_info rsnd_src[] = {
97  *	RSND_SCU(0, 0),
98  *	...
99  * };
100  * static struct rsnd_dai_platform_info rsnd_dai = {
101  *	.playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
102  * };
103  *
104  */
105 
106 /*
107  *		Gen1/Gen2 common functions
108  */
109 int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
110 			struct rsnd_dai *rdai,
111 			int use_busif)
112 {
113 	struct rsnd_dai_stream *io = rsnd_mod_to_io(ssi_mod);
114 	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
115 	int ssi_id = rsnd_mod_id(ssi_mod);
116 
117 	/*
118 	 * SSI_MODE0
119 	 */
120 	rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id),
121 		      !use_busif << ssi_id);
122 
123 	/*
124 	 * SSI_MODE1
125 	 */
126 	if (rsnd_ssi_is_pin_sharing(ssi_mod)) {
127 		int shift = -1;
128 		switch (ssi_id) {
129 		case 1:
130 			shift = 0;
131 			break;
132 		case 2:
133 			shift = 2;
134 			break;
135 		case 4:
136 			shift = 16;
137 			break;
138 		}
139 
140 		if (shift >= 0)
141 			rsnd_mod_bset(ssi_mod, SSI_MODE1,
142 				      0x3 << shift,
143 				      rsnd_dai_is_clk_master(rdai) ?
144 				      0x2 << shift : 0x1 << shift);
145 	}
146 
147 	/*
148 	 * DMA settings for SSIU
149 	 */
150 	if (use_busif) {
151 		u32 val = 0x76543210;
152 		u32 mask = ~0;
153 
154 		rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR,
155 			       rsnd_get_adinr(ssi_mod));
156 		rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE,  1);
157 		rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1);
158 
159 		mask <<= runtime->channels * 4;
160 		val = val & mask;
161 
162 		switch (runtime->sample_bits) {
163 		case 16:
164 			val |= 0x67452301 & ~mask;
165 			break;
166 		case 32:
167 			val |= 0x76543210 & ~mask;
168 			break;
169 		}
170 		rsnd_mod_write(ssi_mod, BUSIF_DALIGN, val);
171 
172 	}
173 
174 	return 0;
175 }
176 
177 int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
178 		       struct rsnd_dai *rdai)
179 {
180 	/*
181 	 * DMA settings for SSIU
182 	 */
183 	rsnd_mod_write(ssi_mod, SSI_CTRL, 0);
184 
185 	return 0;
186 }
187 
188 int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod,
189 			    struct rsnd_dai *rdai)
190 {
191 	struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
192 
193 	if (rsnd_is_gen1(priv))
194 		return 0;
195 
196 	/* enable SSI interrupt if Gen2 */
197 	if (rsnd_ssi_is_dma_mode(ssi_mod))
198 		rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0e000000);
199 	else
200 		rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000);
201 
202 	return 0;
203 }
204 
205 int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod,
206 			    struct rsnd_dai *rdai)
207 {
208 	struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
209 
210 	if (rsnd_is_gen1(priv))
211 		return 0;
212 
213 	/* disable SSI interrupt if Gen2 */
214 	rsnd_mod_write(ssi_mod, INT_ENABLE, 0x00000000);
215 
216 	return 0;
217 }
218 
219 unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
220 				   struct rsnd_dai_stream *io,
221 				   struct snd_pcm_runtime *runtime)
222 {
223 	struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
224 	struct rsnd_src *src;
225 	unsigned int rate = 0;
226 
227 	if (src_mod) {
228 		src = rsnd_mod_to_src(src_mod);
229 
230 		/*
231 		 * return convert rate if SRC is used,
232 		 * otherwise, return runtime->rate as usual
233 		 */
234 		rate = rsnd_src_convert_rate(src);
235 	}
236 
237 	if (!rate)
238 		rate = runtime->rate;
239 
240 	return rate;
241 }
242 
243 static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
244 				     struct rsnd_dai *rdai)
245 {
246 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
247 	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
248 	struct rsnd_src *src = rsnd_mod_to_src(mod);
249 	u32 convert_rate = rsnd_src_convert_rate(src);
250 	u32 fsrate = 0;
251 
252 	if (convert_rate)
253 		fsrate = 0x0400000 / convert_rate * runtime->rate;
254 
255 	/* set/clear soft reset */
256 	rsnd_mod_write(mod, SRC_SWRSR, 0);
257 	rsnd_mod_write(mod, SRC_SWRSR, 1);
258 
259 	/* Set channel number and output bit length */
260 	rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod));
261 
262 	/* Enable the initial value of IFS */
263 	if (fsrate) {
264 		rsnd_mod_write(mod, SRC_IFSCR, 1);
265 
266 		/* Set initial value of IFS */
267 		rsnd_mod_write(mod, SRC_IFSVR, fsrate);
268 	}
269 
270 	/* use DMA transfer */
271 	rsnd_mod_write(mod, SRC_BUSIF_MODE, 1);
272 
273 	return 0;
274 }
275 
276 static int rsnd_src_init(struct rsnd_mod *mod,
277 			 struct rsnd_dai *rdai)
278 {
279 	struct rsnd_src *src = rsnd_mod_to_src(mod);
280 
281 	clk_prepare_enable(src->clk);
282 
283 	/*
284 	 * Initialize the operation of the SRC internal circuits
285 	 * see rsnd_src_start()
286 	 */
287 	rsnd_mod_write(mod, SRC_SRCIR, 1);
288 
289 	return 0;
290 }
291 
292 static int rsnd_src_quit(struct rsnd_mod *mod,
293 			 struct rsnd_dai *rdai)
294 {
295 	struct rsnd_src *src = rsnd_mod_to_src(mod);
296 
297 	clk_disable_unprepare(src->clk);
298 
299 	return 0;
300 }
301 
302 static int rsnd_src_start(struct rsnd_mod *mod)
303 {
304 	/*
305 	 * Cancel the initialization and operate the SRC function
306 	 * see rsnd_src_init()
307 	 */
308 	rsnd_mod_write(mod, SRC_SRCIR, 0);
309 
310 	return 0;
311 }
312 
313 static int rsnd_src_stop(struct rsnd_mod *mod)
314 {
315 	/* nothing to do */
316 	return 0;
317 }
318 
319 /*
320  *		Gen1 functions
321  */
322 static int rsnd_src_set_route_gen1(struct rsnd_mod *mod,
323 				   struct rsnd_dai *rdai)
324 {
325 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
326 	struct src_route_config {
327 		u32 mask;
328 		int shift;
329 	} routes[] = {
330 		{ 0xF,  0, }, /* 0 */
331 		{ 0xF,  4, }, /* 1 */
332 		{ 0xF,  8, }, /* 2 */
333 		{ 0x7, 12, }, /* 3 */
334 		{ 0x7, 16, }, /* 4 */
335 		{ 0x7, 20, }, /* 5 */
336 		{ 0x7, 24, }, /* 6 */
337 		{ 0x3, 28, }, /* 7 */
338 		{ 0x3, 30, }, /* 8 */
339 	};
340 	u32 mask;
341 	u32 val;
342 	int id;
343 
344 	id = rsnd_mod_id(mod);
345 	if (id < 0 || id >= ARRAY_SIZE(routes))
346 		return -EIO;
347 
348 	/*
349 	 * SRC_ROUTE_SELECT
350 	 */
351 	val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
352 	val = val		<< routes[id].shift;
353 	mask = routes[id].mask	<< routes[id].shift;
354 
355 	rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
356 
357 	return 0;
358 }
359 
360 static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod,
361 					    struct rsnd_dai *rdai)
362 {
363 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
364 	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
365 	struct rsnd_src *src = rsnd_mod_to_src(mod);
366 	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
367 	u32 convert_rate = rsnd_src_convert_rate(src);
368 	u32 mask;
369 	u32 val;
370 	int shift;
371 	int id = rsnd_mod_id(mod);
372 	int ret;
373 
374 	/*
375 	 * SRC_TIMING_SELECT
376 	 */
377 	shift	= (id % 4) * 8;
378 	mask	= 0x1F << shift;
379 
380 	/*
381 	 * ADG is used as source clock if SRC was used,
382 	 * then, SSI WS is used as destination clock.
383 	 * SSI WS is used as source clock if SRC is not used
384 	 * (when playback, source/destination become reverse when capture)
385 	 */
386 	ret = 0;
387 	if (convert_rate) {
388 		/* use ADG */
389 		val = 0;
390 		ret = rsnd_adg_set_convert_clk_gen1(priv, mod,
391 						    runtime->rate,
392 						    convert_rate);
393 	} else if (8 == id) {
394 		/* use SSI WS, but SRU8 is special */
395 		val = id << shift;
396 	} else {
397 		/* use SSI WS */
398 		val = (id + 1) << shift;
399 	}
400 
401 	if (ret < 0)
402 		return ret;
403 
404 	switch (id / 4) {
405 	case 0:
406 		rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
407 		break;
408 	case 1:
409 		rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
410 		break;
411 	case 2:
412 		rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
413 		break;
414 	}
415 
416 	return 0;
417 }
418 
419 static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
420 					  struct rsnd_dai *rdai)
421 {
422 	struct rsnd_src *src = rsnd_mod_to_src(mod);
423 	int ret;
424 
425 	ret = rsnd_src_set_convert_rate(mod, rdai);
426 	if (ret < 0)
427 		return ret;
428 
429 	/* Select SRC mode (fixed value) */
430 	rsnd_mod_write(mod, SRC_SRCCR, 0x00010110);
431 
432 	/* Set the restriction value of the FS ratio (98%) */
433 	rsnd_mod_write(mod, SRC_MNFSR,
434 		       rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
435 
436 	/* Gen1/Gen2 are not compatible */
437 	if (rsnd_src_convert_rate(src))
438 		rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
439 
440 	/* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
441 
442 	return 0;
443 }
444 
445 static int rsnd_src_probe_gen1(struct rsnd_mod *mod,
446 			      struct rsnd_dai *rdai)
447 {
448 	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
449 	struct device *dev = rsnd_priv_to_dev(priv);
450 
451 	dev_dbg(dev, "%s[%d] (Gen1) is probed\n",
452 		rsnd_mod_name(mod), rsnd_mod_id(mod));
453 
454 	return 0;
455 }
456 
457 static int rsnd_src_init_gen1(struct rsnd_mod *mod,
458 			      struct rsnd_dai *rdai)
459 {
460 	int ret;
461 
462 	ret = rsnd_src_init(mod, rdai);
463 	if (ret < 0)
464 		return ret;
465 
466 	ret = rsnd_src_set_route_gen1(mod, rdai);
467 	if (ret < 0)
468 		return ret;
469 
470 	ret = rsnd_src_set_convert_rate_gen1(mod, rdai);
471 	if (ret < 0)
472 		return ret;
473 
474 	ret = rsnd_src_set_convert_timing_gen1(mod, rdai);
475 	if (ret < 0)
476 		return ret;
477 
478 	return 0;
479 }
480 
481 static int rsnd_src_start_gen1(struct rsnd_mod *mod,
482 			       struct rsnd_dai *rdai)
483 {
484 	int id = rsnd_mod_id(mod);
485 
486 	rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id));
487 
488 	return rsnd_src_start(mod);
489 }
490 
491 static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
492 			      struct rsnd_dai *rdai)
493 {
494 	int id = rsnd_mod_id(mod);
495 
496 	rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0);
497 
498 	return rsnd_src_stop(mod);
499 }
500 
501 static struct rsnd_mod_ops rsnd_src_gen1_ops = {
502 	.name	= SRC_NAME,
503 	.probe	= rsnd_src_probe_gen1,
504 	.init	= rsnd_src_init_gen1,
505 	.quit	= rsnd_src_quit,
506 	.start	= rsnd_src_start_gen1,
507 	.stop	= rsnd_src_stop_gen1,
508 };
509 
510 /*
511  *		Gen2 functions
512  */
513 static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
514 					  struct rsnd_dai *rdai)
515 {
516 	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
517 	struct device *dev = rsnd_priv_to_dev(priv);
518 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
519 	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
520 	struct rsnd_src *src = rsnd_mod_to_src(mod);
521 	u32 convert_rate = rsnd_src_convert_rate(src);
522 	uint ratio;
523 	int ret;
524 
525 	/* 6 - 1/6 are very enough ratio for SRC_BSDSR */
526 	if (!convert_rate)
527 		ratio = 0;
528 	else if (convert_rate > runtime->rate)
529 		ratio = 100 * convert_rate / runtime->rate;
530 	else
531 		ratio = 100 * runtime->rate / convert_rate;
532 
533 	if (ratio > 600) {
534 		dev_err(dev, "FSO/FSI ratio error\n");
535 		return -EINVAL;
536 	}
537 
538 	ret = rsnd_src_set_convert_rate(mod, rdai);
539 	if (ret < 0)
540 		return ret;
541 
542 	rsnd_mod_write(mod, SRC_SRCCR, 0x00011110);
543 
544 	if (convert_rate) {
545 		/* Gen1/Gen2 are not compatible */
546 		rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
547 	}
548 
549 	switch (rsnd_mod_id(mod)) {
550 	case 5:
551 	case 6:
552 	case 7:
553 	case 8:
554 		rsnd_mod_write(mod, SRC_BSDSR, 0x02400000);
555 		break;
556 	default:
557 		rsnd_mod_write(mod, SRC_BSDSR, 0x01800000);
558 		break;
559 	}
560 
561 	rsnd_mod_write(mod, SRC_BSISR, 0x00100060);
562 
563 	return 0;
564 }
565 
566 static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod,
567 					    struct rsnd_dai *rdai)
568 {
569 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
570 	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
571 	struct rsnd_src *src = rsnd_mod_to_src(mod);
572 	u32 convert_rate = rsnd_src_convert_rate(src);
573 	int ret;
574 
575 	if (convert_rate)
576 		ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io,
577 						    runtime->rate,
578 						    convert_rate);
579 	else
580 		ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io);
581 
582 	return ret;
583 }
584 
585 static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
586 			       struct rsnd_dai *rdai)
587 {
588 	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
589 	struct rsnd_src *src = rsnd_mod_to_src(mod);
590 	struct device *dev = rsnd_priv_to_dev(priv);
591 	int ret;
592 
593 	ret = rsnd_dma_init(priv,
594 			    rsnd_mod_to_dma(mod),
595 			    rsnd_info_is_playback(priv, src),
596 			    src->info->dma_id);
597 	if (ret < 0)
598 		dev_err(dev, "%s[%d] (Gen2) failed\n",
599 			rsnd_mod_name(mod), rsnd_mod_id(mod));
600 	else
601 		dev_dbg(dev, "%s[%d] (Gen2) is probed\n",
602 			rsnd_mod_name(mod), rsnd_mod_id(mod));
603 
604 	return ret;
605 }
606 
607 static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
608 				struct rsnd_dai *rdai)
609 {
610 	rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod));
611 
612 	return 0;
613 }
614 
615 static int rsnd_src_init_gen2(struct rsnd_mod *mod,
616 			      struct rsnd_dai *rdai)
617 {
618 	int ret;
619 
620 	ret = rsnd_src_init(mod, rdai);
621 	if (ret < 0)
622 		return ret;
623 
624 	ret = rsnd_src_set_convert_rate_gen2(mod, rdai);
625 	if (ret < 0)
626 		return ret;
627 
628 	ret = rsnd_src_set_convert_timing_gen2(mod, rdai);
629 	if (ret < 0)
630 		return ret;
631 
632 	return 0;
633 }
634 
635 static int rsnd_src_start_gen2(struct rsnd_mod *mod,
636 			       struct rsnd_dai *rdai)
637 {
638 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
639 	struct rsnd_src *src = rsnd_mod_to_src(mod);
640 	u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11;
641 
642 	rsnd_dma_start(rsnd_mod_to_dma(&src->mod));
643 
644 	rsnd_mod_write(mod, SRC_CTRL, val);
645 
646 	return rsnd_src_start(mod);
647 }
648 
649 static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
650 			      struct rsnd_dai *rdai)
651 {
652 	struct rsnd_src *src = rsnd_mod_to_src(mod);
653 
654 	rsnd_mod_write(mod, SRC_CTRL, 0);
655 
656 	rsnd_dma_stop(rsnd_mod_to_dma(&src->mod));
657 
658 	return rsnd_src_stop(mod);
659 }
660 
661 static struct rsnd_mod_ops rsnd_src_gen2_ops = {
662 	.name	= SRC_NAME,
663 	.probe	= rsnd_src_probe_gen2,
664 	.remove	= rsnd_src_remove_gen2,
665 	.init	= rsnd_src_init_gen2,
666 	.quit	= rsnd_src_quit,
667 	.start	= rsnd_src_start_gen2,
668 	.stop	= rsnd_src_stop_gen2,
669 };
670 
671 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
672 {
673 	if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
674 		id = 0;
675 
676 	return &((struct rsnd_src *)(priv->src) + id)->mod;
677 }
678 
679 static void rsnd_of_parse_src(struct platform_device *pdev,
680 			      const struct rsnd_of_data *of_data,
681 			      struct rsnd_priv *priv)
682 {
683 	struct device_node *src_node;
684 	struct rcar_snd_info *info = rsnd_priv_to_info(priv);
685 	struct rsnd_src_platform_info *src_info;
686 	struct device *dev = &pdev->dev;
687 	int nr;
688 
689 	if (!of_data)
690 		return;
691 
692 	src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
693 	if (!src_node)
694 		return;
695 
696 	nr = of_get_child_count(src_node);
697 	if (!nr)
698 		goto rsnd_of_parse_src_end;
699 
700 	src_info = devm_kzalloc(dev,
701 				sizeof(struct rsnd_src_platform_info) * nr,
702 				GFP_KERNEL);
703 	if (!src_info) {
704 		dev_err(dev, "src info allocation error\n");
705 		goto rsnd_of_parse_src_end;
706 	}
707 
708 	info->src_info		= src_info;
709 	info->src_info_nr	= nr;
710 
711 rsnd_of_parse_src_end:
712 	of_node_put(src_node);
713 }
714 
715 int rsnd_src_probe(struct platform_device *pdev,
716 		   const struct rsnd_of_data *of_data,
717 		   struct rsnd_priv *priv)
718 {
719 	struct rcar_snd_info *info = rsnd_priv_to_info(priv);
720 	struct device *dev = rsnd_priv_to_dev(priv);
721 	struct rsnd_src *src;
722 	struct rsnd_mod_ops *ops;
723 	struct clk *clk;
724 	char name[RSND_SRC_NAME_SIZE];
725 	int i, nr;
726 
727 	ops = NULL;
728 	if (rsnd_is_gen1(priv))
729 		ops = &rsnd_src_gen1_ops;
730 	if (rsnd_is_gen2(priv))
731 		ops = &rsnd_src_gen2_ops;
732 	if (!ops) {
733 		dev_err(dev, "unknown Generation\n");
734 		return -EIO;
735 	}
736 
737 	rsnd_of_parse_src(pdev, of_data, priv);
738 
739 	/*
740 	 * init SRC
741 	 */
742 	nr	= info->src_info_nr;
743 	if (!nr)
744 		return 0;
745 
746 	src	= devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
747 	if (!src) {
748 		dev_err(dev, "SRC allocate failed\n");
749 		return -ENOMEM;
750 	}
751 
752 	priv->src_nr	= nr;
753 	priv->src	= src;
754 
755 	for_each_rsnd_src(src, priv, i) {
756 		snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
757 			 SRC_NAME, i);
758 
759 		clk = devm_clk_get(dev, name);
760 		if (IS_ERR(clk))
761 			return PTR_ERR(clk);
762 
763 		src->info = &info->src_info[i];
764 		src->clk = clk;
765 
766 		rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i);
767 
768 		dev_dbg(dev, "SRC%d probed\n", i);
769 	}
770 
771 	return 0;
772 }
773