File Index
Files and directories
Sign in
FILE

src.c

File preview with syntax highlighting.

linux-6.19.14/sound/soc/renesas/rcar/src.c C
  1// SPDX-License-Identifier: GPL-2.0
  2//
  3// Renesas R-Car SRC support
  4//
  5// Copyright (C) 2013 Renesas Solutions Corp.
  6// Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  7
  8/*
  9 * You can use Synchronous Sampling Rate Convert (if no DVC)
 10 *
 11 *	amixer set "SRC Out Rate" on
 12 *	aplay xxx.wav &
 13 *	amixer set "SRC Out Rate" 96000 // convert rate to 96000Hz
 14 *	amixer set "SRC Out Rate" 22050 // convert rate to 22050Hz
 15 */
 16
 17/*
 18 * you can enable below define if you don't need
 19 * SSI interrupt status debug message when debugging
 20 * see rsnd_print_irq_status()
 21 *
 22 * #define RSND_DEBUG_NO_IRQ_STATUS 1
 23 */
 24
 25#include <linux/of_irq.h>
 26#include "rsnd.h"
 27
 28#define SRC_NAME "src"
 29
 30/* SCU_SYSTEM_STATUS0/1 */
 31#define OUF_SRC(id)	((1 << (id + 16)) | (1 << id))
 32
 33struct rsnd_src {
 34	struct rsnd_mod mod;
 35	struct rsnd_mod *dma;
 36	struct rsnd_kctrl_cfg_s sen;  /* sync convert enable */
 37	struct rsnd_kctrl_cfg_s sync; /* sync convert */
 38	u32 current_sync_rate;
 39	int irq;
 40};
 41
 42#define RSND_SRC_NAME_SIZE 16
 43
 44#define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id)
 45#define rsnd_src_nr(priv) ((priv)->src_nr)
 46#define rsnd_src_sync_is_enabled(mod) (rsnd_mod_to_src(mod)->sen.val)
 47
 48#define rsnd_mod_to_src(_mod)				\
 49	container_of((_mod), struct rsnd_src, mod)
 50
 51#define for_each_rsnd_src(pos, priv, i)				\
 52	for ((i) = 0;						\
 53	     ((i) < rsnd_src_nr(priv)) &&			\
 54	     ((pos) = (struct rsnd_src *)(priv)->src + i);	\
 55	     i++)
 56
 57
 58/*
 59 *		image of SRC (Sampling Rate Converter)
 60 *
 61 * 96kHz   <-> +-----+	48kHz	+-----+	 48kHz	+-------+
 62 * 48kHz   <-> | SRC | <------>	| SSI |	<----->	| codec |
 63 * 44.1kHz <-> +-----+		+-----+		+-------+
 64 * ...
 65 *
 66 */
 67
 68static void rsnd_src_activation(struct rsnd_mod *mod)
 69{
 70	rsnd_mod_write(mod, SRC_SWRSR, 0);
 71	rsnd_mod_write(mod, SRC_SWRSR, 1);
 72}
 73
 74static void rsnd_src_halt(struct rsnd_mod *mod)
 75{
 76	rsnd_mod_write(mod, SRC_SRCIR, 1);
 77	rsnd_mod_write(mod, SRC_SWRSR, 0);
 78}
 79
 80static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io,
 81					 struct rsnd_mod *mod)
 82{
 83	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
 84	int is_play = rsnd_io_is_play(io);
 85
 86	return rsnd_dma_request_channel(rsnd_src_of_node(priv),
 87					SRC_NAME, mod,
 88					is_play ? "rx" : "tx");
 89}
 90
 91static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io,
 92				 struct rsnd_mod *mod)
 93{
 94	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
 95	struct rsnd_src *src = rsnd_mod_to_src(mod);
 96	u32 convert_rate;
 97
 98	if (!runtime)
 99		return 0;
100
101	if (!rsnd_src_sync_is_enabled(mod))
102		return rsnd_io_converted_rate(io);
103
104	convert_rate = src->current_sync_rate;
105
106	if (!convert_rate)
107		convert_rate = rsnd_io_converted_rate(io);
108
109	if (!convert_rate)
110		convert_rate = runtime->rate;
111
112	return convert_rate;
113}
114
115unsigned int rsnd_src_get_rate(struct rsnd_priv *priv,
116			       struct rsnd_dai_stream *io,
117			       int is_in)
118{
119	struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
120	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
121	unsigned int rate = 0;
122	int is_play = rsnd_io_is_play(io);
123
124	/*
125	 * Playback
126	 * runtime_rate -> [SRC] -> convert_rate
127	 *
128	 * Capture
129	 * convert_rate -> [SRC] -> runtime_rate
130	 */
131
132	if (is_play == is_in)
133		return runtime->rate;
134
135	/*
136	 * return convert rate if SRC is used,
137	 * otherwise, return runtime->rate as usual
138	 */
139	if (src_mod)
140		rate = rsnd_src_convert_rate(io, src_mod);
141
142	if (!rate)
143		rate = runtime->rate;
144
145	return rate;
146}
147
148static const u32 bsdsr_table_pattern1[] = {
149	0x01800000, /* 6 - 1/6 */
150	0x01000000, /* 6 - 1/4 */
151	0x00c00000, /* 6 - 1/3 */
152	0x00800000, /* 6 - 1/2 */
153	0x00600000, /* 6 - 2/3 */
154	0x00400000, /* 6 - 1   */
155};
156
157static const u32 bsdsr_table_pattern2[] = {
158	0x02400000, /* 6 - 1/6 */
159	0x01800000, /* 6 - 1/4 */
160	0x01200000, /* 6 - 1/3 */
161	0x00c00000, /* 6 - 1/2 */
162	0x00900000, /* 6 - 2/3 */
163	0x00600000, /* 6 - 1   */
164};
165
166static const u32 bsisr_table[] = {
167	0x00100060, /* 6 - 1/6 */
168	0x00100040, /* 6 - 1/4 */
169	0x00100030, /* 6 - 1/3 */
170	0x00100020, /* 6 - 1/2 */
171	0x00100020, /* 6 - 2/3 */
172	0x00100020, /* 6 - 1   */
173};
174
175static const u32 chan288888[] = {
176	0x00000006, /* 1 to 2 */
177	0x000001fe, /* 1 to 8 */
178	0x000001fe, /* 1 to 8 */
179	0x000001fe, /* 1 to 8 */
180	0x000001fe, /* 1 to 8 */
181	0x000001fe, /* 1 to 8 */
182};
183
184static const u32 chan244888[] = {
185	0x00000006, /* 1 to 2 */
186	0x0000001e, /* 1 to 4 */
187	0x0000001e, /* 1 to 4 */
188	0x000001fe, /* 1 to 8 */
189	0x000001fe, /* 1 to 8 */
190	0x000001fe, /* 1 to 8 */
191};
192
193static const u32 chan222222[] = {
194	0x00000006, /* 1 to 2 */
195	0x00000006, /* 1 to 2 */
196	0x00000006, /* 1 to 2 */
197	0x00000006, /* 1 to 2 */
198	0x00000006, /* 1 to 2 */
199	0x00000006, /* 1 to 2 */
200};
201
202static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
203				      struct rsnd_mod *mod)
204{
205	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
206	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
207	struct rsnd_src *src = rsnd_mod_to_src(mod);
208	u32 fin, fout, new_rate;
209	int inc, cnt, rate;
210	u64 base, val;
211
212	if (!runtime)
213		return;
214
215	if (!rsnd_src_sync_is_enabled(mod))
216		return;
217
218	fin	= rsnd_src_get_in_rate(priv, io);
219	fout	= rsnd_src_get_out_rate(priv, io);
220
221	new_rate = src->sync.val;
222
223	if (!new_rate)
224		new_rate = fout;
225
226	/* Do nothing if no diff */
227	if (new_rate == src->current_sync_rate)
228		return;
229
230	/*
231	 * SRCm_IFSVR::INTIFS can change within 1%
232	 * see
233	 *	SRCm_IFSVR::INTIFS Note
234	 */
235	inc = fout / 100;
236	cnt = abs(new_rate - fout) / inc;
237	if (fout > new_rate)
238		inc *= -1;
239
240	/*
241	 * After start running SRC, we can update only SRC_IFSVR
242	 * for Synchronous Mode
243	 */
244	base = (u64)0x0400000 * fin;
245	rate  = fout;
246	for (int i = 0; i < cnt; i++) {
247		val   = base;
248		rate += inc;
249		do_div(val, rate);
250
251		rsnd_mod_write(mod, SRC_IFSVR, val);
252	}
253	val   = base;
254	do_div(val, new_rate);
255
256	rsnd_mod_write(mod, SRC_IFSVR, val);
257
258	/* update current_sync_rate */
259	src->current_sync_rate = new_rate;
260}
261
262static void rsnd_src_init_convert_rate(struct rsnd_dai_stream *io,
263				       struct rsnd_mod *mod)
264{
265	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
266	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
267	struct device *dev = rsnd_priv_to_dev(priv);
268	int is_play = rsnd_io_is_play(io);
269	int use_src = 0;
270	u32 fin, fout;
271	u32 ifscr, adinr;
272	u32 cr, route;
273	u32 i_busif, o_busif, tmp;
274	const u32 *bsdsr_table;
275	const u32 *chptn;
276	uint ratio;
277	int chan;
278	int idx;
279
280	if (!runtime)
281		return;
282
283	fin  = rsnd_src_get_in_rate(priv, io);
284	fout = rsnd_src_get_out_rate(priv, io);
285
286	chan = rsnd_runtime_channel_original(io);
287
288	/* 6 - 1/6 are very enough ratio for SRC_BSDSR */
289	if (fin == fout)
290		ratio = 0;
291	else if (fin > fout)
292		ratio = 100 * fin / fout;
293	else
294		ratio = 100 * fout / fin;
295
296	if (ratio > 600) {
297		dev_err(dev, "FSO/FSI ratio error\n");
298		return;
299	}
300
301	use_src = (fin != fout) | rsnd_src_sync_is_enabled(mod);
302
303	/*
304	 * SRC_ADINR
305	 */
306	adinr = rsnd_get_adinr_bit(mod, io) | chan;
307
308	/*
309	 * SRC_IFSCR
310	 * SRC_SRCCR / SRC_ROUTE_MODE0
311	 */
312	ifscr	= 0;
313	cr	= 0x00011110;
314	route	= 0x0;
315	if (use_src) {
316		route	= 0x1;
317		ifscr	= 0x1;
318
319		if (rsnd_src_sync_is_enabled(mod)) {
320			cr |= 0x1;
321			route |= rsnd_io_is_play(io) ?
322				(0x1 << 24) : (0x1 << 25);
323		}
324	}
325
326	/*
327	 * SRC_BSDSR / SRC_BSISR
328	 *
329	 * see
330	 *	Combination of Register Setting Related to
331	 *	FSO/FSI Ratio and Channel, Latency
332	 */
333	switch (rsnd_mod_id(mod)) {
334	case 0:
335		chptn		= chan288888;
336		bsdsr_table	= bsdsr_table_pattern1;
337		break;
338	case 1:
339	case 3:
340	case 4:
341		chptn		= chan244888;
342		bsdsr_table	= bsdsr_table_pattern1;
343		break;
344	case 2:
345	case 9:
346		chptn		= chan222222;
347		bsdsr_table	= bsdsr_table_pattern1;
348		break;
349	case 5:
350	case 6:
351	case 7:
352	case 8:
353		chptn		= chan222222;
354		bsdsr_table	= bsdsr_table_pattern2;
355		break;
356	default:
357		goto convert_rate_err;
358	}
359
360	/*
361	 * E3 need to overwrite
362	 */
363	if (rsnd_is_gen3_e3(priv))
364		switch (rsnd_mod_id(mod)) {
365		case 0:
366		case 4:
367			chptn	= chan222222;
368		}
369
370	for (idx = 0; idx < ARRAY_SIZE(chan222222); idx++)
371		if (chptn[idx] & (1 << chan))
372			break;
373
374	if (chan > 8 ||
375	    idx >= ARRAY_SIZE(chan222222))
376		goto convert_rate_err;
377
378	/* BUSIF_MODE */
379	tmp = rsnd_get_busif_shift(io, mod);
380	i_busif = ( is_play ? tmp : 0) | 1;
381	o_busif = (!is_play ? tmp : 0) | 1;
382
383	rsnd_mod_write(mod, SRC_ROUTE_MODE0, route);
384
385	rsnd_mod_write(mod, SRC_SRCIR, 1);	/* initialize */
386	rsnd_mod_write(mod, SRC_ADINR, adinr);
387	rsnd_mod_write(mod, SRC_IFSCR, ifscr);
388	rsnd_mod_write(mod, SRC_SRCCR, cr);
389	rsnd_mod_write(mod, SRC_BSDSR, bsdsr_table[idx]);
390	rsnd_mod_write(mod, SRC_BSISR, bsisr_table[idx]);
391	rsnd_mod_write(mod, SRC_SRCIR, 0);	/* cancel initialize */
392
393	rsnd_mod_write(mod, SRC_I_BUSIF_MODE, i_busif);
394	rsnd_mod_write(mod, SRC_O_BUSIF_MODE, o_busif);
395
396	rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
397
398	rsnd_adg_set_src_timesel_gen2(mod, io, fin, fout);
399
400	/* update SRC_IFSVR */
401	rsnd_src_set_convert_rate(io, mod);
402
403	return;
404
405convert_rate_err:
406	dev_err(dev, "unknown BSDSR/BSDIR settings\n");
407}
408
409static int rsnd_src_irq(struct rsnd_mod *mod,
410			struct rsnd_dai_stream *io,
411			struct rsnd_priv *priv,
412			int enable)
413{
414	struct rsnd_src *src = rsnd_mod_to_src(mod);
415	u32 sys_int_val, int_val, sys_int_mask;
416	int irq = src->irq;
417	int id = rsnd_mod_id(mod);
418
419	sys_int_val =
420	sys_int_mask = OUF_SRC(id);
421	int_val = 0x3300;
422
423	/*
424	 * IRQ is not supported on non-DT
425	 * see
426	 *	rsnd_src_probe_()
427	 */
428	if ((irq <= 0) || !enable) {
429		sys_int_val = 0;
430		int_val = 0;
431	}
432
433	/*
434	 * WORKAROUND
435	 *
436	 * ignore over flow error when rsnd_src_sync_is_enabled()
437	 */
438	if (rsnd_src_sync_is_enabled(mod))
439		sys_int_val = sys_int_val & 0xffff;
440
441	rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val);
442	rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val);
443	rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val);
444
445	return 0;
446}
447
448static void rsnd_src_status_clear(struct rsnd_mod *mod)
449{
450	u32 val = OUF_SRC(rsnd_mod_id(mod));
451
452	rsnd_mod_write(mod, SCU_SYS_STATUS0, val);
453	rsnd_mod_write(mod, SCU_SYS_STATUS1, val);
454}
455
456static bool rsnd_src_error_occurred(struct rsnd_mod *mod)
457{
458	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
459	struct device *dev = rsnd_priv_to_dev(priv);
460	u32 val0, val1;
461	u32 status0, status1;
462	bool ret = false;
463
464	val0 = val1 = OUF_SRC(rsnd_mod_id(mod));
465
466	/*
467	 * WORKAROUND
468	 *
469	 * ignore over flow error when rsnd_src_sync_is_enabled()
470	 */
471	if (rsnd_src_sync_is_enabled(mod))
472		val0 = val0 & 0xffff;
473
474	status0 = rsnd_mod_read(mod, SCU_SYS_STATUS0);
475	status1 = rsnd_mod_read(mod, SCU_SYS_STATUS1);
476	if ((status0 & val0) || (status1 & val1)) {
477		rsnd_print_irq_status(dev, "%s err status : 0x%08x, 0x%08x\n",
478				      rsnd_mod_name(mod), status0, status1);
479
480		ret = true;
481	}
482
483	return ret;
484}
485
486static int rsnd_src_start(struct rsnd_mod *mod,
487			  struct rsnd_dai_stream *io,
488			  struct rsnd_priv *priv)
489{
490	u32 val;
491
492	/*
493	 * WORKAROUND
494	 *
495	 * Enable SRC output if you want to use sync convert together with DVC
496	 */
497	val = (rsnd_io_to_mod_dvc(io) && !rsnd_src_sync_is_enabled(mod)) ?
498		0x01 : 0x11;
499
500	rsnd_mod_write(mod, SRC_CTRL, val);
501
502	return 0;
503}
504
505static int rsnd_src_stop(struct rsnd_mod *mod,
506			 struct rsnd_dai_stream *io,
507			 struct rsnd_priv *priv)
508{
509	rsnd_mod_write(mod, SRC_CTRL, 0);
510
511	return 0;
512}
513
514static int rsnd_src_init(struct rsnd_mod *mod,
515			 struct rsnd_dai_stream *io,
516			 struct rsnd_priv *priv)
517{
518	struct rsnd_src *src = rsnd_mod_to_src(mod);
519	int ret;
520
521	/* reset sync convert_rate */
522	src->sync.val		=
523	src->current_sync_rate	= 0;
524
525	ret = rsnd_mod_power_on(mod);
526	if (ret < 0)
527		return ret;
528
529	rsnd_src_activation(mod);
530
531	rsnd_src_init_convert_rate(io, mod);
532
533	rsnd_src_status_clear(mod);
534
535	return 0;
536}
537
538static int rsnd_src_quit(struct rsnd_mod *mod,
539			 struct rsnd_dai_stream *io,
540			 struct rsnd_priv *priv)
541{
542	struct rsnd_src *src = rsnd_mod_to_src(mod);
543
544	rsnd_src_halt(mod);
545
546	rsnd_mod_power_off(mod);
547
548	/* reset sync convert_rate */
549	src->sync.val		=
550	src->current_sync_rate	= 0;
551
552	return 0;
553}
554
555static void __rsnd_src_interrupt(struct rsnd_mod *mod,
556				 struct rsnd_dai_stream *io)
557{
558	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
559	bool stop = false;
560
561	scoped_guard(spinlock, &priv->lock) {
562		/* ignore all cases if not working */
563		if (!rsnd_io_is_working(io))
564			break;
565
566		if (rsnd_src_error_occurred(mod))
567			stop = true;
568
569		rsnd_src_status_clear(mod);
570	}
571
572	if (stop)
573		snd_pcm_stop_xrun(io->substream);
574}
575
576static irqreturn_t rsnd_src_interrupt(int irq, void *data)
577{
578	struct rsnd_mod *mod = data;
579
580	rsnd_mod_interrupt(mod, __rsnd_src_interrupt);
581
582	return IRQ_HANDLED;
583}
584
585static int rsnd_src_kctrl_accept_runtime(struct rsnd_dai_stream *io)
586{
587	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
588
589	if (!runtime) {
590		struct rsnd_priv *priv = rsnd_io_to_priv(io);
591		struct device *dev = rsnd_priv_to_dev(priv);
592
593		dev_warn(dev, "\"SRC Out Rate\" can use during running\n");
594
595		return 0;
596	}
597
598	return 1;
599}
600
601static int rsnd_src_probe_(struct rsnd_mod *mod,
602			   struct rsnd_dai_stream *io,
603			   struct rsnd_priv *priv)
604{
605	struct rsnd_src *src = rsnd_mod_to_src(mod);
606	struct device *dev = rsnd_priv_to_dev(priv);
607	int irq = src->irq;
608	int ret;
609
610	if (irq > 0) {
611		/*
612		 * IRQ is not supported on non-DT
613		 * see
614		 *	rsnd_src_irq()
615		 */
616		ret = devm_request_irq(dev, irq,
617				       rsnd_src_interrupt,
618				       IRQF_SHARED,
619				       dev_name(dev), mod);
620		if (ret)
621			return ret;
622	}
623
624	ret = rsnd_dma_attach(io, mod, &src->dma);
625
626	return ret;
627}
628
629static int rsnd_src_pcm_new(struct rsnd_mod *mod,
630			    struct rsnd_dai_stream *io,
631			    struct snd_soc_pcm_runtime *rtd)
632{
633	struct rsnd_src *src = rsnd_mod_to_src(mod);
634	int ret;
635
636	/*
637	 * enable SRC sync convert if possible
638	 */
639
640	/*
641	 * It can't use SRC Synchronous convert
642	 * when Capture if it uses CMD
643	 */
644	if (rsnd_io_to_mod_cmd(io) && !rsnd_io_is_play(io))
645		return 0;
646
647	/*
648	 * enable sync convert
649	 */
650	ret = rsnd_kctrl_new_s(mod, io, rtd,
651			       rsnd_io_is_play(io) ?
652			       "SRC Out Rate Switch" :
653			       "SRC In Rate Switch",
654			       rsnd_kctrl_accept_anytime,
655			       rsnd_src_init_convert_rate,
656			       &src->sen, 1);
657	if (ret < 0)
658		return ret;
659
660	ret = rsnd_kctrl_new_s(mod, io, rtd,
661			       rsnd_io_is_play(io) ?
662			       "SRC Out Rate" :
663			       "SRC In Rate",
664			       rsnd_src_kctrl_accept_runtime,
665			       rsnd_src_set_convert_rate,
666			       &src->sync, 192000);
667
668	return ret;
669}
670
671#ifdef CONFIG_DEBUG_FS
672static void rsnd_src_debug_info(struct seq_file *m,
673				struct rsnd_dai_stream *io,
674				struct rsnd_mod *mod)
675{
676	rsnd_debugfs_mod_reg_show(m, mod, RSND_BASE_SCU,
677				  rsnd_mod_id(mod) * 0x20, 0x20);
678	seq_puts(m, "\n");
679	rsnd_debugfs_mod_reg_show(m, mod, RSND_BASE_SCU,
680				  0x1c0, 0x20);
681	seq_puts(m, "\n");
682	rsnd_debugfs_mod_reg_show(m, mod, RSND_BASE_SCU,
683				  0x200 + rsnd_mod_id(mod) * 0x40, 0x40);
684}
685#define DEBUG_INFO .debug_info = rsnd_src_debug_info
686#else
687#define DEBUG_INFO
688#endif
689
690static struct rsnd_mod_ops rsnd_src_ops = {
691	.name		= SRC_NAME,
692	.dma_req	= rsnd_src_dma_req,
693	.probe		= rsnd_src_probe_,
694	.init		= rsnd_src_init,
695	.quit		= rsnd_src_quit,
696	.start		= rsnd_src_start,
697	.stop		= rsnd_src_stop,
698	.irq		= rsnd_src_irq,
699	.pcm_new	= rsnd_src_pcm_new,
700	.get_status	= rsnd_mod_get_status,
701	DEBUG_INFO
702};
703
704struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
705{
706	if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
707		id = 0;
708
709	return rsnd_mod_get(rsnd_src_get(priv, id));
710}
711
712int rsnd_src_probe(struct rsnd_priv *priv)
713{
714	struct device_node *node;
715	struct device *dev = rsnd_priv_to_dev(priv);
716	struct rsnd_src *src;
717	struct clk *clk;
718	char name[RSND_SRC_NAME_SIZE];
719	int i, nr, ret;
720
721	node = rsnd_src_of_node(priv);
722	if (!node)
723		return 0; /* not used is not error */
724
725	nr = rsnd_node_count(priv, node, SRC_NAME);
726	if (!nr) {
727		ret = -EINVAL;
728		goto rsnd_src_probe_done;
729	}
730
731	src	= devm_kcalloc(dev, nr, sizeof(*src), GFP_KERNEL);
732	if (!src) {
733		ret = -ENOMEM;
734		goto rsnd_src_probe_done;
735	}
736
737	priv->src_nr	= nr;
738	priv->src	= src;
739
740	i = 0;
741	for_each_child_of_node_scoped(node, np) {
742		if (!of_device_is_available(np))
743			goto skip;
744
745		i = rsnd_node_fixed_index(dev, np, SRC_NAME, i);
746		if (i < 0) {
747			ret = -EINVAL;
748			goto rsnd_src_probe_done;
749		}
750
751		src = rsnd_src_get(priv, i);
752
753		snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
754			 SRC_NAME, i);
755
756		src->irq = irq_of_parse_and_map(np, 0);
757		if (!src->irq) {
758			ret = -EINVAL;
759			goto rsnd_src_probe_done;
760		}
761
762		clk = devm_clk_get(dev, name);
763		if (IS_ERR(clk)) {
764			ret = PTR_ERR(clk);
765			goto rsnd_src_probe_done;
766		}
767
768		ret = rsnd_mod_init(priv, rsnd_mod_get(src),
769				    &rsnd_src_ops, clk, RSND_MOD_SRC, i);
770		if (ret)
771			goto rsnd_src_probe_done;
772
773skip:
774		i++;
775	}
776
777	ret = 0;
778
779rsnd_src_probe_done:
780	of_node_put(node);
781
782	return ret;
783}
784
785void rsnd_src_remove(struct rsnd_priv *priv)
786{
787	struct rsnd_src *src;
788	int i;
789
790	for_each_rsnd_src(src, priv, i) {
791		rsnd_mod_quit(rsnd_mod_get(src));
792	}
793}
~/ Read-only file preview.