Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.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 = dma->priv;
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 = dma->priv;
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         }
204
205         dma_async_issue_pending(dma->chan);
206 }
207
208 int rsnd_dma_available(struct rsnd_dma *dma)
209 {
210         return !!dma->chan;
211 }
212
213 int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
214                   int is_play, int id,
215                   int (*inquiry)(struct rsnd_dma *dma,
216                                   dma_addr_t *buf, int *len),
217                   int (*complete)(struct rsnd_dma *dma))
218 {
219         struct device *dev = rsnd_priv_to_dev(priv);
220         struct dma_slave_config cfg;
221         dma_cap_mask_t mask;
222         int ret;
223
224         if (dma->chan) {
225                 dev_err(dev, "it already has dma channel\n");
226                 return -EIO;
227         }
228
229         dma_cap_zero(mask);
230         dma_cap_set(DMA_SLAVE, mask);
231
232         dma->chan = dma_request_slave_channel_compat(mask, shdma_chan_filter,
233                                                      (void *)id, dev,
234                                                      is_play ? "tx" : "rx");
235         if (!dma->chan) {
236                 dev_err(dev, "can't get dma channel\n");
237                 return -EIO;
238         }
239
240         cfg.slave_id    = id;
241         cfg.dst_addr    = 0; /* use default addr when playback */
242         cfg.src_addr    = 0; /* use default addr when capture */
243         cfg.direction   = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
244
245         ret = dmaengine_slave_config(dma->chan, &cfg);
246         if (ret < 0)
247                 goto rsnd_dma_init_err;
248
249         dma->dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
250         dma->priv = priv;
251         dma->inquiry = inquiry;
252         dma->complete = complete;
253         INIT_WORK(&dma->work, rsnd_dma_do_work);
254
255         return 0;
256
257 rsnd_dma_init_err:
258         rsnd_dma_quit(priv, dma);
259
260         return ret;
261 }
262
263 void  rsnd_dma_quit(struct rsnd_priv *priv,
264                     struct rsnd_dma *dma)
265 {
266         if (dma->chan)
267                 dma_release_channel(dma->chan);
268
269         dma->chan = NULL;
270 }
271
272 /*
273  *      rsnd_dai functions
274  */
275 #define rsnd_dai_call(rdai, io, fn)                     \
276 ({                                                      \
277         struct rsnd_mod *mod, *n;                       \
278         int ret = 0;                                    \
279         for_each_rsnd_mod(mod, n, io) {                 \
280                 ret = rsnd_mod_call(mod, fn, rdai, io); \
281                 if (ret < 0)                            \
282                         break;                          \
283         }                                               \
284         ret;                                            \
285 })
286
287 int rsnd_dai_connect(struct rsnd_dai *rdai,
288                      struct rsnd_mod *mod,
289                      struct rsnd_dai_stream *io)
290 {
291         struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
292         struct device *dev = rsnd_priv_to_dev(priv);
293
294         if (!mod) {
295                 dev_err(dev, "NULL mod\n");
296                 return -EIO;
297         }
298
299         if (!list_empty(&mod->list)) {
300                 dev_err(dev, "%s%d is not empty\n",
301                         rsnd_mod_name(mod),
302                         rsnd_mod_id(mod));
303                 return -EIO;
304         }
305
306         list_add_tail(&mod->list, &io->head);
307
308         return 0;
309 }
310
311 int rsnd_dai_disconnect(struct rsnd_mod *mod)
312 {
313         list_del_init(&mod->list);
314
315         return 0;
316 }
317
318 int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
319 {
320         int id = rdai - priv->rdai;
321
322         if ((id < 0) || (id >= rsnd_dai_nr(priv)))
323                 return -EINVAL;
324
325         return id;
326 }
327
328 struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id)
329 {
330         if ((id < 0) || (id >= rsnd_dai_nr(priv)))
331                 return NULL;
332
333         return priv->rdai + id;
334 }
335
336 static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
337 {
338         struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
339
340         return rsnd_dai_get(priv, dai->id);
341 }
342
343 int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io)
344 {
345         return &rdai->playback == io;
346 }
347
348 /*
349  *      rsnd_soc_dai functions
350  */
351 int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
352 {
353         struct snd_pcm_substream *substream = io->substream;
354         struct snd_pcm_runtime *runtime = substream->runtime;
355         int pos = io->byte_pos + additional;
356
357         pos %= (runtime->periods * io->byte_per_period);
358
359         return pos;
360 }
361
362 void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
363 {
364         io->byte_pos += byte;
365
366         if (io->byte_pos >= io->next_period_byte) {
367                 struct snd_pcm_substream *substream = io->substream;
368                 struct snd_pcm_runtime *runtime = substream->runtime;
369
370                 io->period_pos++;
371                 io->next_period_byte += io->byte_per_period;
372
373                 if (io->period_pos >= runtime->periods) {
374                         io->byte_pos = 0;
375                         io->period_pos = 0;
376                         io->next_period_byte = io->byte_per_period;
377                 }
378
379                 snd_pcm_period_elapsed(substream);
380         }
381 }
382
383 static int rsnd_dai_stream_init(struct rsnd_dai_stream *io,
384                                 struct snd_pcm_substream *substream)
385 {
386         struct snd_pcm_runtime *runtime = substream->runtime;
387
388         if (!list_empty(&io->head))
389                 return -EIO;
390
391         INIT_LIST_HEAD(&io->head);
392         io->substream           = substream;
393         io->byte_pos            = 0;
394         io->period_pos          = 0;
395         io->byte_per_period     = runtime->period_size *
396                                   runtime->channels *
397                                   samples_to_bytes(runtime, 1);
398         io->next_period_byte    = io->byte_per_period;
399
400         return 0;
401 }
402
403 static
404 struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
405 {
406         struct snd_soc_pcm_runtime *rtd = substream->private_data;
407
408         return  rtd->cpu_dai;
409 }
410
411 static
412 struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
413                                         struct snd_pcm_substream *substream)
414 {
415         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
416                 return &rdai->playback;
417         else
418                 return &rdai->capture;
419 }
420
421 static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
422                             struct snd_soc_dai *dai)
423 {
424         struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
425         struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
426         struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
427         struct rsnd_mod *mod = rsnd_ssi_mod_get_frm_dai(priv,
428                                                 rsnd_dai_id(priv, rdai),
429                                                 rsnd_dai_is_play(rdai, io));
430         int ssi_id = rsnd_mod_id(mod);
431         int ret;
432         unsigned long flags;
433
434         rsnd_lock(priv, flags);
435
436         switch (cmd) {
437         case SNDRV_PCM_TRIGGER_START:
438                 ret = rsnd_dai_stream_init(io, substream);
439                 if (ret < 0)
440                         goto dai_trigger_end;
441
442                 ret = rsnd_platform_call(priv, dai, start, ssi_id);
443                 if (ret < 0)
444                         goto dai_trigger_end;
445
446                 ret = rsnd_gen_path_init(priv, rdai, io);
447                 if (ret < 0)
448                         goto dai_trigger_end;
449
450                 ret = rsnd_dai_call(rdai, io, init);
451                 if (ret < 0)
452                         goto dai_trigger_end;
453
454                 ret = rsnd_dai_call(rdai, io, start);
455                 if (ret < 0)
456                         goto dai_trigger_end;
457                 break;
458         case SNDRV_PCM_TRIGGER_STOP:
459                 ret = rsnd_dai_call(rdai, io, stop);
460                 if (ret < 0)
461                         goto dai_trigger_end;
462
463                 ret = rsnd_dai_call(rdai, io, quit);
464                 if (ret < 0)
465                         goto dai_trigger_end;
466
467                 ret = rsnd_gen_path_exit(priv, rdai, io);
468                 if (ret < 0)
469                         goto dai_trigger_end;
470
471                 ret = rsnd_platform_call(priv, dai, stop, ssi_id);
472                 if (ret < 0)
473                         goto dai_trigger_end;
474                 break;
475         default:
476                 ret = -EINVAL;
477         }
478
479 dai_trigger_end:
480         rsnd_unlock(priv, flags);
481
482         return ret;
483 }
484
485 static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
486 {
487         struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
488
489         /* set master/slave audio interface */
490         switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
491         case SND_SOC_DAIFMT_CBM_CFM:
492                 rdai->clk_master = 1;
493                 break;
494         case SND_SOC_DAIFMT_CBS_CFS:
495                 rdai->clk_master = 0;
496                 break;
497         default:
498                 return -EINVAL;
499         }
500
501         /* set clock inversion */
502         switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
503         case SND_SOC_DAIFMT_NB_IF:
504                 rdai->bit_clk_inv = 0;
505                 rdai->frm_clk_inv = 1;
506                 break;
507         case SND_SOC_DAIFMT_IB_NF:
508                 rdai->bit_clk_inv = 1;
509                 rdai->frm_clk_inv = 0;
510                 break;
511         case SND_SOC_DAIFMT_IB_IF:
512                 rdai->bit_clk_inv = 1;
513                 rdai->frm_clk_inv = 1;
514                 break;
515         case SND_SOC_DAIFMT_NB_NF:
516         default:
517                 rdai->bit_clk_inv = 0;
518                 rdai->frm_clk_inv = 0;
519                 break;
520         }
521
522         /* set format */
523         switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
524         case SND_SOC_DAIFMT_I2S:
525                 rdai->sys_delay = 0;
526                 rdai->data_alignment = 0;
527                 break;
528         case SND_SOC_DAIFMT_LEFT_J:
529                 rdai->sys_delay = 1;
530                 rdai->data_alignment = 0;
531                 break;
532         case SND_SOC_DAIFMT_RIGHT_J:
533                 rdai->sys_delay = 1;
534                 rdai->data_alignment = 1;
535                 break;
536         }
537
538         return 0;
539 }
540
541 static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
542         .trigger        = rsnd_soc_dai_trigger,
543         .set_fmt        = rsnd_soc_dai_set_fmt,
544 };
545
546 static int rsnd_dai_probe(struct platform_device *pdev,
547                           struct rcar_snd_info *info,
548                           struct rsnd_priv *priv)
549 {
550         struct snd_soc_dai_driver *drv;
551         struct rsnd_dai *rdai;
552         struct rsnd_mod *pmod, *cmod;
553         struct device *dev = rsnd_priv_to_dev(priv);
554         int dai_nr;
555         int i;
556
557         /* get max dai nr */
558         for (dai_nr = 0; dai_nr < 32; dai_nr++) {
559                 pmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 1);
560                 cmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 0);
561
562                 if (!pmod && !cmod)
563                         break;
564         }
565
566         if (!dai_nr) {
567                 dev_err(dev, "no dai\n");
568                 return -EIO;
569         }
570
571         drv  = devm_kzalloc(dev, sizeof(*drv)  * dai_nr, GFP_KERNEL);
572         rdai = devm_kzalloc(dev, sizeof(*rdai) * dai_nr, GFP_KERNEL);
573         if (!drv || !rdai) {
574                 dev_err(dev, "dai allocate failed\n");
575                 return -ENOMEM;
576         }
577
578         for (i = 0; i < dai_nr; i++) {
579
580                 pmod = rsnd_ssi_mod_get_frm_dai(priv, i, 1);
581                 cmod = rsnd_ssi_mod_get_frm_dai(priv, i, 0);
582
583                 /*
584                  *      init rsnd_dai
585                  */
586                 INIT_LIST_HEAD(&rdai[i].playback.head);
587                 INIT_LIST_HEAD(&rdai[i].capture.head);
588
589                 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
590
591                 /*
592                  *      init snd_soc_dai_driver
593                  */
594                 drv[i].name     = rdai[i].name;
595                 drv[i].ops      = &rsnd_soc_dai_ops;
596                 if (pmod) {
597                         drv[i].playback.rates           = RSND_RATES;
598                         drv[i].playback.formats         = RSND_FMTS;
599                         drv[i].playback.channels_min    = 2;
600                         drv[i].playback.channels_max    = 2;
601                 }
602                 if (cmod) {
603                         drv[i].capture.rates            = RSND_RATES;
604                         drv[i].capture.formats          = RSND_FMTS;
605                         drv[i].capture.channels_min     = 2;
606                         drv[i].capture.channels_max     = 2;
607                 }
608
609                 dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name,
610                         pmod ? "play"    : " -- ",
611                         cmod ? "capture" : "  --   ");
612         }
613
614         priv->dai_nr    = dai_nr;
615         priv->daidrv    = drv;
616         priv->rdai      = rdai;
617
618         return 0;
619 }
620
621 static void rsnd_dai_remove(struct platform_device *pdev,
622                           struct rsnd_priv *priv)
623 {
624 }
625
626 /*
627  *              pcm ops
628  */
629 static struct snd_pcm_hardware rsnd_pcm_hardware = {
630         .info =         SNDRV_PCM_INFO_INTERLEAVED      |
631                         SNDRV_PCM_INFO_MMAP             |
632                         SNDRV_PCM_INFO_MMAP_VALID       |
633                         SNDRV_PCM_INFO_PAUSE,
634         .formats                = RSND_FMTS,
635         .rates                  = RSND_RATES,
636         .rate_min               = 8000,
637         .rate_max               = 192000,
638         .channels_min           = 2,
639         .channels_max           = 2,
640         .buffer_bytes_max       = 64 * 1024,
641         .period_bytes_min       = 32,
642         .period_bytes_max       = 8192,
643         .periods_min            = 1,
644         .periods_max            = 32,
645         .fifo_size              = 256,
646 };
647
648 static int rsnd_pcm_open(struct snd_pcm_substream *substream)
649 {
650         struct snd_pcm_runtime *runtime = substream->runtime;
651         int ret = 0;
652
653         snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
654
655         ret = snd_pcm_hw_constraint_integer(runtime,
656                                             SNDRV_PCM_HW_PARAM_PERIODS);
657
658         return ret;
659 }
660
661 static int rsnd_hw_params(struct snd_pcm_substream *substream,
662                          struct snd_pcm_hw_params *hw_params)
663 {
664         return snd_pcm_lib_malloc_pages(substream,
665                                         params_buffer_bytes(hw_params));
666 }
667
668 static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
669 {
670         struct snd_pcm_runtime *runtime = substream->runtime;
671         struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
672         struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
673         struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
674
675         return bytes_to_frames(runtime, io->byte_pos);
676 }
677
678 static struct snd_pcm_ops rsnd_pcm_ops = {
679         .open           = rsnd_pcm_open,
680         .ioctl          = snd_pcm_lib_ioctl,
681         .hw_params      = rsnd_hw_params,
682         .hw_free        = snd_pcm_lib_free_pages,
683         .pointer        = rsnd_pointer,
684 };
685
686 /*
687  *              snd_soc_platform
688  */
689
690 #define PREALLOC_BUFFER         (32 * 1024)
691 #define PREALLOC_BUFFER_MAX     (32 * 1024)
692
693 static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
694 {
695         return snd_pcm_lib_preallocate_pages_for_all(
696                 rtd->pcm,
697                 SNDRV_DMA_TYPE_DEV,
698                 rtd->card->snd_card->dev,
699                 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
700 }
701
702 static void rsnd_pcm_free(struct snd_pcm *pcm)
703 {
704         snd_pcm_lib_preallocate_free_for_all(pcm);
705 }
706
707 static struct snd_soc_platform_driver rsnd_soc_platform = {
708         .ops            = &rsnd_pcm_ops,
709         .pcm_new        = rsnd_pcm_new,
710         .pcm_free       = rsnd_pcm_free,
711 };
712
713 static const struct snd_soc_component_driver rsnd_soc_component = {
714         .name           = "rsnd",
715 };
716
717 /*
718  *      rsnd probe
719  */
720 static int rsnd_probe(struct platform_device *pdev)
721 {
722         struct rcar_snd_info *info;
723         struct rsnd_priv *priv;
724         struct device *dev = &pdev->dev;
725         int ret;
726
727         info = pdev->dev.platform_data;
728         if (!info) {
729                 dev_err(dev, "driver needs R-Car sound information\n");
730                 return -ENODEV;
731         }
732
733         /*
734          *      init priv data
735          */
736         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
737         if (!priv) {
738                 dev_err(dev, "priv allocate failed\n");
739                 return -ENODEV;
740         }
741
742         priv->dev       = dev;
743         priv->info      = info;
744         spin_lock_init(&priv->lock);
745
746         /*
747          *      init each module
748          */
749         ret = rsnd_gen_probe(pdev, info, priv);
750         if (ret < 0)
751                 return ret;
752
753         ret = rsnd_scu_probe(pdev, info, priv);
754         if (ret < 0)
755                 return ret;
756
757         ret = rsnd_adg_probe(pdev, info, priv);
758         if (ret < 0)
759                 return ret;
760
761         ret = rsnd_ssi_probe(pdev, info, priv);
762         if (ret < 0)
763                 return ret;
764
765         ret = rsnd_dai_probe(pdev, info, priv);
766         if (ret < 0)
767                 return ret;
768
769         /*
770          *      asoc register
771          */
772         ret = snd_soc_register_platform(dev, &rsnd_soc_platform);
773         if (ret < 0) {
774                 dev_err(dev, "cannot snd soc register\n");
775                 return ret;
776         }
777
778         ret = snd_soc_register_component(dev, &rsnd_soc_component,
779                                          priv->daidrv, rsnd_dai_nr(priv));
780         if (ret < 0) {
781                 dev_err(dev, "cannot snd dai register\n");
782                 goto exit_snd_soc;
783         }
784
785         dev_set_drvdata(dev, priv);
786
787         pm_runtime_enable(dev);
788
789         dev_info(dev, "probed\n");
790         return ret;
791
792 exit_snd_soc:
793         snd_soc_unregister_platform(dev);
794
795         return ret;
796 }
797
798 static int rsnd_remove(struct platform_device *pdev)
799 {
800         struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
801
802         pm_runtime_disable(&pdev->dev);
803
804         /*
805          *      remove each module
806          */
807         rsnd_ssi_remove(pdev, priv);
808         rsnd_adg_remove(pdev, priv);
809         rsnd_scu_remove(pdev, priv);
810         rsnd_dai_remove(pdev, priv);
811         rsnd_gen_remove(pdev, priv);
812
813         return 0;
814 }
815
816 static struct platform_driver rsnd_driver = {
817         .driver = {
818                 .name   = "rcar_sound",
819         },
820         .probe          = rsnd_probe,
821         .remove         = rsnd_remove,
822 };
823 module_platform_driver(rsnd_driver);
824
825 MODULE_LICENSE("GPL");
826 MODULE_DESCRIPTION("Renesas R-Car audio driver");
827 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
828 MODULE_ALIAS("platform:rcar-pcm-audio");