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