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