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 */
26 struct rsnd_kctrl_cfg_s sen
; /* sync convert enable */
27 struct rsnd_kctrl_cfg_s sync
; /* sync convert */
28 u32 convert_rate
; /* sampling rate convert */
32 #define RSND_SRC_NAME_SIZE 16
34 #define rsnd_src_to_dma(src) ((src)->dma)
35 #define rsnd_src_nr(priv) ((priv)->src_nr)
36 #define rsnd_enable_sync_convert(src) ((src)->sen.val)
37 #define rsnd_src_of_node(priv) \
38 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src")
40 #define rsnd_mod_to_src(_mod) \
41 container_of((_mod), struct rsnd_src, mod)
43 #define for_each_rsnd_src(pos, priv, i) \
45 ((i) < rsnd_src_nr(priv)) && \
46 ((pos) = (struct rsnd_src *)(priv)->src + i); \
51 * image of SRC (Sampling Rate Converter)
53 * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
54 * 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
55 * 44.1kHz <-> +-----+ +-----+ +-------+
65 * [mem] -> [SRU] -> [SSI]
70 * [mem] -> [SRC] -> [SSIU] -> [SSI]
75 * How to use SRC bypass mode for debugging
77 * SRC has bypass mode, and it is useful for debugging.
79 * SRCm_MODE controls whether SRC is used or not
80 * SSI_MODE0 controls whether SSIU which receives SRC data
82 * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC,
83 * but SRC bypass mode needs SSI_MODE0 only.
86 * struct rsnd_src_platform_info {
91 * rsnd_src_convert_rate() indicates
92 * above convert_rate, and it controls
93 * whether SRC is used or not.
96 * static struct rsnd_dai_platform_info rsnd_dai = {
97 * .playback = { .ssi = &rsnd_ssi[0], },
101 * static struct rsnd_src_platform_info rsnd_src[] = {
102 * RSND_SCU(48000, 0),
105 * static struct rsnd_dai_platform_info rsnd_dai = {
106 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
109 * ex) uses SRC bypass mode
110 * static struct rsnd_src_platform_info rsnd_src[] = {
114 * static struct rsnd_dai_platform_info rsnd_dai = {
115 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
121 * Gen1/Gen2 common functions
123 static void rsnd_src_soft_reset(struct rsnd_mod
*mod
)
125 rsnd_mod_write(mod
, SRC_SWRSR
, 0);
126 rsnd_mod_write(mod
, SRC_SWRSR
, 1);
130 #define rsnd_src_initialize_lock(mod) __rsnd_src_initialize_lock(mod, 1)
131 #define rsnd_src_initialize_unlock(mod) __rsnd_src_initialize_lock(mod, 0)
132 static void __rsnd_src_initialize_lock(struct rsnd_mod
*mod
, u32 enable
)
134 rsnd_mod_write(mod
, SRC_SRCIR
, enable
);
137 static struct dma_chan
*rsnd_src_dma_req(struct rsnd_dai_stream
*io
,
138 struct rsnd_mod
*mod
)
140 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
141 int is_play
= rsnd_io_is_play(io
);
143 return rsnd_dma_request_channel(rsnd_src_of_node(priv
),
145 is_play
? "rx" : "tx");
148 int rsnd_src_ssiu_start(struct rsnd_mod
*ssi_mod
,
149 struct rsnd_dai_stream
*io
,
152 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
153 int ssi_id
= rsnd_mod_id(ssi_mod
);
158 rsnd_mod_bset(ssi_mod
, SSI_MODE0
, (1 << ssi_id
),
159 !use_busif
<< ssi_id
);
164 if (rsnd_ssi_is_pin_sharing(io
)) {
179 rsnd_mod_bset(ssi_mod
, SSI_MODE1
,
181 rsnd_rdai_is_clk_master(rdai
) ?
182 0x2 << shift
: 0x1 << shift
);
186 * DMA settings for SSIU
189 u32 val
= rsnd_get_dalign(ssi_mod
, io
);
191 rsnd_mod_write(ssi_mod
, SSI_BUSIF_ADINR
,
192 rsnd_get_adinr_bit(ssi_mod
, io
));
193 rsnd_mod_write(ssi_mod
, SSI_BUSIF_MODE
, 1);
194 rsnd_mod_write(ssi_mod
, SSI_CTRL
, 0x1);
196 rsnd_mod_write(ssi_mod
, SSI_BUSIF_DALIGN
, val
);
202 int rsnd_src_ssiu_stop(struct rsnd_mod
*ssi_mod
,
203 struct rsnd_dai_stream
*io
)
206 * DMA settings for SSIU
208 rsnd_mod_write(ssi_mod
, SSI_CTRL
, 0);
213 static u32
rsnd_src_convert_rate(struct rsnd_dai_stream
*io
,
214 struct rsnd_src
*src
)
216 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
222 if (!rsnd_enable_sync_convert(src
))
223 return src
->convert_rate
;
225 convert_rate
= src
->sync
.val
;
228 convert_rate
= src
->convert_rate
;
231 convert_rate
= runtime
->rate
;
236 unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv
*priv
,
237 struct rsnd_dai_stream
*io
,
238 struct snd_pcm_runtime
*runtime
)
240 struct rsnd_mod
*src_mod
= rsnd_io_to_mod_src(io
);
241 struct rsnd_src
*src
;
242 unsigned int rate
= 0;
245 src
= rsnd_mod_to_src(src_mod
);
248 * return convert rate if SRC is used,
249 * otherwise, return runtime->rate as usual
251 rate
= rsnd_src_convert_rate(io
, src
);
255 rate
= runtime
->rate
;
260 static int rsnd_src_set_convert_rate(struct rsnd_mod
*mod
,
261 struct rsnd_dai_stream
*io
)
263 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
264 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
265 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
269 fsrate
= 0x0400000 / convert_rate
* runtime
->rate
;
271 /* Set channel number and output bit length */
272 rsnd_mod_write(mod
, SRC_ADINR
, rsnd_get_adinr_bit(mod
, io
));
274 /* Enable the initial value of IFS */
276 rsnd_mod_write(mod
, SRC_IFSCR
, 1);
278 /* Set initial value of IFS */
279 rsnd_mod_write(mod
, SRC_IFSVR
, fsrate
);
282 /* use DMA transfer */
283 rsnd_mod_write(mod
, SRC_BUSIF_MODE
, 1);
288 static int rsnd_src_hw_params(struct rsnd_mod
*mod
,
289 struct rsnd_dai_stream
*io
,
290 struct snd_pcm_substream
*substream
,
291 struct snd_pcm_hw_params
*fe_params
)
293 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
294 struct snd_soc_pcm_runtime
*fe
= substream
->private_data
;
296 /* default value (mainly for non-DT) */
297 src
->convert_rate
= src
->info
->convert_rate
;
300 * SRC assumes that it is used under DPCM if user want to use
301 * sampling rate convert. Then, SRC should be FE.
302 * And then, this function will be called *after* BE settings.
303 * this means, each BE already has fixuped hw_params.
305 * dpcm_fe_dai_hw_params()
306 * dpcm_be_dai_hw_params()
308 if (fe
->dai_link
->dynamic
) {
309 int stream
= substream
->stream
;
310 struct snd_soc_dpcm
*dpcm
;
311 struct snd_pcm_hw_params
*be_params
;
313 list_for_each_entry(dpcm
, &fe
->dpcm
[stream
].be_clients
, list_be
) {
314 be_params
= &dpcm
->hw_params
;
316 if (params_rate(fe_params
) != params_rate(be_params
))
317 src
->convert_rate
= params_rate(be_params
);
324 static int rsnd_src_init(struct rsnd_mod
*mod
,
325 struct rsnd_priv
*priv
)
327 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
329 rsnd_mod_power_on(mod
);
331 rsnd_src_soft_reset(mod
);
333 rsnd_src_initialize_lock(mod
);
337 /* reset sync convert_rate */
343 static int rsnd_src_quit(struct rsnd_mod
*mod
,
344 struct rsnd_dai_stream
*io
,
345 struct rsnd_priv
*priv
)
347 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
348 struct device
*dev
= rsnd_priv_to_dev(priv
);
350 rsnd_mod_power_off(mod
);
353 dev_warn(dev
, "%s[%d] under/over flow err = %d\n",
354 rsnd_mod_name(mod
), rsnd_mod_id(mod
), src
->err
);
356 src
->convert_rate
= 0;
358 /* reset sync convert_rate */
364 static int rsnd_src_start(struct rsnd_mod
*mod
)
366 rsnd_src_initialize_unlock(mod
);
371 static int rsnd_src_stop(struct rsnd_mod
*mod
)
380 static int rsnd_src_set_route_gen1(struct rsnd_dai_stream
*io
,
381 struct rsnd_mod
*mod
)
383 struct src_route_config
{
390 { 0x7, 12, }, /* 3 */
391 { 0x7, 16, }, /* 4 */
392 { 0x7, 20, }, /* 5 */
393 { 0x7, 24, }, /* 6 */
394 { 0x3, 28, }, /* 7 */
395 { 0x3, 30, }, /* 8 */
401 id
= rsnd_mod_id(mod
);
402 if (id
< 0 || id
>= ARRAY_SIZE(routes
))
408 val
= rsnd_io_is_play(io
) ? 0x1 : 0x2;
409 val
= val
<< routes
[id
].shift
;
410 mask
= routes
[id
].mask
<< routes
[id
].shift
;
412 rsnd_mod_bset(mod
, SRC_ROUTE_SEL
, mask
, val
);
417 static int rsnd_src_set_convert_timing_gen1(struct rsnd_dai_stream
*io
,
418 struct rsnd_mod
*mod
)
420 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
421 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
422 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
423 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
427 int id
= rsnd_mod_id(mod
);
433 shift
= (id
% 4) * 8;
434 mask
= 0x1F << shift
;
437 * ADG is used as source clock if SRC was used,
438 * then, SSI WS is used as destination clock.
439 * SSI WS is used as source clock if SRC is not used
440 * (when playback, source/destination become reverse when capture)
446 ret
= rsnd_adg_set_convert_clk_gen1(priv
, mod
,
449 } else if (8 == id
) {
450 /* use SSI WS, but SRU8 is special */
454 val
= (id
+ 1) << shift
;
462 rsnd_mod_bset(mod
, SRC_TMG_SEL0
, mask
, val
);
465 rsnd_mod_bset(mod
, SRC_TMG_SEL1
, mask
, val
);
468 rsnd_mod_bset(mod
, SRC_TMG_SEL2
, mask
, val
);
475 static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod
*mod
,
476 struct rsnd_dai_stream
*io
)
478 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
481 ret
= rsnd_src_set_convert_rate(mod
, io
);
485 /* Select SRC mode (fixed value) */
486 rsnd_mod_write(mod
, SRC_SRCCR
, 0x00010110);
488 /* Set the restriction value of the FS ratio (98%) */
489 rsnd_mod_write(mod
, SRC_MNFSR
,
490 rsnd_mod_read(mod
, SRC_IFSVR
) / 100 * 98);
492 /* Gen1/Gen2 are not compatible */
493 if (rsnd_src_convert_rate(io
, src
))
494 rsnd_mod_write(mod
, SRC_ROUTE_MODE0
, 1);
496 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
501 static int rsnd_src_init_gen1(struct rsnd_mod
*mod
,
502 struct rsnd_dai_stream
*io
,
503 struct rsnd_priv
*priv
)
507 ret
= rsnd_src_init(mod
, priv
);
511 ret
= rsnd_src_set_route_gen1(io
, mod
);
515 ret
= rsnd_src_set_convert_rate_gen1(mod
, io
);
519 ret
= rsnd_src_set_convert_timing_gen1(io
, mod
);
526 static int rsnd_src_start_gen1(struct rsnd_mod
*mod
,
527 struct rsnd_dai_stream
*io
,
528 struct rsnd_priv
*priv
)
530 int id
= rsnd_mod_id(mod
);
532 rsnd_mod_bset(mod
, SRC_ROUTE_CTRL
, (1 << id
), (1 << id
));
534 return rsnd_src_start(mod
);
537 static int rsnd_src_stop_gen1(struct rsnd_mod
*mod
,
538 struct rsnd_dai_stream
*io
,
539 struct rsnd_priv
*priv
)
541 int id
= rsnd_mod_id(mod
);
543 rsnd_mod_bset(mod
, SRC_ROUTE_CTRL
, (1 << id
), 0);
545 return rsnd_src_stop(mod
);
548 static struct rsnd_mod_ops rsnd_src_gen1_ops
= {
550 .dma_req
= rsnd_src_dma_req
,
551 .init
= rsnd_src_init_gen1
,
552 .quit
= rsnd_src_quit
,
553 .start
= rsnd_src_start_gen1
,
554 .stop
= rsnd_src_stop_gen1
,
555 .hw_params
= rsnd_src_hw_params
,
561 #define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1)
562 #define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0)
563 static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod
*mod
, int enable
)
565 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
566 u32 sys_int_val
, int_val
, sys_int_mask
;
567 int irq
= src
->info
->irq
;
568 int id
= rsnd_mod_id(mod
);
571 sys_int_mask
= OUF_SRC(id
);
575 * IRQ is not supported on non-DT
577 * rsnd_src_probe_gen2()
579 if ((irq
<= 0) || !enable
) {
587 * ignore over flow error when rsnd_enable_sync_convert()
589 if (rsnd_enable_sync_convert(src
))
590 sys_int_val
= sys_int_val
& 0xffff;
592 rsnd_mod_write(mod
, SRC_INT_ENABLE0
, int_val
);
593 rsnd_mod_bset(mod
, SCU_SYS_INT_EN0
, sys_int_mask
, sys_int_val
);
594 rsnd_mod_bset(mod
, SCU_SYS_INT_EN1
, sys_int_mask
, sys_int_val
);
597 static void rsnd_src_error_clear_gen2(struct rsnd_mod
*mod
)
599 u32 val
= OUF_SRC(rsnd_mod_id(mod
));
601 rsnd_mod_bset(mod
, SCU_SYS_STATUS0
, val
, val
);
602 rsnd_mod_bset(mod
, SCU_SYS_STATUS1
, val
, val
);
605 static bool rsnd_src_error_record_gen2(struct rsnd_mod
*mod
)
607 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
611 val0
= val1
= OUF_SRC(rsnd_mod_id(mod
));
616 * ignore over flow error when rsnd_enable_sync_convert()
618 if (rsnd_enable_sync_convert(src
))
619 val0
= val0
& 0xffff;
621 if ((rsnd_mod_read(mod
, SCU_SYS_STATUS0
) & val0
) ||
622 (rsnd_mod_read(mod
, SCU_SYS_STATUS1
) & val1
)) {
623 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
629 /* clear error static */
630 rsnd_src_error_clear_gen2(mod
);
635 static int rsnd_src_start_gen2(struct rsnd_mod
*mod
,
636 struct rsnd_dai_stream
*io
,
637 struct rsnd_priv
*priv
)
639 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
642 val
= rsnd_get_dalign(mod
, io
);
644 rsnd_mod_write(mod
, SRC_BUSIF_DALIGN
, val
);
649 * Enable SRC output if you want to use sync convert together with DVC
651 val
= (rsnd_io_to_mod_dvc(io
) && !rsnd_enable_sync_convert(src
)) ?
654 rsnd_mod_write(mod
, SRC_CTRL
, val
);
656 rsnd_src_error_clear_gen2(mod
);
660 rsnd_src_irq_enable_gen2(mod
);
665 static int rsnd_src_stop_gen2(struct rsnd_mod
*mod
,
666 struct rsnd_dai_stream
*io
,
667 struct rsnd_priv
*priv
)
669 rsnd_src_irq_disable_gen2(mod
);
672 * stop SRC output only
673 * see rsnd_src_quit_gen2
675 rsnd_mod_write(mod
, SRC_CTRL
, 0x01);
677 rsnd_src_error_record_gen2(mod
);
679 return rsnd_src_stop(mod
);
682 static int rsnd_src_quit_gen2(struct rsnd_mod
*mod
,
683 struct rsnd_dai_stream
*io
,
684 struct rsnd_priv
*priv
)
686 /* stop both out/in */
687 rsnd_mod_write(mod
, SRC_CTRL
, 0);
692 static void __rsnd_src_interrupt_gen2(struct rsnd_mod
*mod
,
693 struct rsnd_dai_stream
*io
)
695 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
696 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
697 struct device
*dev
= rsnd_priv_to_dev(priv
);
699 spin_lock(&priv
->lock
);
701 /* ignore all cases if not working */
702 if (!rsnd_io_is_working(io
))
703 goto rsnd_src_interrupt_gen2_out
;
705 if (rsnd_src_error_record_gen2(mod
)) {
707 dev_dbg(dev
, "%s[%d] restart\n",
708 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
710 rsnd_src_stop_gen2(mod
, io
, priv
);
711 rsnd_src_start_gen2(mod
, io
, priv
);
714 if (src
->err
> 1024) {
715 rsnd_src_irq_disable_gen2(mod
);
717 dev_warn(dev
, "no more %s[%d] restart\n",
718 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
721 rsnd_src_interrupt_gen2_out
:
722 spin_unlock(&priv
->lock
);
725 static irqreturn_t
rsnd_src_interrupt_gen2(int irq
, void *data
)
727 struct rsnd_mod
*mod
= data
;
729 rsnd_mod_interrupt(mod
, __rsnd_src_interrupt_gen2
);
734 static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod
*mod
,
735 struct rsnd_dai_stream
*io
)
737 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
738 struct device
*dev
= rsnd_priv_to_dev(priv
);
739 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
740 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
741 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
746 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */
749 else if (convert_rate
> runtime
->rate
)
750 ratio
= 100 * convert_rate
/ runtime
->rate
;
752 ratio
= 100 * runtime
->rate
/ convert_rate
;
755 dev_err(dev
, "FSO/FSI ratio error\n");
759 ret
= rsnd_src_set_convert_rate(mod
, io
);
768 if (rsnd_enable_sync_convert(src
)) {
770 route
|= rsnd_io_is_play(io
) ?
771 (0x1 << 24) : (0x1 << 25);
775 rsnd_mod_write(mod
, SRC_SRCCR
, cr
);
776 rsnd_mod_write(mod
, SRC_ROUTE_MODE0
, route
);
778 switch (rsnd_mod_id(mod
)) {
783 rsnd_mod_write(mod
, SRC_BSDSR
, 0x02400000);
786 rsnd_mod_write(mod
, SRC_BSDSR
, 0x01800000);
790 rsnd_mod_write(mod
, SRC_BSISR
, 0x00100060);
795 static int rsnd_src_set_convert_timing_gen2(struct rsnd_dai_stream
*io
,
796 struct rsnd_mod
*mod
)
798 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
799 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
800 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
804 ret
= rsnd_adg_set_convert_clk_gen2(mod
, io
,
808 ret
= rsnd_adg_set_convert_timing_gen2(mod
, io
);
813 static int rsnd_src_probe_gen2(struct rsnd_mod
*mod
,
814 struct rsnd_dai_stream
*io
,
815 struct rsnd_priv
*priv
)
817 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
818 struct device
*dev
= rsnd_priv_to_dev(priv
);
819 int irq
= src
->info
->irq
;
824 * IRQ is not supported on non-DT
826 * rsnd_src_irq_enable_gen2()
828 ret
= devm_request_irq(dev
, irq
,
829 rsnd_src_interrupt_gen2
,
836 src
->dma
= rsnd_dma_attach(io
, mod
, src
->info
->dma_id
);
837 if (IS_ERR(src
->dma
))
838 return PTR_ERR(src
->dma
);
843 static int rsnd_src_init_gen2(struct rsnd_mod
*mod
,
844 struct rsnd_dai_stream
*io
,
845 struct rsnd_priv
*priv
)
849 ret
= rsnd_src_init(mod
, priv
);
853 ret
= rsnd_src_set_convert_rate_gen2(mod
, io
);
857 ret
= rsnd_src_set_convert_timing_gen2(io
, mod
);
864 static void rsnd_src_reconvert_update(struct rsnd_dai_stream
*io
,
865 struct rsnd_mod
*mod
)
867 struct snd_pcm_runtime
*runtime
= rsnd_io_to_runtime(io
);
868 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
869 u32 convert_rate
= rsnd_src_convert_rate(io
, src
);
876 convert_rate
= runtime
->rate
;
878 fsrate
= 0x0400000 / convert_rate
* runtime
->rate
;
881 rsnd_mod_write(mod
, SRC_IFSVR
, fsrate
);
884 static int rsnd_src_pcm_new_gen2(struct rsnd_mod
*mod
,
885 struct rsnd_dai_stream
*io
,
886 struct snd_soc_pcm_runtime
*rtd
)
888 struct rsnd_dai
*rdai
= rsnd_io_to_rdai(io
);
889 struct rsnd_src
*src
= rsnd_mod_to_src(mod
);
893 * enable SRC sync convert if possible
897 * SRC sync convert needs clock master
899 if (!rsnd_rdai_is_clk_master(rdai
))
903 * enable sync convert
905 ret
= rsnd_kctrl_new_s(mod
, io
, rtd
,
906 rsnd_io_is_play(io
) ?
907 "SRC Out Rate Switch" :
908 "SRC In Rate Switch",
909 rsnd_src_reconvert_update
,
914 ret
= rsnd_kctrl_new_s(mod
, io
, rtd
,
915 rsnd_io_is_play(io
) ?
918 rsnd_src_reconvert_update
,
924 static struct rsnd_mod_ops rsnd_src_gen2_ops
= {
926 .dma_req
= rsnd_src_dma_req
,
927 .probe
= rsnd_src_probe_gen2
,
928 .init
= rsnd_src_init_gen2
,
929 .quit
= rsnd_src_quit_gen2
,
930 .start
= rsnd_src_start_gen2
,
931 .stop
= rsnd_src_stop_gen2
,
932 .hw_params
= rsnd_src_hw_params
,
933 .pcm_new
= rsnd_src_pcm_new_gen2
,
936 struct rsnd_mod
*rsnd_src_mod_get(struct rsnd_priv
*priv
, int id
)
938 if (WARN_ON(id
< 0 || id
>= rsnd_src_nr(priv
)))
941 return rsnd_mod_get((struct rsnd_src
*)(priv
->src
) + id
);
944 static void rsnd_of_parse_src(struct platform_device
*pdev
,
945 const struct rsnd_of_data
*of_data
,
946 struct rsnd_priv
*priv
)
948 struct device_node
*src_node
;
949 struct device_node
*np
;
950 struct rcar_snd_info
*info
= rsnd_priv_to_info(priv
);
951 struct rsnd_src_platform_info
*src_info
;
952 struct device
*dev
= &pdev
->dev
;
958 src_node
= rsnd_src_of_node(priv
);
962 nr
= of_get_child_count(src_node
);
964 goto rsnd_of_parse_src_end
;
966 src_info
= devm_kzalloc(dev
,
967 sizeof(struct rsnd_src_platform_info
) * nr
,
970 dev_err(dev
, "src info allocation error\n");
971 goto rsnd_of_parse_src_end
;
974 info
->src_info
= src_info
;
975 info
->src_info_nr
= nr
;
978 for_each_child_of_node(src_node
, np
) {
979 src_info
[i
].irq
= irq_of_parse_and_map(np
, 0);
984 rsnd_of_parse_src_end
:
985 of_node_put(src_node
);
988 int rsnd_src_probe(struct platform_device
*pdev
,
989 const struct rsnd_of_data
*of_data
,
990 struct rsnd_priv
*priv
)
992 struct rcar_snd_info
*info
= rsnd_priv_to_info(priv
);
993 struct device
*dev
= rsnd_priv_to_dev(priv
);
994 struct rsnd_src
*src
;
995 struct rsnd_mod_ops
*ops
;
997 char name
[RSND_SRC_NAME_SIZE
];
1001 if (rsnd_is_gen1(priv
)) {
1002 ops
= &rsnd_src_gen1_ops
;
1003 dev_warn(dev
, "Gen1 support will be removed soon\n");
1005 if (rsnd_is_gen2(priv
))
1006 ops
= &rsnd_src_gen2_ops
;
1008 dev_err(dev
, "unknown Generation\n");
1012 rsnd_of_parse_src(pdev
, of_data
, priv
);
1017 nr
= info
->src_info_nr
;
1021 src
= devm_kzalloc(dev
, sizeof(*src
) * nr
, GFP_KERNEL
);
1028 for_each_rsnd_src(src
, priv
, i
) {
1029 snprintf(name
, RSND_SRC_NAME_SIZE
, "%s.%d",
1032 clk
= devm_clk_get(dev
, name
);
1034 return PTR_ERR(clk
);
1036 src
->info
= &info
->src_info
[i
];
1038 ret
= rsnd_mod_init(priv
, rsnd_mod_get(src
), ops
, clk
, RSND_MOD_SRC
, i
);
1046 void rsnd_src_remove(struct platform_device
*pdev
,
1047 struct rsnd_priv
*priv
)
1049 struct rsnd_src
*src
;
1052 for_each_rsnd_src(src
, priv
, i
) {
1053 rsnd_mod_quit(rsnd_mod_get(src
));