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