ASoC: rsnd: add recovery support for under/over flow error on SRC
[deliverable/linux.git] / sound / soc / sh / rcar / src.c
1 /*
2 * Renesas R-Car SRC support
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
13 #define SRC_NAME "src"
14
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
22 struct rsnd_src {
23 struct rsnd_src_platform_info *info; /* rcar_snd.h */
24 struct rsnd_mod mod;
25 struct clk *clk;
26 int err;
27 };
28
29 #define RSND_SRC_NAME_SIZE 16
30
31 #define rsnd_src_convert_rate(p) ((p)->info->convert_rate)
32 #define rsnd_mod_to_src(_mod) \
33 container_of((_mod), struct rsnd_src, mod)
34 #define rsnd_src_dma_available(src) \
35 rsnd_dma_available(rsnd_mod_to_dma(&(src)->mod))
36
37 #define for_each_rsnd_src(pos, priv, i) \
38 for ((i) = 0; \
39 ((i) < rsnd_src_nr(priv)) && \
40 ((pos) = (struct rsnd_src *)(priv)->src + i); \
41 i++)
42
43
44 /*
45 * image of SRC (Sampling Rate Converter)
46 *
47 * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
48 * 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
49 * 44.1kHz <-> +-----+ +-----+ +-------+
50 * ...
51 *
52 */
53
54 /*
55 * src.c is caring...
56 *
57 * Gen1
58 *
59 * [mem] -> [SRU] -> [SSI]
60 * |--------|
61 *
62 * Gen2
63 *
64 * [mem] -> [SRC] -> [SSIU] -> [SSI]
65 * |-----------------|
66 */
67
68 /*
69 * How to use SRC bypass mode for debugging
70 *
71 * SRC has bypass mode, and it is useful for debugging.
72 * In Gen2 case,
73 * SRCm_MODE controls whether SRC is used or not
74 * SSI_MODE0 controls whether SSIU which receives SRC data
75 * is used or not.
76 * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC,
77 * but SRC bypass mode needs SSI_MODE0 only.
78 *
79 * This driver request
80 * struct rsnd_src_platform_info {
81 * u32 convert_rate;
82 * int dma_id;
83 * }
84 *
85 * rsnd_src_convert_rate() indicates
86 * above convert_rate, and it controls
87 * whether SRC is used or not.
88 *
89 * ex) doesn't use SRC
90 * static struct rsnd_dai_platform_info rsnd_dai = {
91 * .playback = { .ssi = &rsnd_ssi[0], },
92 * };
93 *
94 * ex) uses SRC
95 * static struct rsnd_src_platform_info rsnd_src[] = {
96 * RSND_SCU(48000, 0),
97 * ...
98 * };
99 * static struct rsnd_dai_platform_info rsnd_dai = {
100 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
101 * };
102 *
103 * ex) uses SRC bypass mode
104 * static struct rsnd_src_platform_info rsnd_src[] = {
105 * RSND_SCU(0, 0),
106 * ...
107 * };
108 * static struct rsnd_dai_platform_info rsnd_dai = {
109 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
110 * };
111 *
112 */
113
114 /*
115 * Gen1/Gen2 common functions
116 */
117 int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
118 struct rsnd_dai *rdai,
119 int use_busif)
120 {
121 struct rsnd_dai_stream *io = rsnd_mod_to_io(ssi_mod);
122 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
123 int ssi_id = rsnd_mod_id(ssi_mod);
124
125 /*
126 * SSI_MODE0
127 */
128 rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id),
129 !use_busif << ssi_id);
130
131 /*
132 * SSI_MODE1
133 */
134 if (rsnd_ssi_is_pin_sharing(ssi_mod)) {
135 int shift = -1;
136 switch (ssi_id) {
137 case 1:
138 shift = 0;
139 break;
140 case 2:
141 shift = 2;
142 break;
143 case 4:
144 shift = 16;
145 break;
146 }
147
148 if (shift >= 0)
149 rsnd_mod_bset(ssi_mod, SSI_MODE1,
150 0x3 << shift,
151 rsnd_dai_is_clk_master(rdai) ?
152 0x2 << shift : 0x1 << shift);
153 }
154
155 /*
156 * DMA settings for SSIU
157 */
158 if (use_busif) {
159 u32 val = 0x76543210;
160 u32 mask = ~0;
161
162 rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR,
163 rsnd_get_adinr(ssi_mod));
164 rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1);
165 rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1);
166
167 mask <<= runtime->channels * 4;
168 val = val & mask;
169
170 switch (runtime->sample_bits) {
171 case 16:
172 val |= 0x67452301 & ~mask;
173 break;
174 case 32:
175 val |= 0x76543210 & ~mask;
176 break;
177 }
178 rsnd_mod_write(ssi_mod, BUSIF_DALIGN, val);
179
180 }
181
182 return 0;
183 }
184
185 int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
186 struct rsnd_dai *rdai)
187 {
188 /*
189 * DMA settings for SSIU
190 */
191 rsnd_mod_write(ssi_mod, SSI_CTRL, 0);
192
193 return 0;
194 }
195
196 int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod,
197 struct rsnd_dai *rdai)
198 {
199 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
200
201 if (rsnd_is_gen1(priv))
202 return 0;
203
204 /* enable SSI interrupt if Gen2 */
205 if (rsnd_ssi_is_dma_mode(ssi_mod))
206 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0e000000);
207 else
208 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000);
209
210 return 0;
211 }
212
213 int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod,
214 struct rsnd_dai *rdai)
215 {
216 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
217
218 if (rsnd_is_gen1(priv))
219 return 0;
220
221 /* disable SSI interrupt if Gen2 */
222 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x00000000);
223
224 return 0;
225 }
226
227 unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
228 struct rsnd_dai_stream *io,
229 struct snd_pcm_runtime *runtime)
230 {
231 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
232 struct rsnd_src *src;
233 unsigned int rate = 0;
234
235 if (src_mod) {
236 src = rsnd_mod_to_src(src_mod);
237
238 /*
239 * return convert rate if SRC is used,
240 * otherwise, return runtime->rate as usual
241 */
242 rate = rsnd_src_convert_rate(src);
243 }
244
245 if (!rate)
246 rate = runtime->rate;
247
248 return rate;
249 }
250
251 static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
252 struct rsnd_dai *rdai)
253 {
254 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
255 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
256 struct rsnd_src *src = rsnd_mod_to_src(mod);
257 u32 convert_rate = rsnd_src_convert_rate(src);
258 u32 fsrate = 0;
259
260 if (convert_rate)
261 fsrate = 0x0400000 / convert_rate * runtime->rate;
262
263 /* set/clear soft reset */
264 rsnd_mod_write(mod, SRC_SWRSR, 0);
265 rsnd_mod_write(mod, SRC_SWRSR, 1);
266
267 /* Set channel number and output bit length */
268 rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod));
269
270 /* Enable the initial value of IFS */
271 if (fsrate) {
272 rsnd_mod_write(mod, SRC_IFSCR, 1);
273
274 /* Set initial value of IFS */
275 rsnd_mod_write(mod, SRC_IFSVR, fsrate);
276 }
277
278 /* use DMA transfer */
279 rsnd_mod_write(mod, SRC_BUSIF_MODE, 1);
280
281 return 0;
282 }
283
284 static int rsnd_src_init(struct rsnd_mod *mod,
285 struct rsnd_dai *rdai)
286 {
287 struct rsnd_src *src = rsnd_mod_to_src(mod);
288
289 clk_prepare_enable(src->clk);
290
291 src->err = 0;
292
293 /*
294 * Initialize the operation of the SRC internal circuits
295 * see rsnd_src_start()
296 */
297 rsnd_mod_write(mod, SRC_SRCIR, 1);
298
299 return 0;
300 }
301
302 static int rsnd_src_quit(struct rsnd_mod *mod,
303 struct rsnd_dai *rdai)
304 {
305 struct rsnd_src *src = rsnd_mod_to_src(mod);
306 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
307 struct device *dev = rsnd_priv_to_dev(priv);
308
309 clk_disable_unprepare(src->clk);
310
311 if (src->err)
312 dev_warn(dev, "src under/over flow err = %d\n", src->err);
313
314 return 0;
315 }
316
317 static int rsnd_src_start(struct rsnd_mod *mod)
318 {
319 /*
320 * Cancel the initialization and operate the SRC function
321 * see rsnd_src_init()
322 */
323 rsnd_mod_write(mod, SRC_SRCIR, 0);
324
325 return 0;
326 }
327
328 static int rsnd_src_stop(struct rsnd_mod *mod)
329 {
330 /* nothing to do */
331 return 0;
332 }
333
334 /*
335 * Gen1 functions
336 */
337 static int rsnd_src_set_route_gen1(struct rsnd_mod *mod,
338 struct rsnd_dai *rdai)
339 {
340 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
341 struct src_route_config {
342 u32 mask;
343 int shift;
344 } routes[] = {
345 { 0xF, 0, }, /* 0 */
346 { 0xF, 4, }, /* 1 */
347 { 0xF, 8, }, /* 2 */
348 { 0x7, 12, }, /* 3 */
349 { 0x7, 16, }, /* 4 */
350 { 0x7, 20, }, /* 5 */
351 { 0x7, 24, }, /* 6 */
352 { 0x3, 28, }, /* 7 */
353 { 0x3, 30, }, /* 8 */
354 };
355 u32 mask;
356 u32 val;
357 int id;
358
359 id = rsnd_mod_id(mod);
360 if (id < 0 || id >= ARRAY_SIZE(routes))
361 return -EIO;
362
363 /*
364 * SRC_ROUTE_SELECT
365 */
366 val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
367 val = val << routes[id].shift;
368 mask = routes[id].mask << routes[id].shift;
369
370 rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
371
372 return 0;
373 }
374
375 static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod,
376 struct rsnd_dai *rdai)
377 {
378 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
379 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
380 struct rsnd_src *src = rsnd_mod_to_src(mod);
381 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
382 u32 convert_rate = rsnd_src_convert_rate(src);
383 u32 mask;
384 u32 val;
385 int shift;
386 int id = rsnd_mod_id(mod);
387 int ret;
388
389 /*
390 * SRC_TIMING_SELECT
391 */
392 shift = (id % 4) * 8;
393 mask = 0x1F << shift;
394
395 /*
396 * ADG is used as source clock if SRC was used,
397 * then, SSI WS is used as destination clock.
398 * SSI WS is used as source clock if SRC is not used
399 * (when playback, source/destination become reverse when capture)
400 */
401 ret = 0;
402 if (convert_rate) {
403 /* use ADG */
404 val = 0;
405 ret = rsnd_adg_set_convert_clk_gen1(priv, mod,
406 runtime->rate,
407 convert_rate);
408 } else if (8 == id) {
409 /* use SSI WS, but SRU8 is special */
410 val = id << shift;
411 } else {
412 /* use SSI WS */
413 val = (id + 1) << shift;
414 }
415
416 if (ret < 0)
417 return ret;
418
419 switch (id / 4) {
420 case 0:
421 rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
422 break;
423 case 1:
424 rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
425 break;
426 case 2:
427 rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
428 break;
429 }
430
431 return 0;
432 }
433
434 static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
435 struct rsnd_dai *rdai)
436 {
437 struct rsnd_src *src = rsnd_mod_to_src(mod);
438 int ret;
439
440 ret = rsnd_src_set_convert_rate(mod, rdai);
441 if (ret < 0)
442 return ret;
443
444 /* Select SRC mode (fixed value) */
445 rsnd_mod_write(mod, SRC_SRCCR, 0x00010110);
446
447 /* Set the restriction value of the FS ratio (98%) */
448 rsnd_mod_write(mod, SRC_MNFSR,
449 rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
450
451 /* Gen1/Gen2 are not compatible */
452 if (rsnd_src_convert_rate(src))
453 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
454
455 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
456
457 return 0;
458 }
459
460 static int rsnd_src_probe_gen1(struct rsnd_mod *mod,
461 struct rsnd_dai *rdai)
462 {
463 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
464 struct device *dev = rsnd_priv_to_dev(priv);
465
466 dev_dbg(dev, "%s[%d] (Gen1) is probed\n",
467 rsnd_mod_name(mod), rsnd_mod_id(mod));
468
469 return 0;
470 }
471
472 static int rsnd_src_init_gen1(struct rsnd_mod *mod,
473 struct rsnd_dai *rdai)
474 {
475 int ret;
476
477 ret = rsnd_src_init(mod, rdai);
478 if (ret < 0)
479 return ret;
480
481 ret = rsnd_src_set_route_gen1(mod, rdai);
482 if (ret < 0)
483 return ret;
484
485 ret = rsnd_src_set_convert_rate_gen1(mod, rdai);
486 if (ret < 0)
487 return ret;
488
489 ret = rsnd_src_set_convert_timing_gen1(mod, rdai);
490 if (ret < 0)
491 return ret;
492
493 return 0;
494 }
495
496 static int rsnd_src_start_gen1(struct rsnd_mod *mod,
497 struct rsnd_dai *rdai)
498 {
499 int id = rsnd_mod_id(mod);
500
501 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id));
502
503 return rsnd_src_start(mod);
504 }
505
506 static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
507 struct rsnd_dai *rdai)
508 {
509 int id = rsnd_mod_id(mod);
510
511 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0);
512
513 return rsnd_src_stop(mod);
514 }
515
516 static struct rsnd_mod_ops rsnd_src_gen1_ops = {
517 .name = SRC_NAME,
518 .probe = rsnd_src_probe_gen1,
519 .init = rsnd_src_init_gen1,
520 .quit = rsnd_src_quit,
521 .start = rsnd_src_start_gen1,
522 .stop = rsnd_src_stop_gen1,
523 };
524
525 /*
526 * Gen2 functions
527 */
528 #define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1)
529 #define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0)
530 static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod *mod, int enable)
531 {
532 struct rsnd_src *src = rsnd_mod_to_src(mod);
533 u32 sys_int_val, int_val, sys_int_mask;
534 int irq = src->info->irq;
535 int id = rsnd_mod_id(mod);
536
537 sys_int_val =
538 sys_int_mask = OUF_SRC(id);
539 int_val = 0x3300;
540
541 /*
542 * IRQ is not supported on non-DT
543 * see
544 * rsnd_src_probe_gen2()
545 */
546 if ((irq <= 0) || !enable) {
547 sys_int_val = 0;
548 int_val = 0;
549 }
550
551 rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val);
552 rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val);
553 rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val);
554 }
555
556 static void rsnd_src_error_clear_gen2(struct rsnd_mod *mod)
557 {
558 u32 val = OUF_SRC(rsnd_mod_id(mod));
559
560 rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val);
561 rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val);
562 }
563
564 static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod)
565 {
566 u32 val = OUF_SRC(rsnd_mod_id(mod));
567 bool ret = false;
568
569 if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val) ||
570 (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val)) {
571 struct rsnd_src *src = rsnd_mod_to_src(mod);
572
573 src->err++;
574 ret = true;
575 }
576
577 /* clear error static */
578 rsnd_src_error_clear_gen2(mod);
579
580 return ret;
581 }
582
583 static int _rsnd_src_start_gen2(struct rsnd_mod *mod)
584 {
585 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
586 u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11;
587
588 rsnd_mod_write(mod, SRC_CTRL, val);
589
590 rsnd_src_error_clear_gen2(mod);
591
592 rsnd_src_start(mod);
593
594 rsnd_src_irq_enable_gen2(mod);
595
596 return 0;
597 }
598
599 static int _rsnd_src_stop_gen2(struct rsnd_mod *mod)
600 {
601 rsnd_src_irq_disable_gen2(mod);
602
603 rsnd_mod_write(mod, SRC_CTRL, 0);
604
605 rsnd_src_error_record_gen2(mod);
606
607 return rsnd_src_stop(mod);
608 }
609
610 static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data)
611 {
612 struct rsnd_mod *mod = data;
613 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
614
615 if (!io)
616 return IRQ_NONE;
617
618 if (rsnd_src_error_record_gen2(mod)) {
619 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
620 struct device *dev = rsnd_priv_to_dev(priv);
621
622 _rsnd_src_stop_gen2(mod);
623 _rsnd_src_start_gen2(mod);
624
625 dev_dbg(dev, "%s[%d] restart\n",
626 rsnd_mod_name(mod), rsnd_mod_id(mod));
627 }
628
629 return IRQ_HANDLED;
630 }
631
632 static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
633 struct rsnd_dai *rdai)
634 {
635 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
636 struct device *dev = rsnd_priv_to_dev(priv);
637 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
638 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
639 struct rsnd_src *src = rsnd_mod_to_src(mod);
640 u32 convert_rate = rsnd_src_convert_rate(src);
641 uint ratio;
642 int ret;
643
644 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */
645 if (!convert_rate)
646 ratio = 0;
647 else if (convert_rate > runtime->rate)
648 ratio = 100 * convert_rate / runtime->rate;
649 else
650 ratio = 100 * runtime->rate / convert_rate;
651
652 if (ratio > 600) {
653 dev_err(dev, "FSO/FSI ratio error\n");
654 return -EINVAL;
655 }
656
657 ret = rsnd_src_set_convert_rate(mod, rdai);
658 if (ret < 0)
659 return ret;
660
661 rsnd_mod_write(mod, SRC_SRCCR, 0x00011110);
662
663 if (convert_rate) {
664 /* Gen1/Gen2 are not compatible */
665 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
666 }
667
668 switch (rsnd_mod_id(mod)) {
669 case 5:
670 case 6:
671 case 7:
672 case 8:
673 rsnd_mod_write(mod, SRC_BSDSR, 0x02400000);
674 break;
675 default:
676 rsnd_mod_write(mod, SRC_BSDSR, 0x01800000);
677 break;
678 }
679
680 rsnd_mod_write(mod, SRC_BSISR, 0x00100060);
681
682 return 0;
683 }
684
685 static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod,
686 struct rsnd_dai *rdai)
687 {
688 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
689 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
690 struct rsnd_src *src = rsnd_mod_to_src(mod);
691 u32 convert_rate = rsnd_src_convert_rate(src);
692 int ret;
693
694 if (convert_rate)
695 ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io,
696 runtime->rate,
697 convert_rate);
698 else
699 ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io);
700
701 return ret;
702 }
703
704 static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
705 struct rsnd_dai *rdai)
706 {
707 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
708 struct rsnd_src *src = rsnd_mod_to_src(mod);
709 struct device *dev = rsnd_priv_to_dev(priv);
710 int irq = src->info->irq;
711 int ret;
712
713 if (irq > 0) {
714 /*
715 * IRQ is not supported on non-DT
716 * see
717 * rsnd_src_irq_enable_gen2()
718 */
719 ret = devm_request_irq(dev, irq,
720 rsnd_src_interrupt_gen2,
721 IRQF_SHARED,
722 dev_name(dev), mod);
723 if (ret)
724 goto rsnd_src_probe_gen2_fail;
725 }
726
727 ret = rsnd_dma_init(priv,
728 rsnd_mod_to_dma(mod),
729 rsnd_info_is_playback(priv, src),
730 src->info->dma_id);
731 if (ret)
732 goto rsnd_src_probe_gen2_fail;
733
734 dev_dbg(dev, "%s[%d] (Gen2) is probed\n",
735 rsnd_mod_name(mod), rsnd_mod_id(mod));
736
737 return ret;
738
739 rsnd_src_probe_gen2_fail:
740 dev_err(dev, "%s[%d] (Gen2) failed\n",
741 rsnd_mod_name(mod), rsnd_mod_id(mod));
742
743 return ret;
744 }
745
746 static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
747 struct rsnd_dai *rdai)
748 {
749 rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod));
750
751 return 0;
752 }
753
754 static int rsnd_src_init_gen2(struct rsnd_mod *mod,
755 struct rsnd_dai *rdai)
756 {
757 int ret;
758
759 ret = rsnd_src_init(mod, rdai);
760 if (ret < 0)
761 return ret;
762
763 ret = rsnd_src_set_convert_rate_gen2(mod, rdai);
764 if (ret < 0)
765 return ret;
766
767 ret = rsnd_src_set_convert_timing_gen2(mod, rdai);
768 if (ret < 0)
769 return ret;
770
771 return 0;
772 }
773
774 static int rsnd_src_start_gen2(struct rsnd_mod *mod,
775 struct rsnd_dai *rdai)
776 {
777 rsnd_dma_start(rsnd_mod_to_dma(mod));
778
779 return _rsnd_src_start_gen2(mod);
780 }
781
782 static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
783 struct rsnd_dai *rdai)
784 {
785 int ret;
786
787 ret = _rsnd_src_stop_gen2(mod);
788
789 rsnd_dma_stop(rsnd_mod_to_dma(mod));
790
791 return ret;
792 }
793
794 static struct rsnd_mod_ops rsnd_src_gen2_ops = {
795 .name = SRC_NAME,
796 .probe = rsnd_src_probe_gen2,
797 .remove = rsnd_src_remove_gen2,
798 .init = rsnd_src_init_gen2,
799 .quit = rsnd_src_quit,
800 .start = rsnd_src_start_gen2,
801 .stop = rsnd_src_stop_gen2,
802 };
803
804 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
805 {
806 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
807 id = 0;
808
809 return &((struct rsnd_src *)(priv->src) + id)->mod;
810 }
811
812 static void rsnd_of_parse_src(struct platform_device *pdev,
813 const struct rsnd_of_data *of_data,
814 struct rsnd_priv *priv)
815 {
816 struct device_node *src_node;
817 struct device_node *np;
818 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
819 struct rsnd_src_platform_info *src_info;
820 struct device *dev = &pdev->dev;
821 int nr, i;
822
823 if (!of_data)
824 return;
825
826 src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
827 if (!src_node)
828 return;
829
830 nr = of_get_child_count(src_node);
831 if (!nr)
832 goto rsnd_of_parse_src_end;
833
834 src_info = devm_kzalloc(dev,
835 sizeof(struct rsnd_src_platform_info) * nr,
836 GFP_KERNEL);
837 if (!src_info) {
838 dev_err(dev, "src info allocation error\n");
839 goto rsnd_of_parse_src_end;
840 }
841
842 info->src_info = src_info;
843 info->src_info_nr = nr;
844
845 i = 0;
846 for_each_child_of_node(src_node, np) {
847 src_info[i].irq = irq_of_parse_and_map(np, 0);
848
849 i++;
850 }
851
852 rsnd_of_parse_src_end:
853 of_node_put(src_node);
854 }
855
856 int rsnd_src_probe(struct platform_device *pdev,
857 const struct rsnd_of_data *of_data,
858 struct rsnd_priv *priv)
859 {
860 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
861 struct device *dev = rsnd_priv_to_dev(priv);
862 struct rsnd_src *src;
863 struct rsnd_mod_ops *ops;
864 struct clk *clk;
865 char name[RSND_SRC_NAME_SIZE];
866 int i, nr;
867
868 ops = NULL;
869 if (rsnd_is_gen1(priv))
870 ops = &rsnd_src_gen1_ops;
871 if (rsnd_is_gen2(priv))
872 ops = &rsnd_src_gen2_ops;
873 if (!ops) {
874 dev_err(dev, "unknown Generation\n");
875 return -EIO;
876 }
877
878 rsnd_of_parse_src(pdev, of_data, priv);
879
880 /*
881 * init SRC
882 */
883 nr = info->src_info_nr;
884 if (!nr)
885 return 0;
886
887 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
888 if (!src) {
889 dev_err(dev, "SRC allocate failed\n");
890 return -ENOMEM;
891 }
892
893 priv->src_nr = nr;
894 priv->src = src;
895
896 for_each_rsnd_src(src, priv, i) {
897 snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
898 SRC_NAME, i);
899
900 clk = devm_clk_get(dev, name);
901 if (IS_ERR(clk))
902 return PTR_ERR(clk);
903
904 src->info = &info->src_info[i];
905 src->clk = clk;
906
907 rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i);
908
909 dev_dbg(dev, "SRC%d probed\n", i);
910 }
911
912 return 0;
913 }
This page took 0.050234 seconds and 5 git commands to generate.