ASoC: rsnd: remove duplicate *priv from rsnd_dma
[linux-2.6-microblaze.git] / sound / soc / sh / rcar / core.c
1 /*
2  * Renesas R-Car SRU/SCU/SSIU/SSI support
3  *
4  * Copyright (C) 2013 Renesas Solutions Corp.
5  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6  *
7  * Based on fsi.c
8  * Kuninori Morimoto <morimoto.kuninori@renesas.com>
9  *
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.
13  */
14
15 /*
16  * Renesas R-Car sound device structure
17  *
18  * Gen1
19  *
20  * SRU          : Sound Routing Unit
21  *  - SRC       : Sampling Rate Converter
22  *  - CMD
23  *    - CTU     : Channel Count Conversion Unit
24  *    - MIX     : Mixer
25  *    - DVC     : Digital Volume and Mute Function
26  *  - SSI       : Serial Sound Interface
27  *
28  * Gen2
29  *
30  * SCU          : Sampling Rate Converter Unit
31  *  - SRC       : Sampling Rate Converter
32  *  - CMD
33  *   - CTU      : Channel Count Conversion Unit
34  *   - MIX      : Mixer
35  *   - DVC      : Digital Volume and Mute Function
36  * SSIU         : Serial Sound Interface Unit
37  *  - SSI       : Serial Sound Interface
38  */
39
40 /*
41  *      driver data Image
42  *
43  * rsnd_priv
44  *   |
45  *   | ** this depends on Gen1/Gen2
46  *   |
47  *   +- gen
48  *   |
49  *   | ** these depend on data path
50  *   | ** gen and platform data control it
51  *   |
52  *   +- rdai[0]
53  *   |   |               sru     ssiu      ssi
54  *   |   +- playback -> [mod] -> [mod] -> [mod] -> ...
55  *   |   |
56  *   |   |               sru     ssiu      ssi
57  *   |   +- capture  -> [mod] -> [mod] -> [mod] -> ...
58  *   |
59  *   +- rdai[1]
60  *   |   |               sru     ssiu      ssi
61  *   |   +- playback -> [mod] -> [mod] -> [mod] -> ...
62  *   |   |
63  *   |   |               sru     ssiu      ssi
64  *   |   +- capture  -> [mod] -> [mod] -> [mod] -> ...
65  *   ...
66  *   |
67  *   | ** these control ssi
68  *   |
69  *   +- ssi
70  *   |  |
71  *   |  +- ssi[0]
72  *   |  +- ssi[1]
73  *   |  +- ssi[2]
74  *   |  ...
75  *   |
76  *   | ** these control scu
77  *   |
78  *   +- scu
79  *      |
80  *      +- scu[0]
81  *      +- scu[1]
82  *      +- scu[2]
83  *      ...
84  *
85  *
86  * for_each_rsnd_dai(xx, priv, xx)
87  *  rdai[0] => rdai[1] => rdai[2] => ...
88  *
89  * for_each_rsnd_mod(xx, rdai, xx)
90  *  [mod] => [mod] => [mod] => ...
91  *
92  * rsnd_dai_call(xxx, fn )
93  *  [mod]->fn() -> [mod]->fn() -> [mod]->fn()...
94  *
95  */
96 #include <linux/pm_runtime.h>
97 #include <linux/shdma-base.h>
98 #include "rsnd.h"
99
100 #define RSND_RATES SNDRV_PCM_RATE_8000_96000
101 #define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
102
103 /*
104  *      rsnd_platform functions
105  */
106 #define rsnd_platform_call(priv, dai, func, param...)   \
107         (!(priv->info->func) ? 0 :              \
108          priv->info->func(param))
109
110 /*
111  *      rsnd_mod functions
112  */
113 char *rsnd_mod_name(struct rsnd_mod *mod)
114 {
115         if (!mod || !mod->ops)
116                 return "unknown";
117
118         return mod->ops->name;
119 }
120
121 void rsnd_mod_init(struct rsnd_priv *priv,
122                    struct rsnd_mod *mod,
123                    struct rsnd_mod_ops *ops,
124                    int id)
125 {
126         mod->priv       = priv;
127         mod->id         = id;
128         mod->ops        = ops;
129         INIT_LIST_HEAD(&mod->list);
130 }
131
132 /*
133  *      rsnd_dma functions
134  */
135 static void rsnd_dma_continue(struct rsnd_dma *dma)
136 {
137         /* push next A or B plane */
138         dma->submit_loop = 1;
139         schedule_work(&dma->work);
140 }
141
142 void rsnd_dma_start(struct rsnd_dma *dma)
143 {
144         /* push both A and B plane*/
145         dma->submit_loop = 2;
146         schedule_work(&dma->work);
147 }
148
149 void rsnd_dma_stop(struct rsnd_dma *dma)
150 {
151         dma->submit_loop = 0;
152         cancel_work_sync(&dma->work);
153         dmaengine_terminate_all(dma->chan);
154 }
155
156 static void rsnd_dma_complete(void *data)
157 {
158         struct rsnd_dma *dma = (struct rsnd_dma *)data;
159         struct rsnd_priv *priv = rsnd_mod_to_priv(rsnd_dma_to_mod(dma));
160         unsigned long flags;
161
162         rsnd_lock(priv, flags);
163
164         dma->complete(dma);
165
166         if (dma->submit_loop)
167                 rsnd_dma_continue(dma);
168
169         rsnd_unlock(priv, flags);
170 }
171
172 static void rsnd_dma_do_work(struct work_struct *work)
173 {
174         struct rsnd_dma *dma = container_of(work, struct rsnd_dma, work);
175         struct rsnd_priv *priv = rsnd_mod_to_priv(rsnd_dma_to_mod(dma));
176         struct device *dev = rsnd_priv_to_dev(priv);
177         struct dma_async_tx_descriptor *desc;
178         dma_addr_t buf;
179         size_t len;
180         int i;
181
182         for (i = 0; i < dma->submit_loop; i++) {
183
184                 if (dma->inquiry(dma, &buf, &len) < 0)
185                         return;
186
187                 desc = dmaengine_prep_slave_single(
188                         dma->chan, buf, len, dma->dir,
189                         DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
190                 if (!desc) {
191                         dev_err(dev, "dmaengine_prep_slave_sg() fail\n");
192                         return;
193                 }
194
195                 desc->callback          = rsnd_dma_complete;
196                 desc->callback_param    = dma;
197
198                 if (dmaengine_submit(desc) < 0) {
199                         dev_err(dev, "dmaengine_submit() fail\n");
200                         return;
201                 }
202
203                 dma_async_issue_pending(dma->chan);
204         }
205 }
206
207 int rsnd_dma_available(struct rsnd_dma *dma)
208 {
209         return !!dma->chan;
210 }
211
212 int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
213                   int is_play, int id,
214                   int (*inquiry)(struct rsnd_dma *dma,
215                                   dma_addr_t *buf, int *len),
216                   int (*complete)(struct rsnd_dma *dma))
217 {
218         struct device *dev = rsnd_priv_to_dev(priv);
219         struct dma_slave_config cfg;
220         dma_cap_mask_t mask;
221         int ret;
222
223         if (dma->chan) {
224                 dev_err(dev, "it already has dma channel\n");
225                 return -EIO;
226         }
227
228         dma_cap_zero(mask);
229         dma_cap_set(DMA_SLAVE, mask);
230
231         dma->chan = dma_request_slave_channel_compat(mask, shdma_chan_filter,
232                                                      (void *)id, dev,
233                                                      is_play ? "tx" : "rx");
234         if (!dma->chan) {
235                 dev_err(dev, "can't get dma channel\n");
236                 return -EIO;
237         }
238
239         cfg.slave_id    = id;
240         cfg.dst_addr    = 0; /* use default addr when playback */
241         cfg.src_addr    = 0; /* use default addr when capture */
242         cfg.direction   = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
243
244         ret = dmaengine_slave_config(dma->chan, &cfg);
245         if (ret < 0)
246                 goto rsnd_dma_init_err;
247
248         dma->dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
249         dma->inquiry = inquiry;
250         dma->complete = complete;
251         INIT_WORK(&dma->work, rsnd_dma_do_work);
252
253         return 0;
254
255 rsnd_dma_init_err:
256         rsnd_dma_quit(priv, dma);
257
258         return ret;
259 }
260
261 void  rsnd_dma_quit(struct rsnd_priv *priv,
262                     struct rsnd_dma *dma)
263 {
264         if (dma->chan)
265                 dma_release_channel(dma->chan);
266
267         dma->chan = NULL;
268 }
269
270 /*
271  *      rsnd_dai functions
272  */
273 #define rsnd_dai_call(rdai, io, fn)                     \
274 ({                                                      \
275         struct rsnd_mod *mod, *n;                       \
276         int ret = 0;                                    \
277         for_each_rsnd_mod(mod, n, io) {                 \
278                 ret = rsnd_mod_call(mod, fn, rdai, io); \
279                 if (ret < 0)                            \
280                         break;                          \
281         }                                               \
282         ret;                                            \
283 })
284
285 int rsnd_dai_connect(struct rsnd_dai *rdai,
286                      struct rsnd_mod *mod,
287                      struct rsnd_dai_stream *io)
288 {
289         if (!mod)
290                 return -EIO;
291
292         if (!list_empty(&mod->list)) {
293                 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
294                 struct device *dev = rsnd_priv_to_dev(priv);
295
296                 dev_err(dev, "%s%d is not empty\n",
297                         rsnd_mod_name(mod),
298                         rsnd_mod_id(mod));
299                 return -EIO;
300         }
301
302         list_add_tail(&mod->list, &io->head);
303
304         return 0;
305 }
306
307 int rsnd_dai_disconnect(struct rsnd_mod *mod)
308 {
309         list_del_init(&mod->list);
310
311         return 0;
312 }
313
314 int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
315 {
316         int id = rdai - priv->rdai;
317
318         if ((id < 0) || (id >= rsnd_dai_nr(priv)))
319                 return -EINVAL;
320
321         return id;
322 }
323
324 struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id)
325 {
326         if ((id < 0) || (id >= rsnd_dai_nr(priv)))
327                 return NULL;
328
329         return priv->rdai + id;
330 }
331
332 static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
333 {
334         struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
335
336         return rsnd_dai_get(priv, dai->id);
337 }
338
339 int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io)
340 {
341         return &rdai->playback == io;
342 }
343
344 /*
345  *      rsnd_soc_dai functions
346  */
347 int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
348 {
349         struct snd_pcm_substream *substream = io->substream;
350         struct snd_pcm_runtime *runtime = substream->runtime;
351         int pos = io->byte_pos + additional;
352
353         pos %= (runtime->periods * io->byte_per_period);
354
355         return pos;
356 }
357
358 void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
359 {
360         io->byte_pos += byte;
361
362         if (io->byte_pos >= io->next_period_byte) {
363                 struct snd_pcm_substream *substream = io->substream;
364                 struct snd_pcm_runtime *runtime = substream->runtime;
365
366                 io->period_pos++;
367                 io->next_period_byte += io->byte_per_period;
368
369                 if (io->period_pos >= runtime->periods) {
370                         io->byte_pos = 0;
371                         io->period_pos = 0;
372                         io->next_period_byte = io->byte_per_period;
373                 }
374
375                 snd_pcm_period_elapsed(substream);
376         }
377 }
378
379 static int rsnd_dai_stream_init(struct rsnd_dai_stream *io,
380                                 struct snd_pcm_substream *substream)
381 {
382         struct snd_pcm_runtime *runtime = substream->runtime;
383
384         if (!list_empty(&io->head))
385                 return -EIO;
386
387         INIT_LIST_HEAD(&io->head);
388         io->substream           = substream;
389         io->byte_pos            = 0;
390         io->period_pos          = 0;
391         io->byte_per_period     = runtime->period_size *
392                                   runtime->channels *
393                                   samples_to_bytes(runtime, 1);
394         io->next_period_byte    = io->byte_per_period;
395
396         return 0;
397 }
398
399 static
400 struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
401 {
402         struct snd_soc_pcm_runtime *rtd = substream->private_data;
403
404         return  rtd->cpu_dai;
405 }
406
407 static
408 struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
409                                         struct snd_pcm_substream *substream)
410 {
411         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
412                 return &rdai->playback;
413         else
414                 return &rdai->capture;
415 }
416
417 static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
418                             struct snd_soc_dai *dai)
419 {
420         struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
421         struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
422         struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
423         struct rsnd_mod *mod = rsnd_ssi_mod_get_frm_dai(priv,
424                                                 rsnd_dai_id(priv, rdai),
425                                                 rsnd_dai_is_play(rdai, io));
426         int ssi_id = rsnd_mod_id(mod);
427         int ret;
428         unsigned long flags;
429
430         rsnd_lock(priv, flags);
431
432         switch (cmd) {
433         case SNDRV_PCM_TRIGGER_START:
434                 ret = rsnd_dai_stream_init(io, substream);
435                 if (ret < 0)
436                         goto dai_trigger_end;
437
438                 ret = rsnd_platform_call(priv, dai, start, ssi_id);
439                 if (ret < 0)
440                         goto dai_trigger_end;
441
442                 ret = rsnd_gen_path_init(priv, rdai, io);
443                 if (ret < 0)
444                         goto dai_trigger_end;
445
446                 ret = rsnd_dai_call(rdai, io, init);
447                 if (ret < 0)
448                         goto dai_trigger_end;
449
450                 ret = rsnd_dai_call(rdai, io, start);
451                 if (ret < 0)
452                         goto dai_trigger_end;
453                 break;
454         case SNDRV_PCM_TRIGGER_STOP:
455                 ret = rsnd_dai_call(rdai, io, stop);
456                 if (ret < 0)
457                         goto dai_trigger_end;
458
459                 ret = rsnd_dai_call(rdai, io, quit);
460                 if (ret < 0)
461                         goto dai_trigger_end;
462
463                 ret = rsnd_gen_path_exit(priv, rdai, io);
464                 if (ret < 0)
465                         goto dai_trigger_end;
466
467                 ret = rsnd_platform_call(priv, dai, stop, ssi_id);
468                 if (ret < 0)
469                         goto dai_trigger_end;
470                 break;
471         default:
472                 ret = -EINVAL;
473         }
474
475 dai_trigger_end:
476         rsnd_unlock(priv, flags);
477
478         return ret;
479 }
480
481 static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
482 {
483         struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
484
485         /* set master/slave audio interface */
486         switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
487         case SND_SOC_DAIFMT_CBM_CFM:
488                 rdai->clk_master = 1;
489                 break;
490         case SND_SOC_DAIFMT_CBS_CFS:
491                 rdai->clk_master = 0;
492                 break;
493         default:
494                 return -EINVAL;
495         }
496
497         /* set clock inversion */
498         switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
499         case SND_SOC_DAIFMT_NB_IF:
500                 rdai->bit_clk_inv = 0;
501                 rdai->frm_clk_inv = 1;
502                 break;
503         case SND_SOC_DAIFMT_IB_NF:
504                 rdai->bit_clk_inv = 1;
505                 rdai->frm_clk_inv = 0;
506                 break;
507         case SND_SOC_DAIFMT_IB_IF:
508                 rdai->bit_clk_inv = 1;
509                 rdai->frm_clk_inv = 1;
510                 break;
511         case SND_SOC_DAIFMT_NB_NF:
512         default:
513                 rdai->bit_clk_inv = 0;
514                 rdai->frm_clk_inv = 0;
515                 break;
516         }
517
518         /* set format */
519         switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
520         case SND_SOC_DAIFMT_I2S:
521                 rdai->sys_delay = 0;
522                 rdai->data_alignment = 0;
523                 break;
524         case SND_SOC_DAIFMT_LEFT_J:
525                 rdai->sys_delay = 1;
526                 rdai->data_alignment = 0;
527                 break;
528         case SND_SOC_DAIFMT_RIGHT_J:
529                 rdai->sys_delay = 1;
530                 rdai->data_alignment = 1;
531                 break;
532         }
533
534         return 0;
535 }
536
537 static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
538         .trigger        = rsnd_soc_dai_trigger,
539         .set_fmt        = rsnd_soc_dai_set_fmt,
540 };
541
542 static int rsnd_dai_probe(struct platform_device *pdev,
543                           struct rcar_snd_info *info,
544                           struct rsnd_priv *priv)
545 {
546         struct snd_soc_dai_driver *drv;
547         struct rsnd_dai *rdai;
548         struct rsnd_mod *pmod, *cmod;
549         struct device *dev = rsnd_priv_to_dev(priv);
550         int dai_nr;
551         int i;
552
553         /* get max dai nr */
554         for (dai_nr = 0; dai_nr < 32; dai_nr++) {
555                 pmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 1);
556                 cmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 0);
557
558                 if (!pmod && !cmod)
559                         break;
560         }
561
562         if (!dai_nr) {
563                 dev_err(dev, "no dai\n");
564                 return -EIO;
565         }
566
567         drv  = devm_kzalloc(dev, sizeof(*drv)  * dai_nr, GFP_KERNEL);
568         rdai = devm_kzalloc(dev, sizeof(*rdai) * dai_nr, GFP_KERNEL);
569         if (!drv || !rdai) {
570                 dev_err(dev, "dai allocate failed\n");
571                 return -ENOMEM;
572         }
573
574         for (i = 0; i < dai_nr; i++) {
575
576                 pmod = rsnd_ssi_mod_get_frm_dai(priv, i, 1);
577                 cmod = rsnd_ssi_mod_get_frm_dai(priv, i, 0);
578
579                 /*
580                  *      init rsnd_dai
581                  */
582                 INIT_LIST_HEAD(&rdai[i].playback.head);
583                 INIT_LIST_HEAD(&rdai[i].capture.head);
584
585                 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
586
587                 /*
588                  *      init snd_soc_dai_driver
589                  */
590                 drv[i].name     = rdai[i].name;
591                 drv[i].ops      = &rsnd_soc_dai_ops;
592                 if (pmod) {
593                         drv[i].playback.rates           = RSND_RATES;
594                         drv[i].playback.formats         = RSND_FMTS;
595                         drv[i].playback.channels_min    = 2;
596                         drv[i].playback.channels_max    = 2;
597                 }
598                 if (cmod) {
599                         drv[i].capture.rates            = RSND_RATES;
600                         drv[i].capture.formats          = RSND_FMTS;
601                         drv[i].capture.channels_min     = 2;
602                         drv[i].capture.channels_max     = 2;
603                 }
604
605                 dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name,
606                         pmod ? "play"    : " -- ",
607                         cmod ? "capture" : "  --   ");
608         }
609
610         priv->dai_nr    = dai_nr;
611         priv->daidrv    = drv;
612         priv->rdai      = rdai;
613
614         return 0;
615 }
616
617 static void rsnd_dai_remove(struct platform_device *pdev,
618                           struct rsnd_priv *priv)
619 {
620 }
621
622 /*
623  *              pcm ops
624  */
625 static struct snd_pcm_hardware rsnd_pcm_hardware = {
626         .info =         SNDRV_PCM_INFO_INTERLEAVED      |
627                         SNDRV_PCM_INFO_MMAP             |
628                         SNDRV_PCM_INFO_MMAP_VALID       |
629                         SNDRV_PCM_INFO_PAUSE,
630         .buffer_bytes_max       = 64 * 1024,
631         .period_bytes_min       = 32,
632         .period_bytes_max       = 8192,
633         .periods_min            = 1,
634         .periods_max            = 32,
635         .fifo_size              = 256,
636 };
637
638 static int rsnd_pcm_open(struct snd_pcm_substream *substream)
639 {
640         struct snd_pcm_runtime *runtime = substream->runtime;
641         int ret = 0;
642
643         snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
644
645         ret = snd_pcm_hw_constraint_integer(runtime,
646                                             SNDRV_PCM_HW_PARAM_PERIODS);
647
648         return ret;
649 }
650
651 static int rsnd_hw_params(struct snd_pcm_substream *substream,
652                          struct snd_pcm_hw_params *hw_params)
653 {
654         return snd_pcm_lib_malloc_pages(substream,
655                                         params_buffer_bytes(hw_params));
656 }
657
658 static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
659 {
660         struct snd_pcm_runtime *runtime = substream->runtime;
661         struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
662         struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
663         struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
664
665         return bytes_to_frames(runtime, io->byte_pos);
666 }
667
668 static struct snd_pcm_ops rsnd_pcm_ops = {
669         .open           = rsnd_pcm_open,
670         .ioctl          = snd_pcm_lib_ioctl,
671         .hw_params      = rsnd_hw_params,
672         .hw_free        = snd_pcm_lib_free_pages,
673         .pointer        = rsnd_pointer,
674 };
675
676 /*
677  *              snd_soc_platform
678  */
679
680 #define PREALLOC_BUFFER         (32 * 1024)
681 #define PREALLOC_BUFFER_MAX     (32 * 1024)
682
683 static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
684 {
685         return snd_pcm_lib_preallocate_pages_for_all(
686                 rtd->pcm,
687                 SNDRV_DMA_TYPE_DEV,
688                 rtd->card->snd_card->dev,
689                 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
690 }
691
692 static void rsnd_pcm_free(struct snd_pcm *pcm)
693 {
694         snd_pcm_lib_preallocate_free_for_all(pcm);
695 }
696
697 static struct snd_soc_platform_driver rsnd_soc_platform = {
698         .ops            = &rsnd_pcm_ops,
699         .pcm_new        = rsnd_pcm_new,
700         .pcm_free       = rsnd_pcm_free,
701 };
702
703 static const struct snd_soc_component_driver rsnd_soc_component = {
704         .name           = "rsnd",
705 };
706
707 /*
708  *      rsnd probe
709  */
710 static int rsnd_probe(struct platform_device *pdev)
711 {
712         struct rcar_snd_info *info;
713         struct rsnd_priv *priv;
714         struct device *dev = &pdev->dev;
715         int ret;
716
717         info = pdev->dev.platform_data;
718         if (!info) {
719                 dev_err(dev, "driver needs R-Car sound information\n");
720                 return -ENODEV;
721         }
722
723         /*
724          *      init priv data
725          */
726         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
727         if (!priv) {
728                 dev_err(dev, "priv allocate failed\n");
729                 return -ENODEV;
730         }
731
732         priv->dev       = dev;
733         priv->info      = info;
734         spin_lock_init(&priv->lock);
735
736         /*
737          *      init each module
738          */
739         ret = rsnd_gen_probe(pdev, info, priv);
740         if (ret < 0)
741                 return ret;
742
743         ret = rsnd_scu_probe(pdev, info, priv);
744         if (ret < 0)
745                 return ret;
746
747         ret = rsnd_adg_probe(pdev, info, priv);
748         if (ret < 0)
749                 return ret;
750
751         ret = rsnd_ssi_probe(pdev, info, priv);
752         if (ret < 0)
753                 return ret;
754
755         ret = rsnd_dai_probe(pdev, info, priv);
756         if (ret < 0)
757                 return ret;
758
759         /*
760          *      asoc register
761          */
762         ret = snd_soc_register_platform(dev, &rsnd_soc_platform);
763         if (ret < 0) {
764                 dev_err(dev, "cannot snd soc register\n");
765                 return ret;
766         }
767
768         ret = snd_soc_register_component(dev, &rsnd_soc_component,
769                                          priv->daidrv, rsnd_dai_nr(priv));
770         if (ret < 0) {
771                 dev_err(dev, "cannot snd dai register\n");
772                 goto exit_snd_soc;
773         }
774
775         dev_set_drvdata(dev, priv);
776
777         pm_runtime_enable(dev);
778
779         dev_info(dev, "probed\n");
780         return ret;
781
782 exit_snd_soc:
783         snd_soc_unregister_platform(dev);
784
785         return ret;
786 }
787
788 static int rsnd_remove(struct platform_device *pdev)
789 {
790         struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
791
792         pm_runtime_disable(&pdev->dev);
793
794         /*
795          *      remove each module
796          */
797         rsnd_ssi_remove(pdev, priv);
798         rsnd_adg_remove(pdev, priv);
799         rsnd_scu_remove(pdev, priv);
800         rsnd_dai_remove(pdev, priv);
801         rsnd_gen_remove(pdev, priv);
802
803         return 0;
804 }
805
806 static struct platform_driver rsnd_driver = {
807         .driver = {
808                 .name   = "rcar_sound",
809         },
810         .probe          = rsnd_probe,
811         .remove         = rsnd_remove,
812 };
813 module_platform_driver(rsnd_driver);
814
815 MODULE_LICENSE("GPL");
816 MODULE_DESCRIPTION("Renesas R-Car audio driver");
817 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
818 MODULE_ALIAS("platform:rcar-pcm-audio");