1 // SPDX-License-Identifier: GPL-2.0
3 // Renesas R-Car SRU/SCU/SSIU/SSI support
5 // Copyright (C) 2013 Renesas Solutions Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
9 // Kuninori Morimoto <morimoto.kuninori@renesas.com>
12 * Renesas R-Car sound device structure
16 * SRU : Sound Routing Unit
17 * - SRC : Sampling Rate Converter
19 * - CTU : Channel Count Conversion Unit
21 * - DVC : Digital Volume and Mute Function
22 * - SSI : Serial Sound Interface
26 * SCU : Sampling Rate Converter Unit
27 * - SRC : Sampling Rate Converter
29 * - CTU : Channel Count Conversion Unit
31 * - DVC : Digital Volume and Mute Function
32 * SSIU : Serial Sound Interface Unit
33 * - SSI : Serial Sound Interface
41 * | ** this depends on Gen1/Gen2
45 * | ** these depend on data path
46 * | ** gen and platform data control it
50 * | +- playback -> [mod] -> [mod] -> [mod] -> ...
53 * | +- capture -> [mod] -> [mod] -> [mod] -> ...
57 * | +- playback -> [mod] -> [mod] -> [mod] -> ...
60 * | +- capture -> [mod] -> [mod] -> [mod] -> ...
63 * | ** these control ssi
72 * | ** these control src
82 * for_each_rsnd_dai(xx, priv, xx)
83 * rdai[0] => rdai[1] => rdai[2] => ...
85 * for_each_rsnd_mod(xx, rdai, xx)
86 * [mod] => [mod] => [mod] => ...
88 * rsnd_dai_call(xxx, fn )
89 * [mod]->fn() -> [mod]->fn() -> [mod]->fn()...
94 * you can enable below define if you don't need
95 * DAI status debug message when debugging
96 * see rsnd_dbg_dai_call()
98 * #define RSND_DEBUG_NO_DAI_CALL 1
101 #include <linux/pm_runtime.h>
104 #define RSND_RATES SNDRV_PCM_RATE_8000_192000
105 #define RSND_FMTS (SNDRV_PCM_FMTBIT_S8 |\
106 SNDRV_PCM_FMTBIT_S16_LE |\
107 SNDRV_PCM_FMTBIT_S24_LE)
109 static const struct of_device_id rsnd_of_match[] = {
110 { .compatible = "renesas,rcar_sound-gen1", .data = (void *)RSND_GEN1 },
111 { .compatible = "renesas,rcar_sound-gen2", .data = (void *)RSND_GEN2 },
112 { .compatible = "renesas,rcar_sound-gen3", .data = (void *)RSND_GEN3 },
113 /* Special Handling */
114 { .compatible = "renesas,rcar_sound-r8a77990", .data = (void *)(RSND_GEN3 | RSND_SOC_E) },
117 MODULE_DEVICE_TABLE(of, rsnd_of_match);
122 void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type)
124 if (mod->type != type) {
125 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
126 struct device *dev = rsnd_priv_to_dev(priv);
128 dev_warn(dev, "%s is not your expected module\n",
133 struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
134 struct rsnd_mod *mod)
136 if (!mod || !mod->ops || !mod->ops->dma_req)
139 return mod->ops->dma_req(io, mod);
142 #define MOD_NAME_NUM 5
143 #define MOD_NAME_SIZE 16
144 char *rsnd_mod_name(struct rsnd_mod *mod)
146 static char names[MOD_NAME_NUM][MOD_NAME_SIZE];
148 char *name = names[num];
151 if (num >= MOD_NAME_NUM)
155 * Let's use same char to avoid pointlessness memory
156 * Thus, rsnd_mod_name() should be used immediately
159 if ((mod)->ops->id_sub) {
160 snprintf(name, MOD_NAME_SIZE, "%s[%d%d]",
163 rsnd_mod_id_sub(mod));
165 snprintf(name, MOD_NAME_SIZE, "%s[%d]",
173 u32 *rsnd_mod_get_status(struct rsnd_mod *mod,
174 struct rsnd_dai_stream *io,
175 enum rsnd_mod_type type)
180 int rsnd_mod_id_raw(struct rsnd_mod *mod)
185 int rsnd_mod_id(struct rsnd_mod *mod)
188 return (mod)->ops->id(mod);
190 return rsnd_mod_id_raw(mod);
193 int rsnd_mod_id_sub(struct rsnd_mod *mod)
195 if ((mod)->ops->id_sub)
196 return (mod)->ops->id_sub(mod);
201 int rsnd_mod_init(struct rsnd_priv *priv,
202 struct rsnd_mod *mod,
203 struct rsnd_mod_ops *ops,
205 enum rsnd_mod_type type,
208 int ret = clk_prepare(clk);
222 void rsnd_mod_quit(struct rsnd_mod *mod)
224 clk_unprepare(mod->clk);
228 void rsnd_mod_interrupt(struct rsnd_mod *mod,
229 void (*callback)(struct rsnd_mod *mod,
230 struct rsnd_dai_stream *io))
232 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
233 struct rsnd_dai *rdai;
236 for_each_rsnd_dai(rdai, priv, i) {
237 struct rsnd_dai_stream *io = &rdai->playback;
239 if (mod == io->mod[mod->type])
243 if (mod == io->mod[mod->type])
248 int rsnd_io_is_working(struct rsnd_dai_stream *io)
250 /* see rsnd_dai_stream_init/quit() */
252 return snd_pcm_running(io->substream);
257 int rsnd_runtime_channel_original_with_params(struct rsnd_dai_stream *io,
258 struct snd_pcm_hw_params *params)
260 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
263 * params will be added when refine
265 * __rsnd_soc_hw_rule_rate()
266 * __rsnd_soc_hw_rule_channels()
269 return params_channels(params);
271 return runtime->channels;
275 int rsnd_runtime_channel_after_ctu_with_params(struct rsnd_dai_stream *io,
276 struct snd_pcm_hw_params *params)
278 int chan = rsnd_runtime_channel_original_with_params(io, params);
279 struct rsnd_mod *ctu_mod = rsnd_io_to_mod_ctu(io);
282 u32 converted_chan = rsnd_io_converted_chan(io);
287 * converted_chan will be used for CTU,
289 * User shouldn't use CTU with TDM Split mode.
291 if (rsnd_runtime_is_tdm_split(io)) {
292 struct device *dev = rsnd_priv_to_dev(rsnd_io_to_priv(io));
294 dev_err(dev, "CTU and TDM Split should be used\n");
298 return converted_chan;
304 int rsnd_channel_normalization(int chan)
306 if (WARN_ON((chan > 8) || (chan < 0)))
309 /* TDM Extend Mode needs 8ch */
316 int rsnd_runtime_channel_for_ssi_with_params(struct rsnd_dai_stream *io,
317 struct snd_pcm_hw_params *params)
319 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
320 int chan = rsnd_io_is_play(io) ?
321 rsnd_runtime_channel_after_ctu_with_params(io, params) :
322 rsnd_runtime_channel_original_with_params(io, params);
325 if (rsnd_runtime_is_multi_ssi(io))
326 chan /= rsnd_rdai_ssi_lane_get(rdai);
328 return rsnd_channel_normalization(chan);
331 int rsnd_runtime_is_multi_ssi(struct rsnd_dai_stream *io)
333 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
334 int lane = rsnd_rdai_ssi_lane_get(rdai);
335 int chan = rsnd_io_is_play(io) ?
336 rsnd_runtime_channel_after_ctu(io) :
337 rsnd_runtime_channel_original(io);
339 return (chan > 2) && (lane > 1);
342 int rsnd_runtime_is_tdm(struct rsnd_dai_stream *io)
344 return rsnd_runtime_channel_for_ssi(io) >= 6;
347 int rsnd_runtime_is_tdm_split(struct rsnd_dai_stream *io)
349 return !!rsnd_flags_has(io, RSND_STREAM_TDM_SPLIT);
355 u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
357 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
358 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
359 struct device *dev = rsnd_priv_to_dev(priv);
361 switch (snd_pcm_format_width(runtime->format)) {
370 dev_warn(dev, "not supported sample bits\n");
378 u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
380 static const u32 dalign_values[8] = {
381 0x76543210, 0x00000032, 0x00007654, 0x00000076,
382 0xfedcba98, 0x000000ba, 0x0000fedc, 0x000000fe,
385 struct rsnd_mod *ssiu = rsnd_io_to_mod_ssiu(io);
386 struct rsnd_mod *target;
387 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
391 * *Hardware* L/R and *Software* L/R are inverted for 16bit data.
395 * We need to care about inversion timing to control
396 * Playback/Capture correctly.
397 * The point is [DVC] needs *Hardware* L/R, [MEM] needs *Software* L/R
399 * sL/R : software L/R
400 * hL/R : hardware L/R
401 * (*) : conversion timing
404 * sL/R (*) hL/R hL/R hL/R hL/R hL/R
405 * [MEM] -> [SRC] -> [DVC] -> [CMD] -> [SSIU] -> [SSI] -> codec
408 * hL/R hL/R hL/R hL/R hL/R (*) sL/R
409 * codec -> [SSI] -> [SSIU] -> [SRC] -> [DVC] -> [CMD] -> [MEM]
411 if (rsnd_io_is_play(io)) {
412 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
414 target = src ? src : ssiu;
416 struct rsnd_mod *cmd = rsnd_io_to_mod_cmd(io);
418 target = cmd ? cmd : ssiu;
422 id = rsnd_mod_id_sub(mod);
424 dalign = dalign_values[id];
426 if (mod == target && snd_pcm_format_width(runtime->format) == 16) {
427 /* Target mod needs inverted DALIGN when 16bit */
428 dalign = (dalign & 0xf0f0f0f0) >> 4 |
429 (dalign & 0x0f0f0f0f) << 4;
435 u32 rsnd_get_busif_shift(struct rsnd_dai_stream *io, struct rsnd_mod *mod)
437 enum rsnd_mod_type playback_mods[] = {
442 enum rsnd_mod_type capture_mods[] = {
447 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
448 struct rsnd_mod *tmod = NULL;
449 enum rsnd_mod_type *mods =
450 rsnd_io_is_play(io) ?
451 playback_mods : capture_mods;
455 * This is needed for 24bit data
456 * We need to shift 8bit
458 * Linux 24bit data is located as 0x00******
459 * HW 24bit data is located as 0x******00
462 if (snd_pcm_format_width(runtime->format) != 24)
465 for (i = 0; i < ARRAY_SIZE(playback_mods); i++) {
466 tmod = rsnd_io_to_mod(io, mods[i]);
474 if (rsnd_io_is_play(io))
475 return (0 << 20) | /* shift to Left */
476 (8 << 16); /* 8bit */
478 return (1 << 20) | /* shift to Right */
479 (8 << 16); /* 8bit */
485 struct rsnd_mod *rsnd_mod_next(int *iterator,
486 struct rsnd_dai_stream *io,
487 enum rsnd_mod_type *array,
490 int max = array ? array_size : RSND_MOD_MAX;
492 for (; *iterator < max; (*iterator)++) {
493 enum rsnd_mod_type type = (array) ? array[*iterator] : *iterator;
494 struct rsnd_mod *mod = rsnd_io_to_mod(io, type);
503 static enum rsnd_mod_type rsnd_mod_sequence[][RSND_MOD_MAX] = {
537 static int rsnd_status_update(u32 *status,
538 int shift, int add, int timing)
540 u32 mask = 0xF << shift;
541 u8 val = (*status >> shift) & 0xF;
542 u8 next_val = (val + add) & 0xF;
543 int func_call = (val == timing);
545 if (next_val == 0xF) /* underflow case */
548 *status = (*status & ~mask) + (next_val << shift);
553 #define rsnd_dai_call(fn, io, param...) \
555 struct device *dev = rsnd_priv_to_dev(rsnd_io_to_priv(io)); \
556 struct rsnd_mod *mod; \
557 int is_play = rsnd_io_is_play(io); \
559 enum rsnd_mod_type *types = rsnd_mod_sequence[is_play]; \
560 for_each_rsnd_mod_arrays(i, mod, io, types, RSND_MOD_MAX) { \
562 u32 *status = mod->ops->get_status(mod, io, types[i]); \
563 int func_call = rsnd_status_update(status, \
564 __rsnd_mod_shift_##fn, \
565 __rsnd_mod_add_##fn, \
566 __rsnd_mod_call_##fn); \
567 rsnd_dbg_dai_call(dev, "%s\t0x%08x %s\n", \
568 rsnd_mod_name(mod), *status, \
569 (func_call && (mod)->ops->fn) ? #fn : ""); \
570 if (func_call && (mod)->ops->fn) \
571 tmp = (mod)->ops->fn(mod, io, param); \
572 if (tmp && (tmp != -EPROBE_DEFER)) \
573 dev_err(dev, "%s : %s error %d\n", \
574 rsnd_mod_name(mod), #fn, tmp); \
580 int rsnd_dai_connect(struct rsnd_mod *mod,
581 struct rsnd_dai_stream *io,
582 enum rsnd_mod_type type)
584 struct rsnd_priv *priv;
590 if (io->mod[type] == mod)
596 priv = rsnd_mod_to_priv(mod);
597 dev = rsnd_priv_to_dev(priv);
601 dev_dbg(dev, "%s is connected to io (%s)\n",
603 rsnd_io_is_play(io) ? "Playback" : "Capture");
608 static void rsnd_dai_disconnect(struct rsnd_mod *mod,
609 struct rsnd_dai_stream *io,
610 enum rsnd_mod_type type)
612 io->mod[type] = NULL;
615 int rsnd_rdai_channels_ctrl(struct rsnd_dai *rdai,
618 if (max_channels > 0)
619 rdai->max_channels = max_channels;
621 return rdai->max_channels;
624 int rsnd_rdai_ssi_lane_ctrl(struct rsnd_dai *rdai,
628 rdai->ssi_lane = ssi_lane;
630 return rdai->ssi_lane;
633 int rsnd_rdai_width_ctrl(struct rsnd_dai *rdai, int width)
636 rdai->chan_width = width;
638 return rdai->chan_width;
641 struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id)
643 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
646 return priv->rdai + id;
649 static struct snd_soc_dai_driver
650 *rsnd_daidrv_get(struct rsnd_priv *priv, int id)
652 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
655 return priv->daidrv + id;
658 #define rsnd_dai_to_priv(dai) snd_soc_dai_get_drvdata(dai)
659 static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
661 struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
663 return rsnd_rdai_get(priv, dai->id);
667 * rsnd_soc_dai functions
669 void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io)
671 struct snd_pcm_substream *substream = io->substream;
674 * this function should be called...
676 * - if rsnd_dai_pointer_update() returns true
677 * - without spin lock
680 snd_pcm_period_elapsed(substream);
683 static void rsnd_dai_stream_init(struct rsnd_dai_stream *io,
684 struct snd_pcm_substream *substream)
686 io->substream = substream;
689 static void rsnd_dai_stream_quit(struct rsnd_dai_stream *io)
691 io->substream = NULL;
695 struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
697 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
699 return asoc_rtd_to_cpu(rtd, 0);
703 struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
704 struct snd_pcm_substream *substream)
706 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
707 return &rdai->playback;
709 return &rdai->capture;
712 static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
713 struct snd_soc_dai *dai)
715 struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
716 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
717 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
721 spin_lock_irqsave(&priv->lock, flags);
724 case SNDRV_PCM_TRIGGER_START:
725 case SNDRV_PCM_TRIGGER_RESUME:
726 ret = rsnd_dai_call(init, io, priv);
728 goto dai_trigger_end;
730 ret = rsnd_dai_call(start, io, priv);
732 goto dai_trigger_end;
734 ret = rsnd_dai_call(irq, io, priv, 1);
736 goto dai_trigger_end;
739 case SNDRV_PCM_TRIGGER_STOP:
740 case SNDRV_PCM_TRIGGER_SUSPEND:
741 ret = rsnd_dai_call(irq, io, priv, 0);
743 ret |= rsnd_dai_call(stop, io, priv);
745 ret |= rsnd_dai_call(quit, io, priv);
753 spin_unlock_irqrestore(&priv->lock, flags);
758 static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
760 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
762 /* set clock master for audio interface */
763 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
764 case SND_SOC_DAIFMT_CBM_CFM:
765 rdai->clk_master = 0;
767 case SND_SOC_DAIFMT_CBS_CFS:
768 rdai->clk_master = 1; /* cpu is master */
775 rdai->bit_clk_inv = 0;
776 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
777 case SND_SOC_DAIFMT_I2S:
779 rdai->data_alignment = 0;
780 rdai->frm_clk_inv = 0;
782 case SND_SOC_DAIFMT_LEFT_J:
783 case SND_SOC_DAIFMT_DSP_B:
785 rdai->data_alignment = 0;
786 rdai->frm_clk_inv = 1;
788 case SND_SOC_DAIFMT_RIGHT_J:
790 rdai->data_alignment = 1;
791 rdai->frm_clk_inv = 1;
793 case SND_SOC_DAIFMT_DSP_A:
795 rdai->data_alignment = 0;
796 rdai->frm_clk_inv = 1;
800 /* set clock inversion */
801 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
802 case SND_SOC_DAIFMT_NB_IF:
803 rdai->frm_clk_inv = !rdai->frm_clk_inv;
805 case SND_SOC_DAIFMT_IB_NF:
806 rdai->bit_clk_inv = !rdai->bit_clk_inv;
808 case SND_SOC_DAIFMT_IB_IF:
809 rdai->bit_clk_inv = !rdai->bit_clk_inv;
810 rdai->frm_clk_inv = !rdai->frm_clk_inv;
812 case SND_SOC_DAIFMT_NB_NF:
820 static int rsnd_soc_set_dai_tdm_slot(struct snd_soc_dai *dai,
821 u32 tx_mask, u32 rx_mask,
822 int slots, int slot_width)
824 struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
825 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
826 struct device *dev = rsnd_priv_to_dev(priv);
828 switch (slot_width) {
843 /* TDM Extend Mode */
844 rsnd_rdai_channels_set(rdai, slots);
845 rsnd_rdai_ssi_lane_set(rdai, 1);
846 rsnd_rdai_width_set(rdai, slot_width);
849 dev_err(dev, "unsupported TDM slots (%d)\n", slots);
856 static unsigned int rsnd_soc_hw_channels_list[] = {
860 static unsigned int rsnd_soc_hw_rate_list[] = {
875 static int rsnd_soc_hw_rule(struct rsnd_dai *rdai,
876 unsigned int *list, int list_num,
877 struct snd_interval *baseline, struct snd_interval *iv)
879 struct snd_interval p;
883 snd_interval_any(&p);
887 for (i = 0; i < list_num; i++) {
889 if (!snd_interval_test(iv, list[i]))
892 rate = rsnd_ssi_clk_query(rdai,
893 baseline->min, list[i], NULL);
895 p.min = min(p.min, list[i]);
896 p.max = max(p.max, list[i]);
899 rate = rsnd_ssi_clk_query(rdai,
900 baseline->max, list[i], NULL);
902 p.min = min(p.min, list[i]);
903 p.max = max(p.max, list[i]);
907 return snd_interval_refine(iv, &p);
910 static int rsnd_soc_hw_rule_rate(struct snd_pcm_hw_params *params,
911 struct snd_pcm_hw_rule *rule)
913 struct snd_interval *ic_ = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
914 struct snd_interval *ir = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
915 struct snd_interval ic;
916 struct rsnd_dai_stream *io = rule->private;
917 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
920 * possible sampling rate limitation is same as
921 * 2ch if it supports multi ssi
922 * and same as 8ch if TDM 6ch (see rsnd_ssi_config_init())
926 ic.max = rsnd_runtime_channel_for_ssi_with_params(io, params);
928 return rsnd_soc_hw_rule(rdai, rsnd_soc_hw_rate_list,
929 ARRAY_SIZE(rsnd_soc_hw_rate_list),
933 static int rsnd_soc_hw_rule_channels(struct snd_pcm_hw_params *params,
934 struct snd_pcm_hw_rule *rule)
936 struct snd_interval *ic_ = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
937 struct snd_interval *ir = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
938 struct snd_interval ic;
939 struct rsnd_dai_stream *io = rule->private;
940 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
943 * possible sampling rate limitation is same as
944 * 2ch if it supports multi ssi
945 * and same as 8ch if TDM 6ch (see rsnd_ssi_config_init())
949 ic.max = rsnd_runtime_channel_for_ssi_with_params(io, params);
951 return rsnd_soc_hw_rule(rdai, rsnd_soc_hw_channels_list,
952 ARRAY_SIZE(rsnd_soc_hw_channels_list),
956 static const struct snd_pcm_hardware rsnd_pcm_hardware = {
957 .info = SNDRV_PCM_INFO_INTERLEAVED |
958 SNDRV_PCM_INFO_MMAP |
959 SNDRV_PCM_INFO_MMAP_VALID,
960 .buffer_bytes_max = 64 * 1024,
961 .period_bytes_min = 32,
962 .period_bytes_max = 8192,
968 static int rsnd_soc_dai_startup(struct snd_pcm_substream *substream,
969 struct snd_soc_dai *dai)
971 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
972 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
973 struct snd_pcm_hw_constraint_list *constraint = &rdai->constraint;
974 struct snd_pcm_runtime *runtime = substream->runtime;
975 unsigned int max_channels = rsnd_rdai_channels_get(rdai);
978 rsnd_dai_stream_init(io, substream);
982 * It depends on Platform design
984 constraint->list = rsnd_soc_hw_channels_list;
985 constraint->count = 0;
986 constraint->mask = 0;
988 for (i = 0; i < ARRAY_SIZE(rsnd_soc_hw_channels_list); i++) {
989 if (rsnd_soc_hw_channels_list[i] > max_channels)
991 constraint->count = i + 1;
994 snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
996 snd_pcm_hw_constraint_list(runtime, 0,
997 SNDRV_PCM_HW_PARAM_CHANNELS, constraint);
999 snd_pcm_hw_constraint_integer(runtime,
1000 SNDRV_PCM_HW_PARAM_PERIODS);
1003 * Sampling Rate / Channel Limitation
1004 * It depends on Clock Master Mode
1006 if (rsnd_rdai_is_clk_master(rdai)) {
1007 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
1009 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1010 rsnd_soc_hw_rule_rate,
1011 is_play ? &rdai->playback : &rdai->capture,
1012 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
1013 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1014 rsnd_soc_hw_rule_channels,
1015 is_play ? &rdai->playback : &rdai->capture,
1016 SNDRV_PCM_HW_PARAM_RATE, -1);
1022 static void rsnd_soc_dai_shutdown(struct snd_pcm_substream *substream,
1023 struct snd_soc_dai *dai)
1025 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
1026 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
1027 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
1030 * call rsnd_dai_call without spinlock
1032 rsnd_dai_call(cleanup, io, priv);
1034 rsnd_dai_stream_quit(io);
1037 static int rsnd_soc_dai_prepare(struct snd_pcm_substream *substream,
1038 struct snd_soc_dai *dai)
1040 struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
1041 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
1042 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
1044 return rsnd_dai_call(prepare, io, priv);
1047 static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
1048 .startup = rsnd_soc_dai_startup,
1049 .shutdown = rsnd_soc_dai_shutdown,
1050 .trigger = rsnd_soc_dai_trigger,
1051 .set_fmt = rsnd_soc_dai_set_fmt,
1052 .set_tdm_slot = rsnd_soc_set_dai_tdm_slot,
1053 .prepare = rsnd_soc_dai_prepare,
1056 static void rsnd_parse_tdm_split_mode(struct rsnd_priv *priv,
1057 struct rsnd_dai_stream *io,
1058 struct device_node *dai_np)
1060 struct device *dev = rsnd_priv_to_dev(priv);
1061 struct device_node *ssiu_np = rsnd_ssiu_of_node(priv);
1062 struct device_node *np;
1063 int is_play = rsnd_io_is_play(io);
1070 * This driver assumes that it is TDM Split mode
1071 * if it includes ssiu node
1074 struct device_node *node = is_play ?
1075 of_parse_phandle(dai_np, "playback", i) :
1076 of_parse_phandle(dai_np, "capture", i);
1081 for_each_child_of_node(ssiu_np, np) {
1083 rsnd_flags_set(io, RSND_STREAM_TDM_SPLIT);
1084 dev_dbg(dev, "%s is part of TDM Split\n", io->name);
1091 of_node_put(ssiu_np);
1094 static void rsnd_parse_connect_simple(struct rsnd_priv *priv,
1095 struct rsnd_dai_stream *io,
1096 struct device_node *dai_np)
1098 if (!rsnd_io_to_mod_ssi(io))
1101 rsnd_parse_tdm_split_mode(priv, io, dai_np);
1104 static void rsnd_parse_connect_graph(struct rsnd_priv *priv,
1105 struct rsnd_dai_stream *io,
1106 struct device_node *endpoint)
1108 struct device *dev = rsnd_priv_to_dev(priv);
1109 struct device_node *remote_node;
1111 if (!rsnd_io_to_mod_ssi(io))
1114 remote_node = of_graph_get_remote_port_parent(endpoint);
1117 if (strstr(remote_node->full_name, "hdmi@fead0000")) {
1118 rsnd_flags_set(io, RSND_STREAM_HDMI0);
1119 dev_dbg(dev, "%s connected to HDMI0\n", io->name);
1123 if (strstr(remote_node->full_name, "hdmi@feae0000")) {
1124 rsnd_flags_set(io, RSND_STREAM_HDMI1);
1125 dev_dbg(dev, "%s connected to HDMI1\n", io->name);
1128 rsnd_parse_tdm_split_mode(priv, io, endpoint);
1130 of_node_put(remote_node);
1133 void rsnd_parse_connect_common(struct rsnd_dai *rdai,
1134 struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id),
1135 struct device_node *node,
1136 struct device_node *playback,
1137 struct device_node *capture)
1139 struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
1140 struct device_node *np;
1147 for_each_child_of_node(node, np) {
1148 struct rsnd_mod *mod = mod_get(priv, i);
1151 rsnd_dai_connect(mod, &rdai->playback, mod->type);
1153 rsnd_dai_connect(mod, &rdai->capture, mod->type);
1160 static struct device_node *rsnd_dai_of_node(struct rsnd_priv *priv,
1163 struct device *dev = rsnd_priv_to_dev(priv);
1164 struct device_node *np = dev->of_node;
1165 struct device_node *dai_node;
1166 struct device_node *ret;
1171 * parse both previous dai (= rcar_sound,dai), and
1172 * graph dai (= ports/port)
1174 dai_node = of_get_child_by_name(np, RSND_NODE_DAI);
1177 goto of_node_compatible;
1182 dai_node = of_graph_get_next_endpoint(np, NULL);
1191 of_node_put(dai_node);
1197 #define PREALLOC_BUFFER (32 * 1024)
1198 #define PREALLOC_BUFFER_MAX (32 * 1024)
1200 static int rsnd_preallocate_pages(struct snd_soc_pcm_runtime *rtd,
1201 struct rsnd_dai_stream *io,
1204 struct rsnd_priv *priv = rsnd_io_to_priv(io);
1205 struct device *dev = rsnd_priv_to_dev(priv);
1206 struct snd_pcm_substream *substream;
1209 * use Audio-DMAC dev if we can use IPMMU
1211 * rsnd_dmaen_attach()
1216 for (substream = rtd->pcm->streams[stream].substream;
1218 substream = substream->next) {
1219 snd_pcm_set_managed_buffer(substream,
1222 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
1228 static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd,
1229 struct snd_soc_dai *dai)
1231 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
1234 ret = rsnd_dai_call(pcm_new, &rdai->playback, rtd);
1238 ret = rsnd_dai_call(pcm_new, &rdai->capture, rtd);
1242 ret = rsnd_preallocate_pages(rtd, &rdai->playback,
1243 SNDRV_PCM_STREAM_PLAYBACK);
1247 ret = rsnd_preallocate_pages(rtd, &rdai->capture,
1248 SNDRV_PCM_STREAM_CAPTURE);
1255 static void __rsnd_dai_probe(struct rsnd_priv *priv,
1256 struct device_node *dai_np,
1259 struct rsnd_dai_stream *io_playback;
1260 struct rsnd_dai_stream *io_capture;
1261 struct snd_soc_dai_driver *drv;
1262 struct rsnd_dai *rdai;
1263 struct device *dev = rsnd_priv_to_dev(priv);
1266 rdai = rsnd_rdai_get(priv, dai_i);
1267 drv = rsnd_daidrv_get(priv, dai_i);
1268 io_playback = &rdai->playback;
1269 io_capture = &rdai->capture;
1271 snprintf(rdai->name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", dai_i);
1274 drv->name = rdai->name;
1275 drv->ops = &rsnd_soc_dai_ops;
1276 drv->pcm_new = rsnd_pcm_new;
1278 snprintf(io_playback->name, RSND_DAI_NAME_SIZE,
1279 "DAI%d Playback", dai_i);
1280 drv->playback.rates = RSND_RATES;
1281 drv->playback.formats = RSND_FMTS;
1282 drv->playback.channels_min = 2;
1283 drv->playback.channels_max = 8;
1284 drv->playback.stream_name = io_playback->name;
1286 snprintf(io_capture->name, RSND_DAI_NAME_SIZE,
1287 "DAI%d Capture", dai_i);
1288 drv->capture.rates = RSND_RATES;
1289 drv->capture.formats = RSND_FMTS;
1290 drv->capture.channels_min = 2;
1291 drv->capture.channels_max = 8;
1292 drv->capture.stream_name = io_capture->name;
1294 io_playback->rdai = rdai;
1295 io_capture->rdai = rdai;
1296 rsnd_rdai_channels_set(rdai, 2); /* default 2ch */
1297 rsnd_rdai_ssi_lane_set(rdai, 1); /* default 1lane */
1298 rsnd_rdai_width_set(rdai, 32); /* default 32bit width */
1300 for (io_i = 0;; io_i++) {
1301 struct device_node *playback = of_parse_phandle(dai_np, "playback", io_i);
1302 struct device_node *capture = of_parse_phandle(dai_np, "capture", io_i);
1304 if (!playback && !capture)
1307 rsnd_parse_connect_ssi(rdai, playback, capture);
1308 rsnd_parse_connect_ssiu(rdai, playback, capture);
1309 rsnd_parse_connect_src(rdai, playback, capture);
1310 rsnd_parse_connect_ctu(rdai, playback, capture);
1311 rsnd_parse_connect_mix(rdai, playback, capture);
1312 rsnd_parse_connect_dvc(rdai, playback, capture);
1314 of_node_put(playback);
1315 of_node_put(capture);
1318 if (rsnd_ssi_is_pin_sharing(io_capture) ||
1319 rsnd_ssi_is_pin_sharing(io_playback)) {
1320 /* should have symmetric_rate if pin sharing */
1321 drv->symmetric_rate = 1;
1324 dev_dbg(dev, "%s (%s/%s)\n", rdai->name,
1325 rsnd_io_to_mod_ssi(io_playback) ? "play" : " -- ",
1326 rsnd_io_to_mod_ssi(io_capture) ? "capture" : " -- ");
1329 static int rsnd_dai_probe(struct rsnd_priv *priv)
1331 struct device_node *dai_node;
1332 struct device_node *dai_np;
1333 struct snd_soc_dai_driver *rdrv;
1334 struct device *dev = rsnd_priv_to_dev(priv);
1335 struct rsnd_dai *rdai;
1340 dai_node = rsnd_dai_of_node(priv, &is_graph);
1342 nr = of_graph_get_endpoint_count(dai_node);
1344 nr = of_get_child_count(dai_node);
1349 rdrv = devm_kcalloc(dev, nr, sizeof(*rdrv), GFP_KERNEL);
1350 rdai = devm_kcalloc(dev, nr, sizeof(*rdai), GFP_KERNEL);
1355 priv->daidrv = rdrv;
1363 for_each_endpoint_of_node(dai_node, dai_np) {
1364 __rsnd_dai_probe(priv, dai_np, dai_i);
1365 if (rsnd_is_gen3(priv)) {
1366 rdai = rsnd_rdai_get(priv, dai_i);
1368 rsnd_parse_connect_graph(priv, &rdai->playback, dai_np);
1369 rsnd_parse_connect_graph(priv, &rdai->capture, dai_np);
1374 for_each_child_of_node(dai_node, dai_np) {
1375 __rsnd_dai_probe(priv, dai_np, dai_i);
1376 if (rsnd_is_gen3(priv)) {
1377 rdai = rsnd_rdai_get(priv, dai_i);
1379 rsnd_parse_connect_simple(priv, &rdai->playback, dai_np);
1380 rsnd_parse_connect_simple(priv, &rdai->capture, dai_np);
1392 static int rsnd_hw_params(struct snd_soc_component *component,
1393 struct snd_pcm_substream *substream,
1394 struct snd_pcm_hw_params *hw_params)
1396 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
1397 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
1398 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
1399 struct snd_soc_pcm_runtime *fe = asoc_substream_to_rtd(substream);
1402 * rsnd assumes that it might be used under DPCM if user want to use
1403 * channel / rate convert. Then, rsnd should be FE.
1404 * And then, this function will be called *after* BE settings.
1405 * this means, each BE already has fixuped hw_params.
1407 * dpcm_fe_dai_hw_params()
1408 * dpcm_be_dai_hw_params()
1410 io->converted_rate = 0;
1411 io->converted_chan = 0;
1412 if (fe->dai_link->dynamic) {
1413 struct rsnd_priv *priv = rsnd_io_to_priv(io);
1414 struct device *dev = rsnd_priv_to_dev(priv);
1415 struct snd_soc_dpcm *dpcm;
1416 int stream = substream->stream;
1418 for_each_dpcm_be(fe, stream, dpcm) {
1419 struct snd_pcm_hw_params *be_params = &dpcm->hw_params;
1421 if (params_channels(hw_params) != params_channels(be_params))
1422 io->converted_chan = params_channels(be_params);
1423 if (params_rate(hw_params) != params_rate(be_params))
1424 io->converted_rate = params_rate(be_params);
1426 if (io->converted_chan)
1427 dev_dbg(dev, "convert channels = %d\n", io->converted_chan);
1428 if (io->converted_rate) {
1430 * SRC supports convert rates from params_rate(hw_params)/k_down
1431 * to params_rate(hw_params)*k_up, where k_up is always 6, and
1432 * k_down depends on number of channels and SRC unit.
1433 * So all SRC units can upsample audio up to 6 times regardless
1434 * its number of channels. And all SRC units can downsample
1435 * 2 channel audio up to 6 times too.
1440 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
1442 dev_dbg(dev, "convert rate = %d\n", io->converted_rate);
1444 channel = io->converted_chan ? io->converted_chan :
1445 params_channels(hw_params);
1447 switch (rsnd_mod_id(src_mod)) {
1449 * SRC0 can downsample 4, 6 and 8 channel audio up to 4 times.
1450 * SRC1, SRC3 and SRC4 can downsample 4 channel audio
1452 * SRC1, SRC3 and SRC4 can downsample 6 and 8 channel audio
1453 * no more than twice.
1468 /* Other SRC units do not support more than 2 channels */
1474 if (params_rate(hw_params) > io->converted_rate * k_down) {
1475 hw_param_interval(hw_params, SNDRV_PCM_HW_PARAM_RATE)->min =
1476 io->converted_rate * k_down;
1477 hw_param_interval(hw_params, SNDRV_PCM_HW_PARAM_RATE)->max =
1478 io->converted_rate * k_down;
1479 hw_params->cmask |= SNDRV_PCM_HW_PARAM_RATE;
1480 } else if (params_rate(hw_params) * k_up < io->converted_rate) {
1481 hw_param_interval(hw_params, SNDRV_PCM_HW_PARAM_RATE)->min =
1482 (io->converted_rate + k_up - 1) / k_up;
1483 hw_param_interval(hw_params, SNDRV_PCM_HW_PARAM_RATE)->max =
1484 (io->converted_rate + k_up - 1) / k_up;
1485 hw_params->cmask |= SNDRV_PCM_HW_PARAM_RATE;
1489 * TBD: Max SRC input and output rates also depend on number
1490 * of channels and SRC unit:
1491 * SRC1, SRC3 and SRC4 do not support more than 128kHz
1492 * for 6 channel and 96kHz for 8 channel audio.
1493 * Perhaps this function should return EINVAL if the input or
1494 * the output rate exceeds the limitation.
1499 return rsnd_dai_call(hw_params, io, substream, hw_params);
1502 static int rsnd_hw_free(struct snd_soc_component *component,
1503 struct snd_pcm_substream *substream)
1505 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
1506 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
1507 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
1509 return rsnd_dai_call(hw_free, io, substream);
1512 static snd_pcm_uframes_t rsnd_pointer(struct snd_soc_component *component,
1513 struct snd_pcm_substream *substream)
1515 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
1516 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
1517 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
1518 snd_pcm_uframes_t pointer = 0;
1520 rsnd_dai_call(pointer, io, &pointer);
1528 static int rsnd_kctrl_info(struct snd_kcontrol *kctrl,
1529 struct snd_ctl_elem_info *uinfo)
1531 struct rsnd_kctrl_cfg *cfg = snd_kcontrol_chip(kctrl);
1534 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1535 uinfo->count = cfg->size;
1536 uinfo->value.enumerated.items = cfg->max;
1537 if (uinfo->value.enumerated.item >= cfg->max)
1538 uinfo->value.enumerated.item = cfg->max - 1;
1539 strscpy(uinfo->value.enumerated.name,
1540 cfg->texts[uinfo->value.enumerated.item],
1541 sizeof(uinfo->value.enumerated.name));
1543 uinfo->count = cfg->size;
1544 uinfo->value.integer.min = 0;
1545 uinfo->value.integer.max = cfg->max;
1546 uinfo->type = (cfg->max == 1) ?
1547 SNDRV_CTL_ELEM_TYPE_BOOLEAN :
1548 SNDRV_CTL_ELEM_TYPE_INTEGER;
1554 static int rsnd_kctrl_get(struct snd_kcontrol *kctrl,
1555 struct snd_ctl_elem_value *uc)
1557 struct rsnd_kctrl_cfg *cfg = snd_kcontrol_chip(kctrl);
1560 for (i = 0; i < cfg->size; i++)
1562 uc->value.enumerated.item[i] = cfg->val[i];
1564 uc->value.integer.value[i] = cfg->val[i];
1569 static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
1570 struct snd_ctl_elem_value *uc)
1572 struct rsnd_kctrl_cfg *cfg = snd_kcontrol_chip(kctrl);
1575 if (!cfg->accept(cfg->io))
1578 for (i = 0; i < cfg->size; i++) {
1580 change |= (uc->value.enumerated.item[i] != cfg->val[i]);
1581 cfg->val[i] = uc->value.enumerated.item[i];
1583 change |= (uc->value.integer.value[i] != cfg->val[i]);
1584 cfg->val[i] = uc->value.integer.value[i];
1588 if (change && cfg->update)
1589 cfg->update(cfg->io, cfg->mod);
1594 int rsnd_kctrl_accept_anytime(struct rsnd_dai_stream *io)
1599 int rsnd_kctrl_accept_runtime(struct rsnd_dai_stream *io)
1601 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
1602 struct rsnd_priv *priv = rsnd_io_to_priv(io);
1603 struct device *dev = rsnd_priv_to_dev(priv);
1606 dev_warn(dev, "Can't update kctrl when idle\n");
1613 struct rsnd_kctrl_cfg *rsnd_kctrl_init_m(struct rsnd_kctrl_cfg_m *cfg)
1615 cfg->cfg.val = cfg->val;
1620 struct rsnd_kctrl_cfg *rsnd_kctrl_init_s(struct rsnd_kctrl_cfg_s *cfg)
1622 cfg->cfg.val = &cfg->val;
1627 const char * const volume_ramp_rate[] = {
1628 "128 dB/1 step", /* 00000 */
1629 "64 dB/1 step", /* 00001 */
1630 "32 dB/1 step", /* 00010 */
1631 "16 dB/1 step", /* 00011 */
1632 "8 dB/1 step", /* 00100 */
1633 "4 dB/1 step", /* 00101 */
1634 "2 dB/1 step", /* 00110 */
1635 "1 dB/1 step", /* 00111 */
1636 "0.5 dB/1 step", /* 01000 */
1637 "0.25 dB/1 step", /* 01001 */
1638 "0.125 dB/1 step", /* 01010 = VOLUME_RAMP_MAX_MIX */
1639 "0.125 dB/2 steps", /* 01011 */
1640 "0.125 dB/4 steps", /* 01100 */
1641 "0.125 dB/8 steps", /* 01101 */
1642 "0.125 dB/16 steps", /* 01110 */
1643 "0.125 dB/32 steps", /* 01111 */
1644 "0.125 dB/64 steps", /* 10000 */
1645 "0.125 dB/128 steps", /* 10001 */
1646 "0.125 dB/256 steps", /* 10010 */
1647 "0.125 dB/512 steps", /* 10011 */
1648 "0.125 dB/1024 steps", /* 10100 */
1649 "0.125 dB/2048 steps", /* 10101 */
1650 "0.125 dB/4096 steps", /* 10110 */
1651 "0.125 dB/8192 steps", /* 10111 = VOLUME_RAMP_MAX_DVC */
1654 int rsnd_kctrl_new(struct rsnd_mod *mod,
1655 struct rsnd_dai_stream *io,
1656 struct snd_soc_pcm_runtime *rtd,
1657 const unsigned char *name,
1658 int (*accept)(struct rsnd_dai_stream *io),
1659 void (*update)(struct rsnd_dai_stream *io,
1660 struct rsnd_mod *mod),
1661 struct rsnd_kctrl_cfg *cfg,
1662 const char * const *texts,
1666 struct snd_card *card = rtd->card->snd_card;
1667 struct snd_kcontrol *kctrl;
1668 struct snd_kcontrol_new knew = {
1669 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1671 .info = rsnd_kctrl_info,
1673 .get = rsnd_kctrl_get,
1674 .put = rsnd_kctrl_put,
1679 * 1) Avoid duplicate register for DVC with MIX case
1680 * 2) Allow duplicate register for MIX
1681 * 3) re-register if card was rebinded
1683 list_for_each_entry(kctrl, &card->controls, list) {
1684 struct rsnd_kctrl_cfg *c = kctrl->private_data;
1690 if (size > RSND_MAX_CHANNELS)
1693 kctrl = snd_ctl_new1(&knew, cfg);
1697 ret = snd_ctl_add(card, kctrl);
1704 cfg->accept = accept;
1705 cfg->update = update;
1717 static const struct snd_soc_component_driver rsnd_soc_component = {
1719 .hw_params = rsnd_hw_params,
1720 .hw_free = rsnd_hw_free,
1721 .pointer = rsnd_pointer,
1724 static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
1725 struct rsnd_dai_stream *io)
1729 ret = rsnd_dai_call(probe, io, priv);
1730 if (ret == -EAGAIN) {
1731 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io);
1732 struct rsnd_mod *mod;
1736 * Fallback to PIO mode
1740 * call "remove" for SSI/SRC/DVC
1741 * SSI will be switch to PIO mode if it was DMA mode
1744 * rsnd_ssi_fallback()
1746 rsnd_dai_call(remove, io, priv);
1749 * remove all mod from io
1750 * and, re connect ssi
1752 for_each_rsnd_mod(i, mod, io)
1753 rsnd_dai_disconnect(mod, io, i);
1754 rsnd_dai_connect(ssi_mod, io, RSND_MOD_SSI);
1759 rsnd_dai_call(fallback, io, priv);
1763 * DAI has SSI which is PIO mode only now.
1765 ret = rsnd_dai_call(probe, io, priv);
1774 static int rsnd_probe(struct platform_device *pdev)
1776 struct rsnd_priv *priv;
1777 struct device *dev = &pdev->dev;
1778 struct rsnd_dai *rdai;
1779 int (*probe_func[])(struct rsnd_priv *priv) = {
1797 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1802 priv->flags = (unsigned long)of_device_get_match_data(dev);
1803 spin_lock_init(&priv->lock);
1808 for (i = 0; i < ARRAY_SIZE(probe_func); i++) {
1809 ret = probe_func[i](priv);
1814 for_each_rsnd_dai(rdai, priv, i) {
1815 ret = rsnd_rdai_continuance_probe(priv, &rdai->playback);
1817 goto exit_snd_probe;
1819 ret = rsnd_rdai_continuance_probe(priv, &rdai->capture);
1821 goto exit_snd_probe;
1824 dev_set_drvdata(dev, priv);
1829 ret = devm_snd_soc_register_component(dev, &rsnd_soc_component,
1830 priv->daidrv, rsnd_rdai_nr(priv));
1832 dev_err(dev, "cannot snd dai register\n");
1833 goto exit_snd_probe;
1836 pm_runtime_enable(dev);
1838 dev_info(dev, "probed\n");
1842 for_each_rsnd_dai(rdai, priv, i) {
1843 rsnd_dai_call(remove, &rdai->playback, priv);
1844 rsnd_dai_call(remove, &rdai->capture, priv);
1848 * adg is very special mod which can't use rsnd_dai_call(remove),
1849 * and it registers ADG clock on probe.
1850 * It should be unregister if probe failed.
1851 * Mainly it is assuming -EPROBE_DEFER case
1853 rsnd_adg_remove(priv);
1858 static int rsnd_remove(struct platform_device *pdev)
1860 struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
1861 struct rsnd_dai *rdai;
1862 void (*remove_func[])(struct rsnd_priv *priv) = {
1874 pm_runtime_disable(&pdev->dev);
1876 for_each_rsnd_dai(rdai, priv, i) {
1877 ret |= rsnd_dai_call(remove, &rdai->playback, priv);
1878 ret |= rsnd_dai_call(remove, &rdai->capture, priv);
1881 for (i = 0; i < ARRAY_SIZE(remove_func); i++)
1882 remove_func[i](priv);
1887 static int __maybe_unused rsnd_suspend(struct device *dev)
1889 struct rsnd_priv *priv = dev_get_drvdata(dev);
1891 rsnd_adg_clk_disable(priv);
1896 static int __maybe_unused rsnd_resume(struct device *dev)
1898 struct rsnd_priv *priv = dev_get_drvdata(dev);
1900 rsnd_adg_clk_enable(priv);
1905 static const struct dev_pm_ops rsnd_pm_ops = {
1906 SET_SYSTEM_SLEEP_PM_OPS(rsnd_suspend, rsnd_resume)
1909 static struct platform_driver rsnd_driver = {
1911 .name = "rcar_sound",
1913 .of_match_table = rsnd_of_match,
1915 .probe = rsnd_probe,
1916 .remove = rsnd_remove,
1918 module_platform_driver(rsnd_driver);
1920 MODULE_LICENSE("GPL v2");
1921 MODULE_DESCRIPTION("Renesas R-Car audio driver");
1922 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
1923 MODULE_ALIAS("platform:rcar-pcm-audio");