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(ssi_mod)) {
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_hw_start(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_hw_stop(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);
694 rsnd_mod_write(mod, SRC_CTRL, 0);
696 rsnd_src_error_record_gen2(mod);
698 return rsnd_src_stop(mod);
701 static void __rsnd_src_interrupt_gen2(struct rsnd_mod *mod,
702 struct rsnd_dai_stream *io)
704 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
706 spin_lock(&priv->lock);
708 /* ignore all cases if not working */
709 if (!rsnd_io_is_working(io))
710 goto rsnd_src_interrupt_gen2_out;
712 if (rsnd_src_error_record_gen2(mod)) {
713 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
714 struct rsnd_src *src = rsnd_mod_to_src(mod);
715 struct device *dev = rsnd_priv_to_dev(priv);
717 dev_dbg(dev, "%s[%d] restart\n",
718 rsnd_mod_name(mod), rsnd_mod_id(mod));
720 _rsnd_src_stop_gen2(mod);
722 _rsnd_src_start_gen2(mod, io);
724 dev_warn(dev, "no more SRC restart\n");
727 rsnd_src_interrupt_gen2_out:
728 spin_unlock(&priv->lock);
731 static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data)
733 struct rsnd_mod *mod = data;
735 rsnd_mod_interrupt(mod, __rsnd_src_interrupt_gen2);
740 static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
741 struct rsnd_dai_stream *io)
743 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
744 struct device *dev = rsnd_priv_to_dev(priv);
745 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
746 struct rsnd_src *src = rsnd_mod_to_src(mod);
747 u32 convert_rate = rsnd_src_convert_rate(io, src);
752 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */
755 else if (convert_rate > runtime->rate)
756 ratio = 100 * convert_rate / runtime->rate;
758 ratio = 100 * runtime->rate / convert_rate;
761 dev_err(dev, "FSO/FSI ratio error\n");
765 ret = rsnd_src_set_convert_rate(mod, io);
774 if (rsnd_enable_sync_convert(src)) {
776 route |= rsnd_io_is_play(io) ?
777 (0x1 << 24) : (0x1 << 25);
781 rsnd_mod_write(mod, SRC_SRCCR, cr);
782 rsnd_mod_write(mod, SRC_ROUTE_MODE0, route);
784 switch (rsnd_mod_id(mod)) {
789 rsnd_mod_write(mod, SRC_BSDSR, 0x02400000);
792 rsnd_mod_write(mod, SRC_BSDSR, 0x01800000);
796 rsnd_mod_write(mod, SRC_BSISR, 0x00100060);
801 static int rsnd_src_set_convert_timing_gen2(struct rsnd_dai_stream *io,
802 struct rsnd_mod *mod)
804 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
805 struct rsnd_src *src = rsnd_mod_to_src(mod);
806 u32 convert_rate = rsnd_src_convert_rate(io, src);
810 ret = rsnd_adg_set_convert_clk_gen2(mod, io,
814 ret = rsnd_adg_set_convert_timing_gen2(mod, io);
819 static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
820 struct rsnd_dai_stream *io,
821 struct rsnd_priv *priv)
823 struct rsnd_src *src = rsnd_mod_to_src(mod);
824 struct device *dev = rsnd_priv_to_dev(priv);
825 int irq = src->info->irq;
830 * IRQ is not supported on non-DT
832 * rsnd_src_irq_enable_gen2()
834 ret = devm_request_irq(dev, irq,
835 rsnd_src_interrupt_gen2,
842 ret = rsnd_dma_init(io,
843 rsnd_mod_to_dma(mod),
849 static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
850 struct rsnd_dai_stream *io,
851 struct rsnd_priv *priv)
853 rsnd_dma_quit(io, rsnd_mod_to_dma(mod));
858 static int rsnd_src_init_gen2(struct rsnd_mod *mod,
859 struct rsnd_dai_stream *io,
860 struct rsnd_priv *priv)
864 ret = rsnd_src_init(mod, priv);
868 ret = rsnd_src_set_convert_rate_gen2(mod, io);
872 ret = rsnd_src_set_convert_timing_gen2(io, mod);
879 static int rsnd_src_start_gen2(struct rsnd_mod *mod,
880 struct rsnd_dai_stream *io,
881 struct rsnd_priv *priv)
883 rsnd_dma_start(io, rsnd_mod_to_dma(mod));
885 return _rsnd_src_start_gen2(mod, io);
888 static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
889 struct rsnd_dai_stream *io,
890 struct rsnd_priv *priv)
894 ret = _rsnd_src_stop_gen2(mod);
896 rsnd_dma_stop(io, rsnd_mod_to_dma(mod));
901 static void rsnd_src_reconvert_update(struct rsnd_dai_stream *io,
902 struct rsnd_mod *mod)
904 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
905 struct rsnd_src *src = rsnd_mod_to_src(mod);
906 u32 convert_rate = rsnd_src_convert_rate(io, src);
913 convert_rate = runtime->rate;
915 fsrate = 0x0400000 / convert_rate * runtime->rate;
918 rsnd_mod_write(mod, SRC_IFSVR, fsrate);
921 static int rsnd_src_pcm_new(struct rsnd_mod *mod,
922 struct rsnd_dai_stream *io,
923 struct snd_soc_pcm_runtime *rtd)
925 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
926 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
927 struct rsnd_src *src = rsnd_mod_to_src(mod);
931 * enable SRC sync convert if possible
935 * Gen1 is not supported
937 if (rsnd_is_gen1(priv))
941 * SRC sync convert needs clock master
943 if (!rsnd_rdai_is_clk_master(rdai))
947 * enable sync convert
949 ret = rsnd_kctrl_new_s(mod, io, rtd,
950 rsnd_io_is_play(io) ?
951 "SRC Out Rate Switch" :
952 "SRC In Rate Switch",
953 rsnd_src_reconvert_update,
958 ret = rsnd_kctrl_new_s(mod, io, rtd,
959 rsnd_io_is_play(io) ?
962 rsnd_src_reconvert_update,
968 static struct rsnd_mod_ops rsnd_src_gen2_ops = {
970 .dma_req = rsnd_src_dma_req,
971 .probe = rsnd_src_probe_gen2,
972 .remove = rsnd_src_remove_gen2,
973 .init = rsnd_src_init_gen2,
974 .quit = rsnd_src_quit,
975 .start = rsnd_src_start_gen2,
976 .stop = rsnd_src_stop_gen2,
977 .hw_params = rsnd_src_hw_params,
978 .pcm_new = rsnd_src_pcm_new,
981 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
983 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
986 return &((struct rsnd_src *)(priv->src) + id)->mod;
989 static void rsnd_of_parse_src(struct platform_device *pdev,
990 const struct rsnd_of_data *of_data,
991 struct rsnd_priv *priv)
993 struct device_node *src_node;
994 struct device_node *np;
995 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
996 struct rsnd_src_platform_info *src_info;
997 struct device *dev = &pdev->dev;
1003 src_node = rsnd_src_of_node(priv);
1007 nr = of_get_child_count(src_node);
1009 goto rsnd_of_parse_src_end;
1011 src_info = devm_kzalloc(dev,
1012 sizeof(struct rsnd_src_platform_info) * nr,
1015 dev_err(dev, "src info allocation error\n");
1016 goto rsnd_of_parse_src_end;
1019 info->src_info = src_info;
1020 info->src_info_nr = nr;
1023 for_each_child_of_node(src_node, np) {
1024 src_info[i].irq = irq_of_parse_and_map(np, 0);
1029 rsnd_of_parse_src_end:
1030 of_node_put(src_node);
1033 int rsnd_src_probe(struct platform_device *pdev,
1034 const struct rsnd_of_data *of_data,
1035 struct rsnd_priv *priv)
1037 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
1038 struct device *dev = rsnd_priv_to_dev(priv);
1039 struct rsnd_src *src;
1040 struct rsnd_mod_ops *ops;
1042 char name[RSND_SRC_NAME_SIZE];
1046 if (rsnd_is_gen1(priv))
1047 ops = &rsnd_src_gen1_ops;
1048 if (rsnd_is_gen2(priv))
1049 ops = &rsnd_src_gen2_ops;
1051 dev_err(dev, "unknown Generation\n");
1055 rsnd_of_parse_src(pdev, of_data, priv);
1060 nr = info->src_info_nr;
1064 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
1071 for_each_rsnd_src(src, priv, i) {
1072 snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
1075 clk = devm_clk_get(dev, name);
1077 return PTR_ERR(clk);
1079 src->info = &info->src_info[i];
1081 ret = rsnd_mod_init(priv, &src->mod, ops, clk, RSND_MOD_SRC, i);
1089 void rsnd_src_remove(struct platform_device *pdev,
1090 struct rsnd_priv *priv)
1092 struct rsnd_src *src;
1095 for_each_rsnd_src(src, priv, i) {
1096 rsnd_mod_quit(&src->mod);