Commit | Line | Data |
---|---|---|
07539c1d | 1 | /* |
ba9c949f | 2 | * Renesas R-Car SRC support |
07539c1d KM |
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 | ||
8aefda50 KM |
13 | #define SRC_NAME "src" |
14 | ||
cfcefe01 KM |
15 | /* SRCx_STATUS */ |
16 | #define OUF_SRCO ((1 << 12) | (1 << 13)) | |
17 | #define OUF_SRCI ((1 << 9) | (1 << 8)) | |
18 | ||
19 | /* SCU_SYSTEM_STATUS0/1 */ | |
20 | #define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) | |
21 | ||
ba9c949f KM |
22 | struct rsnd_src { |
23 | struct rsnd_src_platform_info *info; /* rcar_snd.h */ | |
07539c1d | 24 | struct rsnd_mod mod; |
43cb6954 KM |
25 | struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ |
26 | struct rsnd_kctrl_cfg_s sync; /* sync convert */ | |
3b7843ff | 27 | u32 convert_rate; /* sampling rate convert */ |
cfcefe01 | 28 | int err; |
07539c1d KM |
29 | }; |
30 | ||
ba9c949f | 31 | #define RSND_SRC_NAME_SIZE 16 |
374a5281 | 32 | |
da599fd3 | 33 | #define rsnd_src_nr(priv) ((priv)->src_nr) |
43cb6954 | 34 | #define rsnd_enable_sync_convert(src) ((src)->sen.val) |
82e76ed3 KM |
35 | #define rsnd_src_of_node(priv) \ |
36 | of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") | |
37 | ||
ba9c949f KM |
38 | #define rsnd_mod_to_src(_mod) \ |
39 | container_of((_mod), struct rsnd_src, mod) | |
39cf3c40 | 40 | |
ba9c949f | 41 | #define for_each_rsnd_src(pos, priv, i) \ |
39cf3c40 | 42 | for ((i) = 0; \ |
ba9c949f KM |
43 | ((i) < rsnd_src_nr(priv)) && \ |
44 | ((pos) = (struct rsnd_src *)(priv)->src + i); \ | |
39cf3c40 KM |
45 | i++) |
46 | ||
47 | ||
ef749400 KM |
48 | /* |
49 | * image of SRC (Sampling Rate Converter) | |
50 | * | |
51 | * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+ | |
52 | * 48kHz <-> | SRC | <------> | SSI | <-----> | codec | | |
53 | * 44.1kHz <-> +-----+ +-----+ +-------+ | |
54 | * ... | |
55 | * | |
56 | */ | |
374a5281 | 57 | |
c926b746 | 58 | /* |
ba9c949f | 59 | * src.c is caring... |
c926b746 KM |
60 | * |
61 | * Gen1 | |
62 | * | |
63 | * [mem] -> [SRU] -> [SSI] | |
64 | * |--------| | |
65 | * | |
66 | * Gen2 | |
67 | * | |
ba9c949f | 68 | * [mem] -> [SRC] -> [SSIU] -> [SSI] |
c926b746 KM |
69 | * |-----------------| |
70 | */ | |
71 | ||
41c6221c KM |
72 | /* |
73 | * How to use SRC bypass mode for debugging | |
74 | * | |
75 | * SRC has bypass mode, and it is useful for debugging. | |
76 | * In Gen2 case, | |
77 | * SRCm_MODE controls whether SRC is used or not | |
78 | * SSI_MODE0 controls whether SSIU which receives SRC data | |
79 | * is used or not. | |
80 | * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC, | |
81 | * but SRC bypass mode needs SSI_MODE0 only. | |
82 | * | |
83 | * This driver request | |
ba9c949f | 84 | * struct rsnd_src_platform_info { |
41c6221c | 85 | * u32 convert_rate; |
29e69fd2 | 86 | * int dma_id; |
41c6221c KM |
87 | * } |
88 | * | |
ba9c949f | 89 | * rsnd_src_convert_rate() indicates |
41c6221c KM |
90 | * above convert_rate, and it controls |
91 | * whether SRC is used or not. | |
92 | * | |
93 | * ex) doesn't use SRC | |
29e69fd2 KM |
94 | * static struct rsnd_dai_platform_info rsnd_dai = { |
95 | * .playback = { .ssi = &rsnd_ssi[0], }, | |
41c6221c KM |
96 | * }; |
97 | * | |
98 | * ex) uses SRC | |
29e69fd2 KM |
99 | * static struct rsnd_src_platform_info rsnd_src[] = { |
100 | * RSND_SCU(48000, 0), | |
101 | * ... | |
102 | * }; | |
103 | * static struct rsnd_dai_platform_info rsnd_dai = { | |
104 | * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, | |
41c6221c KM |
105 | * }; |
106 | * | |
107 | * ex) uses SRC bypass mode | |
29e69fd2 KM |
108 | * static struct rsnd_src_platform_info rsnd_src[] = { |
109 | * RSND_SCU(0, 0), | |
110 | * ... | |
111 | * }; | |
112 | * static struct rsnd_dai_platform_info rsnd_dai = { | |
113 | * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, | |
41c6221c KM |
114 | * }; |
115 | * | |
116 | */ | |
117 | ||
1b7b08ef KM |
118 | /* |
119 | * Gen1/Gen2 common functions | |
120 | */ | |
9b99e9a7 KM |
121 | static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, |
122 | struct rsnd_mod *mod) | |
72adc61f KM |
123 | { |
124 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | |
72adc61f KM |
125 | int is_play = rsnd_io_is_play(io); |
126 | ||
127 | return rsnd_dma_request_channel(rsnd_src_of_node(priv), | |
128 | mod, | |
129 | is_play ? "rx" : "tx"); | |
130 | } | |
131 | ||
d9288d0b | 132 | int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, |
4e2639ff | 133 | struct rsnd_dai_stream *io, |
d9288d0b | 134 | int use_busif) |
7b5ce975 | 135 | { |
f708d944 | 136 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
1cc71959 | 137 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
374e5426 | 138 | int ssi_id = rsnd_mod_id(ssi_mod); |
7b5ce975 KM |
139 | |
140 | /* | |
141 | * SSI_MODE0 | |
142 | */ | |
221bf523 | 143 | rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id), |
d9288d0b | 144 | !use_busif << ssi_id); |
7b5ce975 KM |
145 | |
146 | /* | |
147 | * SSI_MODE1 | |
148 | */ | |
374e5426 | 149 | if (rsnd_ssi_is_pin_sharing(ssi_mod)) { |
7b5ce975 | 150 | int shift = -1; |
374e5426 | 151 | switch (ssi_id) { |
7b5ce975 KM |
152 | case 1: |
153 | shift = 0; | |
154 | break; | |
155 | case 2: | |
156 | shift = 2; | |
157 | break; | |
158 | case 4: | |
159 | shift = 16; | |
160 | break; | |
161 | } | |
162 | ||
163 | if (shift >= 0) | |
221bf523 | 164 | rsnd_mod_bset(ssi_mod, SSI_MODE1, |
7b5ce975 | 165 | 0x3 << shift, |
3ed6448c | 166 | rsnd_rdai_is_clk_master(rdai) ? |
7b5ce975 KM |
167 | 0x2 << shift : 0x1 << shift); |
168 | } | |
169 | ||
d9288d0b KM |
170 | /* |
171 | * DMA settings for SSIU | |
172 | */ | |
173 | if (use_busif) { | |
1cc71959 KM |
174 | u32 val = 0x76543210; |
175 | u32 mask = ~0; | |
176 | ||
d9288d0b | 177 | rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR, |
4e2639ff | 178 | rsnd_get_adinr(ssi_mod, io)); |
d9288d0b KM |
179 | rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1); |
180 | rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1); | |
1cc71959 KM |
181 | |
182 | mask <<= runtime->channels * 4; | |
183 | val = val & mask; | |
184 | ||
185 | switch (runtime->sample_bits) { | |
186 | case 16: | |
187 | val |= 0x67452301 & ~mask; | |
188 | break; | |
189 | case 32: | |
190 | val |= 0x76543210 & ~mask; | |
191 | break; | |
192 | } | |
cdde84d1 | 193 | rsnd_mod_write(ssi_mod, SSI_BUSIF_DALIGN, val); |
1cc71959 | 194 | |
d9288d0b KM |
195 | } |
196 | ||
197 | return 0; | |
198 | } | |
199 | ||
4e2639ff KM |
200 | int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod, |
201 | struct rsnd_dai_stream *io) | |
d9288d0b KM |
202 | { |
203 | /* | |
204 | * DMA settings for SSIU | |
205 | */ | |
660cdce2 | 206 | rsnd_mod_write(ssi_mod, SSI_CTRL, 0); |
d9288d0b | 207 | |
7b5ce975 KM |
208 | return 0; |
209 | } | |
210 | ||
f708d944 | 211 | int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod) |
b8cc41e9 KM |
212 | { |
213 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); | |
214 | ||
c17dba8b KM |
215 | if (rsnd_is_gen1(priv)) |
216 | return 0; | |
217 | ||
218 | /* enable SSI interrupt if Gen2 */ | |
efa991dc KM |
219 | rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, |
220 | rsnd_ssi_is_dma_mode(ssi_mod) ? | |
221 | 0x0e000000 : 0x0f000000); | |
b8cc41e9 KM |
222 | |
223 | return 0; | |
224 | } | |
225 | ||
f708d944 | 226 | int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod) |
c17dba8b KM |
227 | { |
228 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); | |
229 | ||
230 | if (rsnd_is_gen1(priv)) | |
231 | return 0; | |
232 | ||
233 | /* disable SSI interrupt if Gen2 */ | |
efa991dc | 234 | rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, 0x00000000); |
c17dba8b KM |
235 | |
236 | return 0; | |
237 | } | |
238 | ||
88c61cff KM |
239 | static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io, |
240 | struct rsnd_src *src) | |
43cb6954 | 241 | { |
43cb6954 KM |
242 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
243 | u32 convert_rate; | |
244 | ||
245 | if (!runtime) | |
246 | return 0; | |
247 | ||
248 | if (!rsnd_enable_sync_convert(src)) | |
249 | return src->convert_rate; | |
250 | ||
251 | convert_rate = src->sync.val; | |
252 | ||
253 | if (!convert_rate) | |
254 | convert_rate = src->convert_rate; | |
255 | ||
256 | if (!convert_rate) | |
257 | convert_rate = runtime->rate; | |
258 | ||
259 | return convert_rate; | |
260 | } | |
261 | ||
ba9c949f | 262 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, |
374e5426 | 263 | struct rsnd_dai_stream *io, |
1b7b08ef KM |
264 | struct snd_pcm_runtime *runtime) |
265 | { | |
b1eac430 | 266 | struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); |
ba9c949f | 267 | struct rsnd_src *src; |
b1eac430 | 268 | unsigned int rate = 0; |
1b7b08ef | 269 | |
b1eac430 KM |
270 | if (src_mod) { |
271 | src = rsnd_mod_to_src(src_mod); | |
272 | ||
273 | /* | |
274 | * return convert rate if SRC is used, | |
275 | * otherwise, return runtime->rate as usual | |
276 | */ | |
88c61cff | 277 | rate = rsnd_src_convert_rate(io, src); |
b1eac430 | 278 | } |
1b7b08ef | 279 | |
1b7b08ef KM |
280 | if (!rate) |
281 | rate = runtime->rate; | |
282 | ||
283 | return rate; | |
284 | } | |
285 | ||
4e2639ff KM |
286 | static int rsnd_src_set_convert_rate(struct rsnd_mod *mod, |
287 | struct rsnd_dai_stream *io) | |
1b7b08ef KM |
288 | { |
289 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); | |
ba9c949f | 290 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
88c61cff | 291 | u32 convert_rate = rsnd_src_convert_rate(io, src); |
1b7b08ef KM |
292 | u32 fsrate = 0; |
293 | ||
294 | if (convert_rate) | |
295 | fsrate = 0x0400000 / convert_rate * runtime->rate; | |
296 | ||
297 | /* set/clear soft reset */ | |
298 | rsnd_mod_write(mod, SRC_SWRSR, 0); | |
299 | rsnd_mod_write(mod, SRC_SWRSR, 1); | |
300 | ||
1b7b08ef | 301 | /* Set channel number and output bit length */ |
4e2639ff | 302 | rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod, io)); |
1b7b08ef KM |
303 | |
304 | /* Enable the initial value of IFS */ | |
305 | if (fsrate) { | |
306 | rsnd_mod_write(mod, SRC_IFSCR, 1); | |
307 | ||
308 | /* Set initial value of IFS */ | |
309 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); | |
310 | } | |
311 | ||
312 | /* use DMA transfer */ | |
313 | rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); | |
314 | ||
315 | return 0; | |
316 | } | |
317 | ||
3b7843ff | 318 | static int rsnd_src_hw_params(struct rsnd_mod *mod, |
2c0fac19 | 319 | struct rsnd_dai_stream *io, |
3b7843ff KM |
320 | struct snd_pcm_substream *substream, |
321 | struct snd_pcm_hw_params *fe_params) | |
322 | { | |
323 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
324 | struct snd_soc_pcm_runtime *fe = substream->private_data; | |
325 | ||
326 | /* default value (mainly for non-DT) */ | |
327 | src->convert_rate = src->info->convert_rate; | |
328 | ||
329 | /* | |
330 | * SRC assumes that it is used under DPCM if user want to use | |
331 | * sampling rate convert. Then, SRC should be FE. | |
332 | * And then, this function will be called *after* BE settings. | |
333 | * this means, each BE already has fixuped hw_params. | |
334 | * see | |
335 | * dpcm_fe_dai_hw_params() | |
336 | * dpcm_be_dai_hw_params() | |
337 | */ | |
338 | if (fe->dai_link->dynamic) { | |
339 | int stream = substream->stream; | |
340 | struct snd_soc_dpcm *dpcm; | |
341 | struct snd_pcm_hw_params *be_params; | |
342 | ||
343 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | |
344 | be_params = &dpcm->hw_params; | |
345 | ||
346 | if (params_rate(fe_params) != params_rate(be_params)) | |
347 | src->convert_rate = params_rate(be_params); | |
348 | } | |
349 | } | |
350 | ||
351 | return 0; | |
352 | } | |
353 | ||
354 | static int rsnd_src_init(struct rsnd_mod *mod, | |
355 | struct rsnd_priv *priv) | |
1b7b08ef | 356 | { |
ba9c949f | 357 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
1b7b08ef | 358 | |
85642952 | 359 | rsnd_mod_hw_start(mod); |
1b7b08ef | 360 | |
cfcefe01 KM |
361 | src->err = 0; |
362 | ||
43cb6954 KM |
363 | /* reset sync convert_rate */ |
364 | src->sync.val = 0; | |
365 | ||
603cefa5 KM |
366 | /* |
367 | * Initialize the operation of the SRC internal circuits | |
368 | * see rsnd_src_start() | |
369 | */ | |
370 | rsnd_mod_write(mod, SRC_SRCIR, 1); | |
371 | ||
1b7b08ef KM |
372 | return 0; |
373 | } | |
374 | ||
ba9c949f | 375 | static int rsnd_src_quit(struct rsnd_mod *mod, |
2c0fac19 | 376 | struct rsnd_dai_stream *io, |
690602fc | 377 | struct rsnd_priv *priv) |
1b7b08ef | 378 | { |
ba9c949f | 379 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
cfcefe01 | 380 | struct device *dev = rsnd_priv_to_dev(priv); |
1b7b08ef | 381 | |
85642952 | 382 | rsnd_mod_hw_stop(mod); |
1b7b08ef | 383 | |
cfcefe01 | 384 | if (src->err) |
337b0b4c KM |
385 | dev_warn(dev, "%s[%d] under/over flow err = %d\n", |
386 | rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); | |
cfcefe01 | 387 | |
3b7843ff KM |
388 | src->convert_rate = 0; |
389 | ||
43cb6954 KM |
390 | /* reset sync convert_rate */ |
391 | src->sync.val = 0; | |
392 | ||
1b7b08ef KM |
393 | return 0; |
394 | } | |
395 | ||
f0ef0cb8 | 396 | static int rsnd_src_start(struct rsnd_mod *mod) |
1b7b08ef | 397 | { |
1b7b08ef KM |
398 | /* |
399 | * Cancel the initialization and operate the SRC function | |
603cefa5 | 400 | * see rsnd_src_init() |
1b7b08ef KM |
401 | */ |
402 | rsnd_mod_write(mod, SRC_SRCIR, 0); | |
403 | ||
1b7b08ef KM |
404 | return 0; |
405 | } | |
406 | ||
f0ef0cb8 | 407 | static int rsnd_src_stop(struct rsnd_mod *mod) |
1b7b08ef | 408 | { |
933cc8cb | 409 | /* nothing to do */ |
1b7b08ef KM |
410 | return 0; |
411 | } | |
412 | ||
1b7b08ef KM |
413 | /* |
414 | * Gen1 functions | |
415 | */ | |
88c61cff KM |
416 | static int rsnd_src_set_route_gen1(struct rsnd_dai_stream *io, |
417 | struct rsnd_mod *mod) | |
374a5281 | 418 | { |
ba9c949f | 419 | struct src_route_config { |
374a5281 KM |
420 | u32 mask; |
421 | int shift; | |
422 | } routes[] = { | |
423 | { 0xF, 0, }, /* 0 */ | |
424 | { 0xF, 4, }, /* 1 */ | |
425 | { 0xF, 8, }, /* 2 */ | |
426 | { 0x7, 12, }, /* 3 */ | |
427 | { 0x7, 16, }, /* 4 */ | |
428 | { 0x7, 20, }, /* 5 */ | |
429 | { 0x7, 24, }, /* 6 */ | |
430 | { 0x3, 28, }, /* 7 */ | |
431 | { 0x3, 30, }, /* 8 */ | |
432 | }; | |
374a5281 KM |
433 | u32 mask; |
434 | u32 val; | |
374a5281 KM |
435 | int id; |
436 | ||
374a5281 | 437 | id = rsnd_mod_id(mod); |
b5f3d7af | 438 | if (id < 0 || id >= ARRAY_SIZE(routes)) |
374a5281 KM |
439 | return -EIO; |
440 | ||
441 | /* | |
442 | * SRC_ROUTE_SELECT | |
443 | */ | |
985a4f6e | 444 | val = rsnd_io_is_play(io) ? 0x1 : 0x2; |
374a5281 KM |
445 | val = val << routes[id].shift; |
446 | mask = routes[id].mask << routes[id].shift; | |
447 | ||
448 | rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); | |
449 | ||
28dc4b63 KM |
450 | return 0; |
451 | } | |
452 | ||
88c61cff KM |
453 | static int rsnd_src_set_convert_timing_gen1(struct rsnd_dai_stream *io, |
454 | struct rsnd_mod *mod) | |
28dc4b63 KM |
455 | { |
456 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | |
ba9c949f | 457 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
28dc4b63 | 458 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
88c61cff | 459 | u32 convert_rate = rsnd_src_convert_rate(io, src); |
28dc4b63 KM |
460 | u32 mask; |
461 | u32 val; | |
462 | int shift; | |
463 | int id = rsnd_mod_id(mod); | |
464 | int ret; | |
465 | ||
374a5281 KM |
466 | /* |
467 | * SRC_TIMING_SELECT | |
468 | */ | |
469 | shift = (id % 4) * 8; | |
470 | mask = 0x1F << shift; | |
ef749400 KM |
471 | |
472 | /* | |
473 | * ADG is used as source clock if SRC was used, | |
474 | * then, SSI WS is used as destination clock. | |
475 | * SSI WS is used as source clock if SRC is not used | |
476 | * (when playback, source/destination become reverse when capture) | |
477 | */ | |
28dc4b63 KM |
478 | ret = 0; |
479 | if (convert_rate) { | |
480 | /* use ADG */ | |
ef749400 | 481 | val = 0; |
28dc4b63 KM |
482 | ret = rsnd_adg_set_convert_clk_gen1(priv, mod, |
483 | runtime->rate, | |
484 | convert_rate); | |
485 | } else if (8 == id) { | |
486 | /* use SSI WS, but SRU8 is special */ | |
374a5281 | 487 | val = id << shift; |
28dc4b63 KM |
488 | } else { |
489 | /* use SSI WS */ | |
374a5281 | 490 | val = (id + 1) << shift; |
28dc4b63 KM |
491 | } |
492 | ||
493 | if (ret < 0) | |
494 | return ret; | |
374a5281 KM |
495 | |
496 | switch (id / 4) { | |
497 | case 0: | |
498 | rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); | |
499 | break; | |
500 | case 1: | |
501 | rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); | |
502 | break; | |
503 | case 2: | |
504 | rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); | |
505 | break; | |
506 | } | |
507 | ||
508 | return 0; | |
509 | } | |
510 | ||
4e2639ff KM |
511 | static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod, |
512 | struct rsnd_dai_stream *io) | |
374a5281 | 513 | { |
933cc8cb | 514 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
1b7b08ef | 515 | int ret; |
ef749400 | 516 | |
4e2639ff | 517 | ret = rsnd_src_set_convert_rate(mod, io); |
1b7b08ef KM |
518 | if (ret < 0) |
519 | return ret; | |
ef749400 | 520 | |
1b7b08ef KM |
521 | /* Select SRC mode (fixed value) */ |
522 | rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); | |
ef749400 | 523 | |
1b7b08ef KM |
524 | /* Set the restriction value of the FS ratio (98%) */ |
525 | rsnd_mod_write(mod, SRC_MNFSR, | |
526 | rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); | |
ef749400 | 527 | |
933cc8cb | 528 | /* Gen1/Gen2 are not compatible */ |
88c61cff | 529 | if (rsnd_src_convert_rate(io, src)) |
933cc8cb KM |
530 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); |
531 | ||
1b7b08ef | 532 | /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ |
ef749400 | 533 | |
374a5281 KM |
534 | return 0; |
535 | } | |
536 | ||
ba9c949f | 537 | static int rsnd_src_init_gen1(struct rsnd_mod *mod, |
2c0fac19 | 538 | struct rsnd_dai_stream *io, |
690602fc | 539 | struct rsnd_priv *priv) |
07539c1d | 540 | { |
374a5281 KM |
541 | int ret; |
542 | ||
3b7843ff | 543 | ret = rsnd_src_init(mod, priv); |
7b5ce975 KM |
544 | if (ret < 0) |
545 | return ret; | |
546 | ||
88c61cff | 547 | ret = rsnd_src_set_route_gen1(io, mod); |
374a5281 KM |
548 | if (ret < 0) |
549 | return ret; | |
550 | ||
4e2639ff | 551 | ret = rsnd_src_set_convert_rate_gen1(mod, io); |
374a5281 KM |
552 | if (ret < 0) |
553 | return ret; | |
07539c1d | 554 | |
88c61cff | 555 | ret = rsnd_src_set_convert_timing_gen1(io, mod); |
28dc4b63 KM |
556 | if (ret < 0) |
557 | return ret; | |
558 | ||
a204d90c KM |
559 | return 0; |
560 | } | |
561 | ||
ba9c949f | 562 | static int rsnd_src_start_gen1(struct rsnd_mod *mod, |
2c0fac19 | 563 | struct rsnd_dai_stream *io, |
690602fc | 564 | struct rsnd_priv *priv) |
a204d90c | 565 | { |
1b7b08ef | 566 | int id = rsnd_mod_id(mod); |
a204d90c | 567 | |
1b7b08ef | 568 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); |
374a5281 | 569 | |
f0ef0cb8 | 570 | return rsnd_src_start(mod); |
07539c1d KM |
571 | } |
572 | ||
ba9c949f | 573 | static int rsnd_src_stop_gen1(struct rsnd_mod *mod, |
2c0fac19 | 574 | struct rsnd_dai_stream *io, |
690602fc | 575 | struct rsnd_priv *priv) |
a204d90c | 576 | { |
e7ce74ea | 577 | int id = rsnd_mod_id(mod); |
a204d90c | 578 | |
1b7b08ef | 579 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); |
e7ce74ea | 580 | |
f0ef0cb8 | 581 | return rsnd_src_stop(mod); |
a204d90c KM |
582 | } |
583 | ||
ba9c949f | 584 | static struct rsnd_mod_ops rsnd_src_gen1_ops = { |
8aefda50 | 585 | .name = SRC_NAME, |
72adc61f | 586 | .dma_req = rsnd_src_dma_req, |
ba9c949f KM |
587 | .init = rsnd_src_init_gen1, |
588 | .quit = rsnd_src_quit, | |
589 | .start = rsnd_src_start_gen1, | |
590 | .stop = rsnd_src_stop_gen1, | |
3b7843ff | 591 | .hw_params = rsnd_src_hw_params, |
1b7b08ef | 592 | }; |
e7ce74ea | 593 | |
1b7b08ef KM |
594 | /* |
595 | * Gen2 functions | |
596 | */ | |
cfcefe01 KM |
597 | #define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1) |
598 | #define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0) | |
599 | static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod *mod, int enable) | |
600 | { | |
601 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
602 | u32 sys_int_val, int_val, sys_int_mask; | |
603 | int irq = src->info->irq; | |
604 | int id = rsnd_mod_id(mod); | |
605 | ||
606 | sys_int_val = | |
607 | sys_int_mask = OUF_SRC(id); | |
608 | int_val = 0x3300; | |
609 | ||
610 | /* | |
611 | * IRQ is not supported on non-DT | |
612 | * see | |
613 | * rsnd_src_probe_gen2() | |
614 | */ | |
615 | if ((irq <= 0) || !enable) { | |
616 | sys_int_val = 0; | |
617 | int_val = 0; | |
618 | } | |
619 | ||
1a1bf58a KM |
620 | /* |
621 | * WORKAROUND | |
622 | * | |
623 | * ignore over flow error when rsnd_enable_sync_convert() | |
624 | */ | |
625 | if (rsnd_enable_sync_convert(src)) | |
626 | sys_int_val = sys_int_val & 0xffff; | |
627 | ||
cfcefe01 KM |
628 | rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); |
629 | rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); | |
630 | rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); | |
631 | } | |
632 | ||
633 | static void rsnd_src_error_clear_gen2(struct rsnd_mod *mod) | |
634 | { | |
635 | u32 val = OUF_SRC(rsnd_mod_id(mod)); | |
636 | ||
637 | rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val); | |
638 | rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val); | |
639 | } | |
640 | ||
641 | static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod) | |
642 | { | |
1a1bf58a KM |
643 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
644 | u32 val0, val1; | |
cfcefe01 KM |
645 | bool ret = false; |
646 | ||
1a1bf58a KM |
647 | val0 = val1 = OUF_SRC(rsnd_mod_id(mod)); |
648 | ||
649 | /* | |
650 | * WORKAROUND | |
651 | * | |
652 | * ignore over flow error when rsnd_enable_sync_convert() | |
653 | */ | |
654 | if (rsnd_enable_sync_convert(src)) | |
655 | val0 = val0 & 0xffff; | |
656 | ||
657 | if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) || | |
658 | (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) { | |
cfcefe01 KM |
659 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
660 | ||
661 | src->err++; | |
662 | ret = true; | |
663 | } | |
664 | ||
665 | /* clear error static */ | |
666 | rsnd_src_error_clear_gen2(mod); | |
667 | ||
668 | return ret; | |
669 | } | |
670 | ||
88c61cff KM |
671 | static int _rsnd_src_start_gen2(struct rsnd_mod *mod, |
672 | struct rsnd_dai_stream *io) | |
cfcefe01 | 673 | { |
1a1bf58a KM |
674 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
675 | u32 val; | |
676 | ||
677 | /* | |
678 | * WORKAROUND | |
679 | * | |
680 | * Enable SRC output if you want to use sync convert together with DVC | |
681 | */ | |
682 | val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ? | |
683 | 0x01 : 0x11; | |
cfcefe01 KM |
684 | |
685 | rsnd_mod_write(mod, SRC_CTRL, val); | |
686 | ||
687 | rsnd_src_error_clear_gen2(mod); | |
688 | ||
689 | rsnd_src_start(mod); | |
690 | ||
691 | rsnd_src_irq_enable_gen2(mod); | |
692 | ||
693 | return 0; | |
694 | } | |
695 | ||
696 | static int _rsnd_src_stop_gen2(struct rsnd_mod *mod) | |
697 | { | |
698 | rsnd_src_irq_disable_gen2(mod); | |
699 | ||
700 | rsnd_mod_write(mod, SRC_CTRL, 0); | |
701 | ||
702 | rsnd_src_error_record_gen2(mod); | |
703 | ||
704 | return rsnd_src_stop(mod); | |
705 | } | |
706 | ||
88c61cff KM |
707 | static void __rsnd_src_interrupt_gen2(struct rsnd_mod *mod, |
708 | struct rsnd_dai_stream *io) | |
cfcefe01 | 709 | { |
02299d98 KM |
710 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
711 | ||
712 | spin_lock(&priv->lock); | |
cfcefe01 | 713 | |
02299d98 | 714 | /* ignore all cases if not working */ |
d5bbe7de | 715 | if (!rsnd_io_is_working(io)) |
02299d98 | 716 | goto rsnd_src_interrupt_gen2_out; |
cfcefe01 KM |
717 | |
718 | if (rsnd_src_error_record_gen2(mod)) { | |
719 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | |
639b231f | 720 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
cfcefe01 KM |
721 | struct device *dev = rsnd_priv_to_dev(priv); |
722 | ||
cfcefe01 KM |
723 | dev_dbg(dev, "%s[%d] restart\n", |
724 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | |
639b231f KM |
725 | |
726 | _rsnd_src_stop_gen2(mod); | |
727 | if (src->err < 1024) | |
88c61cff | 728 | _rsnd_src_start_gen2(mod, io); |
639b231f KM |
729 | else |
730 | dev_warn(dev, "no more SRC restart\n"); | |
cfcefe01 | 731 | } |
88c61cff | 732 | |
02299d98 KM |
733 | rsnd_src_interrupt_gen2_out: |
734 | spin_unlock(&priv->lock); | |
88c61cff KM |
735 | } |
736 | ||
737 | static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data) | |
738 | { | |
739 | struct rsnd_mod *mod = data; | |
740 | ||
741 | rsnd_mod_interrupt(mod, __rsnd_src_interrupt_gen2); | |
cfcefe01 KM |
742 | |
743 | return IRQ_HANDLED; | |
744 | } | |
745 | ||
4e2639ff KM |
746 | static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod, |
747 | struct rsnd_dai_stream *io) | |
629509c5 | 748 | { |
054cd7f4 KM |
749 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
750 | struct device *dev = rsnd_priv_to_dev(priv); | |
054cd7f4 KM |
751 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
752 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
88c61cff | 753 | u32 convert_rate = rsnd_src_convert_rate(io, src); |
43cb6954 | 754 | u32 cr, route; |
054cd7f4 | 755 | uint ratio; |
629509c5 KM |
756 | int ret; |
757 | ||
054cd7f4 | 758 | /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ |
b167a578 | 759 | if (!convert_rate) |
054cd7f4 | 760 | ratio = 0; |
b167a578 KM |
761 | else if (convert_rate > runtime->rate) |
762 | ratio = 100 * convert_rate / runtime->rate; | |
054cd7f4 | 763 | else |
b167a578 | 764 | ratio = 100 * runtime->rate / convert_rate; |
054cd7f4 KM |
765 | |
766 | if (ratio > 600) { | |
767 | dev_err(dev, "FSO/FSI ratio error\n"); | |
768 | return -EINVAL; | |
769 | } | |
770 | ||
4e2639ff | 771 | ret = rsnd_src_set_convert_rate(mod, io); |
629509c5 KM |
772 | if (ret < 0) |
773 | return ret; | |
774 | ||
43cb6954 KM |
775 | cr = 0x00011110; |
776 | route = 0x0; | |
933cc8cb | 777 | if (convert_rate) { |
43cb6954 KM |
778 | route = 0x1; |
779 | ||
780 | if (rsnd_enable_sync_convert(src)) { | |
781 | cr |= 0x1; | |
782 | route |= rsnd_io_is_play(io) ? | |
783 | (0x1 << 24) : (0x1 << 25); | |
784 | } | |
933cc8cb KM |
785 | } |
786 | ||
43cb6954 KM |
787 | rsnd_mod_write(mod, SRC_SRCCR, cr); |
788 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); | |
789 | ||
054cd7f4 KM |
790 | switch (rsnd_mod_id(mod)) { |
791 | case 5: | |
792 | case 6: | |
793 | case 7: | |
794 | case 8: | |
795 | rsnd_mod_write(mod, SRC_BSDSR, 0x02400000); | |
796 | break; | |
797 | default: | |
798 | rsnd_mod_write(mod, SRC_BSDSR, 0x01800000); | |
799 | break; | |
800 | } | |
801 | ||
629509c5 KM |
802 | rsnd_mod_write(mod, SRC_BSISR, 0x00100060); |
803 | ||
804 | return 0; | |
805 | } | |
806 | ||
88c61cff KM |
807 | static int rsnd_src_set_convert_timing_gen2(struct rsnd_dai_stream *io, |
808 | struct rsnd_mod *mod) | |
629509c5 KM |
809 | { |
810 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); | |
ba9c949f | 811 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
88c61cff | 812 | u32 convert_rate = rsnd_src_convert_rate(io, src); |
629509c5 KM |
813 | int ret; |
814 | ||
815 | if (convert_rate) | |
f708d944 | 816 | ret = rsnd_adg_set_convert_clk_gen2(mod, io, |
629509c5 KM |
817 | runtime->rate, |
818 | convert_rate); | |
819 | else | |
f708d944 | 820 | ret = rsnd_adg_set_convert_timing_gen2(mod, io); |
629509c5 KM |
821 | |
822 | return ret; | |
823 | } | |
824 | ||
ba9c949f | 825 | static int rsnd_src_probe_gen2(struct rsnd_mod *mod, |
2c0fac19 | 826 | struct rsnd_dai_stream *io, |
690602fc | 827 | struct rsnd_priv *priv) |
76c6fb5c | 828 | { |
ba9c949f | 829 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
76c6fb5c | 830 | struct device *dev = rsnd_priv_to_dev(priv); |
cfcefe01 | 831 | int irq = src->info->irq; |
76c6fb5c | 832 | int ret; |
76c6fb5c | 833 | |
cfcefe01 KM |
834 | if (irq > 0) { |
835 | /* | |
836 | * IRQ is not supported on non-DT | |
837 | * see | |
838 | * rsnd_src_irq_enable_gen2() | |
839 | */ | |
840 | ret = devm_request_irq(dev, irq, | |
841 | rsnd_src_interrupt_gen2, | |
842 | IRQF_SHARED, | |
843 | dev_name(dev), mod); | |
844 | if (ret) | |
b543b52a | 845 | return ret; |
cfcefe01 KM |
846 | } |
847 | ||
9b99e9a7 | 848 | ret = rsnd_dma_init(io, |
76c6fb5c | 849 | rsnd_mod_to_dma(mod), |
ba9c949f | 850 | src->info->dma_id); |
8aefda50 | 851 | |
76c6fb5c KM |
852 | return ret; |
853 | } | |
854 | ||
ba9c949f | 855 | static int rsnd_src_remove_gen2(struct rsnd_mod *mod, |
2c0fac19 | 856 | struct rsnd_dai_stream *io, |
690602fc | 857 | struct rsnd_priv *priv) |
76c6fb5c | 858 | { |
9b99e9a7 | 859 | rsnd_dma_quit(io, rsnd_mod_to_dma(mod)); |
76c6fb5c KM |
860 | |
861 | return 0; | |
862 | } | |
863 | ||
ba9c949f | 864 | static int rsnd_src_init_gen2(struct rsnd_mod *mod, |
2c0fac19 | 865 | struct rsnd_dai_stream *io, |
690602fc | 866 | struct rsnd_priv *priv) |
629509c5 KM |
867 | { |
868 | int ret; | |
869 | ||
3b7843ff | 870 | ret = rsnd_src_init(mod, priv); |
629509c5 KM |
871 | if (ret < 0) |
872 | return ret; | |
873 | ||
4e2639ff | 874 | ret = rsnd_src_set_convert_rate_gen2(mod, io); |
629509c5 KM |
875 | if (ret < 0) |
876 | return ret; | |
877 | ||
88c61cff | 878 | ret = rsnd_src_set_convert_timing_gen2(io, mod); |
629509c5 KM |
879 | if (ret < 0) |
880 | return ret; | |
881 | ||
882 | return 0; | |
883 | } | |
884 | ||
ba9c949f | 885 | static int rsnd_src_start_gen2(struct rsnd_mod *mod, |
2c0fac19 | 886 | struct rsnd_dai_stream *io, |
690602fc | 887 | struct rsnd_priv *priv) |
629509c5 | 888 | { |
9b99e9a7 | 889 | rsnd_dma_start(io, rsnd_mod_to_dma(mod)); |
629509c5 | 890 | |
88c61cff | 891 | return _rsnd_src_start_gen2(mod, io); |
629509c5 KM |
892 | } |
893 | ||
ba9c949f | 894 | static int rsnd_src_stop_gen2(struct rsnd_mod *mod, |
2c0fac19 | 895 | struct rsnd_dai_stream *io, |
690602fc | 896 | struct rsnd_priv *priv) |
629509c5 | 897 | { |
cfcefe01 | 898 | int ret; |
629509c5 | 899 | |
cfcefe01 | 900 | ret = _rsnd_src_stop_gen2(mod); |
629509c5 | 901 | |
9b99e9a7 | 902 | rsnd_dma_stop(io, rsnd_mod_to_dma(mod)); |
629509c5 | 903 | |
cfcefe01 | 904 | return ret; |
629509c5 KM |
905 | } |
906 | ||
b65a7ccc KM |
907 | static void rsnd_src_reconvert_update(struct rsnd_dai_stream *io, |
908 | struct rsnd_mod *mod) | |
43cb6954 | 909 | { |
43cb6954 KM |
910 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
911 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
88c61cff | 912 | u32 convert_rate = rsnd_src_convert_rate(io, src); |
43cb6954 KM |
913 | u32 fsrate; |
914 | ||
915 | if (!runtime) | |
916 | return; | |
917 | ||
918 | if (!convert_rate) | |
919 | convert_rate = runtime->rate; | |
920 | ||
921 | fsrate = 0x0400000 / convert_rate * runtime->rate; | |
922 | ||
923 | /* update IFS */ | |
924 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); | |
925 | } | |
926 | ||
927 | static int rsnd_src_pcm_new(struct rsnd_mod *mod, | |
2c0fac19 | 928 | struct rsnd_dai_stream *io, |
43cb6954 KM |
929 | struct snd_soc_pcm_runtime *rtd) |
930 | { | |
931 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | |
43cb6954 KM |
932 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
933 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
934 | int ret; | |
935 | ||
936 | /* | |
937 | * enable SRC sync convert if possible | |
938 | */ | |
939 | ||
940 | /* | |
941 | * Gen1 is not supported | |
942 | */ | |
943 | if (rsnd_is_gen1(priv)) | |
944 | return 0; | |
945 | ||
946 | /* | |
947 | * SRC sync convert needs clock master | |
948 | */ | |
949 | if (!rsnd_rdai_is_clk_master(rdai)) | |
950 | return 0; | |
951 | ||
43cb6954 KM |
952 | /* |
953 | * enable sync convert | |
954 | */ | |
b65a7ccc | 955 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
43cb6954 KM |
956 | rsnd_io_is_play(io) ? |
957 | "SRC Out Rate Switch" : | |
958 | "SRC In Rate Switch", | |
959 | rsnd_src_reconvert_update, | |
960 | &src->sen, 1); | |
961 | if (ret < 0) | |
962 | return ret; | |
963 | ||
b65a7ccc | 964 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
43cb6954 KM |
965 | rsnd_io_is_play(io) ? |
966 | "SRC Out Rate" : | |
967 | "SRC In Rate", | |
968 | rsnd_src_reconvert_update, | |
969 | &src->sync, 192000); | |
970 | ||
971 | return ret; | |
972 | } | |
973 | ||
ba9c949f | 974 | static struct rsnd_mod_ops rsnd_src_gen2_ops = { |
8aefda50 | 975 | .name = SRC_NAME, |
72adc61f | 976 | .dma_req = rsnd_src_dma_req, |
ba9c949f KM |
977 | .probe = rsnd_src_probe_gen2, |
978 | .remove = rsnd_src_remove_gen2, | |
979 | .init = rsnd_src_init_gen2, | |
980 | .quit = rsnd_src_quit, | |
981 | .start = rsnd_src_start_gen2, | |
982 | .stop = rsnd_src_stop_gen2, | |
3b7843ff | 983 | .hw_params = rsnd_src_hw_params, |
43cb6954 | 984 | .pcm_new = rsnd_src_pcm_new, |
629509c5 KM |
985 | }; |
986 | ||
ba9c949f | 987 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) |
07539c1d | 988 | { |
ba9c949f | 989 | if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) |
8b14719b | 990 | id = 0; |
07539c1d | 991 | |
ba9c949f | 992 | return &((struct rsnd_src *)(priv->src) + id)->mod; |
07539c1d KM |
993 | } |
994 | ||
90e8e50f KM |
995 | static void rsnd_of_parse_src(struct platform_device *pdev, |
996 | const struct rsnd_of_data *of_data, | |
997 | struct rsnd_priv *priv) | |
998 | { | |
999 | struct device_node *src_node; | |
cfcefe01 | 1000 | struct device_node *np; |
90e8e50f KM |
1001 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
1002 | struct rsnd_src_platform_info *src_info; | |
1003 | struct device *dev = &pdev->dev; | |
cfcefe01 | 1004 | int nr, i; |
90e8e50f KM |
1005 | |
1006 | if (!of_data) | |
1007 | return; | |
1008 | ||
82e76ed3 | 1009 | src_node = rsnd_src_of_node(priv); |
90e8e50f KM |
1010 | if (!src_node) |
1011 | return; | |
1012 | ||
1013 | nr = of_get_child_count(src_node); | |
1014 | if (!nr) | |
f451e48d | 1015 | goto rsnd_of_parse_src_end; |
90e8e50f KM |
1016 | |
1017 | src_info = devm_kzalloc(dev, | |
1018 | sizeof(struct rsnd_src_platform_info) * nr, | |
1019 | GFP_KERNEL); | |
1020 | if (!src_info) { | |
1021 | dev_err(dev, "src info allocation error\n"); | |
f451e48d | 1022 | goto rsnd_of_parse_src_end; |
90e8e50f KM |
1023 | } |
1024 | ||
1025 | info->src_info = src_info; | |
1026 | info->src_info_nr = nr; | |
f451e48d | 1027 | |
cfcefe01 KM |
1028 | i = 0; |
1029 | for_each_child_of_node(src_node, np) { | |
1030 | src_info[i].irq = irq_of_parse_and_map(np, 0); | |
1031 | ||
1032 | i++; | |
1033 | } | |
1034 | ||
f451e48d KM |
1035 | rsnd_of_parse_src_end: |
1036 | of_node_put(src_node); | |
90e8e50f KM |
1037 | } |
1038 | ||
ba9c949f | 1039 | int rsnd_src_probe(struct platform_device *pdev, |
90e8e50f | 1040 | const struct rsnd_of_data *of_data, |
07539c1d KM |
1041 | struct rsnd_priv *priv) |
1042 | { | |
5da39cf3 | 1043 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
07539c1d | 1044 | struct device *dev = rsnd_priv_to_dev(priv); |
ba9c949f | 1045 | struct rsnd_src *src; |
013f38fe | 1046 | struct rsnd_mod_ops *ops; |
ef749400 | 1047 | struct clk *clk; |
ba9c949f | 1048 | char name[RSND_SRC_NAME_SIZE]; |
2f78dd7f | 1049 | int i, nr, ret; |
07539c1d | 1050 | |
033e7ed8 KM |
1051 | ops = NULL; |
1052 | if (rsnd_is_gen1(priv)) | |
1053 | ops = &rsnd_src_gen1_ops; | |
1054 | if (rsnd_is_gen2(priv)) | |
1055 | ops = &rsnd_src_gen2_ops; | |
1056 | if (!ops) { | |
1057 | dev_err(dev, "unknown Generation\n"); | |
1058 | return -EIO; | |
1059 | } | |
1060 | ||
90e8e50f KM |
1061 | rsnd_of_parse_src(pdev, of_data, priv); |
1062 | ||
07539c1d | 1063 | /* |
ba9c949f | 1064 | * init SRC |
07539c1d | 1065 | */ |
ba9c949f | 1066 | nr = info->src_info_nr; |
389933d9 KM |
1067 | if (!nr) |
1068 | return 0; | |
1069 | ||
ba9c949f | 1070 | src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); |
33363f7a | 1071 | if (!src) |
07539c1d | 1072 | return -ENOMEM; |
07539c1d | 1073 | |
ba9c949f KM |
1074 | priv->src_nr = nr; |
1075 | priv->src = src; | |
07539c1d | 1076 | |
ba9c949f | 1077 | for_each_rsnd_src(src, priv, i) { |
8aefda50 KM |
1078 | snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", |
1079 | SRC_NAME, i); | |
ef749400 KM |
1080 | |
1081 | clk = devm_clk_get(dev, name); | |
1082 | if (IS_ERR(clk)) | |
1083 | return PTR_ERR(clk); | |
1084 | ||
ba9c949f | 1085 | src->info = &info->src_info[i]; |
07539c1d | 1086 | |
2099bc8e | 1087 | ret = rsnd_mod_init(priv, &src->mod, ops, clk, RSND_MOD_SRC, i); |
2f78dd7f KM |
1088 | if (ret) |
1089 | return ret; | |
374a5281 | 1090 | } |
07539c1d KM |
1091 | |
1092 | return 0; | |
1093 | } | |
2f78dd7f KM |
1094 | |
1095 | void rsnd_src_remove(struct platform_device *pdev, | |
1096 | struct rsnd_priv *priv) | |
1097 | { | |
1098 | struct rsnd_src *src; | |
1099 | int i; | |
1100 | ||
1101 | for_each_rsnd_src(src, priv, i) { | |
1102 | rsnd_mod_quit(&src->mod); | |
1103 | } | |
1104 | } |