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