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