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