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