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