2 * Renesas R-Car SRU/SCU/SSIU/SSI support
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
8 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
16 * Renesas R-Car sound device structure
20 * SRU : Sound Routing Unit
21 * - SRC : Sampling Rate Converter
23 * - CTU : Channel Count Conversion Unit
25 * - DVC : Digital Volume and Mute Function
26 * - SSI : Serial Sound Interface
30 * SCU : Sampling Rate Converter Unit
31 * - SRC : Sampling Rate Converter
33 * - CTU : Channel Count Conversion Unit
35 * - DVC : Digital Volume and Mute Function
36 * SSIU : Serial Sound Interface Unit
37 * - SSI : Serial Sound Interface
45 * | ** this depends on Gen1/Gen2
49 * | ** these depend on data path
50 * | ** gen and platform data control it
54 * | +- playback -> [mod] -> [mod] -> [mod] -> ...
57 * | +- capture -> [mod] -> [mod] -> [mod] -> ...
61 * | +- playback -> [mod] -> [mod] -> [mod] -> ...
64 * | +- capture -> [mod] -> [mod] -> [mod] -> ...
67 * | ** these control ssi
76 * | ** these control src
86 * for_each_rsnd_dai(xx, priv, xx)
87 * rdai[0] => rdai[1] => rdai[2] => ...
89 * for_each_rsnd_mod(xx, rdai, xx)
90 * [mod] => [mod] => [mod] => ...
92 * rsnd_dai_call(xxx, fn )
93 * [mod]->fn() -> [mod]->fn() -> [mod]->fn()...
96 #include <linux/pm_runtime.h>
99 #define RSND_RATES SNDRV_PCM_RATE_8000_96000
100 #define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
102 static const struct of_device_id rsnd_of_match[] = {
103 { .compatible = "renesas,rcar_sound-gen1", .data = (void *)RSND_GEN1 },
104 { .compatible = "renesas,rcar_sound-gen2", .data = (void *)RSND_GEN2 },
105 { .compatible = "renesas,rcar_sound-gen3", .data = (void *)RSND_GEN2 }, /* gen2 compatible */
108 MODULE_DEVICE_TABLE(of, rsnd_of_match);
113 void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type)
115 if (mod->type != type) {
116 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
117 struct device *dev = rsnd_priv_to_dev(priv);
119 dev_warn(dev, "%s[%d] is not your expected module\n",
120 rsnd_mod_name(mod), rsnd_mod_id(mod));
124 char *rsnd_mod_name(struct rsnd_mod *mod)
126 if (!mod || !mod->ops)
129 return mod->ops->name;
132 struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
133 struct rsnd_mod *mod)
135 if (!mod || !mod->ops || !mod->ops->dma_req)
138 return mod->ops->dma_req(io, mod);
141 int rsnd_mod_init(struct rsnd_priv *priv,
142 struct rsnd_mod *mod,
143 struct rsnd_mod_ops *ops,
145 enum rsnd_mod_type type,
148 int ret = clk_prepare(clk);
162 void rsnd_mod_quit(struct rsnd_mod *mod)
165 clk_unprepare(mod->clk);
168 void rsnd_mod_interrupt(struct rsnd_mod *mod,
169 void (*callback)(struct rsnd_mod *mod,
170 struct rsnd_dai_stream *io))
172 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
173 struct rsnd_dai_stream *io;
174 struct rsnd_dai *rdai;
177 for_each_rsnd_dai(rdai, priv, i) {
178 io = &rdai->playback;
179 if (mod == io->mod[mod->type])
183 if (mod == io->mod[mod->type])
188 int rsnd_io_is_working(struct rsnd_dai_stream *io)
190 /* see rsnd_dai_stream_init/quit() */
191 return !!io->substream;
197 u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
199 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
200 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
201 struct device *dev = rsnd_priv_to_dev(priv);
202 u32 adinr = runtime->channels;
204 switch (runtime->sample_bits) {
212 dev_warn(dev, "not supported sample bits\n");
219 u32 rsnd_get_adinr_chan(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
221 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
222 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
223 struct device *dev = rsnd_priv_to_dev(priv);
224 u32 chan = runtime->channels;
234 dev_warn(dev, "not supported channel\n");
245 u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
247 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
248 struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
249 struct rsnd_mod *target = src ? src : ssi;
250 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
251 u32 val = 0x76543210;
254 mask <<= runtime->channels * 4;
257 switch (runtime->sample_bits) {
259 val |= 0x67452301 & ~mask;
262 val |= 0x76543210 & ~mask;
267 * exchange channeles on SRC if possible,
268 * otherwise, R/L volume settings on DVC
269 * changes inverted channels
280 #define rsnd_mod_call(idx, io, func, param...) \
282 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
283 struct rsnd_mod *mod = (io)->mod[idx]; \
284 struct device *dev = rsnd_priv_to_dev(priv); \
285 u32 *status = (io)->mod_status + idx; \
286 u32 mask = 0xF << __rsnd_mod_shift_##func; \
287 u8 val = (*status >> __rsnd_mod_shift_##func) & 0xF; \
288 u8 add = ((val + __rsnd_mod_add_##func) & 0xF); \
290 int call = (val == __rsnd_mod_call_##func) && (mod)->ops->func; \
291 *status = (*status & ~mask) + \
292 (add << __rsnd_mod_shift_##func); \
293 dev_dbg(dev, "%s[%d]\t0x%08x %s\n", \
294 rsnd_mod_name(mod), rsnd_mod_id(mod), \
295 *status, call ? #func : ""); \
297 ret = (mod)->ops->func(mod, io, param); \
301 #define rsnd_dai_call(fn, io, param...) \
303 struct rsnd_mod *mod; \
305 for (i = 0; i < RSND_MOD_MAX; i++) { \
306 mod = (io)->mod[i]; \
309 ret |= rsnd_mod_call(i, io, fn, param); \
314 int rsnd_dai_connect(struct rsnd_mod *mod,
315 struct rsnd_dai_stream *io,
316 enum rsnd_mod_type type)
318 struct rsnd_priv *priv;
324 priv = rsnd_mod_to_priv(mod);
325 dev = rsnd_priv_to_dev(priv);
329 dev_dbg(dev, "%s[%d] is connected to io (%s)\n",
330 rsnd_mod_name(mod), rsnd_mod_id(mod),
331 rsnd_io_is_play(io) ? "Playback" : "Capture");
336 static void rsnd_dai_disconnect(struct rsnd_mod *mod,
337 struct rsnd_dai_stream *io,
338 enum rsnd_mod_type type)
340 io->mod[type] = NULL;
343 struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id)
345 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
348 return priv->rdai + id;
351 #define rsnd_dai_to_priv(dai) snd_soc_dai_get_drvdata(dai)
352 static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
354 struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
356 return rsnd_rdai_get(priv, dai->id);
360 * rsnd_soc_dai functions
362 int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
364 struct snd_pcm_substream *substream = io->substream;
365 struct snd_pcm_runtime *runtime = substream->runtime;
366 int pos = io->byte_pos + additional;
368 pos %= (runtime->periods * io->byte_per_period);
373 bool rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
375 io->byte_pos += byte;
377 if (io->byte_pos >= io->next_period_byte) {
378 struct snd_pcm_substream *substream = io->substream;
379 struct snd_pcm_runtime *runtime = substream->runtime;
382 io->next_period_byte += io->byte_per_period;
384 if (io->period_pos >= runtime->periods) {
387 io->next_period_byte = io->byte_per_period;
396 void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io)
398 struct snd_pcm_substream *substream = io->substream;
401 * this function should be called...
403 * - if rsnd_dai_pointer_update() returns true
404 * - without spin lock
407 snd_pcm_period_elapsed(substream);
410 static void rsnd_dai_stream_init(struct rsnd_dai_stream *io,
411 struct snd_pcm_substream *substream)
413 struct snd_pcm_runtime *runtime = substream->runtime;
415 io->substream = substream;
418 io->byte_per_period = runtime->period_size *
420 samples_to_bytes(runtime, 1);
421 io->next_period_byte = io->byte_per_period;
424 static void rsnd_dai_stream_quit(struct rsnd_dai_stream *io)
426 io->substream = NULL;
430 struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
432 struct snd_soc_pcm_runtime *rtd = substream->private_data;
438 struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
439 struct snd_pcm_substream *substream)
441 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
442 return &rdai->playback;
444 return &rdai->capture;
447 static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
448 struct snd_soc_dai *dai)
450 struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
451 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
452 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
456 spin_lock_irqsave(&priv->lock, flags);
459 case SNDRV_PCM_TRIGGER_START:
460 rsnd_dai_stream_init(io, substream);
462 ret = rsnd_dai_call(init, io, priv);
464 goto dai_trigger_end;
466 ret = rsnd_dai_call(start, io, priv);
468 goto dai_trigger_end;
470 case SNDRV_PCM_TRIGGER_STOP:
471 ret = rsnd_dai_call(stop, io, priv);
473 ret |= rsnd_dai_call(quit, io, priv);
475 rsnd_dai_stream_quit(io);
482 spin_unlock_irqrestore(&priv->lock, flags);
487 static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
489 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
491 /* set master/slave audio interface */
492 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
493 case SND_SOC_DAIFMT_CBM_CFM:
494 rdai->clk_master = 0;
496 case SND_SOC_DAIFMT_CBS_CFS:
497 rdai->clk_master = 1; /* codec is slave, cpu is master */
504 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
505 case SND_SOC_DAIFMT_I2S:
507 rdai->data_alignment = 0;
508 rdai->frm_clk_inv = 0;
510 case SND_SOC_DAIFMT_LEFT_J:
512 rdai->data_alignment = 0;
513 rdai->frm_clk_inv = 1;
515 case SND_SOC_DAIFMT_RIGHT_J:
517 rdai->data_alignment = 1;
518 rdai->frm_clk_inv = 1;
522 /* set clock inversion */
523 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
524 case SND_SOC_DAIFMT_NB_IF:
525 rdai->bit_clk_inv = rdai->bit_clk_inv;
526 rdai->frm_clk_inv = !rdai->frm_clk_inv;
528 case SND_SOC_DAIFMT_IB_NF:
529 rdai->bit_clk_inv = !rdai->bit_clk_inv;
530 rdai->frm_clk_inv = rdai->frm_clk_inv;
532 case SND_SOC_DAIFMT_IB_IF:
533 rdai->bit_clk_inv = !rdai->bit_clk_inv;
534 rdai->frm_clk_inv = !rdai->frm_clk_inv;
536 case SND_SOC_DAIFMT_NB_NF:
544 static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
545 .trigger = rsnd_soc_dai_trigger,
546 .set_fmt = rsnd_soc_dai_set_fmt,
549 static int rsnd_dai_probe(struct platform_device *pdev,
550 struct rsnd_priv *priv)
552 struct device_node *dai_node;
553 struct device_node *dai_np, *np, *node;
554 struct device_node *playback, *capture;
555 struct rsnd_dai_stream *io_playback;
556 struct rsnd_dai_stream *io_capture;
557 struct snd_soc_dai_driver *drv;
558 struct rsnd_dai *rdai;
559 struct device *dev = &pdev->dev;
560 int nr, dai_i, io_i, np_i;
563 dai_node = rsnd_dai_of_node(priv);
564 nr = of_get_child_count(dai_node);
567 goto rsnd_dai_probe_done;
570 drv = devm_kzalloc(dev, sizeof(*drv) * nr, GFP_KERNEL);
571 rdai = devm_kzalloc(dev, sizeof(*rdai) * nr, GFP_KERNEL);
574 goto rsnd_dai_probe_done;
585 for_each_child_of_node(dai_node, dai_np) {
586 rdai = rsnd_rdai_get(priv, dai_i);
588 io_playback = &rdai->playback;
589 io_capture = &rdai->capture;
591 snprintf(rdai->name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", dai_i);
594 drv->name = rdai->name;
595 drv->ops = &rsnd_soc_dai_ops;
597 snprintf(rdai->playback.name, RSND_DAI_NAME_SIZE,
598 "DAI%d Playback", dai_i);
599 drv->playback.rates = RSND_RATES;
600 drv->playback.formats = RSND_FMTS;
601 drv->playback.channels_min = 2;
602 drv->playback.channels_max = 2;
603 drv->playback.stream_name = rdai->playback.name;
605 snprintf(rdai->capture.name, RSND_DAI_NAME_SIZE,
606 "DAI%d Capture", dai_i);
607 drv->capture.rates = RSND_RATES;
608 drv->capture.formats = RSND_FMTS;
609 drv->capture.channels_min = 2;
610 drv->capture.channels_max = 2;
611 drv->capture.stream_name = rdai->capture.name;
613 rdai->playback.rdai = rdai;
614 rdai->capture.rdai = rdai;
616 #define mod_parse(name) \
617 node = rsnd_##name##_of_node(priv); \
619 struct rsnd_mod *mod; \
621 for_each_child_of_node(node, np) { \
622 mod = rsnd_##name##_mod_get(priv, np_i); \
623 if (np == playback) \
624 rsnd_dai_connect(mod, io_playback, mod->type); \
626 rsnd_dai_connect(mod, io_capture, mod->type); \
632 for (io_i = 0;; io_i++) {
633 playback = of_parse_phandle(dai_np, "playback", io_i);
634 capture = of_parse_phandle(dai_np, "capture", io_i);
636 if (!playback && !capture)
645 of_node_put(playback);
646 of_node_put(capture);
651 dev_dbg(dev, "%s (%s/%s)\n", rdai->name,
652 rsnd_io_to_mod_ssi(io_playback) ? "play" : " -- ",
653 rsnd_io_to_mod_ssi(io_capture) ? "capture" : " -- ");
659 of_node_put(dai_node);
667 static struct snd_pcm_hardware rsnd_pcm_hardware = {
668 .info = SNDRV_PCM_INFO_INTERLEAVED |
669 SNDRV_PCM_INFO_MMAP |
670 SNDRV_PCM_INFO_MMAP_VALID,
671 .buffer_bytes_max = 64 * 1024,
672 .period_bytes_min = 32,
673 .period_bytes_max = 8192,
679 static int rsnd_pcm_open(struct snd_pcm_substream *substream)
681 struct snd_pcm_runtime *runtime = substream->runtime;
684 snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
686 ret = snd_pcm_hw_constraint_integer(runtime,
687 SNDRV_PCM_HW_PARAM_PERIODS);
692 static int rsnd_hw_params(struct snd_pcm_substream *substream,
693 struct snd_pcm_hw_params *hw_params)
695 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
696 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
697 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
700 ret = rsnd_dai_call(hw_params, io, substream, hw_params);
704 return snd_pcm_lib_malloc_pages(substream,
705 params_buffer_bytes(hw_params));
708 static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
710 struct snd_pcm_runtime *runtime = substream->runtime;
711 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
712 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
713 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
715 return bytes_to_frames(runtime, io->byte_pos);
718 static struct snd_pcm_ops rsnd_pcm_ops = {
719 .open = rsnd_pcm_open,
720 .ioctl = snd_pcm_lib_ioctl,
721 .hw_params = rsnd_hw_params,
722 .hw_free = snd_pcm_lib_free_pages,
723 .pointer = rsnd_pointer,
729 #define kcontrol_to_cfg(kctrl) ((struct rsnd_kctrl_cfg *)kctrl->private_value)
730 static int rsnd_kctrl_info(struct snd_kcontrol *kctrl,
731 struct snd_ctl_elem_info *uinfo)
733 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
736 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
737 uinfo->count = cfg->size;
738 uinfo->value.enumerated.items = cfg->max;
739 if (uinfo->value.enumerated.item >= cfg->max)
740 uinfo->value.enumerated.item = cfg->max - 1;
741 strlcpy(uinfo->value.enumerated.name,
742 cfg->texts[uinfo->value.enumerated.item],
743 sizeof(uinfo->value.enumerated.name));
745 uinfo->count = cfg->size;
746 uinfo->value.integer.min = 0;
747 uinfo->value.integer.max = cfg->max;
748 uinfo->type = (cfg->max == 1) ?
749 SNDRV_CTL_ELEM_TYPE_BOOLEAN :
750 SNDRV_CTL_ELEM_TYPE_INTEGER;
756 static int rsnd_kctrl_get(struct snd_kcontrol *kctrl,
757 struct snd_ctl_elem_value *uc)
759 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
762 for (i = 0; i < cfg->size; i++)
764 uc->value.enumerated.item[i] = cfg->val[i];
766 uc->value.integer.value[i] = cfg->val[i];
771 static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
772 struct snd_ctl_elem_value *uc)
774 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
775 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
778 for (i = 0; i < cfg->size; i++) {
780 change |= (uc->value.enumerated.item[i] != cfg->val[i]);
781 cfg->val[i] = uc->value.enumerated.item[i];
783 change |= (uc->value.integer.value[i] != cfg->val[i]);
784 cfg->val[i] = uc->value.integer.value[i];
789 cfg->update(cfg->io, mod);
794 static int __rsnd_kctrl_new(struct rsnd_mod *mod,
795 struct rsnd_dai_stream *io,
796 struct snd_soc_pcm_runtime *rtd,
797 const unsigned char *name,
798 struct rsnd_kctrl_cfg *cfg,
799 void (*update)(struct rsnd_dai_stream *io,
800 struct rsnd_mod *mod))
802 struct snd_soc_card *soc_card = rtd->card;
803 struct snd_card *card = rtd->card->snd_card;
804 struct snd_kcontrol *kctrl;
805 struct snd_kcontrol_new knew = {
806 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
808 .info = rsnd_kctrl_info,
809 .index = rtd - soc_card->rtd,
810 .get = rsnd_kctrl_get,
811 .put = rsnd_kctrl_put,
812 .private_value = (unsigned long)cfg,
816 kctrl = snd_ctl_new1(&knew, mod);
820 ret = snd_ctl_add(card, kctrl);
822 snd_ctl_free_one(kctrl);
826 cfg->update = update;
834 void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg)
836 snd_ctl_remove(cfg->card, cfg->kctrl);
839 int rsnd_kctrl_new_m(struct rsnd_mod *mod,
840 struct rsnd_dai_stream *io,
841 struct snd_soc_pcm_runtime *rtd,
842 const unsigned char *name,
843 void (*update)(struct rsnd_dai_stream *io,
844 struct rsnd_mod *mod),
845 struct rsnd_kctrl_cfg_m *_cfg,
849 _cfg->cfg.size = RSND_DVC_CHANNELS;
850 _cfg->cfg.val = _cfg->val;
851 return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
854 int rsnd_kctrl_new_s(struct rsnd_mod *mod,
855 struct rsnd_dai_stream *io,
856 struct snd_soc_pcm_runtime *rtd,
857 const unsigned char *name,
858 void (*update)(struct rsnd_dai_stream *io,
859 struct rsnd_mod *mod),
860 struct rsnd_kctrl_cfg_s *_cfg,
865 _cfg->cfg.val = &_cfg->val;
866 return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
869 int rsnd_kctrl_new_e(struct rsnd_mod *mod,
870 struct rsnd_dai_stream *io,
871 struct snd_soc_pcm_runtime *rtd,
872 const unsigned char *name,
873 struct rsnd_kctrl_cfg_s *_cfg,
874 void (*update)(struct rsnd_dai_stream *io,
875 struct rsnd_mod *mod),
876 const char * const *texts,
881 _cfg->cfg.val = &_cfg->val;
882 _cfg->cfg.texts = texts;
883 return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
890 #define PREALLOC_BUFFER (32 * 1024)
891 #define PREALLOC_BUFFER_MAX (32 * 1024)
893 static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
895 struct snd_soc_dai *dai = rtd->cpu_dai;
896 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
899 ret = rsnd_dai_call(pcm_new, &rdai->playback, rtd);
903 ret = rsnd_dai_call(pcm_new, &rdai->capture, rtd);
907 return snd_pcm_lib_preallocate_pages_for_all(
910 rtd->card->snd_card->dev,
911 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
914 static struct snd_soc_platform_driver rsnd_soc_platform = {
915 .ops = &rsnd_pcm_ops,
916 .pcm_new = rsnd_pcm_new,
919 static const struct snd_soc_component_driver rsnd_soc_component = {
923 static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
924 struct rsnd_dai_stream *io)
928 ret = rsnd_dai_call(probe, io, priv);
929 if (ret == -EAGAIN) {
930 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io);
934 * Fallback to PIO mode
938 * call "remove" for SSI/SRC/DVC
939 * SSI will be switch to PIO mode if it was DMA mode
942 * rsnd_ssi_fallback()
944 rsnd_dai_call(remove, io, priv);
947 * remove all mod from io
948 * and, re connect ssi
950 for (i = 0; i < RSND_MOD_MAX; i++)
951 rsnd_dai_disconnect((io)->mod[i], io, i);
952 rsnd_dai_connect(ssi_mod, io, RSND_MOD_SSI);
957 rsnd_dai_call(fallback, io, priv);
961 * DAI has SSI which is PIO mode only now.
963 ret = rsnd_dai_call(probe, io, priv);
972 static int rsnd_probe(struct platform_device *pdev)
974 struct rsnd_priv *priv;
975 struct device *dev = &pdev->dev;
976 struct rsnd_dai *rdai;
977 const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
978 int (*probe_func[])(struct platform_device *pdev,
979 struct rsnd_priv *priv) = {
997 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
999 dev_err(dev, "priv allocate failed\n");
1004 priv->flags = (u32)of_id->data;
1005 spin_lock_init(&priv->lock);
1010 for (i = 0; i < ARRAY_SIZE(probe_func); i++) {
1011 ret = probe_func[i](pdev, priv);
1016 for_each_rsnd_dai(rdai, priv, i) {
1017 ret = rsnd_rdai_continuance_probe(priv, &rdai->playback);
1019 goto exit_snd_probe;
1021 ret = rsnd_rdai_continuance_probe(priv, &rdai->capture);
1023 goto exit_snd_probe;
1026 dev_set_drvdata(dev, priv);
1031 ret = snd_soc_register_platform(dev, &rsnd_soc_platform);
1033 dev_err(dev, "cannot snd soc register\n");
1037 ret = snd_soc_register_component(dev, &rsnd_soc_component,
1038 priv->daidrv, rsnd_rdai_nr(priv));
1040 dev_err(dev, "cannot snd dai register\n");
1044 pm_runtime_enable(dev);
1046 dev_info(dev, "probed\n");
1050 snd_soc_unregister_platform(dev);
1052 for_each_rsnd_dai(rdai, priv, i) {
1053 rsnd_dai_call(remove, &rdai->playback, priv);
1054 rsnd_dai_call(remove, &rdai->capture, priv);
1060 static int rsnd_remove(struct platform_device *pdev)
1062 struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
1063 struct rsnd_dai *rdai;
1064 void (*remove_func[])(struct platform_device *pdev,
1065 struct rsnd_priv *priv) = {
1077 pm_runtime_disable(&pdev->dev);
1079 for_each_rsnd_dai(rdai, priv, i) {
1080 ret |= rsnd_dai_call(remove, &rdai->playback, priv);
1081 ret |= rsnd_dai_call(remove, &rdai->capture, priv);
1084 for (i = 0; i < ARRAY_SIZE(remove_func); i++)
1085 remove_func[i](pdev, priv);
1087 snd_soc_unregister_component(&pdev->dev);
1088 snd_soc_unregister_platform(&pdev->dev);
1093 static struct platform_driver rsnd_driver = {
1095 .name = "rcar_sound",
1096 .of_match_table = rsnd_of_match,
1098 .probe = rsnd_probe,
1099 .remove = rsnd_remove,
1101 module_platform_driver(rsnd_driver);
1103 MODULE_LICENSE("GPL");
1104 MODULE_DESCRIPTION("Renesas R-Car audio driver");
1105 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
1106 MODULE_ALIAS("platform:rcar-pcm-audio");