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