2 * Renesas R-Car SRC support
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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.
13 #define SRC_NAME "src"
16 #define OUF_SRCO ((1 << 12) | (1 << 13))
17 #define OUF_SRCI ((1 << 9) | (1 << 8))
19 /* SCU_SYSTEM_STATUS0/1 */
20 #define OUF_SRC(id) ((1 << (id + 16)) | (1 << id))
23 struct rsnd_src_platform_info
*info
; /* rcar_snd.h */
25 struct rsnd_kctrl_cfg_s sen
; /* sync convert enable */
26 struct rsnd_kctrl_cfg_s sync
; /* sync convert */
27 u32 convert_rate
; /* sampling rate convert */
31 #define RSND_SRC_NAME_SIZE 16
33 #define rsnd_src_nr(priv) ((priv)->src_nr)
34 #define rsnd_enable_sync_convert(src) ((src)->sen.val)
35 #define rsnd_src_of_node(priv) \
36 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src")
38 #define rsnd_mod_to_src(_mod) \
39 container_of((_mod), struct rsnd_src, mod)
41 #define for_each_rsnd_src(pos, priv, i) \
43 ((i) < rsnd_src_nr(priv)) && \
44 ((pos) = (struct rsnd_src *)(priv)->src + i); \
49 * image of SRC (Sampling Rate Converter)
51 * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
52 * 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
53 * 44.1kHz <-> +-----+ +-----+ +-------+
63 * [mem] -> [SRU] -> [SSI]
68 * [mem] -> [SRC] -> [SSIU] -> [SSI]
73 * How to use SRC bypass mode for debugging
75 * SRC has bypass mode, and it is useful for debugging.
77 * SRCm_MODE controls whether SRC is used or not
78 * SSI_MODE0 controls whether SSIU which receives SRC data
80 * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC,
81 * but SRC bypass mode needs SSI_MODE0 only.
84 * struct rsnd_src_platform_info {
89 * rsnd_src_convert_rate() indicates
90 * above convert_rate, and it controls
91 * whether SRC is used or not.
94 * static struct rsnd_dai_platform_info rsnd_dai = {
95 * .playback = { .ssi = &rsnd_ssi[0], },
99 * static struct rsnd_src_platform_info rsnd_src[] = {
100 * RSND_SCU(48000, 0),
103 * static struct rsnd_dai_platform_info rsnd_dai = {
104 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
107 * ex) uses SRC bypass mode
108 * static struct rsnd_src_platform_info rsnd_src[] = {
112 * static struct rsnd_dai_platform_info rsnd_dai = {
113 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
119 * Gen1/Gen2 common functions
121 static void rsnd_src_soft_reset(struct rsnd_mod
*mod
)
123 rsnd_mod_write(mod
, SRC_SWRSR
, 0);
124 rsnd_mod_write(mod
, SRC_SWRSR
, 1);
127 static struct dma_chan
*rsnd_src_dma_req(struct rsnd_dai_stream
*io
,
128 struct rsnd_mod
*mod
)
130 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
131 int is_play
= rsnd_io_is_play(io
);
133 return rsnd_dma_request_channel(rsnd_src_of_node(priv
),
135 is_play
? "rx" : "tx");
138 int rsnd_src_ssiu_start(struct rsnd_mod
*ssi_mod
,
139 struct rsnd_dai_stream
*io
,
142 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
143 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
144 int ssi_id
= rsnd_mod_id(ssi_mod
);
149 rsnd_mod_bset(ssi_mod
, SSI_MODE0
, (1 << ssi_id
),
150 !use_busif
<< ssi_id
);
155 if (rsnd_ssi_is_pin_sharing(ssi_mod
)) {
170 rsnd_mod_bset(ssi_mod
, SSI_MODE1
,
172 rsnd_rdai_is_clk_master(rdai
) ?
173 0x2 << shift
: 0x1 << shift
);
177 * DMA settings for SSIU
180 u32 val
= 0x76543210;
183 rsnd_mod_write(ssi_mod
, SSI_BUSIF_ADINR
,
184 rsnd_get_adinr(ssi_mod
, io
));
185 rsnd_mod_write(ssi_mod
, SSI_BUSIF_MODE
, 1);
186 rsnd_mod_write(ssi_mod
, SSI_CTRL
, 0x1);
188 mask
<<= runtime
->channels
* 4;
191 switch (runtime
->sample_bits
) {
193 val
|= 0x67452301 & ~mask
;
196 val
|= 0x76543210 & ~mask
;
199 rsnd_mod_write(ssi_mod
, SSI_BUSIF_DALIGN
, val
);
206 int rsnd_src_ssiu_stop(struct rsnd_mod
*ssi_mod
,
207 struct rsnd_dai_stream
*io
)
210 * DMA settings for SSIU
212 rsnd_mod_write(ssi_mod
, SSI_CTRL
, 0);
217 int rsnd_src_ssi_irq_enable(struct rsnd_mod
*ssi_mod
)
219 struct rsnd_priv
*priv
= rsnd_mod_to_priv(ssi_mod
);
221 if (rsnd_is_gen1(priv
))
224 /* enable SSI interrupt if Gen2 */
225 rsnd_mod_write(ssi_mod
, SSI_INT_ENABLE
,
226 rsnd_ssi_is_dma_mode(ssi_mod
) ?
227 0x0e000000 : 0x0f000000);
232 int rsnd_src_ssi_irq_disable(struct rsnd_mod
*ssi_mod
)
234 struct rsnd_priv
*priv
= rsnd_mod_to_priv(ssi_mod
);
236 if (rsnd_is_gen1(priv
))
239 /* disable SSI interrupt if Gen2 */
240 rsnd_mod_write(ssi_mod
, SSI_INT_ENABLE
, 0x00000000);
245 static u32
rsnd_src_convert_rate(struct rsnd_dai_stream
*io
,
246 struct rsnd_src
*src
)
248 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
254 if (!rsnd_enable_sync_convert(src
))
255 return src
->convert_rate
;
257 convert_rate
= src
->sync
.val
;
260 convert_rate
= src
->convert_rate
;
263 convert_rate
= runtime
->rate
;
268 unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv
*priv
,
269 struct rsnd_dai_stream
*io
,
270 struct snd_pcm_runtime
*runtime
)
272 struct rsnd_mod
*src_mod
= rsnd_io_to_mod_src(io
);
273 struct rsnd_src
*src
;
274 unsigned int rate
= 0;
277 src
= rsnd_mod_to_src(src_mod
);
280 * return convert rate if SRC is used,
281 * otherwise, return runtime->rate as usual
283 rate
= rsnd_src_convert_rate(io
, src
);
287 rate
= runtime
->rate
;
292 static int rsnd_src_set_convert_rate(struct rsnd_mod
*mod
,
293 struct rsnd_dai_stream
*io
)
295 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
296 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
297 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
301 fsrate
= 0x0400000 / convert_rate
* runtime
->rate
;
303 /* Set channel number and output bit length */
304 rsnd_mod_write(mod
, SRC_ADINR
, rsnd_get_adinr(mod
, io
));
306 /* Enable the initial value of IFS */
308 rsnd_mod_write(mod
, SRC_IFSCR
, 1);
310 /* Set initial value of IFS */
311 rsnd_mod_write(mod
, SRC_IFSVR
, fsrate
);
314 /* use DMA transfer */
315 rsnd_mod_write(mod
, SRC_BUSIF_MODE
, 1);
320 static int rsnd_src_hw_params(struct rsnd_mod
*mod
,
321 struct rsnd_dai_stream
*io
,
322 struct snd_pcm_substream
*substream
,
323 struct snd_pcm_hw_params
*fe_params
)
325 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
326 struct snd_soc_pcm_runtime
*fe
= substream
->private_data
;
328 /* default value (mainly for non-DT) */
329 src
->convert_rate
= src
->info
->convert_rate
;
332 * SRC assumes that it is used under DPCM if user want to use
333 * sampling rate convert. Then, SRC should be FE.
334 * And then, this function will be called *after* BE settings.
335 * this means, each BE already has fixuped hw_params.
337 * dpcm_fe_dai_hw_params()
338 * dpcm_be_dai_hw_params()
340 if (fe
->dai_link
->dynamic
) {
341 int stream
= substream
->stream
;
342 struct snd_soc_dpcm
*dpcm
;
343 struct snd_pcm_hw_params
*be_params
;
345 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
346 be_params
= &dpcm
->hw_params
;
348 if (params_rate(fe_params
) != params_rate(be_params
))
349 src
->convert_rate
= params_rate(be_params
);
356 static int rsnd_src_init(struct rsnd_mod
*mod
,
357 struct rsnd_priv
*priv
)
359 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
361 rsnd_mod_hw_start(mod
);
363 rsnd_src_soft_reset(mod
);
367 /* reset sync convert_rate */
371 * Initialize the operation of the SRC internal circuits
372 * see rsnd_src_start()
374 rsnd_mod_write(mod
, SRC_SRCIR
, 1);
379 static int rsnd_src_quit(struct rsnd_mod
*mod
,
380 struct rsnd_dai_stream
*io
,
381 struct rsnd_priv
*priv
)
383 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
384 struct device
*dev
= rsnd_priv_to_dev(priv
);
386 rsnd_mod_hw_stop(mod
);
389 dev_warn(dev
, "%s[%d] under/over flow err = %d\n",
390 rsnd_mod_name(mod
), rsnd_mod_id(mod
), src
->err
);
392 src
->convert_rate
= 0;
394 /* reset sync convert_rate */
400 static int rsnd_src_start(struct rsnd_mod
*mod
)
403 * Cancel the initialization and operate the SRC function
404 * see rsnd_src_init()
406 rsnd_mod_write(mod
, SRC_SRCIR
, 0);
411 static int rsnd_src_stop(struct rsnd_mod
*mod
)
420 static int rsnd_src_set_route_gen1(struct rsnd_dai_stream
*io
,
421 struct rsnd_mod
*mod
)
423 struct src_route_config
{
430 { 0x7, 12, }, /* 3 */
431 { 0x7, 16, }, /* 4 */
432 { 0x7, 20, }, /* 5 */
433 { 0x7, 24, }, /* 6 */
434 { 0x3, 28, }, /* 7 */
435 { 0x3, 30, }, /* 8 */
441 id
= rsnd_mod_id(mod
);
442 if (id
< 0 || id
>= ARRAY_SIZE(routes
))
448 val
= rsnd_io_is_play(io
) ? 0x1 : 0x2;
449 val
= val
<< routes
[id
].shift
;
450 mask
= routes
[id
].mask
<< routes
[id
].shift
;
452 rsnd_mod_bset(mod
, SRC_ROUTE_SEL
, mask
, val
);
457 static int rsnd_src_set_convert_timing_gen1(struct rsnd_dai_stream
*io
,
458 struct rsnd_mod
*mod
)
460 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
461 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
462 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
463 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
467 int id
= rsnd_mod_id(mod
);
473 shift
= (id
% 4) * 8;
474 mask
= 0x1F << shift
;
477 * ADG is used as source clock if SRC was used,
478 * then, SSI WS is used as destination clock.
479 * SSI WS is used as source clock if SRC is not used
480 * (when playback, source/destination become reverse when capture)
486 ret
= rsnd_adg_set_convert_clk_gen1(priv
, mod
,
489 } else if (8 == id
) {
490 /* use SSI WS, but SRU8 is special */
494 val
= (id
+ 1) << shift
;
502 rsnd_mod_bset(mod
, SRC_TMG_SEL0
, mask
, val
);
505 rsnd_mod_bset(mod
, SRC_TMG_SEL1
, mask
, val
);
508 rsnd_mod_bset(mod
, SRC_TMG_SEL2
, mask
, val
);
515 static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod
*mod
,
516 struct rsnd_dai_stream
*io
)
518 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
521 ret
= rsnd_src_set_convert_rate(mod
, io
);
525 /* Select SRC mode (fixed value) */
526 rsnd_mod_write(mod
, SRC_SRCCR
, 0x00010110);
528 /* Set the restriction value of the FS ratio (98%) */
529 rsnd_mod_write(mod
, SRC_MNFSR
,
530 rsnd_mod_read(mod
, SRC_IFSVR
) / 100 * 98);
532 /* Gen1/Gen2 are not compatible */
533 if (rsnd_src_convert_rate(io
, src
))
534 rsnd_mod_write(mod
, SRC_ROUTE_MODE0
, 1);
536 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
541 static int rsnd_src_init_gen1(struct rsnd_mod
*mod
,
542 struct rsnd_dai_stream
*io
,
543 struct rsnd_priv
*priv
)
547 ret
= rsnd_src_init(mod
, priv
);
551 ret
= rsnd_src_set_route_gen1(io
, mod
);
555 ret
= rsnd_src_set_convert_rate_gen1(mod
, io
);
559 ret
= rsnd_src_set_convert_timing_gen1(io
, mod
);
566 static int rsnd_src_start_gen1(struct rsnd_mod
*mod
,
567 struct rsnd_dai_stream
*io
,
568 struct rsnd_priv
*priv
)
570 int id
= rsnd_mod_id(mod
);
572 rsnd_mod_bset(mod
, SRC_ROUTE_CTRL
, (1 << id
), (1 << id
));
574 return rsnd_src_start(mod
);
577 static int rsnd_src_stop_gen1(struct rsnd_mod
*mod
,
578 struct rsnd_dai_stream
*io
,
579 struct rsnd_priv
*priv
)
581 int id
= rsnd_mod_id(mod
);
583 rsnd_mod_bset(mod
, SRC_ROUTE_CTRL
, (1 << id
), 0);
585 return rsnd_src_stop(mod
);
588 static struct rsnd_mod_ops rsnd_src_gen1_ops
= {
590 .dma_req
= rsnd_src_dma_req
,
591 .init
= rsnd_src_init_gen1
,
592 .quit
= rsnd_src_quit
,
593 .start
= rsnd_src_start_gen1
,
594 .stop
= rsnd_src_stop_gen1
,
595 .hw_params
= rsnd_src_hw_params
,
601 #define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1)
602 #define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0)
603 static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod
*mod
, int enable
)
605 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
606 u32 sys_int_val
, int_val
, sys_int_mask
;
607 int irq
= src
->info
->irq
;
608 int id
= rsnd_mod_id(mod
);
611 sys_int_mask
= OUF_SRC(id
);
615 * IRQ is not supported on non-DT
617 * rsnd_src_probe_gen2()
619 if ((irq
<= 0) || !enable
) {
627 * ignore over flow error when rsnd_enable_sync_convert()
629 if (rsnd_enable_sync_convert(src
))
630 sys_int_val
= sys_int_val
& 0xffff;
632 rsnd_mod_write(mod
, SRC_INT_ENABLE0
, int_val
);
633 rsnd_mod_bset(mod
, SCU_SYS_INT_EN0
, sys_int_mask
, sys_int_val
);
634 rsnd_mod_bset(mod
, SCU_SYS_INT_EN1
, sys_int_mask
, sys_int_val
);
637 static void rsnd_src_error_clear_gen2(struct rsnd_mod
*mod
)
639 u32 val
= OUF_SRC(rsnd_mod_id(mod
));
641 rsnd_mod_bset(mod
, SCU_SYS_STATUS0
, val
, val
);
642 rsnd_mod_bset(mod
, SCU_SYS_STATUS1
, val
, val
);
645 static bool rsnd_src_error_record_gen2(struct rsnd_mod
*mod
)
647 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
651 val0
= val1
= OUF_SRC(rsnd_mod_id(mod
));
656 * ignore over flow error when rsnd_enable_sync_convert()
658 if (rsnd_enable_sync_convert(src
))
659 val0
= val0
& 0xffff;
661 if ((rsnd_mod_read(mod
, SCU_SYS_STATUS0
) & val0
) ||
662 (rsnd_mod_read(mod
, SCU_SYS_STATUS1
) & val1
)) {
663 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
669 /* clear error static */
670 rsnd_src_error_clear_gen2(mod
);
675 static int _rsnd_src_start_gen2(struct rsnd_mod
*mod
,
676 struct rsnd_dai_stream
*io
)
678 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
684 * Enable SRC output if you want to use sync convert together with DVC
686 val
= (rsnd_io_to_mod_dvc(io
) && !rsnd_enable_sync_convert(src
)) ?
689 rsnd_mod_write(mod
, SRC_CTRL
, val
);
691 rsnd_src_error_clear_gen2(mod
);
695 rsnd_src_irq_enable_gen2(mod
);
700 static int _rsnd_src_stop_gen2(struct rsnd_mod
*mod
)
702 rsnd_src_irq_disable_gen2(mod
);
704 rsnd_mod_write(mod
, SRC_CTRL
, 0);
706 rsnd_src_error_record_gen2(mod
);
708 return rsnd_src_stop(mod
);
711 static void __rsnd_src_interrupt_gen2(struct rsnd_mod
*mod
,
712 struct rsnd_dai_stream
*io
)
714 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
716 spin_lock(&priv
->lock
);
718 /* ignore all cases if not working */
719 if (!rsnd_io_is_working(io
))
720 goto rsnd_src_interrupt_gen2_out
;
722 if (rsnd_src_error_record_gen2(mod
)) {
723 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
724 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
725 struct device
*dev
= rsnd_priv_to_dev(priv
);
727 dev_dbg(dev
, "%s[%d] restart\n",
728 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
730 _rsnd_src_stop_gen2(mod
);
732 _rsnd_src_start_gen2(mod
, io
);
734 dev_warn(dev
, "no more SRC restart\n");
737 rsnd_src_interrupt_gen2_out
:
738 spin_unlock(&priv
->lock
);
741 static irqreturn_t
rsnd_src_interrupt_gen2(int irq
, void *data
)
743 struct rsnd_mod
*mod
= data
;
745 rsnd_mod_interrupt(mod
, __rsnd_src_interrupt_gen2
);
750 static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod
*mod
,
751 struct rsnd_dai_stream
*io
)
753 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
754 struct device
*dev
= rsnd_priv_to_dev(priv
);
755 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
756 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
757 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
762 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */
765 else if (convert_rate
> runtime
->rate
)
766 ratio
= 100 * convert_rate
/ runtime
->rate
;
768 ratio
= 100 * runtime
->rate
/ convert_rate
;
771 dev_err(dev
, "FSO/FSI ratio error\n");
775 ret
= rsnd_src_set_convert_rate(mod
, io
);
784 if (rsnd_enable_sync_convert(src
)) {
786 route
|= rsnd_io_is_play(io
) ?
787 (0x1 << 24) : (0x1 << 25);
791 rsnd_mod_write(mod
, SRC_SRCCR
, cr
);
792 rsnd_mod_write(mod
, SRC_ROUTE_MODE0
, route
);
794 switch (rsnd_mod_id(mod
)) {
799 rsnd_mod_write(mod
, SRC_BSDSR
, 0x02400000);
802 rsnd_mod_write(mod
, SRC_BSDSR
, 0x01800000);
806 rsnd_mod_write(mod
, SRC_BSISR
, 0x00100060);
811 static int rsnd_src_set_convert_timing_gen2(struct rsnd_dai_stream
*io
,
812 struct rsnd_mod
*mod
)
814 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
815 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
816 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
820 ret
= rsnd_adg_set_convert_clk_gen2(mod
, io
,
824 ret
= rsnd_adg_set_convert_timing_gen2(mod
, io
);
829 static int rsnd_src_probe_gen2(struct rsnd_mod
*mod
,
830 struct rsnd_dai_stream
*io
,
831 struct rsnd_priv
*priv
)
833 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
834 struct device
*dev
= rsnd_priv_to_dev(priv
);
835 int irq
= src
->info
->irq
;
840 * IRQ is not supported on non-DT
842 * rsnd_src_irq_enable_gen2()
844 ret
= devm_request_irq(dev
, irq
,
845 rsnd_src_interrupt_gen2
,
852 ret
= rsnd_dma_init(io
,
853 rsnd_mod_to_dma(mod
),
859 static int rsnd_src_remove_gen2(struct rsnd_mod
*mod
,
860 struct rsnd_dai_stream
*io
,
861 struct rsnd_priv
*priv
)
863 rsnd_dma_quit(io
, rsnd_mod_to_dma(mod
));
868 static int rsnd_src_init_gen2(struct rsnd_mod
*mod
,
869 struct rsnd_dai_stream
*io
,
870 struct rsnd_priv
*priv
)
874 ret
= rsnd_src_init(mod
, priv
);
878 ret
= rsnd_src_set_convert_rate_gen2(mod
, io
);
882 ret
= rsnd_src_set_convert_timing_gen2(io
, mod
);
889 static int rsnd_src_start_gen2(struct rsnd_mod
*mod
,
890 struct rsnd_dai_stream
*io
,
891 struct rsnd_priv
*priv
)
893 rsnd_dma_start(io
, rsnd_mod_to_dma(mod
));
895 return _rsnd_src_start_gen2(mod
, io
);
898 static int rsnd_src_stop_gen2(struct rsnd_mod
*mod
,
899 struct rsnd_dai_stream
*io
,
900 struct rsnd_priv
*priv
)
904 ret
= _rsnd_src_stop_gen2(mod
);
906 rsnd_dma_stop(io
, rsnd_mod_to_dma(mod
));
911 static void rsnd_src_reconvert_update(struct rsnd_dai_stream
*io
,
912 struct rsnd_mod
*mod
)
914 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
915 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
916 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
923 convert_rate
= runtime
->rate
;
925 fsrate
= 0x0400000 / convert_rate
* runtime
->rate
;
928 rsnd_mod_write(mod
, SRC_IFSVR
, fsrate
);
931 static int rsnd_src_pcm_new(struct rsnd_mod
*mod
,
932 struct rsnd_dai_stream
*io
,
933 struct snd_soc_pcm_runtime
*rtd
)
935 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
936 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
937 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
941 * enable SRC sync convert if possible
945 * Gen1 is not supported
947 if (rsnd_is_gen1(priv
))
951 * SRC sync convert needs clock master
953 if (!rsnd_rdai_is_clk_master(rdai
))
957 * enable sync convert
959 ret
= rsnd_kctrl_new_s(mod
, io
, rtd
,
960 rsnd_io_is_play(io
) ?
961 "SRC Out Rate Switch" :
962 "SRC In Rate Switch",
963 rsnd_src_reconvert_update
,
968 ret
= rsnd_kctrl_new_s(mod
, io
, rtd
,
969 rsnd_io_is_play(io
) ?
972 rsnd_src_reconvert_update
,
978 static struct rsnd_mod_ops rsnd_src_gen2_ops
= {
980 .dma_req
= rsnd_src_dma_req
,
981 .probe
= rsnd_src_probe_gen2
,
982 .remove
= rsnd_src_remove_gen2
,
983 .init
= rsnd_src_init_gen2
,
984 .quit
= rsnd_src_quit
,
985 .start
= rsnd_src_start_gen2
,
986 .stop
= rsnd_src_stop_gen2
,
987 .hw_params
= rsnd_src_hw_params
,
988 .pcm_new
= rsnd_src_pcm_new
,
991 struct rsnd_mod
*rsnd_src_mod_get(struct rsnd_priv
*priv
, int id
)
993 if (WARN_ON(id
< 0 || id
>= rsnd_src_nr(priv
)))
996 return &((struct rsnd_src
*)(priv
->src
) + id
)->mod
;
999 static void rsnd_of_parse_src(struct platform_device
*pdev
,
1000 const struct rsnd_of_data
*of_data
,
1001 struct rsnd_priv
*priv
)
1003 struct device_node
*src_node
;
1004 struct device_node
*np
;
1005 struct rcar_snd_info
*info
= rsnd_priv_to_info(priv
);
1006 struct rsnd_src_platform_info
*src_info
;
1007 struct device
*dev
= &pdev
->dev
;
1013 src_node
= rsnd_src_of_node(priv
);
1017 nr
= of_get_child_count(src_node
);
1019 goto rsnd_of_parse_src_end
;
1021 src_info
= devm_kzalloc(dev
,
1022 sizeof(struct rsnd_src_platform_info
) * nr
,
1025 dev_err(dev
, "src info allocation error\n");
1026 goto rsnd_of_parse_src_end
;
1029 info
->src_info
= src_info
;
1030 info
->src_info_nr
= nr
;
1033 for_each_child_of_node(src_node
, np
) {
1034 src_info
[i
].irq
= irq_of_parse_and_map(np
, 0);
1039 rsnd_of_parse_src_end
:
1040 of_node_put(src_node
);
1043 int rsnd_src_probe(struct platform_device
*pdev
,
1044 const struct rsnd_of_data
*of_data
,
1045 struct rsnd_priv
*priv
)
1047 struct rcar_snd_info
*info
= rsnd_priv_to_info(priv
);
1048 struct device
*dev
= rsnd_priv_to_dev(priv
);
1049 struct rsnd_src
*src
;
1050 struct rsnd_mod_ops
*ops
;
1052 char name
[RSND_SRC_NAME_SIZE
];
1056 if (rsnd_is_gen1(priv
))
1057 ops
= &rsnd_src_gen1_ops
;
1058 if (rsnd_is_gen2(priv
))
1059 ops
= &rsnd_src_gen2_ops
;
1061 dev_err(dev
, "unknown Generation\n");
1065 rsnd_of_parse_src(pdev
, of_data
, priv
);
1070 nr
= info
->src_info_nr
;
1074 src
= devm_kzalloc(dev
, sizeof(*src
) * nr
, GFP_KERNEL
);
1081 for_each_rsnd_src(src
, priv
, i
) {
1082 snprintf(name
, RSND_SRC_NAME_SIZE
, "%s.%d",
1085 clk
= devm_clk_get(dev
, name
);
1087 return PTR_ERR(clk
);
1089 src
->info
= &info
->src_info
[i
];
1091 ret
= rsnd_mod_init(priv
, &src
->mod
, ops
, clk
, RSND_MOD_SRC
, i
);
1099 void rsnd_src_remove(struct platform_device
*pdev
,
1100 struct rsnd_priv
*priv
)
1102 struct rsnd_src
*src
;
1105 for_each_rsnd_src(src
, priv
, i
) {
1106 rsnd_mod_quit(&src
->mod
);