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>
97 #include <linux/shdma-base.h>
100 #define RSND_RATES SNDRV_PCM_RATE_8000_96000
101 #define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
103 static struct rsnd_of_data rsnd_of_data_gen1 = {
107 static struct rsnd_of_data rsnd_of_data_gen2 = {
111 static struct of_device_id rsnd_of_match[] = {
112 { .compatible = "renesas,rcar_sound-gen1", .data = &rsnd_of_data_gen1 },
113 { .compatible = "renesas,rcar_sound-gen2", .data = &rsnd_of_data_gen2 },
116 MODULE_DEVICE_TABLE(of, rsnd_of_match);
119 * rsnd_platform functions
121 #define rsnd_platform_call(priv, dai, func, param...) \
122 (!(priv->info->func) ? 0 : \
123 priv->info->func(param))
125 #define rsnd_is_enable_path(io, name) \
126 ((io)->info ? (io)->info->name : NULL)
127 #define rsnd_info_id(priv, io, name) \
128 ((io)->info->name - priv->info->name##_info)
133 char *rsnd_mod_name(struct rsnd_mod *mod)
135 if (!mod || !mod->ops)
138 return mod->ops->name;
141 void rsnd_mod_init(struct rsnd_priv *priv,
142 struct rsnd_mod *mod,
143 struct rsnd_mod_ops *ops,
144 enum rsnd_mod_type type,
156 static void __rsnd_dma_start(struct rsnd_dma *dma);
157 static void rsnd_dma_continue(struct rsnd_dma *dma)
159 /* push next A or B plane */
160 dma->submit_loop = 1;
161 schedule_work(&dma->work);
164 void rsnd_dma_start(struct rsnd_dma *dma)
166 /* push both A and B plane*/
168 dma->submit_loop = 2;
169 __rsnd_dma_start(dma);
172 void rsnd_dma_stop(struct rsnd_dma *dma)
174 dma->submit_loop = 0;
175 cancel_work_sync(&dma->work);
176 dmaengine_terminate_all(dma->chan);
179 static void rsnd_dma_complete(void *data)
181 struct rsnd_dma *dma = (struct rsnd_dma *)data;
182 struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
183 struct rsnd_priv *priv = rsnd_mod_to_priv(rsnd_dma_to_mod(dma));
184 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
187 rsnd_lock(priv, flags);
190 * Renesas sound Gen1 needs 1 DMAC,
192 * In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri.
193 * But, Audio-DMAC-peri-peri doesn't have interrupt,
194 * and this driver is assuming that here.
196 * If Audio-DMAC-peri-peri has interrpt,
197 * rsnd_dai_pointer_update() will be called twice,
198 * ant it will breaks io->byte_pos
200 if (dma->submit_loop)
201 rsnd_dma_continue(dma);
203 rsnd_unlock(priv, flags);
205 rsnd_dai_pointer_update(io, io->byte_per_period);
208 static void __rsnd_dma_start(struct rsnd_dma *dma)
210 struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
211 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
212 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
213 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
214 struct device *dev = rsnd_priv_to_dev(priv);
215 struct dma_async_tx_descriptor *desc;
217 size_t len = io->byte_per_period;
220 for (i = 0; i < dma->submit_loop; i++) {
222 buf = runtime->dma_addr +
223 rsnd_dai_pointer_offset(io, dma->offset + len);
226 desc = dmaengine_prep_slave_single(
227 dma->chan, buf, len, dma->dir,
228 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
230 dev_err(dev, "dmaengine_prep_slave_sg() fail\n");
234 desc->callback = rsnd_dma_complete;
235 desc->callback_param = dma;
237 if (dmaengine_submit(desc) < 0) {
238 dev_err(dev, "dmaengine_submit() fail\n");
242 dma_async_issue_pending(dma->chan);
246 static void rsnd_dma_do_work(struct work_struct *work)
248 struct rsnd_dma *dma = container_of(work, struct rsnd_dma, work);
250 __rsnd_dma_start(dma);
253 int rsnd_dma_available(struct rsnd_dma *dma)
258 #define DMA_NAME_SIZE 16
259 #define MOD_MAX 4 /* MEM/SSI/SRC/DVC */
260 static int _rsnd_dma_of_name(char *dma_name, struct rsnd_mod *mod)
263 return snprintf(dma_name, DMA_NAME_SIZE / 2, "%s%d",
264 rsnd_mod_name(mod), rsnd_mod_id(mod));
266 return snprintf(dma_name, DMA_NAME_SIZE / 2, "mem");
270 static void rsnd_dma_of_name(struct rsnd_dma *dma,
271 int is_play, char *dma_name)
273 struct rsnd_mod *this = rsnd_dma_to_mod(dma);
274 struct rsnd_dai_stream *io = rsnd_mod_to_io(this);
275 struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
276 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
277 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
278 struct rsnd_mod *mod[MOD_MAX];
279 struct rsnd_mod *src_mod, *dst_mod;
283 for (i = 0; i < MOD_MAX; i++)
293 * mem -> SRC -> DVC -> SSI
295 mod[0] = NULL; /* for "mem" */
297 for (i = 1; i < MOD_MAX; i++) {
314 src_mod = mod[index - 1];
315 dst_mod = mod[index];
317 src_mod = mod[index];
318 dst_mod = mod[index + 1];
322 index = _rsnd_dma_of_name(dma_name + index, src_mod);
323 *(dma_name + index++) = '_';
324 index = _rsnd_dma_of_name(dma_name + index, dst_mod);
327 int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
330 struct device *dev = rsnd_priv_to_dev(priv);
331 struct dma_slave_config cfg;
332 char dma_name[DMA_NAME_SIZE];
337 dev_err(dev, "it already has dma channel\n");
342 dma_cap_set(DMA_SLAVE, mask);
345 rsnd_dma_of_name(dma, is_play, dma_name);
347 snprintf(dma_name, DMA_NAME_SIZE,
348 is_play ? "tx" : "rx");
350 dev_dbg(dev, "dma name : %s\n", dma_name);
352 dma->chan = dma_request_slave_channel_compat(mask, shdma_chan_filter,
356 dev_err(dev, "can't get dma channel\n");
361 cfg.dst_addr = 0; /* use default addr when playback */
362 cfg.src_addr = 0; /* use default addr when capture */
363 cfg.direction = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
365 ret = dmaengine_slave_config(dma->chan, &cfg);
367 goto rsnd_dma_init_err;
369 dma->dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
370 INIT_WORK(&dma->work, rsnd_dma_do_work);
375 rsnd_dma_quit(priv, dma);
380 void rsnd_dma_quit(struct rsnd_priv *priv,
381 struct rsnd_dma *dma)
384 dma_release_channel(dma->chan);
392 u32 rsnd_get_adinr(struct rsnd_mod *mod)
394 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
395 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
396 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
397 struct device *dev = rsnd_priv_to_dev(priv);
398 u32 adinr = runtime->channels;
400 switch (runtime->sample_bits) {
408 dev_warn(dev, "not supported sample bits\n");
418 #define __rsnd_mod_call(mod, func, rdai...) \
420 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
421 struct device *dev = rsnd_priv_to_dev(priv); \
422 dev_dbg(dev, "%s [%d] %s\n", \
423 rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \
424 (mod)->ops->func(mod, rdai); \
427 #define rsnd_mod_call(mod, func, rdai...) \
428 (!(mod) ? -ENODEV : \
429 !((mod)->ops->func) ? 0 : \
430 __rsnd_mod_call(mod, func, rdai))
432 #define rsnd_dai_call(fn, io, rdai...) \
434 struct rsnd_mod *mod; \
436 for (i = 0; i < RSND_MOD_MAX; i++) { \
437 mod = (io)->mod[i]; \
440 ret = rsnd_mod_call(mod, fn, rdai); \
447 static int rsnd_dai_connect(struct rsnd_mod *mod,
448 struct rsnd_dai_stream *io)
453 if (io->mod[mod->type]) {
454 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
455 struct device *dev = rsnd_priv_to_dev(priv);
457 dev_err(dev, "%s%d is not empty\n",
463 io->mod[mod->type] = mod;
469 int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
471 int id = rdai - priv->rdai;
473 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
479 struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id)
481 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
484 return priv->rdai + id;
487 static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
489 struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
491 return rsnd_dai_get(priv, dai->id);
494 int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io)
496 return &rdai->playback == io;
500 * rsnd_soc_dai functions
502 int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
504 struct snd_pcm_substream *substream = io->substream;
505 struct snd_pcm_runtime *runtime = substream->runtime;
506 int pos = io->byte_pos + additional;
508 pos %= (runtime->periods * io->byte_per_period);
513 void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
515 io->byte_pos += byte;
517 if (io->byte_pos >= io->next_period_byte) {
518 struct snd_pcm_substream *substream = io->substream;
519 struct snd_pcm_runtime *runtime = substream->runtime;
522 io->next_period_byte += io->byte_per_period;
524 if (io->period_pos >= runtime->periods) {
527 io->next_period_byte = io->byte_per_period;
530 snd_pcm_period_elapsed(substream);
534 static int rsnd_dai_stream_init(struct rsnd_dai_stream *io,
535 struct snd_pcm_substream *substream)
537 struct snd_pcm_runtime *runtime = substream->runtime;
539 io->substream = substream;
542 io->byte_per_period = runtime->period_size *
544 samples_to_bytes(runtime, 1);
545 io->next_period_byte = io->byte_per_period;
551 struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
553 struct snd_soc_pcm_runtime *rtd = substream->private_data;
559 struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
560 struct snd_pcm_substream *substream)
562 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
563 return &rdai->playback;
565 return &rdai->capture;
568 static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
569 struct snd_soc_dai *dai)
571 struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
572 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
573 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
574 int ssi_id = rsnd_mod_id(rsnd_io_to_mod_ssi(io));
578 rsnd_lock(priv, flags);
581 case SNDRV_PCM_TRIGGER_START:
582 ret = rsnd_dai_stream_init(io, substream);
584 goto dai_trigger_end;
586 ret = rsnd_platform_call(priv, dai, start, ssi_id);
588 goto dai_trigger_end;
590 ret = rsnd_dai_call(init, io, rdai);
592 goto dai_trigger_end;
594 ret = rsnd_dai_call(start, io, rdai);
596 goto dai_trigger_end;
598 case SNDRV_PCM_TRIGGER_STOP:
599 ret = rsnd_dai_call(stop, io, rdai);
601 goto dai_trigger_end;
603 ret = rsnd_dai_call(quit, io, rdai);
605 goto dai_trigger_end;
607 ret = rsnd_platform_call(priv, dai, stop, ssi_id);
609 goto dai_trigger_end;
616 rsnd_unlock(priv, flags);
621 static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
623 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
625 /* set master/slave audio interface */
626 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
627 case SND_SOC_DAIFMT_CBM_CFM:
628 rdai->clk_master = 0;
630 case SND_SOC_DAIFMT_CBS_CFS:
631 rdai->clk_master = 1; /* codec is slave, cpu is master */
637 /* set clock inversion */
638 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
639 case SND_SOC_DAIFMT_NB_IF:
640 rdai->bit_clk_inv = 0;
641 rdai->frm_clk_inv = 1;
643 case SND_SOC_DAIFMT_IB_NF:
644 rdai->bit_clk_inv = 1;
645 rdai->frm_clk_inv = 0;
647 case SND_SOC_DAIFMT_IB_IF:
648 rdai->bit_clk_inv = 1;
649 rdai->frm_clk_inv = 1;
651 case SND_SOC_DAIFMT_NB_NF:
653 rdai->bit_clk_inv = 0;
654 rdai->frm_clk_inv = 0;
659 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
660 case SND_SOC_DAIFMT_I2S:
662 rdai->data_alignment = 0;
664 case SND_SOC_DAIFMT_LEFT_J:
666 rdai->data_alignment = 0;
668 case SND_SOC_DAIFMT_RIGHT_J:
670 rdai->data_alignment = 1;
677 static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
678 .trigger = rsnd_soc_dai_trigger,
679 .set_fmt = rsnd_soc_dai_set_fmt,
682 #define rsnd_path_parse(priv, io, type) \
684 struct rsnd_mod *mod; \
688 if (rsnd_is_enable_path(io, type)) { \
689 id = rsnd_info_id(priv, io, type); \
691 mod = rsnd_##type##_mod_get(priv, id); \
692 ret = rsnd_dai_connect(mod, io); \
698 static int rsnd_path_init(struct rsnd_priv *priv,
699 struct rsnd_dai *rdai,
700 struct rsnd_dai_stream *io)
705 * Gen1 is created by SRU/SSI, and this SRU is base module of
706 * Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU)
709 * Gen1 SRU = Gen2 SCU + SSIU + etc
711 * Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is
716 ret = rsnd_path_parse(priv, io, src);
721 ret = rsnd_path_parse(priv, io, ssi);
726 ret = rsnd_path_parse(priv, io, dvc);
733 static void rsnd_of_parse_dai(struct platform_device *pdev,
734 const struct rsnd_of_data *of_data,
735 struct rsnd_priv *priv)
737 struct device_node *dai_node, *dai_np;
738 struct device_node *ssi_node, *ssi_np;
739 struct device_node *src_node, *src_np;
740 struct device_node *playback, *capture;
741 struct rsnd_dai_platform_info *dai_info;
742 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
743 struct device *dev = &pdev->dev;
745 int dai_i, ssi_i, src_i;
750 dai_node = of_get_child_by_name(dev->of_node, "rcar_sound,dai");
754 nr = of_get_child_count(dai_node);
758 dai_info = devm_kzalloc(dev,
759 sizeof(struct rsnd_dai_platform_info) * nr,
762 dev_err(dev, "dai info allocation error\n");
766 info->dai_info_nr = nr;
767 info->dai_info = dai_info;
769 ssi_node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi");
770 src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
772 #define mod_parse(name) \
774 struct rsnd_##name##_platform_info *name##_info; \
777 for_each_child_of_node(name##_node, name##_np) { \
778 name##_info = info->name##_info + name##_i; \
780 if (name##_np == playback) \
781 dai_info->playback.name = name##_info; \
782 if (name##_np == capture) \
783 dai_info->capture.name = name##_info; \
793 for_each_child_of_node(dai_node, dai_np) {
794 dai_info = info->dai_info + dai_i;
798 playback = of_parse_phandle(dai_np, "playback", i);
799 capture = of_parse_phandle(dai_np, "capture", i);
801 if (!playback && !capture)
808 of_node_put(playback);
810 of_node_put(capture);
817 static int rsnd_dai_probe(struct platform_device *pdev,
818 const struct rsnd_of_data *of_data,
819 struct rsnd_priv *priv)
821 struct snd_soc_dai_driver *drv;
822 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
823 struct rsnd_dai *rdai;
824 struct rsnd_ssi_platform_info *pmod, *cmod;
825 struct device *dev = rsnd_priv_to_dev(priv);
829 rsnd_of_parse_dai(pdev, of_data, priv);
831 dai_nr = info->dai_info_nr;
833 dev_err(dev, "no dai\n");
837 drv = devm_kzalloc(dev, sizeof(*drv) * dai_nr, GFP_KERNEL);
838 rdai = devm_kzalloc(dev, sizeof(*rdai) * dai_nr, GFP_KERNEL);
840 dev_err(dev, "dai allocate failed\n");
844 priv->rdai_nr = dai_nr;
848 for (i = 0; i < dai_nr; i++) {
849 rdai[i].info = &info->dai_info[i];
851 pmod = rdai[i].info->playback.ssi;
852 cmod = rdai[i].info->capture.ssi;
857 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
860 * init snd_soc_dai_driver
862 drv[i].name = rdai[i].name;
863 drv[i].ops = &rsnd_soc_dai_ops;
865 drv[i].playback.rates = RSND_RATES;
866 drv[i].playback.formats = RSND_FMTS;
867 drv[i].playback.channels_min = 2;
868 drv[i].playback.channels_max = 2;
870 rdai[i].playback.info = &info->dai_info[i].playback;
871 rsnd_path_init(priv, &rdai[i], &rdai[i].playback);
874 drv[i].capture.rates = RSND_RATES;
875 drv[i].capture.formats = RSND_FMTS;
876 drv[i].capture.channels_min = 2;
877 drv[i].capture.channels_max = 2;
879 rdai[i].capture.info = &info->dai_info[i].capture;
880 rsnd_path_init(priv, &rdai[i], &rdai[i].capture);
883 dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name,
884 pmod ? "play" : " -- ",
885 cmod ? "capture" : " -- ");
894 static struct snd_pcm_hardware rsnd_pcm_hardware = {
895 .info = SNDRV_PCM_INFO_INTERLEAVED |
896 SNDRV_PCM_INFO_MMAP |
897 SNDRV_PCM_INFO_MMAP_VALID |
898 SNDRV_PCM_INFO_PAUSE,
899 .buffer_bytes_max = 64 * 1024,
900 .period_bytes_min = 32,
901 .period_bytes_max = 8192,
907 static int rsnd_pcm_open(struct snd_pcm_substream *substream)
909 struct snd_pcm_runtime *runtime = substream->runtime;
912 snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
914 ret = snd_pcm_hw_constraint_integer(runtime,
915 SNDRV_PCM_HW_PARAM_PERIODS);
920 static int rsnd_hw_params(struct snd_pcm_substream *substream,
921 struct snd_pcm_hw_params *hw_params)
923 return snd_pcm_lib_malloc_pages(substream,
924 params_buffer_bytes(hw_params));
927 static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
929 struct snd_pcm_runtime *runtime = substream->runtime;
930 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
931 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
932 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
934 return bytes_to_frames(runtime, io->byte_pos);
937 static struct snd_pcm_ops rsnd_pcm_ops = {
938 .open = rsnd_pcm_open,
939 .ioctl = snd_pcm_lib_ioctl,
940 .hw_params = rsnd_hw_params,
941 .hw_free = snd_pcm_lib_free_pages,
942 .pointer = rsnd_pointer,
949 #define PREALLOC_BUFFER (32 * 1024)
950 #define PREALLOC_BUFFER_MAX (32 * 1024)
952 static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
954 struct rsnd_priv *priv = snd_soc_dai_get_drvdata(rtd->cpu_dai);
955 struct rsnd_dai *rdai;
958 for_each_rsnd_dai(rdai, priv, i) {
959 ret = rsnd_dai_call(pcm_new, &rdai->playback, rdai, rtd);
963 ret = rsnd_dai_call(pcm_new, &rdai->capture, rdai, rtd);
968 return snd_pcm_lib_preallocate_pages_for_all(
971 rtd->card->snd_card->dev,
972 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
975 static void rsnd_pcm_free(struct snd_pcm *pcm)
977 snd_pcm_lib_preallocate_free_for_all(pcm);
980 static struct snd_soc_platform_driver rsnd_soc_platform = {
981 .ops = &rsnd_pcm_ops,
982 .pcm_new = rsnd_pcm_new,
983 .pcm_free = rsnd_pcm_free,
986 static const struct snd_soc_component_driver rsnd_soc_component = {
993 static int rsnd_probe(struct platform_device *pdev)
995 struct rcar_snd_info *info;
996 struct rsnd_priv *priv;
997 struct device *dev = &pdev->dev;
998 struct rsnd_dai *rdai;
999 const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
1000 const struct rsnd_of_data *of_data;
1001 int (*probe_func[])(struct platform_device *pdev,
1002 const struct rsnd_of_data *of_data,
1003 struct rsnd_priv *priv) = {
1016 info = devm_kzalloc(&pdev->dev,
1017 sizeof(struct rcar_snd_info), GFP_KERNEL);
1018 of_data = of_id->data;
1020 info = pdev->dev.platform_data;
1024 dev_err(dev, "driver needs R-Car sound information\n");
1031 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1033 dev_err(dev, "priv allocate failed\n");
1039 spin_lock_init(&priv->lock);
1044 for (i = 0; i < ARRAY_SIZE(probe_func); i++) {
1045 ret = probe_func[i](pdev, of_data, priv);
1050 for_each_rsnd_dai(rdai, priv, i) {
1051 ret = rsnd_dai_call(probe, &rdai->playback, rdai);
1055 ret = rsnd_dai_call(probe, &rdai->capture, rdai);
1063 ret = snd_soc_register_platform(dev, &rsnd_soc_platform);
1065 dev_err(dev, "cannot snd soc register\n");
1069 ret = snd_soc_register_component(dev, &rsnd_soc_component,
1070 priv->daidrv, rsnd_rdai_nr(priv));
1072 dev_err(dev, "cannot snd dai register\n");
1076 dev_set_drvdata(dev, priv);
1078 pm_runtime_enable(dev);
1080 dev_info(dev, "probed\n");
1084 snd_soc_unregister_platform(dev);
1089 static int rsnd_remove(struct platform_device *pdev)
1091 struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
1092 struct rsnd_dai *rdai;
1095 pm_runtime_disable(&pdev->dev);
1097 for_each_rsnd_dai(rdai, priv, i) {
1098 ret = rsnd_dai_call(remove, &rdai->playback, rdai);
1102 ret = rsnd_dai_call(remove, &rdai->capture, rdai);
1110 static struct platform_driver rsnd_driver = {
1112 .name = "rcar_sound",
1113 .of_match_table = rsnd_of_match,
1115 .probe = rsnd_probe,
1116 .remove = rsnd_remove,
1118 module_platform_driver(rsnd_driver);
1120 MODULE_LICENSE("GPL");
1121 MODULE_DESCRIPTION("Renesas R-Car audio driver");
1122 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
1123 MODULE_ALIAS("platform:rcar-pcm-audio");