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);
128 #define rsnd_src_initialize_lock(mod) __rsnd_src_initialize_lock(mod, 1)
129 #define rsnd_src_initialize_unlock(mod) __rsnd_src_initialize_lock(mod, 0)
130 static void __rsnd_src_initialize_lock(struct rsnd_mod *mod, u32 enable)
132 rsnd_mod_write(mod, SRC_SRCIR, enable);
135 static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io,
136 struct rsnd_mod *mod)
138 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
139 int is_play = rsnd_io_is_play(io);
141 return rsnd_dma_request_channel(rsnd_src_of_node(priv),
143 is_play ? "rx" : "tx");
146 int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
147 struct rsnd_dai_stream *io,
150 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
151 int ssi_id = rsnd_mod_id(ssi_mod);
156 rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id),
157 !use_busif << ssi_id);
162 if (rsnd_ssi_is_pin_sharing(io)) {
177 rsnd_mod_bset(ssi_mod, SSI_MODE1,
179 rsnd_rdai_is_clk_master(rdai) ?
180 0x2 << shift : 0x1 << shift);
184 * DMA settings for SSIU
187 u32 val = rsnd_get_dalign(ssi_mod, io);
189 rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR,
190 rsnd_get_adinr_bit(ssi_mod, io));
191 rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1);
192 rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1);
194 rsnd_mod_write(ssi_mod, SSI_BUSIF_DALIGN, val);
200 int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
201 struct rsnd_dai_stream *io)
204 * DMA settings for SSIU
206 rsnd_mod_write(ssi_mod, SSI_CTRL, 0);
211 int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod)
213 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
215 if (rsnd_is_gen1(priv))
218 /* enable SSI interrupt if Gen2 */
219 rsnd_mod_write(ssi_mod, SSI_INT_ENABLE,
220 rsnd_ssi_is_dma_mode(ssi_mod) ?
221 0x0e000000 : 0x0f000000);
226 int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod)
228 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
230 if (rsnd_is_gen1(priv))
233 /* disable SSI interrupt if Gen2 */
234 rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, 0x00000000);
239 static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io,
240 struct rsnd_src *src)
242 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
248 if (!rsnd_enable_sync_convert(src))
249 return src->convert_rate;
251 convert_rate = src->sync.val;
254 convert_rate = src->convert_rate;
257 convert_rate = runtime->rate;
262 unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
263 struct rsnd_dai_stream *io,
264 struct snd_pcm_runtime *runtime)
266 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
267 struct rsnd_src *src;
268 unsigned int rate = 0;
271 src = rsnd_mod_to_src(src_mod);
274 * return convert rate if SRC is used,
275 * otherwise, return runtime->rate as usual
277 rate = rsnd_src_convert_rate(io, src);
281 rate = runtime->rate;
286 static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
287 struct rsnd_dai_stream *io)
289 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
290 struct rsnd_src *src = rsnd_mod_to_src(mod);
291 u32 convert_rate = rsnd_src_convert_rate(io, src);
295 fsrate = 0x0400000 / convert_rate * runtime->rate;
297 /* Set channel number and output bit length */
298 rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr_bit(mod, io));
300 /* Enable the initial value of IFS */
302 rsnd_mod_write(mod, SRC_IFSCR, 1);
304 /* Set initial value of IFS */
305 rsnd_mod_write(mod, SRC_IFSVR, fsrate);
308 /* use DMA transfer */
309 rsnd_mod_write(mod, SRC_BUSIF_MODE, 1);
314 static int rsnd_src_hw_params(struct rsnd_mod *mod,
315 struct rsnd_dai_stream *io,
316 struct snd_pcm_substream *substream,
317 struct snd_pcm_hw_params *fe_params)
319 struct rsnd_src *src = rsnd_mod_to_src(mod);
320 struct snd_soc_pcm_runtime *fe = substream->private_data;
322 /* default value (mainly for non-DT) */
323 src->convert_rate = src->info->convert_rate;
326 * SRC assumes that it is used under DPCM if user want to use
327 * sampling rate convert. Then, SRC should be FE.
328 * And then, this function will be called *after* BE settings.
329 * this means, each BE already has fixuped hw_params.
331 * dpcm_fe_dai_hw_params()
332 * dpcm_be_dai_hw_params()
334 if (fe->dai_link->dynamic) {
335 int stream = substream->stream;
336 struct snd_soc_dpcm *dpcm;
337 struct snd_pcm_hw_params *be_params;
339 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
340 be_params = &dpcm->hw_params;
342 if (params_rate(fe_params) != params_rate(be_params))
343 src->convert_rate = params_rate(be_params);
350 static int rsnd_src_init(struct rsnd_mod *mod,
351 struct rsnd_priv *priv)
353 struct rsnd_src *src = rsnd_mod_to_src(mod);
355 rsnd_mod_power_on(mod);
357 rsnd_src_soft_reset(mod);
359 rsnd_src_initialize_lock(mod);
363 /* reset sync convert_rate */
369 static int rsnd_src_quit(struct rsnd_mod *mod,
370 struct rsnd_dai_stream *io,
371 struct rsnd_priv *priv)
373 struct rsnd_src *src = rsnd_mod_to_src(mod);
374 struct device *dev = rsnd_priv_to_dev(priv);
376 rsnd_mod_power_off(mod);
379 dev_warn(dev, "%s[%d] under/over flow err = %d\n",
380 rsnd_mod_name(mod), rsnd_mod_id(mod), src->err);
382 src->convert_rate = 0;
384 /* reset sync convert_rate */
390 static int rsnd_src_start(struct rsnd_mod *mod)
392 rsnd_src_initialize_unlock(mod);
397 static int rsnd_src_stop(struct rsnd_mod *mod)
406 static int rsnd_src_set_route_gen1(struct rsnd_dai_stream *io,
407 struct rsnd_mod *mod)
409 struct src_route_config {
416 { 0x7, 12, }, /* 3 */
417 { 0x7, 16, }, /* 4 */
418 { 0x7, 20, }, /* 5 */
419 { 0x7, 24, }, /* 6 */
420 { 0x3, 28, }, /* 7 */
421 { 0x3, 30, }, /* 8 */
427 id = rsnd_mod_id(mod);
428 if (id < 0 || id >= ARRAY_SIZE(routes))
434 val = rsnd_io_is_play(io) ? 0x1 : 0x2;
435 val = val << routes[id].shift;
436 mask = routes[id].mask << routes[id].shift;
438 rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
443 static int rsnd_src_set_convert_timing_gen1(struct rsnd_dai_stream *io,
444 struct rsnd_mod *mod)
446 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
447 struct rsnd_src *src = rsnd_mod_to_src(mod);
448 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
449 u32 convert_rate = rsnd_src_convert_rate(io, src);
453 int id = rsnd_mod_id(mod);
459 shift = (id % 4) * 8;
460 mask = 0x1F << shift;
463 * ADG is used as source clock if SRC was used,
464 * then, SSI WS is used as destination clock.
465 * SSI WS is used as source clock if SRC is not used
466 * (when playback, source/destination become reverse when capture)
472 ret = rsnd_adg_set_convert_clk_gen1(priv, mod,
475 } else if (8 == id) {
476 /* use SSI WS, but SRU8 is special */
480 val = (id + 1) << shift;
488 rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
491 rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
494 rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
501 static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
502 struct rsnd_dai_stream *io)
504 struct rsnd_src *src = rsnd_mod_to_src(mod);
507 ret = rsnd_src_set_convert_rate(mod, io);
511 /* Select SRC mode (fixed value) */
512 rsnd_mod_write(mod, SRC_SRCCR, 0x00010110);
514 /* Set the restriction value of the FS ratio (98%) */
515 rsnd_mod_write(mod, SRC_MNFSR,
516 rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
518 /* Gen1/Gen2 are not compatible */
519 if (rsnd_src_convert_rate(io, src))
520 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
522 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
527 static int rsnd_src_init_gen1(struct rsnd_mod *mod,
528 struct rsnd_dai_stream *io,
529 struct rsnd_priv *priv)
533 ret = rsnd_src_init(mod, priv);
537 ret = rsnd_src_set_route_gen1(io, mod);
541 ret = rsnd_src_set_convert_rate_gen1(mod, io);
545 ret = rsnd_src_set_convert_timing_gen1(io, mod);
552 static int rsnd_src_start_gen1(struct rsnd_mod *mod,
553 struct rsnd_dai_stream *io,
554 struct rsnd_priv *priv)
556 int id = rsnd_mod_id(mod);
558 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id));
560 return rsnd_src_start(mod);
563 static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
564 struct rsnd_dai_stream *io,
565 struct rsnd_priv *priv)
567 int id = rsnd_mod_id(mod);
569 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0);
571 return rsnd_src_stop(mod);
574 static struct rsnd_mod_ops rsnd_src_gen1_ops = {
576 .dma_req = rsnd_src_dma_req,
577 .init = rsnd_src_init_gen1,
578 .quit = rsnd_src_quit,
579 .start = rsnd_src_start_gen1,
580 .stop = rsnd_src_stop_gen1,
581 .hw_params = rsnd_src_hw_params,
587 #define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1)
588 #define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0)
589 static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod *mod, int enable)
591 struct rsnd_src *src = rsnd_mod_to_src(mod);
592 u32 sys_int_val, int_val, sys_int_mask;
593 int irq = src->info->irq;
594 int id = rsnd_mod_id(mod);
597 sys_int_mask = OUF_SRC(id);
601 * IRQ is not supported on non-DT
603 * rsnd_src_probe_gen2()
605 if ((irq <= 0) || !enable) {
613 * ignore over flow error when rsnd_enable_sync_convert()
615 if (rsnd_enable_sync_convert(src))
616 sys_int_val = sys_int_val & 0xffff;
618 rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val);
619 rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val);
620 rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val);
623 static void rsnd_src_error_clear_gen2(struct rsnd_mod *mod)
625 u32 val = OUF_SRC(rsnd_mod_id(mod));
627 rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val);
628 rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val);
631 static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod)
633 struct rsnd_src *src = rsnd_mod_to_src(mod);
637 val0 = val1 = OUF_SRC(rsnd_mod_id(mod));
642 * ignore over flow error when rsnd_enable_sync_convert()
644 if (rsnd_enable_sync_convert(src))
645 val0 = val0 & 0xffff;
647 if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) ||
648 (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) {
649 struct rsnd_src *src = rsnd_mod_to_src(mod);
655 /* clear error static */
656 rsnd_src_error_clear_gen2(mod);
661 static int _rsnd_src_start_gen2(struct rsnd_mod *mod,
662 struct rsnd_dai_stream *io)
664 struct rsnd_src *src = rsnd_mod_to_src(mod);
667 val = rsnd_get_dalign(mod, io);
669 rsnd_mod_write(mod, SRC_BUSIF_DALIGN, val);
674 * Enable SRC output if you want to use sync convert together with DVC
676 val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ?
679 rsnd_mod_write(mod, SRC_CTRL, val);
681 rsnd_src_error_clear_gen2(mod);
685 rsnd_src_irq_enable_gen2(mod);
690 static int _rsnd_src_stop_gen2(struct rsnd_mod *mod)
692 rsnd_src_irq_disable_gen2(mod);
695 * stop SRC output only
696 * see rsnd_src_quit_gen2
698 rsnd_mod_write(mod, SRC_CTRL, 0x01);
700 rsnd_src_error_record_gen2(mod);
702 return rsnd_src_stop(mod);
705 static int rsnd_src_quit_gen2(struct rsnd_mod *mod,
706 struct rsnd_dai_stream *io,
707 struct rsnd_priv *priv)
709 /* stop both out/in */
710 rsnd_mod_write(mod, SRC_CTRL, 0);
715 static void __rsnd_src_interrupt_gen2(struct rsnd_mod *mod,
716 struct rsnd_dai_stream *io)
718 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
720 spin_lock(&priv->lock);
722 /* ignore all cases if not working */
723 if (!rsnd_io_is_working(io))
724 goto rsnd_src_interrupt_gen2_out;
726 if (rsnd_src_error_record_gen2(mod)) {
727 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
728 struct rsnd_src *src = rsnd_mod_to_src(mod);
729 struct device *dev = rsnd_priv_to_dev(priv);
731 dev_dbg(dev, "%s[%d] restart\n",
732 rsnd_mod_name(mod), rsnd_mod_id(mod));
734 _rsnd_src_stop_gen2(mod);
736 _rsnd_src_start_gen2(mod, io);
738 dev_warn(dev, "no more SRC restart\n");
741 rsnd_src_interrupt_gen2_out:
742 spin_unlock(&priv->lock);
745 static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data)
747 struct rsnd_mod *mod = data;
749 rsnd_mod_interrupt(mod, __rsnd_src_interrupt_gen2);
754 static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
755 struct rsnd_dai_stream *io)
757 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
758 struct device *dev = rsnd_priv_to_dev(priv);
759 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
760 struct rsnd_src *src = rsnd_mod_to_src(mod);
761 u32 convert_rate = rsnd_src_convert_rate(io, src);
766 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */
769 else if (convert_rate > runtime->rate)
770 ratio = 100 * convert_rate / runtime->rate;
772 ratio = 100 * runtime->rate / convert_rate;
775 dev_err(dev, "FSO/FSI ratio error\n");
779 ret = rsnd_src_set_convert_rate(mod, io);
788 if (rsnd_enable_sync_convert(src)) {
790 route |= rsnd_io_is_play(io) ?
791 (0x1 << 24) : (0x1 << 25);
795 rsnd_mod_write(mod, SRC_SRCCR, cr);
796 rsnd_mod_write(mod, SRC_ROUTE_MODE0, route);
798 switch (rsnd_mod_id(mod)) {
803 rsnd_mod_write(mod, SRC_BSDSR, 0x02400000);
806 rsnd_mod_write(mod, SRC_BSDSR, 0x01800000);
810 rsnd_mod_write(mod, SRC_BSISR, 0x00100060);
815 static int rsnd_src_set_convert_timing_gen2(struct rsnd_dai_stream *io,
816 struct rsnd_mod *mod)
818 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
819 struct rsnd_src *src = rsnd_mod_to_src(mod);
820 u32 convert_rate = rsnd_src_convert_rate(io, src);
824 ret = rsnd_adg_set_convert_clk_gen2(mod, io,
828 ret = rsnd_adg_set_convert_timing_gen2(mod, io);
833 static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
834 struct rsnd_dai_stream *io,
835 struct rsnd_priv *priv)
837 struct rsnd_src *src = rsnd_mod_to_src(mod);
838 struct device *dev = rsnd_priv_to_dev(priv);
839 int irq = src->info->irq;
844 * IRQ is not supported on non-DT
846 * rsnd_src_irq_enable_gen2()
848 ret = devm_request_irq(dev, irq,
849 rsnd_src_interrupt_gen2,
856 ret = rsnd_dma_init(io,
857 rsnd_mod_to_dma(mod),
863 static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
864 struct rsnd_dai_stream *io,
865 struct rsnd_priv *priv)
867 rsnd_dma_quit(io, rsnd_mod_to_dma(mod));
872 static int rsnd_src_init_gen2(struct rsnd_mod *mod,
873 struct rsnd_dai_stream *io,
874 struct rsnd_priv *priv)
878 ret = rsnd_src_init(mod, priv);
882 ret = rsnd_src_set_convert_rate_gen2(mod, io);
886 ret = rsnd_src_set_convert_timing_gen2(io, mod);
893 static int rsnd_src_start_gen2(struct rsnd_mod *mod,
894 struct rsnd_dai_stream *io,
895 struct rsnd_priv *priv)
897 rsnd_dma_start(io, rsnd_mod_to_dma(mod));
899 return _rsnd_src_start_gen2(mod, io);
902 static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
903 struct rsnd_dai_stream *io,
904 struct rsnd_priv *priv)
908 ret = _rsnd_src_stop_gen2(mod);
910 rsnd_dma_stop(io, rsnd_mod_to_dma(mod));
915 static void rsnd_src_reconvert_update(struct rsnd_dai_stream *io,
916 struct rsnd_mod *mod)
918 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
919 struct rsnd_src *src = rsnd_mod_to_src(mod);
920 u32 convert_rate = rsnd_src_convert_rate(io, src);
927 convert_rate = runtime->rate;
929 fsrate = 0x0400000 / convert_rate * runtime->rate;
932 rsnd_mod_write(mod, SRC_IFSVR, fsrate);
935 static int rsnd_src_pcm_new_gen2(struct rsnd_mod *mod,
936 struct rsnd_dai_stream *io,
937 struct snd_soc_pcm_runtime *rtd)
939 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
940 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
941 struct rsnd_src *src = rsnd_mod_to_src(mod);
945 * enable SRC sync convert if possible
949 * SRC sync convert needs clock master
951 if (!rsnd_rdai_is_clk_master(rdai))
955 * SRC In doesn't work if DVC was enabled
957 if (dvc && !rsnd_io_is_play(io))
961 * enable sync convert
963 ret = rsnd_kctrl_new_s(mod, io, rtd,
964 rsnd_io_is_play(io) ?
965 "SRC Out Rate Switch" :
966 "SRC In Rate Switch",
967 rsnd_src_reconvert_update,
972 ret = rsnd_kctrl_new_s(mod, io, rtd,
973 rsnd_io_is_play(io) ?
976 rsnd_src_reconvert_update,
982 static struct rsnd_mod_ops rsnd_src_gen2_ops = {
984 .dma_req = rsnd_src_dma_req,
985 .probe = rsnd_src_probe_gen2,
986 .remove = rsnd_src_remove_gen2,
987 .init = rsnd_src_init_gen2,
988 .quit = rsnd_src_quit_gen2,
989 .start = rsnd_src_start_gen2,
990 .stop = rsnd_src_stop_gen2,
991 .hw_params = rsnd_src_hw_params,
992 .pcm_new = rsnd_src_pcm_new_gen2,
995 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
997 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
1000 return rsnd_mod_get((struct rsnd_src *)(priv->src) + id);
1003 static void rsnd_of_parse_src(struct platform_device *pdev,
1004 const struct rsnd_of_data *of_data,
1005 struct rsnd_priv *priv)
1007 struct device_node *src_node;
1008 struct device_node *np;
1009 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
1010 struct rsnd_src_platform_info *src_info;
1011 struct device *dev = &pdev->dev;
1017 src_node = rsnd_src_of_node(priv);
1021 nr = of_get_child_count(src_node);
1023 goto rsnd_of_parse_src_end;
1025 src_info = devm_kzalloc(dev,
1026 sizeof(struct rsnd_src_platform_info) * nr,
1029 dev_err(dev, "src info allocation error\n");
1030 goto rsnd_of_parse_src_end;
1033 info->src_info = src_info;
1034 info->src_info_nr = nr;
1037 for_each_child_of_node(src_node, np) {
1038 src_info[i].irq = irq_of_parse_and_map(np, 0);
1043 rsnd_of_parse_src_end:
1044 of_node_put(src_node);
1047 int rsnd_src_probe(struct platform_device *pdev,
1048 const struct rsnd_of_data *of_data,
1049 struct rsnd_priv *priv)
1051 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
1052 struct device *dev = rsnd_priv_to_dev(priv);
1053 struct rsnd_src *src;
1054 struct rsnd_mod_ops *ops;
1056 char name[RSND_SRC_NAME_SIZE];
1060 if (rsnd_is_gen1(priv)) {
1061 ops = &rsnd_src_gen1_ops;
1062 dev_warn(dev, "Gen1 support will be removed soon\n");
1064 if (rsnd_is_gen2(priv))
1065 ops = &rsnd_src_gen2_ops;
1067 dev_err(dev, "unknown Generation\n");
1071 rsnd_of_parse_src(pdev, of_data, priv);
1076 nr = info->src_info_nr;
1080 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
1087 for_each_rsnd_src(src, priv, i) {
1088 snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
1091 clk = devm_clk_get(dev, name);
1093 return PTR_ERR(clk);
1095 src->info = &info->src_info[i];
1097 ret = rsnd_mod_init(priv, rsnd_mod_get(src), ops, clk, RSND_MOD_SRC, i);
1105 void rsnd_src_remove(struct platform_device *pdev,
1106 struct rsnd_priv *priv)
1108 struct rsnd_src *src;
1111 for_each_rsnd_src(src, priv, i) {
1112 rsnd_mod_quit(rsnd_mod_get(src));