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