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 rsnd_of_data rsnd_of_data_gen1 = {
106 static const struct rsnd_of_data rsnd_of_data_gen2 = {
110 static const struct of_device_id rsnd_of_match[] = {
111 { .compatible = "renesas,rcar_sound-gen1", .data = &rsnd_of_data_gen1 },
112 { .compatible = "renesas,rcar_sound-gen2", .data = &rsnd_of_data_gen2 },
115 MODULE_DEVICE_TABLE(of, rsnd_of_match);
118 * rsnd_platform functions
120 #define rsnd_platform_call(priv, dai, func, param...) \
121 (!(priv->info->func) ? 0 : \
122 priv->info->func(param))
124 #define rsnd_is_enable_path(io, name) \
125 ((io)->info ? (io)->info->name : NULL)
126 #define rsnd_info_id(priv, io, name) \
127 ((io)->info->name - priv->info->name##_info)
132 char *rsnd_mod_name(struct rsnd_mod *mod)
134 if (!mod || !mod->ops)
137 return mod->ops->name;
140 struct dma_chan *rsnd_mod_dma_req(struct rsnd_mod *mod)
142 if (!mod || !mod->ops || !mod->ops->dma_req)
145 return mod->ops->dma_req(mod);
148 int rsnd_mod_init(struct rsnd_mod *mod,
149 struct rsnd_mod_ops *ops,
151 enum rsnd_mod_type type,
154 int ret = clk_prepare(clk);
167 void rsnd_mod_quit(struct rsnd_mod *mod)
170 clk_unprepare(mod->clk);
173 int rsnd_mod_is_working(struct rsnd_mod *mod)
175 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
177 /* see rsnd_dai_stream_init/quit() */
178 return !!io->substream;
184 u32 rsnd_get_adinr(struct rsnd_mod *mod)
186 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
187 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
188 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
189 struct device *dev = rsnd_priv_to_dev(priv);
190 u32 adinr = runtime->channels;
192 switch (runtime->sample_bits) {
200 dev_warn(dev, "not supported sample bits\n");
210 #define __rsnd_mod_call(mod, func, param...) \
212 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
213 struct device *dev = rsnd_priv_to_dev(priv); \
214 u32 mask = 0xF << __rsnd_mod_shift_##func; \
215 u8 val = (mod->status >> __rsnd_mod_shift_##func) & 0xF; \
216 u8 add = ((val + __rsnd_mod_add_##func) & 0xF); \
219 if (val == __rsnd_mod_call_##func) { \
221 ret = (mod)->ops->func(mod, param); \
222 mod->status = (mod->status & ~mask) + \
223 (add << __rsnd_mod_shift_##func); \
225 dev_dbg(dev, "%s[%d] 0x%08x %s\n", \
226 rsnd_mod_name(mod), rsnd_mod_id(mod), mod->status, \
227 called ? #func : ""); \
231 #define rsnd_mod_call(mod, func, param...) \
232 (!(mod) ? -ENODEV : \
233 !((mod)->ops->func) ? 0 : \
234 __rsnd_mod_call(mod, func, param))
236 #define rsnd_dai_call(fn, io, param...) \
238 struct rsnd_mod *mod; \
240 for (i = 0; i < RSND_MOD_MAX; i++) { \
241 mod = (io)->mod[i]; \
244 ret = rsnd_mod_call(mod, fn, param); \
251 static int rsnd_dai_connect(struct rsnd_mod *mod,
252 struct rsnd_dai_stream *io)
257 if (io->mod[mod->type]) {
258 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
259 struct device *dev = rsnd_priv_to_dev(priv);
261 dev_err(dev, "%s[%d] is not empty\n",
267 io->mod[mod->type] = mod;
273 static void rsnd_dai_disconnect(struct rsnd_mod *mod,
274 struct rsnd_dai_stream *io)
277 io->mod[mod->type] = NULL;
280 struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id)
282 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
285 return priv->rdai + id;
288 #define rsnd_dai_to_priv(dai) snd_soc_dai_get_drvdata(dai)
289 static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
291 struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
293 return rsnd_rdai_get(priv, dai->id);
297 * rsnd_soc_dai functions
299 int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
301 struct snd_pcm_substream *substream = io->substream;
302 struct snd_pcm_runtime *runtime = substream->runtime;
303 int pos = io->byte_pos + additional;
305 pos %= (runtime->periods * io->byte_per_period);
310 bool rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
312 io->byte_pos += byte;
314 if (io->byte_pos >= io->next_period_byte) {
315 struct snd_pcm_substream *substream = io->substream;
316 struct snd_pcm_runtime *runtime = substream->runtime;
319 io->next_period_byte += io->byte_per_period;
321 if (io->period_pos >= runtime->periods) {
324 io->next_period_byte = io->byte_per_period;
333 void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io)
335 struct snd_pcm_substream *substream = io->substream;
338 * this function should be called...
340 * - if rsnd_dai_pointer_update() returns true
341 * - without spin lock
344 snd_pcm_period_elapsed(substream);
347 static void rsnd_dai_stream_init(struct rsnd_dai_stream *io,
348 struct snd_pcm_substream *substream)
350 struct snd_pcm_runtime *runtime = substream->runtime;
352 io->substream = substream;
355 io->byte_per_period = runtime->period_size *
357 samples_to_bytes(runtime, 1);
358 io->next_period_byte = io->byte_per_period;
361 static void rsnd_dai_stream_quit(struct rsnd_dai_stream *io)
363 io->substream = NULL;
367 struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
369 struct snd_soc_pcm_runtime *rtd = substream->private_data;
375 struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
376 struct snd_pcm_substream *substream)
378 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
379 return &rdai->playback;
381 return &rdai->capture;
384 static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
385 struct snd_soc_dai *dai)
387 struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
388 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
389 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
390 int ssi_id = rsnd_mod_id(rsnd_io_to_mod_ssi(io));
394 spin_lock_irqsave(&priv->lock, flags);
397 case SNDRV_PCM_TRIGGER_START:
398 rsnd_dai_stream_init(io, substream);
400 ret = rsnd_platform_call(priv, dai, start, ssi_id);
402 goto dai_trigger_end;
404 ret = rsnd_dai_call(init, io, priv);
406 goto dai_trigger_end;
408 ret = rsnd_dai_call(start, io, priv);
410 goto dai_trigger_end;
412 case SNDRV_PCM_TRIGGER_STOP:
413 ret = rsnd_dai_call(stop, io, priv);
415 goto dai_trigger_end;
417 ret = rsnd_dai_call(quit, io, priv);
419 goto dai_trigger_end;
421 ret = rsnd_platform_call(priv, dai, stop, ssi_id);
423 goto dai_trigger_end;
425 rsnd_dai_stream_quit(io);
432 spin_unlock_irqrestore(&priv->lock, flags);
437 static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
439 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
441 /* set master/slave audio interface */
442 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
443 case SND_SOC_DAIFMT_CBM_CFM:
444 rdai->clk_master = 0;
446 case SND_SOC_DAIFMT_CBS_CFS:
447 rdai->clk_master = 1; /* codec is slave, cpu is master */
454 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
455 case SND_SOC_DAIFMT_I2S:
457 rdai->data_alignment = 0;
458 rdai->frm_clk_inv = 0;
460 case SND_SOC_DAIFMT_LEFT_J:
462 rdai->data_alignment = 0;
463 rdai->frm_clk_inv = 1;
465 case SND_SOC_DAIFMT_RIGHT_J:
467 rdai->data_alignment = 1;
468 rdai->frm_clk_inv = 1;
472 /* set clock inversion */
473 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
474 case SND_SOC_DAIFMT_NB_IF:
475 rdai->bit_clk_inv = rdai->bit_clk_inv;
476 rdai->frm_clk_inv = !rdai->frm_clk_inv;
478 case SND_SOC_DAIFMT_IB_NF:
479 rdai->bit_clk_inv = !rdai->bit_clk_inv;
480 rdai->frm_clk_inv = rdai->frm_clk_inv;
482 case SND_SOC_DAIFMT_IB_IF:
483 rdai->bit_clk_inv = !rdai->bit_clk_inv;
484 rdai->frm_clk_inv = !rdai->frm_clk_inv;
486 case SND_SOC_DAIFMT_NB_NF:
494 static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
495 .trigger = rsnd_soc_dai_trigger,
496 .set_fmt = rsnd_soc_dai_set_fmt,
499 #define rsnd_path_parse(priv, io, type) \
501 struct rsnd_mod *mod; \
505 if (rsnd_is_enable_path(io, type)) { \
506 id = rsnd_info_id(priv, io, type); \
508 mod = rsnd_##type##_mod_get(priv, id); \
509 ret = rsnd_dai_connect(mod, io); \
515 #define rsnd_path_break(priv, io, type) \
517 struct rsnd_mod *mod; \
520 if (rsnd_is_enable_path(io, type)) { \
521 id = rsnd_info_id(priv, io, type); \
523 mod = rsnd_##type##_mod_get(priv, id); \
524 rsnd_dai_disconnect(mod, io); \
529 static int rsnd_path_init(struct rsnd_priv *priv,
530 struct rsnd_dai *rdai,
531 struct rsnd_dai_stream *io)
536 * Gen1 is created by SRU/SSI, and this SRU is base module of
537 * Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU)
540 * Gen1 SRU = Gen2 SCU + SSIU + etc
542 * Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is
547 ret = rsnd_path_parse(priv, io, src);
552 ret = rsnd_path_parse(priv, io, ssi);
557 ret = rsnd_path_parse(priv, io, dvc);
564 static void rsnd_of_parse_dai(struct platform_device *pdev,
565 const struct rsnd_of_data *of_data,
566 struct rsnd_priv *priv)
568 struct device_node *dai_node, *dai_np;
569 struct device_node *ssi_node, *ssi_np;
570 struct device_node *src_node, *src_np;
571 struct device_node *dvc_node, *dvc_np;
572 struct device_node *playback, *capture;
573 struct rsnd_dai_platform_info *dai_info;
574 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
575 struct device *dev = &pdev->dev;
577 int dai_i, ssi_i, src_i, dvc_i;
582 dai_node = of_get_child_by_name(dev->of_node, "rcar_sound,dai");
586 nr = of_get_child_count(dai_node);
590 dai_info = devm_kzalloc(dev,
591 sizeof(struct rsnd_dai_platform_info) * nr,
594 dev_err(dev, "dai info allocation error\n");
598 info->dai_info_nr = nr;
599 info->dai_info = dai_info;
601 ssi_node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi");
602 src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
603 dvc_node = of_get_child_by_name(dev->of_node, "rcar_sound,dvc");
605 #define mod_parse(name) \
607 struct rsnd_##name##_platform_info *name##_info; \
610 for_each_child_of_node(name##_node, name##_np) { \
611 name##_info = info->name##_info + name##_i; \
613 if (name##_np == playback) \
614 dai_info->playback.name = name##_info; \
615 if (name##_np == capture) \
616 dai_info->capture.name = name##_info; \
626 for_each_child_of_node(dai_node, dai_np) {
627 dai_info = info->dai_info + dai_i;
631 playback = of_parse_phandle(dai_np, "playback", i);
632 capture = of_parse_phandle(dai_np, "capture", i);
634 if (!playback && !capture)
641 of_node_put(playback);
642 of_node_put(capture);
649 static int rsnd_dai_probe(struct platform_device *pdev,
650 const struct rsnd_of_data *of_data,
651 struct rsnd_priv *priv)
653 struct snd_soc_dai_driver *drv;
654 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
655 struct rsnd_dai *rdai;
656 struct rsnd_ssi_platform_info *pmod, *cmod;
657 struct device *dev = rsnd_priv_to_dev(priv);
661 rsnd_of_parse_dai(pdev, of_data, priv);
663 dai_nr = info->dai_info_nr;
665 dev_err(dev, "no dai\n");
669 drv = devm_kzalloc(dev, sizeof(*drv) * dai_nr, GFP_KERNEL);
670 rdai = devm_kzalloc(dev, sizeof(*rdai) * dai_nr, GFP_KERNEL);
672 dev_err(dev, "dai allocate failed\n");
676 priv->rdai_nr = dai_nr;
680 for (i = 0; i < dai_nr; i++) {
682 pmod = info->dai_info[i].playback.ssi;
683 cmod = info->dai_info[i].capture.ssi;
688 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
692 * init snd_soc_dai_driver
694 drv[i].name = rdai[i].name;
695 drv[i].ops = &rsnd_soc_dai_ops;
697 snprintf(rdai[i].playback.name, RSND_DAI_NAME_SIZE,
698 "DAI%d Playback", i);
700 drv[i].playback.rates = RSND_RATES;
701 drv[i].playback.formats = RSND_FMTS;
702 drv[i].playback.channels_min = 2;
703 drv[i].playback.channels_max = 2;
704 drv[i].playback.stream_name = rdai[i].playback.name;
706 rdai[i].playback.info = &info->dai_info[i].playback;
707 rdai[i].playback.rdai = rdai + i;
708 rsnd_path_init(priv, &rdai[i], &rdai[i].playback);
711 snprintf(rdai[i].capture.name, RSND_DAI_NAME_SIZE,
714 drv[i].capture.rates = RSND_RATES;
715 drv[i].capture.formats = RSND_FMTS;
716 drv[i].capture.channels_min = 2;
717 drv[i].capture.channels_max = 2;
718 drv[i].capture.stream_name = rdai[i].capture.name;
720 rdai[i].capture.info = &info->dai_info[i].capture;
721 rdai[i].capture.rdai = rdai + i;
722 rsnd_path_init(priv, &rdai[i], &rdai[i].capture);
725 dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name,
726 pmod ? "play" : " -- ",
727 cmod ? "capture" : " -- ");
736 static struct snd_pcm_hardware rsnd_pcm_hardware = {
737 .info = SNDRV_PCM_INFO_INTERLEAVED |
738 SNDRV_PCM_INFO_MMAP |
739 SNDRV_PCM_INFO_MMAP_VALID,
740 .buffer_bytes_max = 64 * 1024,
741 .period_bytes_min = 32,
742 .period_bytes_max = 8192,
748 static int rsnd_pcm_open(struct snd_pcm_substream *substream)
750 struct snd_pcm_runtime *runtime = substream->runtime;
753 snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
755 ret = snd_pcm_hw_constraint_integer(runtime,
756 SNDRV_PCM_HW_PARAM_PERIODS);
761 static int rsnd_hw_params(struct snd_pcm_substream *substream,
762 struct snd_pcm_hw_params *hw_params)
764 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
765 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
766 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
769 ret = rsnd_dai_call(hw_params, io, substream, hw_params);
773 return snd_pcm_lib_malloc_pages(substream,
774 params_buffer_bytes(hw_params));
777 static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
779 struct snd_pcm_runtime *runtime = substream->runtime;
780 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
781 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
782 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
784 return bytes_to_frames(runtime, io->byte_pos);
787 static struct snd_pcm_ops rsnd_pcm_ops = {
788 .open = rsnd_pcm_open,
789 .ioctl = snd_pcm_lib_ioctl,
790 .hw_params = rsnd_hw_params,
791 .hw_free = snd_pcm_lib_free_pages,
792 .pointer = rsnd_pointer,
798 #define kcontrol_to_cfg(kctrl) ((struct rsnd_kctrl_cfg *)kctrl->private_value)
799 static int rsnd_kctrl_info(struct snd_kcontrol *kctrl,
800 struct snd_ctl_elem_info *uinfo)
802 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
805 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
806 uinfo->count = cfg->size;
807 uinfo->value.enumerated.items = cfg->max;
808 if (uinfo->value.enumerated.item >= cfg->max)
809 uinfo->value.enumerated.item = cfg->max - 1;
810 strlcpy(uinfo->value.enumerated.name,
811 cfg->texts[uinfo->value.enumerated.item],
812 sizeof(uinfo->value.enumerated.name));
814 uinfo->count = cfg->size;
815 uinfo->value.integer.min = 0;
816 uinfo->value.integer.max = cfg->max;
817 uinfo->type = (cfg->max == 1) ?
818 SNDRV_CTL_ELEM_TYPE_BOOLEAN :
819 SNDRV_CTL_ELEM_TYPE_INTEGER;
825 static int rsnd_kctrl_get(struct snd_kcontrol *kctrl,
826 struct snd_ctl_elem_value *uc)
828 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
831 for (i = 0; i < cfg->size; i++)
833 uc->value.enumerated.item[i] = cfg->val[i];
835 uc->value.integer.value[i] = cfg->val[i];
840 static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
841 struct snd_ctl_elem_value *uc)
843 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
844 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
847 for (i = 0; i < cfg->size; i++) {
849 change |= (uc->value.enumerated.item[i] != cfg->val[i]);
850 cfg->val[i] = uc->value.enumerated.item[i];
852 change |= (uc->value.integer.value[i] != cfg->val[i]);
853 cfg->val[i] = uc->value.integer.value[i];
863 static int __rsnd_kctrl_new(struct rsnd_mod *mod,
864 struct snd_soc_pcm_runtime *rtd,
865 const unsigned char *name,
866 struct rsnd_kctrl_cfg *cfg,
867 void (*update)(struct rsnd_mod *mod))
869 struct snd_soc_card *soc_card = rtd->card;
870 struct snd_card *card = rtd->card->snd_card;
871 struct snd_kcontrol *kctrl;
872 struct snd_kcontrol_new knew = {
873 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
875 .info = rsnd_kctrl_info,
876 .index = rtd - soc_card->rtd,
877 .get = rsnd_kctrl_get,
878 .put = rsnd_kctrl_put,
879 .private_value = (unsigned long)cfg,
883 kctrl = snd_ctl_new1(&knew, mod);
887 ret = snd_ctl_add(card, kctrl);
889 snd_ctl_free_one(kctrl);
893 cfg->update = update;
900 void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg)
902 snd_ctl_remove(cfg->card, cfg->kctrl);
905 int rsnd_kctrl_new_m(struct rsnd_mod *mod,
906 struct snd_soc_pcm_runtime *rtd,
907 const unsigned char *name,
908 void (*update)(struct rsnd_mod *mod),
909 struct rsnd_kctrl_cfg_m *_cfg,
913 _cfg->cfg.size = RSND_DVC_CHANNELS;
914 _cfg->cfg.val = _cfg->val;
915 return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update);
918 int rsnd_kctrl_new_s(struct rsnd_mod *mod,
919 struct snd_soc_pcm_runtime *rtd,
920 const unsigned char *name,
921 void (*update)(struct rsnd_mod *mod),
922 struct rsnd_kctrl_cfg_s *_cfg,
927 _cfg->cfg.val = &_cfg->val;
928 return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update);
931 int rsnd_kctrl_new_e(struct rsnd_mod *mod,
932 struct snd_soc_pcm_runtime *rtd,
933 const unsigned char *name,
934 struct rsnd_kctrl_cfg_s *_cfg,
935 void (*update)(struct rsnd_mod *mod),
936 const char * const *texts,
941 _cfg->cfg.val = &_cfg->val;
942 _cfg->cfg.texts = texts;
943 return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update);
950 #define PREALLOC_BUFFER (32 * 1024)
951 #define PREALLOC_BUFFER_MAX (32 * 1024)
953 static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
955 struct snd_soc_dai *dai = rtd->cpu_dai;
956 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
959 ret = rsnd_dai_call(pcm_new, &rdai->playback, rtd);
963 ret = rsnd_dai_call(pcm_new, &rdai->capture, rtd);
967 return snd_pcm_lib_preallocate_pages_for_all(
970 rtd->card->snd_card->dev,
971 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
974 static struct snd_soc_platform_driver rsnd_soc_platform = {
975 .ops = &rsnd_pcm_ops,
976 .pcm_new = rsnd_pcm_new,
979 static const struct snd_soc_component_driver rsnd_soc_component = {
983 static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
984 struct rsnd_dai_stream *io)
988 ret = rsnd_dai_call(probe, io, priv);
989 if (ret == -EAGAIN) {
991 * Fallback to PIO mode
995 * call "remove" for SSI/SRC/DVC
996 * SSI will be switch to PIO mode if it was DMA mode
999 * rsnd_ssi_fallback()
1001 rsnd_dai_call(remove, io, priv);
1004 * remove SRC/DVC from DAI,
1006 rsnd_path_break(priv, io, src);
1007 rsnd_path_break(priv, io, dvc);
1012 rsnd_dai_call(fallback, io, priv);
1016 * DAI has SSI which is PIO mode only now.
1018 ret = rsnd_dai_call(probe, io, priv);
1027 static int rsnd_probe(struct platform_device *pdev)
1029 struct rcar_snd_info *info;
1030 struct rsnd_priv *priv;
1031 struct device *dev = &pdev->dev;
1032 struct rsnd_dai *rdai;
1033 const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
1034 const struct rsnd_of_data *of_data;
1035 int (*probe_func[])(struct platform_device *pdev,
1036 const struct rsnd_of_data *of_data,
1037 struct rsnd_priv *priv) = {
1051 info = devm_kzalloc(&pdev->dev,
1052 sizeof(struct rcar_snd_info), GFP_KERNEL);
1053 of_data = of_id->data;
1055 info = pdev->dev.platform_data;
1059 dev_err(dev, "driver needs R-Car sound information\n");
1066 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1068 dev_err(dev, "priv allocate failed\n");
1074 spin_lock_init(&priv->lock);
1079 for (i = 0; i < ARRAY_SIZE(probe_func); i++) {
1080 ret = probe_func[i](pdev, of_data, priv);
1085 for_each_rsnd_dai(rdai, priv, i) {
1086 ret = rsnd_rdai_continuance_probe(priv, &rdai->playback);
1088 goto exit_snd_probe;
1090 ret = rsnd_rdai_continuance_probe(priv, &rdai->capture);
1092 goto exit_snd_probe;
1095 dev_set_drvdata(dev, priv);
1100 ret = snd_soc_register_platform(dev, &rsnd_soc_platform);
1102 dev_err(dev, "cannot snd soc register\n");
1106 ret = snd_soc_register_component(dev, &rsnd_soc_component,
1107 priv->daidrv, rsnd_rdai_nr(priv));
1109 dev_err(dev, "cannot snd dai register\n");
1113 pm_runtime_enable(dev);
1115 dev_info(dev, "probed\n");
1119 snd_soc_unregister_platform(dev);
1121 for_each_rsnd_dai(rdai, priv, i) {
1122 rsnd_dai_call(remove, &rdai->playback, priv);
1123 rsnd_dai_call(remove, &rdai->capture, priv);
1129 static int rsnd_remove(struct platform_device *pdev)
1131 struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
1132 struct rsnd_dai *rdai;
1133 void (*remove_func[])(struct platform_device *pdev,
1134 struct rsnd_priv *priv) = {
1141 pm_runtime_disable(&pdev->dev);
1143 for_each_rsnd_dai(rdai, priv, i) {
1144 ret |= rsnd_dai_call(remove, &rdai->playback, priv);
1145 ret |= rsnd_dai_call(remove, &rdai->capture, priv);
1148 for (i = 0; i < ARRAY_SIZE(remove_func); i++)
1149 remove_func[i](pdev, priv);
1151 snd_soc_unregister_component(&pdev->dev);
1152 snd_soc_unregister_platform(&pdev->dev);
1157 static struct platform_driver rsnd_driver = {
1159 .name = "rcar_sound",
1160 .of_match_table = rsnd_of_match,
1162 .probe = rsnd_probe,
1163 .remove = rsnd_remove,
1165 module_platform_driver(rsnd_driver);
1167 MODULE_LICENSE("GPL");
1168 MODULE_DESCRIPTION("Renesas R-Car audio driver");
1169 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
1170 MODULE_ALIAS("platform:rcar-pcm-audio");