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