ASoC: rsnd: tidyup rsnd_io_to_xxx() macro declaration position
[deliverable/linux.git] / sound / soc / sh / rcar / core.c
CommitLineData
1536a968
KM
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 * |
ba9c949f 76 * | ** these control src
1536a968 77 * |
ba9c949f 78 * +- src
1536a968 79 * |
ba9c949f
KM
80 * +- src[0]
81 * +- src[1]
82 * +- src[2]
1536a968
KM
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>
9ade09d6 97#include <linux/shdma-base.h>
1536a968
KM
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
90e8e50f
KM
103static struct rsnd_of_data rsnd_of_data_gen1 = {
104 .flags = RSND_GEN1,
105};
106
107static struct rsnd_of_data rsnd_of_data_gen2 = {
108 .flags = RSND_GEN2,
109};
110
111static 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 },
114 {},
115};
116MODULE_DEVICE_TABLE(of, rsnd_of_match);
117
1536a968
KM
118/*
119 * rsnd_platform functions
120 */
121#define rsnd_platform_call(priv, dai, func, param...) \
740ad6c3 122 (!(priv->info->func) ? 0 : \
1536a968
KM
123 priv->info->func(param))
124
389933d9
KM
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)
129
cdaa3cdf
KM
130/*
131 * rsnd_mod functions
132 */
133char *rsnd_mod_name(struct rsnd_mod *mod)
134{
135 if (!mod || !mod->ops)
136 return "unknown";
137
138 return mod->ops->name;
139}
140
d9288d0b
KM
141char *rsnd_mod_dma_name(struct rsnd_mod *mod)
142{
143 if (!mod || !mod->ops)
144 return "unknown";
145
146 if (!mod->ops->dma_name)
147 return mod->ops->name;
148
149 return mod->ops->dma_name(mod);
150}
151
cdaa3cdf
KM
152void rsnd_mod_init(struct rsnd_priv *priv,
153 struct rsnd_mod *mod,
154 struct rsnd_mod_ops *ops,
a126021d 155 enum rsnd_mod_type type,
cdaa3cdf
KM
156 int id)
157{
158 mod->priv = priv;
159 mod->id = id;
160 mod->ops = ops;
a126021d 161 mod->type = type;
cdaa3cdf
KM
162}
163
0a4d94c0
KM
164/*
165 * rsnd_dma functions
166 */
0a4d94c0
KM
167void rsnd_dma_stop(struct rsnd_dma *dma)
168{
0a4d94c0
KM
169 dmaengine_terminate_all(dma->chan);
170}
171
172static void rsnd_dma_complete(void *data)
173{
174 struct rsnd_dma *dma = (struct rsnd_dma *)data;
4686a0ad 175 struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
4686a0ad 176 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
0a4d94c0 177
4686a0ad
KM
178 /*
179 * Renesas sound Gen1 needs 1 DMAC,
180 * Gen2 needs 2 DMAC.
181 * In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri.
182 * But, Audio-DMAC-peri-peri doesn't have interrupt,
183 * and this driver is assuming that here.
184 *
185 * If Audio-DMAC-peri-peri has interrpt,
186 * rsnd_dai_pointer_update() will be called twice,
187 * ant it will breaks io->byte_pos
188 */
836b31fe
KM
189
190 rsnd_dai_pointer_update(io, io->byte_per_period);
0a4d94c0
KM
191}
192
ccd01559 193void rsnd_dma_start(struct rsnd_dma *dma)
0a4d94c0 194{
4686a0ad
KM
195 struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
196 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
197 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
ccd01559 198 struct snd_pcm_substream *substream = io->substream;
0a4d94c0
KM
199 struct device *dev = rsnd_priv_to_dev(priv);
200 struct dma_async_tx_descriptor *desc;
0a4d94c0 201
ccd01559 202 desc = dmaengine_prep_dma_cyclic(dma->chan,
34037100 203 (dma->addr) ? dma->addr :
ccd01559
KM
204 substream->runtime->dma_addr,
205 snd_pcm_lib_buffer_bytes(substream),
206 snd_pcm_lib_period_bytes(substream),
207 dma->dir,
208 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
0a4d94c0 209
ccd01559
KM
210 if (!desc) {
211 dev_err(dev, "dmaengine_prep_slave_sg() fail\n");
212 return;
0a4d94c0 213 }
0a4d94c0 214
ccd01559
KM
215 desc->callback = rsnd_dma_complete;
216 desc->callback_param = dma;
217
218 if (dmaengine_submit(desc) < 0) {
219 dev_err(dev, "dmaengine_submit() fail\n");
220 return;
221 }
f5cab3b8 222
ccd01559 223 dma_async_issue_pending(dma->chan);
f5cab3b8
KM
224}
225
0a4d94c0
KM
226int rsnd_dma_available(struct rsnd_dma *dma)
227{
228 return !!dma->chan;
229}
230
199e7688
KM
231#define DMA_NAME_SIZE 16
232#define MOD_MAX 4 /* MEM/SSI/SRC/DVC */
233static int _rsnd_dma_of_name(char *dma_name, struct rsnd_mod *mod)
234{
235 if (mod)
236 return snprintf(dma_name, DMA_NAME_SIZE / 2, "%s%d",
d9288d0b 237 rsnd_mod_dma_name(mod), rsnd_mod_id(mod));
199e7688
KM
238 else
239 return snprintf(dma_name, DMA_NAME_SIZE / 2, "mem");
240
241}
242
37523034
KM
243static void rsnd_dma_of_name(struct rsnd_mod *mod_from,
244 struct rsnd_mod *mod_to,
245 char *dma_name)
246{
247 int index = 0;
248
249 index = _rsnd_dma_of_name(dma_name + index, mod_from);
250 *(dma_name + index++) = '_';
251 index = _rsnd_dma_of_name(dma_name + index, mod_to);
252}
253
254static void rsnd_dma_of_path(struct rsnd_dma *dma,
255 int is_play,
256 struct rsnd_mod **mod_from,
257 struct rsnd_mod **mod_to)
199e7688
KM
258{
259 struct rsnd_mod *this = rsnd_dma_to_mod(dma);
260 struct rsnd_dai_stream *io = rsnd_mod_to_io(this);
261 struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
262 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
263 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
264 struct rsnd_mod *mod[MOD_MAX];
199e7688
KM
265 int i, index;
266
267
268 for (i = 0; i < MOD_MAX; i++)
269 mod[i] = NULL;
270
271 /*
272 * in play case...
273 *
274 * src -> dst
275 *
276 * mem -> SSI
277 * mem -> SRC -> SSI
278 * mem -> SRC -> DVC -> SSI
279 */
280 mod[0] = NULL; /* for "mem" */
281 index = 1;
282 for (i = 1; i < MOD_MAX; i++) {
283 if (!src) {
284 mod[i] = ssi;
199e7688
KM
285 } else if (!dvc) {
286 mod[i] = src;
287 src = NULL;
288 } else {
34cb6123
KM
289 if ((!is_play) && (this == src))
290 this = dvc;
291
292 mod[i] = (is_play) ? src : dvc;
293 i++;
294 mod[i] = (is_play) ? dvc : src;
295 src = NULL;
199e7688
KM
296 dvc = NULL;
297 }
298
299 if (mod[i] == this)
300 index = i;
c08c3b08
KM
301
302 if (mod[i] == ssi)
303 break;
199e7688
KM
304 }
305
306 if (is_play) {
37523034
KM
307 *mod_from = mod[index - 1];
308 *mod_to = mod[index];
199e7688 309 } else {
37523034
KM
310 *mod_from = mod[index];
311 *mod_to = mod[index - 1];
199e7688 312 }
199e7688
KM
313}
314
0a4d94c0 315int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
4686a0ad 316 int is_play, int id)
0a4d94c0
KM
317{
318 struct device *dev = rsnd_priv_to_dev(priv);
9ade09d6 319 struct dma_slave_config cfg;
37523034
KM
320 struct rsnd_mod *mod_from;
321 struct rsnd_mod *mod_to;
199e7688 322 char dma_name[DMA_NAME_SIZE];
0a4d94c0 323 dma_cap_mask_t mask;
9ade09d6 324 int ret;
0a4d94c0
KM
325
326 if (dma->chan) {
327 dev_err(dev, "it already has dma channel\n");
328 return -EIO;
329 }
330
331 dma_cap_zero(mask);
332 dma_cap_set(DMA_SLAVE, mask);
333
37523034
KM
334 rsnd_dma_of_path(dma, is_play, &mod_from, &mod_to);
335 rsnd_dma_of_name(mod_from, mod_to, dma_name);
336
337 cfg.slave_id = id;
338 cfg.direction = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
339 cfg.src_addr = rsnd_gen_dma_addr(priv, mod_from, is_play, 1);
340 cfg.dst_addr = rsnd_gen_dma_addr(priv, mod_to, is_play, 0);
2bf865ba
KM
341 cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
342 cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
199e7688 343
37523034
KM
344 dev_dbg(dev, "dma : %s %pad -> %pad\n",
345 dma_name, &cfg.src_addr, &cfg.dst_addr);
199e7688 346
9ade09d6
KM
347 dma->chan = dma_request_slave_channel_compat(mask, shdma_chan_filter,
348 (void *)id, dev,
199e7688 349 dma_name);
0a4d94c0
KM
350 if (!dma->chan) {
351 dev_err(dev, "can't get dma channel\n");
d3a76823 352 goto rsnd_dma_channel_err;
0a4d94c0
KM
353 }
354
9ade09d6
KM
355 ret = dmaengine_slave_config(dma->chan, &cfg);
356 if (ret < 0)
357 goto rsnd_dma_init_err;
358
34037100 359 dma->addr = is_play ? cfg.src_addr : cfg.dst_addr;
cd7bcc60 360 dma->dir = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
0a4d94c0
KM
361
362 return 0;
9ade09d6
KM
363
364rsnd_dma_init_err:
365 rsnd_dma_quit(priv, dma);
d3a76823 366rsnd_dma_channel_err:
9ade09d6 367
d3a76823
KM
368 /*
369 * DMA failed. try to PIO mode
370 * see
97463e19 371 * rsnd_ssi_fallback()
d3a76823
KM
372 * rsnd_rdai_continuance_probe()
373 */
374 return -EAGAIN;
0a4d94c0
KM
375}
376
377void rsnd_dma_quit(struct rsnd_priv *priv,
378 struct rsnd_dma *dma)
379{
380 if (dma->chan)
381 dma_release_channel(dma->chan);
382
383 dma->chan = NULL;
384}
385
d7bdbc5d
KM
386/*
387 * settting function
388 */
389u32 rsnd_get_adinr(struct rsnd_mod *mod)
390{
391 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
392 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
393 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
394 struct device *dev = rsnd_priv_to_dev(priv);
395 u32 adinr = runtime->channels;
396
397 switch (runtime->sample_bits) {
398 case 16:
399 adinr |= (8 << 16);
400 break;
401 case 32:
402 adinr |= (0 << 16);
403 break;
404 default:
405 dev_warn(dev, "not supported sample bits\n");
406 return 0;
407 }
408
409 return adinr;
410}
411
1536a968
KM
412/*
413 * rsnd_dai functions
414 */
68b6af36 415#define __rsnd_mod_call(mod, func, rdai...) \
d870a91e
KM
416({ \
417 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
418 struct device *dev = rsnd_priv_to_dev(priv); \
417f9642
KM
419 u32 mask = 1 << __rsnd_mod_shift_##func; \
420 u32 call = __rsnd_mod_call_##func << __rsnd_mod_shift_##func; \
421 int ret = 0; \
422 if ((mod->status & mask) == call) { \
423 dev_dbg(dev, "%s[%d] %s\n", \
424 rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \
425 ret = (mod)->ops->func(mod, rdai); \
426 mod->status = (mod->status & ~mask) | (~call & mask); \
427 } \
428 ret; \
d870a91e
KM
429})
430
68b6af36 431#define rsnd_mod_call(mod, func, rdai...) \
d870a91e
KM
432 (!(mod) ? -ENODEV : \
433 !((mod)->ops->func) ? 0 : \
68b6af36 434 __rsnd_mod_call(mod, func, rdai))
d870a91e 435
68b6af36 436#define rsnd_dai_call(fn, io, rdai...) \
d870a91e 437({ \
a126021d
KM
438 struct rsnd_mod *mod; \
439 int ret = 0, i; \
440 for (i = 0; i < RSND_MOD_MAX; i++) { \
441 mod = (io)->mod[i]; \
442 if (!mod) \
443 continue; \
68b6af36 444 ret = rsnd_mod_call(mod, fn, rdai); \
d870a91e
KM
445 if (ret < 0) \
446 break; \
447 } \
448 ret; \
cdaa3cdf
KM
449})
450
a126021d 451static int rsnd_dai_connect(struct rsnd_mod *mod,
9bfed6cf 452 struct rsnd_dai_stream *io)
cdaa3cdf 453{
6020779b 454 if (!mod)
cdaa3cdf 455 return -EIO;
cdaa3cdf 456
a126021d 457 if (io->mod[mod->type]) {
6020779b
KM
458 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
459 struct device *dev = rsnd_priv_to_dev(priv);
460
cdaa3cdf
KM
461 dev_err(dev, "%s%d is not empty\n",
462 rsnd_mod_name(mod),
463 rsnd_mod_id(mod));
464 return -EIO;
465 }
466
a126021d 467 io->mod[mod->type] = mod;
4686a0ad 468 mod->io = io;
cdaa3cdf
KM
469
470 return 0;
471}
472
d3a76823
KM
473static void rsnd_dai_disconnect(struct rsnd_mod *mod,
474 struct rsnd_dai_stream *io)
475{
476 mod->io = NULL;
477 io->mod[mod->type] = NULL;
478}
479
4b4dab82
KM
480int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
481{
482 int id = rdai - priv->rdai;
483
ecba9e72 484 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
4b4dab82
KM
485 return -EINVAL;
486
487 return id;
488}
489
1536a968
KM
490struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id)
491{
ecba9e72 492 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
2192f81c
KM
493 return NULL;
494
1536a968
KM
495 return priv->rdai + id;
496}
497
498static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
499{
500 struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
501
502 return rsnd_dai_get(priv, dai->id);
503}
504
505int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io)
506{
507 return &rdai->playback == io;
508}
509
510/*
511 * rsnd_soc_dai functions
512 */
513int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
514{
515 struct snd_pcm_substream *substream = io->substream;
516 struct snd_pcm_runtime *runtime = substream->runtime;
517 int pos = io->byte_pos + additional;
518
519 pos %= (runtime->periods * io->byte_per_period);
520
521 return pos;
522}
523
524void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
525{
526 io->byte_pos += byte;
527
528 if (io->byte_pos >= io->next_period_byte) {
529 struct snd_pcm_substream *substream = io->substream;
530 struct snd_pcm_runtime *runtime = substream->runtime;
531
532 io->period_pos++;
533 io->next_period_byte += io->byte_per_period;
534
535 if (io->period_pos >= runtime->periods) {
536 io->byte_pos = 0;
537 io->period_pos = 0;
538 io->next_period_byte = io->byte_per_period;
539 }
540
541 snd_pcm_period_elapsed(substream);
542 }
543}
544
545static int rsnd_dai_stream_init(struct rsnd_dai_stream *io,
546 struct snd_pcm_substream *substream)
547{
548 struct snd_pcm_runtime *runtime = substream->runtime;
549
1536a968
KM
550 io->substream = substream;
551 io->byte_pos = 0;
552 io->period_pos = 0;
553 io->byte_per_period = runtime->period_size *
554 runtime->channels *
555 samples_to_bytes(runtime, 1);
556 io->next_period_byte = io->byte_per_period;
557
558 return 0;
559}
560
561static
562struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
563{
564 struct snd_soc_pcm_runtime *rtd = substream->private_data;
565
566 return rtd->cpu_dai;
567}
568
569static
570struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
571 struct snd_pcm_substream *substream)
572{
573 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
574 return &rdai->playback;
575 else
576 return &rdai->capture;
577}
578
579static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
580 struct snd_soc_dai *dai)
581{
582 struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
583 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
584 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
29e69fd2 585 int ssi_id = rsnd_mod_id(rsnd_io_to_mod_ssi(io));
1536a968
KM
586 int ret;
587 unsigned long flags;
588
589 rsnd_lock(priv, flags);
590
591 switch (cmd) {
592 case SNDRV_PCM_TRIGGER_START:
593 ret = rsnd_dai_stream_init(io, substream);
594 if (ret < 0)
595 goto dai_trigger_end;
596
597 ret = rsnd_platform_call(priv, dai, start, ssi_id);
598 if (ret < 0)
599 goto dai_trigger_end;
600
68b6af36 601 ret = rsnd_dai_call(init, io, rdai);
cdaa3cdf
KM
602 if (ret < 0)
603 goto dai_trigger_end;
604
68b6af36 605 ret = rsnd_dai_call(start, io, rdai);
cdaa3cdf
KM
606 if (ret < 0)
607 goto dai_trigger_end;
1536a968
KM
608 break;
609 case SNDRV_PCM_TRIGGER_STOP:
68b6af36 610 ret = rsnd_dai_call(stop, io, rdai);
cdaa3cdf
KM
611 if (ret < 0)
612 goto dai_trigger_end;
613
68b6af36 614 ret = rsnd_dai_call(quit, io, rdai);
cdaa3cdf
KM
615 if (ret < 0)
616 goto dai_trigger_end;
617
3337744a
KM
618 ret = rsnd_platform_call(priv, dai, stop, ssi_id);
619 if (ret < 0)
620 goto dai_trigger_end;
1536a968
KM
621 break;
622 default:
623 ret = -EINVAL;
624 }
625
626dai_trigger_end:
627 rsnd_unlock(priv, flags);
628
629 return ret;
630}
631
632static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
633{
634 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
635
636 /* set master/slave audio interface */
637 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
638 case SND_SOC_DAIFMT_CBM_CFM:
e1508289 639 rdai->clk_master = 0;
1536a968
KM
640 break;
641 case SND_SOC_DAIFMT_CBS_CFS:
e1508289 642 rdai->clk_master = 1; /* codec is slave, cpu is master */
1536a968
KM
643 break;
644 default:
645 return -EINVAL;
646 }
647
1536a968
KM
648 /* set format */
649 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
650 case SND_SOC_DAIFMT_I2S:
651 rdai->sys_delay = 0;
652 rdai->data_alignment = 0;
1a7889ca 653 rdai->frm_clk_inv = 0;
1536a968
KM
654 break;
655 case SND_SOC_DAIFMT_LEFT_J:
656 rdai->sys_delay = 1;
657 rdai->data_alignment = 0;
1a7889ca 658 rdai->frm_clk_inv = 1;
1536a968
KM
659 break;
660 case SND_SOC_DAIFMT_RIGHT_J:
661 rdai->sys_delay = 1;
662 rdai->data_alignment = 1;
1a7889ca
KM
663 rdai->frm_clk_inv = 1;
664 break;
665 }
666
667 /* set clock inversion */
668 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
669 case SND_SOC_DAIFMT_NB_IF:
670 rdai->bit_clk_inv = rdai->bit_clk_inv;
671 rdai->frm_clk_inv = !rdai->frm_clk_inv;
672 break;
673 case SND_SOC_DAIFMT_IB_NF:
674 rdai->bit_clk_inv = !rdai->bit_clk_inv;
675 rdai->frm_clk_inv = rdai->frm_clk_inv;
676 break;
677 case SND_SOC_DAIFMT_IB_IF:
678 rdai->bit_clk_inv = !rdai->bit_clk_inv;
679 rdai->frm_clk_inv = !rdai->frm_clk_inv;
680 break;
681 case SND_SOC_DAIFMT_NB_NF:
682 default:
1536a968
KM
683 break;
684 }
685
686 return 0;
687}
688
689static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
690 .trigger = rsnd_soc_dai_trigger,
691 .set_fmt = rsnd_soc_dai_set_fmt,
692};
693
739f9502
KM
694#define rsnd_path_parse(priv, io, type) \
695({ \
696 struct rsnd_mod *mod; \
697 int ret = 0; \
698 int id = -1; \
699 \
700 if (rsnd_is_enable_path(io, type)) { \
701 id = rsnd_info_id(priv, io, type); \
702 if (id >= 0) { \
703 mod = rsnd_##type##_mod_get(priv, id); \
704 ret = rsnd_dai_connect(mod, io); \
705 } \
706 } \
707 ret; \
708})
709
d3a76823
KM
710#define rsnd_path_break(priv, io, type) \
711{ \
712 struct rsnd_mod *mod; \
713 int id = -1; \
714 \
715 if (rsnd_is_enable_path(io, type)) { \
716 id = rsnd_info_id(priv, io, type); \
717 if (id >= 0) { \
718 mod = rsnd_##type##_mod_get(priv, id); \
719 rsnd_dai_disconnect(mod, io); \
720 } \
721 } \
722}
723
9bfed6cf
KM
724static int rsnd_path_init(struct rsnd_priv *priv,
725 struct rsnd_dai *rdai,
726 struct rsnd_dai_stream *io)
727{
9bfed6cf 728 int ret;
9bfed6cf
KM
729
730 /*
731 * Gen1 is created by SRU/SSI, and this SRU is base module of
732 * Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU)
733 *
734 * Easy image is..
735 * Gen1 SRU = Gen2 SCU + SSIU + etc
736 *
737 * Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is
738 * using fixed path.
9bfed6cf 739 */
9bfed6cf 740
ba9c949f 741 /* SRC */
739f9502
KM
742 ret = rsnd_path_parse(priv, io, src);
743 if (ret < 0)
744 return ret;
9bfed6cf
KM
745
746 /* SSI */
739f9502
KM
747 ret = rsnd_path_parse(priv, io, ssi);
748 if (ret < 0)
749 return ret;
9bfed6cf 750
bff58ea4
KM
751 /* DVC */
752 ret = rsnd_path_parse(priv, io, dvc);
753 if (ret < 0)
754 return ret;
9bfed6cf
KM
755
756 return ret;
757}
758
90e8e50f
KM
759static void rsnd_of_parse_dai(struct platform_device *pdev,
760 const struct rsnd_of_data *of_data,
761 struct rsnd_priv *priv)
762{
763 struct device_node *dai_node, *dai_np;
764 struct device_node *ssi_node, *ssi_np;
765 struct device_node *src_node, *src_np;
34cb6123 766 struct device_node *dvc_node, *dvc_np;
90e8e50f
KM
767 struct device_node *playback, *capture;
768 struct rsnd_dai_platform_info *dai_info;
769 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
770 struct device *dev = &pdev->dev;
771 int nr, i;
34cb6123 772 int dai_i, ssi_i, src_i, dvc_i;
90e8e50f
KM
773
774 if (!of_data)
775 return;
776
777 dai_node = of_get_child_by_name(dev->of_node, "rcar_sound,dai");
778 if (!dai_node)
779 return;
780
781 nr = of_get_child_count(dai_node);
782 if (!nr)
783 return;
784
785 dai_info = devm_kzalloc(dev,
786 sizeof(struct rsnd_dai_platform_info) * nr,
787 GFP_KERNEL);
788 if (!dai_info) {
789 dev_err(dev, "dai info allocation error\n");
790 return;
791 }
792
793 info->dai_info_nr = nr;
794 info->dai_info = dai_info;
795
796 ssi_node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi");
797 src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
34cb6123 798 dvc_node = of_get_child_by_name(dev->of_node, "rcar_sound,dvc");
90e8e50f
KM
799
800#define mod_parse(name) \
801if (name##_node) { \
802 struct rsnd_##name##_platform_info *name##_info; \
803 \
804 name##_i = 0; \
805 for_each_child_of_node(name##_node, name##_np) { \
806 name##_info = info->name##_info + name##_i; \
807 \
808 if (name##_np == playback) \
809 dai_info->playback.name = name##_info; \
810 if (name##_np == capture) \
811 dai_info->capture.name = name##_info; \
812 \
813 name##_i++; \
814 } \
815}
816
817 /*
818 * parse all dai
819 */
820 dai_i = 0;
821 for_each_child_of_node(dai_node, dai_np) {
822 dai_info = info->dai_info + dai_i;
823
824 for (i = 0;; i++) {
825
826 playback = of_parse_phandle(dai_np, "playback", i);
827 capture = of_parse_phandle(dai_np, "capture", i);
828
829 if (!playback && !capture)
830 break;
831
832 mod_parse(ssi);
833 mod_parse(src);
34cb6123 834 mod_parse(dvc);
90e8e50f 835
a493b6a6
JL
836 of_node_put(playback);
837 of_node_put(capture);
90e8e50f
KM
838 }
839
840 dai_i++;
841 }
842}
843
1536a968 844static int rsnd_dai_probe(struct platform_device *pdev,
90e8e50f 845 const struct rsnd_of_data *of_data,
1536a968
KM
846 struct rsnd_priv *priv)
847{
848 struct snd_soc_dai_driver *drv;
78f13d0c 849 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
1536a968 850 struct rsnd_dai *rdai;
29e69fd2 851 struct rsnd_ssi_platform_info *pmod, *cmod;
1536a968 852 struct device *dev = rsnd_priv_to_dev(priv);
90e8e50f 853 int dai_nr;
4b4dab82
KM
854 int i;
855
90e8e50f
KM
856 rsnd_of_parse_dai(pdev, of_data, priv);
857
90e8e50f 858 dai_nr = info->dai_info_nr;
4b4dab82
KM
859 if (!dai_nr) {
860 dev_err(dev, "no dai\n");
861 return -EIO;
862 }
1536a968
KM
863
864 drv = devm_kzalloc(dev, sizeof(*drv) * dai_nr, GFP_KERNEL);
865 rdai = devm_kzalloc(dev, sizeof(*rdai) * dai_nr, GFP_KERNEL);
866 if (!drv || !rdai) {
867 dev_err(dev, "dai allocate failed\n");
868 return -ENOMEM;
869 }
870
ecba9e72 871 priv->rdai_nr = dai_nr;
49848073
KM
872 priv->daidrv = drv;
873 priv->rdai = rdai;
874
1536a968 875 for (i = 0; i < dai_nr; i++) {
29e69fd2 876 rdai[i].info = &info->dai_info[i];
1536a968 877
29e69fd2
KM
878 pmod = rdai[i].info->playback.ssi;
879 cmod = rdai[i].info->capture.ssi;
1536a968
KM
880
881 /*
882 * init rsnd_dai
883 */
1536a968
KM
884 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
885
886 /*
887 * init snd_soc_dai_driver
888 */
889 drv[i].name = rdai[i].name;
890 drv[i].ops = &rsnd_soc_dai_ops;
4b4dab82 891 if (pmod) {
1536a968
KM
892 drv[i].playback.rates = RSND_RATES;
893 drv[i].playback.formats = RSND_FMTS;
894 drv[i].playback.channels_min = 2;
895 drv[i].playback.channels_max = 2;
389933d9 896
29e69fd2 897 rdai[i].playback.info = &info->dai_info[i].playback;
9bfed6cf 898 rsnd_path_init(priv, &rdai[i], &rdai[i].playback);
1536a968 899 }
4b4dab82 900 if (cmod) {
1536a968
KM
901 drv[i].capture.rates = RSND_RATES;
902 drv[i].capture.formats = RSND_FMTS;
903 drv[i].capture.channels_min = 2;
904 drv[i].capture.channels_max = 2;
389933d9 905
29e69fd2 906 rdai[i].capture.info = &info->dai_info[i].capture;
9bfed6cf 907 rsnd_path_init(priv, &rdai[i], &rdai[i].capture);
1536a968
KM
908 }
909
4b4dab82
KM
910 dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name,
911 pmod ? "play" : " -- ",
912 cmod ? "capture" : " -- ");
1536a968
KM
913 }
914
1536a968
KM
915 return 0;
916}
917
1536a968
KM
918/*
919 * pcm ops
920 */
921static struct snd_pcm_hardware rsnd_pcm_hardware = {
922 .info = SNDRV_PCM_INFO_INTERLEAVED |
923 SNDRV_PCM_INFO_MMAP |
706c6621 924 SNDRV_PCM_INFO_MMAP_VALID,
1536a968
KM
925 .buffer_bytes_max = 64 * 1024,
926 .period_bytes_min = 32,
927 .period_bytes_max = 8192,
928 .periods_min = 1,
929 .periods_max = 32,
930 .fifo_size = 256,
931};
932
933static int rsnd_pcm_open(struct snd_pcm_substream *substream)
934{
935 struct snd_pcm_runtime *runtime = substream->runtime;
936 int ret = 0;
937
938 snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
939
940 ret = snd_pcm_hw_constraint_integer(runtime,
941 SNDRV_PCM_HW_PARAM_PERIODS);
942
943 return ret;
944}
945
946static int rsnd_hw_params(struct snd_pcm_substream *substream,
947 struct snd_pcm_hw_params *hw_params)
948{
949 return snd_pcm_lib_malloc_pages(substream,
950 params_buffer_bytes(hw_params));
951}
952
953static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
954{
955 struct snd_pcm_runtime *runtime = substream->runtime;
956 struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
957 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
958 struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
959
960 return bytes_to_frames(runtime, io->byte_pos);
961}
962
963static struct snd_pcm_ops rsnd_pcm_ops = {
964 .open = rsnd_pcm_open,
965 .ioctl = snd_pcm_lib_ioctl,
966 .hw_params = rsnd_hw_params,
967 .hw_free = snd_pcm_lib_free_pages,
968 .pointer = rsnd_pointer,
969};
970
170a2497
KM
971/*
972 * snd_kcontrol
973 */
974#define kcontrol_to_cfg(kctrl) ((struct rsnd_kctrl_cfg *)kctrl->private_value)
975static int rsnd_kctrl_info(struct snd_kcontrol *kctrl,
976 struct snd_ctl_elem_info *uinfo)
977{
978 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
979
980 if (cfg->texts) {
981 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
982 uinfo->count = cfg->size;
983 uinfo->value.enumerated.items = cfg->max;
984 if (uinfo->value.enumerated.item >= cfg->max)
985 uinfo->value.enumerated.item = cfg->max - 1;
986 strlcpy(uinfo->value.enumerated.name,
987 cfg->texts[uinfo->value.enumerated.item],
988 sizeof(uinfo->value.enumerated.name));
989 } else {
990 uinfo->count = cfg->size;
991 uinfo->value.integer.min = 0;
992 uinfo->value.integer.max = cfg->max;
993 uinfo->type = (cfg->max == 1) ?
994 SNDRV_CTL_ELEM_TYPE_BOOLEAN :
995 SNDRV_CTL_ELEM_TYPE_INTEGER;
996 }
997
998 return 0;
999}
1000
1001static int rsnd_kctrl_get(struct snd_kcontrol *kctrl,
1002 struct snd_ctl_elem_value *uc)
1003{
1004 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
1005 int i;
1006
1007 for (i = 0; i < cfg->size; i++)
1008 if (cfg->texts)
1009 uc->value.enumerated.item[i] = cfg->val[i];
1010 else
1011 uc->value.integer.value[i] = cfg->val[i];
1012
1013 return 0;
1014}
1015
1016static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
1017 struct snd_ctl_elem_value *uc)
1018{
1019 struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
1020 struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
1021 int i, change = 0;
1022
1023 for (i = 0; i < cfg->size; i++) {
1024 if (cfg->texts) {
1025 change |= (uc->value.enumerated.item[i] != cfg->val[i]);
1026 cfg->val[i] = uc->value.enumerated.item[i];
1027 } else {
1028 change |= (uc->value.integer.value[i] != cfg->val[i]);
1029 cfg->val[i] = uc->value.integer.value[i];
1030 }
1031 }
1032
1033 if (change)
1034 cfg->update(mod);
1035
1036 return change;
1037}
1038
1039static int __rsnd_kctrl_new(struct rsnd_mod *mod,
1040 struct rsnd_dai *rdai,
1041 struct snd_soc_pcm_runtime *rtd,
1042 const unsigned char *name,
1043 struct rsnd_kctrl_cfg *cfg,
1044 void (*update)(struct rsnd_mod *mod))
1045{
1046 struct snd_card *card = rtd->card->snd_card;
1047 struct snd_kcontrol *kctrl;
1048 struct snd_kcontrol_new knew = {
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 .name = name,
1051 .info = rsnd_kctrl_info,
1052 .get = rsnd_kctrl_get,
1053 .put = rsnd_kctrl_put,
1054 .private_value = (unsigned long)cfg,
1055 };
1056 int ret;
1057
1058 kctrl = snd_ctl_new1(&knew, mod);
1059 if (!kctrl)
1060 return -ENOMEM;
1061
1062 ret = snd_ctl_add(card, kctrl);
1063 if (ret < 0)
1064 return ret;
1065
1066 cfg->update = update;
1067
1068 return 0;
1069}
1070
1071int rsnd_kctrl_new_m(struct rsnd_mod *mod,
1072 struct rsnd_dai *rdai,
1073 struct snd_soc_pcm_runtime *rtd,
1074 const unsigned char *name,
1075 void (*update)(struct rsnd_mod *mod),
1076 struct rsnd_kctrl_cfg_m *_cfg,
1077 u32 max)
1078{
1079 _cfg->cfg.max = max;
1080 _cfg->cfg.size = RSND_DVC_CHANNELS;
1081 _cfg->cfg.val = _cfg->val;
1082 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update);
1083}
1084
1085int rsnd_kctrl_new_s(struct rsnd_mod *mod,
1086 struct rsnd_dai *rdai,
1087 struct snd_soc_pcm_runtime *rtd,
1088 const unsigned char *name,
1089 void (*update)(struct rsnd_mod *mod),
1090 struct rsnd_kctrl_cfg_s *_cfg,
1091 u32 max)
1092{
1093 _cfg->cfg.max = max;
1094 _cfg->cfg.size = 1;
1095 _cfg->cfg.val = &_cfg->val;
1096 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update);
1097}
1098
1099int rsnd_kctrl_new_e(struct rsnd_mod *mod,
1100 struct rsnd_dai *rdai,
1101 struct snd_soc_pcm_runtime *rtd,
1102 const unsigned char *name,
1103 struct rsnd_kctrl_cfg_s *_cfg,
1104 void (*update)(struct rsnd_mod *mod),
1105 const char * const *texts,
1106 u32 max)
1107{
1108 _cfg->cfg.max = max;
1109 _cfg->cfg.size = 1;
1110 _cfg->cfg.val = &_cfg->val;
1111 _cfg->cfg.texts = texts;
1112 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update);
1113}
1114
1536a968
KM
1115/*
1116 * snd_soc_platform
1117 */
1118
1119#define PREALLOC_BUFFER (32 * 1024)
1120#define PREALLOC_BUFFER_MAX (32 * 1024)
1121
1122static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
1123{
7c63f3c0
KM
1124 struct snd_soc_dai *dai = rtd->cpu_dai;
1125 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
1126 int ret;
bff58ea4 1127
7c63f3c0
KM
1128 ret = rsnd_dai_call(pcm_new, &rdai->playback, rdai, rtd);
1129 if (ret)
1130 return ret;
bff58ea4 1131
7c63f3c0
KM
1132 ret = rsnd_dai_call(pcm_new, &rdai->capture, rdai, rtd);
1133 if (ret)
1134 return ret;
bff58ea4 1135
1536a968
KM
1136 return snd_pcm_lib_preallocate_pages_for_all(
1137 rtd->pcm,
1138 SNDRV_DMA_TYPE_DEV,
1139 rtd->card->snd_card->dev,
1140 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
1141}
1142
1536a968
KM
1143static struct snd_soc_platform_driver rsnd_soc_platform = {
1144 .ops = &rsnd_pcm_ops,
1145 .pcm_new = rsnd_pcm_new,
1536a968
KM
1146};
1147
1148static const struct snd_soc_component_driver rsnd_soc_component = {
1149 .name = "rsnd",
1150};
1151
d3a76823
KM
1152static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
1153 struct rsnd_dai *rdai,
1154 int is_play)
1155{
1156 struct rsnd_dai_stream *io = is_play ? &rdai->playback : &rdai->capture;
1157 int ret;
1158
1159 ret = rsnd_dai_call(probe, io, rdai);
1160 if (ret == -EAGAIN) {
1161 /*
1162 * Fallback to PIO mode
1163 */
1164
1165 /*
1166 * call "remove" for SSI/SRC/DVC
1167 * SSI will be switch to PIO mode if it was DMA mode
1168 * see
1169 * rsnd_dma_init()
97463e19 1170 * rsnd_ssi_fallback()
d3a76823
KM
1171 */
1172 rsnd_dai_call(remove, io, rdai);
1173
1174 /*
1175 * remove SRC/DVC from DAI,
1176 */
1177 rsnd_path_break(priv, io, src);
1178 rsnd_path_break(priv, io, dvc);
1179
97463e19
KM
1180 /*
1181 * fallback
1182 */
1183 rsnd_dai_call(fallback, io, rdai);
1184
d3a76823
KM
1185 /*
1186 * retry to "probe".
1187 * DAI has SSI which is PIO mode only now.
1188 */
1189 ret = rsnd_dai_call(probe, io, rdai);
1190 }
1191
1192 return ret;
1193}
1194
1536a968
KM
1195/*
1196 * rsnd probe
1197 */
1198static int rsnd_probe(struct platform_device *pdev)
1199{
1200 struct rcar_snd_info *info;
1201 struct rsnd_priv *priv;
1202 struct device *dev = &pdev->dev;
7681f6ac 1203 struct rsnd_dai *rdai;
90e8e50f
KM
1204 const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
1205 const struct rsnd_of_data *of_data;
d1ac970f 1206 int (*probe_func[])(struct platform_device *pdev,
90e8e50f 1207 const struct rsnd_of_data *of_data,
d1ac970f
KM
1208 struct rsnd_priv *priv) = {
1209 rsnd_gen_probe,
1210 rsnd_ssi_probe,
ba9c949f 1211 rsnd_src_probe,
bff58ea4 1212 rsnd_dvc_probe,
d1ac970f
KM
1213 rsnd_adg_probe,
1214 rsnd_dai_probe,
1215 };
1216 int ret, i;
1536a968 1217
90e8e50f
KM
1218 info = NULL;
1219 of_data = NULL;
1220 if (of_id) {
1221 info = devm_kzalloc(&pdev->dev,
1222 sizeof(struct rcar_snd_info), GFP_KERNEL);
1223 of_data = of_id->data;
1224 } else {
1225 info = pdev->dev.platform_data;
1226 }
1227
1536a968
KM
1228 if (!info) {
1229 dev_err(dev, "driver needs R-Car sound information\n");
1230 return -ENODEV;
1231 }
1232
1233 /*
1234 * init priv data
1235 */
1236 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1237 if (!priv) {
1238 dev_err(dev, "priv allocate failed\n");
1239 return -ENODEV;
1240 }
1241
9f464f8e 1242 priv->pdev = pdev;
1536a968
KM
1243 priv->info = info;
1244 spin_lock_init(&priv->lock);
1245
1246 /*
1247 * init each module
1248 */
d1ac970f 1249 for (i = 0; i < ARRAY_SIZE(probe_func); i++) {
90e8e50f 1250 ret = probe_func[i](pdev, of_data, priv);
d1ac970f
KM
1251 if (ret)
1252 return ret;
1253 }
07539c1d 1254
7681f6ac 1255 for_each_rsnd_dai(rdai, priv, i) {
d3a76823 1256 ret = rsnd_rdai_continuance_probe(priv, rdai, 1);
7681f6ac 1257 if (ret)
d62a3dcd 1258 goto exit_snd_probe;
dfc9403b 1259
d3a76823 1260 ret = rsnd_rdai_continuance_probe(priv, rdai, 0);
7681f6ac 1261 if (ret)
d62a3dcd 1262 goto exit_snd_probe;
7681f6ac 1263 }
4b4dab82 1264
1536a968
KM
1265 /*
1266 * asoc register
1267 */
1268 ret = snd_soc_register_platform(dev, &rsnd_soc_platform);
1269 if (ret < 0) {
1270 dev_err(dev, "cannot snd soc register\n");
1271 return ret;
1272 }
1273
1274 ret = snd_soc_register_component(dev, &rsnd_soc_component,
ecba9e72 1275 priv->daidrv, rsnd_rdai_nr(priv));
1536a968
KM
1276 if (ret < 0) {
1277 dev_err(dev, "cannot snd dai register\n");
1278 goto exit_snd_soc;
1279 }
1280
1281 dev_set_drvdata(dev, priv);
1282
1283 pm_runtime_enable(dev);
1284
1285 dev_info(dev, "probed\n");
1286 return ret;
1287
1288exit_snd_soc:
1289 snd_soc_unregister_platform(dev);
d62a3dcd
KM
1290exit_snd_probe:
1291 for_each_rsnd_dai(rdai, priv, i) {
1292 rsnd_dai_call(remove, &rdai->playback, rdai);
1293 rsnd_dai_call(remove, &rdai->capture, rdai);
1294 }
1536a968
KM
1295
1296 return ret;
1297}
1298
1299static int rsnd_remove(struct platform_device *pdev)
1300{
1301 struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
7681f6ac 1302 struct rsnd_dai *rdai;
d62a3dcd 1303 int ret = 0, i;
1536a968
KM
1304
1305 pm_runtime_disable(&pdev->dev);
1306
7681f6ac 1307 for_each_rsnd_dai(rdai, priv, i) {
d62a3dcd
KM
1308 ret |= rsnd_dai_call(remove, &rdai->playback, rdai);
1309 ret |= rsnd_dai_call(remove, &rdai->capture, rdai);
7681f6ac 1310 }
1536a968 1311
d62a3dcd 1312 return ret;
1536a968
KM
1313}
1314
1315static struct platform_driver rsnd_driver = {
1316 .driver = {
1317 .name = "rcar_sound",
90e8e50f 1318 .of_match_table = rsnd_of_match,
1536a968
KM
1319 },
1320 .probe = rsnd_probe,
1321 .remove = rsnd_remove,
1322};
1323module_platform_driver(rsnd_driver);
1324
1325MODULE_LICENSE("GPL");
1326MODULE_DESCRIPTION("Renesas R-Car audio driver");
1327MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
1328MODULE_ALIAS("platform:rcar-pcm-audio");
This page took 0.194791 seconds and 5 git commands to generate.