Commit | Line | Data |
---|---|---|
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 | ||
90e8e50f KM |
102 | static struct rsnd_of_data rsnd_of_data_gen1 = { |
103 | .flags = RSND_GEN1, | |
104 | }; | |
105 | ||
106 | static struct rsnd_of_data rsnd_of_data_gen2 = { | |
107 | .flags = RSND_GEN2, | |
108 | }; | |
109 | ||
33187fb4 | 110 | static 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 }, | |
113 | {}, | |
114 | }; | |
115 | MODULE_DEVICE_TABLE(of, rsnd_of_match); | |
116 | ||
1536a968 KM |
117 | /* |
118 | * rsnd_platform functions | |
119 | */ | |
120 | #define rsnd_platform_call(priv, dai, func, param...) \ | |
740ad6c3 | 121 | (!(priv->info->func) ? 0 : \ |
1536a968 KM |
122 | priv->info->func(param)) |
123 | ||
389933d9 KM |
124 | #define rsnd_is_enable_path(io, name) \ |
125 | ((io)->info ? (io)->info->name : NULL) | |
126 | #define rsnd_info_id(priv, io, name) \ | |
127 | ((io)->info->name - priv->info->name##_info) | |
128 | ||
cdaa3cdf KM |
129 | /* |
130 | * rsnd_mod functions | |
131 | */ | |
132 | char *rsnd_mod_name(struct rsnd_mod *mod) | |
133 | { | |
134 | if (!mod || !mod->ops) | |
135 | return "unknown"; | |
136 | ||
137 | return mod->ops->name; | |
138 | } | |
139 | ||
72adc61f | 140 | struct dma_chan *rsnd_mod_dma_req(struct rsnd_mod *mod) |
d9288d0b | 141 | { |
72adc61f KM |
142 | if (!mod || !mod->ops || !mod->ops->dma_req) |
143 | return NULL; | |
d9288d0b | 144 | |
72adc61f | 145 | return mod->ops->dma_req(mod); |
d9288d0b KM |
146 | } |
147 | ||
2f78dd7f | 148 | int rsnd_mod_init(struct rsnd_mod *mod, |
cdaa3cdf | 149 | struct rsnd_mod_ops *ops, |
85642952 | 150 | struct clk *clk, |
a126021d | 151 | enum rsnd_mod_type type, |
cdaa3cdf KM |
152 | int id) |
153 | { | |
2f78dd7f KM |
154 | int ret = clk_prepare(clk); |
155 | ||
156 | if (ret) | |
157 | return ret; | |
158 | ||
cdaa3cdf KM |
159 | mod->id = id; |
160 | mod->ops = ops; | |
a126021d | 161 | mod->type = type; |
85642952 | 162 | mod->clk = clk; |
2f78dd7f KM |
163 | |
164 | return ret; | |
165 | } | |
166 | ||
167 | void rsnd_mod_quit(struct rsnd_mod *mod) | |
168 | { | |
169 | if (mod->clk) | |
170 | clk_unprepare(mod->clk); | |
cdaa3cdf KM |
171 | } |
172 | ||
d7bdbc5d KM |
173 | /* |
174 | * settting function | |
175 | */ | |
176 | u32 rsnd_get_adinr(struct rsnd_mod *mod) | |
177 | { | |
178 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | |
179 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); | |
180 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); | |
181 | struct device *dev = rsnd_priv_to_dev(priv); | |
182 | u32 adinr = runtime->channels; | |
183 | ||
184 | switch (runtime->sample_bits) { | |
185 | case 16: | |
186 | adinr |= (8 << 16); | |
187 | break; | |
188 | case 32: | |
189 | adinr |= (0 << 16); | |
190 | break; | |
191 | default: | |
192 | dev_warn(dev, "not supported sample bits\n"); | |
193 | return 0; | |
194 | } | |
195 | ||
196 | return adinr; | |
197 | } | |
198 | ||
1536a968 KM |
199 | /* |
200 | * rsnd_dai functions | |
201 | */ | |
690602fc | 202 | #define __rsnd_mod_call(mod, func, param...) \ |
d870a91e KM |
203 | ({ \ |
204 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \ | |
205 | struct device *dev = rsnd_priv_to_dev(priv); \ | |
417f9642 KM |
206 | u32 mask = 1 << __rsnd_mod_shift_##func; \ |
207 | u32 call = __rsnd_mod_call_##func << __rsnd_mod_shift_##func; \ | |
208 | int ret = 0; \ | |
209 | if ((mod->status & mask) == call) { \ | |
210 | dev_dbg(dev, "%s[%d] %s\n", \ | |
211 | rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \ | |
690602fc | 212 | ret = (mod)->ops->func(mod, param); \ |
417f9642 KM |
213 | mod->status = (mod->status & ~mask) | (~call & mask); \ |
214 | } \ | |
215 | ret; \ | |
d870a91e KM |
216 | }) |
217 | ||
690602fc | 218 | #define rsnd_mod_call(mod, func, param...) \ |
d870a91e KM |
219 | (!(mod) ? -ENODEV : \ |
220 | !((mod)->ops->func) ? 0 : \ | |
690602fc | 221 | __rsnd_mod_call(mod, func, param)) |
d870a91e | 222 | |
690602fc | 223 | #define rsnd_dai_call(fn, io, param...) \ |
d870a91e | 224 | ({ \ |
a126021d KM |
225 | struct rsnd_mod *mod; \ |
226 | int ret = 0, i; \ | |
227 | for (i = 0; i < RSND_MOD_MAX; i++) { \ | |
228 | mod = (io)->mod[i]; \ | |
229 | if (!mod) \ | |
230 | continue; \ | |
690602fc | 231 | ret = rsnd_mod_call(mod, fn, param); \ |
d870a91e KM |
232 | if (ret < 0) \ |
233 | break; \ | |
234 | } \ | |
235 | ret; \ | |
cdaa3cdf KM |
236 | }) |
237 | ||
a126021d | 238 | static int rsnd_dai_connect(struct rsnd_mod *mod, |
9bfed6cf | 239 | struct rsnd_dai_stream *io) |
cdaa3cdf | 240 | { |
6020779b | 241 | if (!mod) |
cdaa3cdf | 242 | return -EIO; |
cdaa3cdf | 243 | |
a126021d | 244 | if (io->mod[mod->type]) { |
6020779b KM |
245 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
246 | struct device *dev = rsnd_priv_to_dev(priv); | |
247 | ||
072bd1e7 | 248 | dev_err(dev, "%s[%d] is not empty\n", |
cdaa3cdf KM |
249 | rsnd_mod_name(mod), |
250 | rsnd_mod_id(mod)); | |
251 | return -EIO; | |
252 | } | |
253 | ||
a126021d | 254 | io->mod[mod->type] = mod; |
4686a0ad | 255 | mod->io = io; |
cdaa3cdf KM |
256 | |
257 | return 0; | |
258 | } | |
259 | ||
d3a76823 KM |
260 | static void rsnd_dai_disconnect(struct rsnd_mod *mod, |
261 | struct rsnd_dai_stream *io) | |
262 | { | |
263 | mod->io = NULL; | |
264 | io->mod[mod->type] = NULL; | |
265 | } | |
266 | ||
710d0889 | 267 | struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id) |
1536a968 | 268 | { |
ecba9e72 | 269 | if ((id < 0) || (id >= rsnd_rdai_nr(priv))) |
2192f81c KM |
270 | return NULL; |
271 | ||
1536a968 KM |
272 | return priv->rdai + id; |
273 | } | |
274 | ||
275 | static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai) | |
276 | { | |
277 | struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai); | |
278 | ||
710d0889 | 279 | return rsnd_rdai_get(priv, dai->id); |
1536a968 KM |
280 | } |
281 | ||
1536a968 KM |
282 | /* |
283 | * rsnd_soc_dai functions | |
284 | */ | |
285 | int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional) | |
286 | { | |
287 | struct snd_pcm_substream *substream = io->substream; | |
288 | struct snd_pcm_runtime *runtime = substream->runtime; | |
289 | int pos = io->byte_pos + additional; | |
290 | ||
291 | pos %= (runtime->periods * io->byte_per_period); | |
292 | ||
293 | return pos; | |
294 | } | |
295 | ||
296 | void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte) | |
297 | { | |
298 | io->byte_pos += byte; | |
299 | ||
300 | if (io->byte_pos >= io->next_period_byte) { | |
301 | struct snd_pcm_substream *substream = io->substream; | |
302 | struct snd_pcm_runtime *runtime = substream->runtime; | |
303 | ||
304 | io->period_pos++; | |
305 | io->next_period_byte += io->byte_per_period; | |
306 | ||
307 | if (io->period_pos >= runtime->periods) { | |
308 | io->byte_pos = 0; | |
309 | io->period_pos = 0; | |
310 | io->next_period_byte = io->byte_per_period; | |
311 | } | |
312 | ||
313 | snd_pcm_period_elapsed(substream); | |
314 | } | |
315 | } | |
316 | ||
317 | static int rsnd_dai_stream_init(struct rsnd_dai_stream *io, | |
318 | struct snd_pcm_substream *substream) | |
319 | { | |
320 | struct snd_pcm_runtime *runtime = substream->runtime; | |
321 | ||
1536a968 KM |
322 | io->substream = substream; |
323 | io->byte_pos = 0; | |
324 | io->period_pos = 0; | |
325 | io->byte_per_period = runtime->period_size * | |
326 | runtime->channels * | |
327 | samples_to_bytes(runtime, 1); | |
328 | io->next_period_byte = io->byte_per_period; | |
329 | ||
330 | return 0; | |
331 | } | |
332 | ||
333 | static | |
334 | struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream) | |
335 | { | |
336 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
337 | ||
338 | return rtd->cpu_dai; | |
339 | } | |
340 | ||
341 | static | |
342 | struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai, | |
343 | struct snd_pcm_substream *substream) | |
344 | { | |
345 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | |
346 | return &rdai->playback; | |
347 | else | |
348 | return &rdai->capture; | |
349 | } | |
350 | ||
351 | static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd, | |
352 | struct snd_soc_dai *dai) | |
353 | { | |
354 | struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai); | |
355 | struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); | |
356 | struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream); | |
29e69fd2 | 357 | int ssi_id = rsnd_mod_id(rsnd_io_to_mod_ssi(io)); |
1536a968 KM |
358 | int ret; |
359 | unsigned long flags; | |
360 | ||
361 | rsnd_lock(priv, flags); | |
362 | ||
363 | switch (cmd) { | |
364 | case SNDRV_PCM_TRIGGER_START: | |
365 | ret = rsnd_dai_stream_init(io, substream); | |
366 | if (ret < 0) | |
367 | goto dai_trigger_end; | |
368 | ||
369 | ret = rsnd_platform_call(priv, dai, start, ssi_id); | |
370 | if (ret < 0) | |
371 | goto dai_trigger_end; | |
372 | ||
690602fc | 373 | ret = rsnd_dai_call(init, io, priv); |
cdaa3cdf KM |
374 | if (ret < 0) |
375 | goto dai_trigger_end; | |
376 | ||
690602fc | 377 | ret = rsnd_dai_call(start, io, priv); |
cdaa3cdf KM |
378 | if (ret < 0) |
379 | goto dai_trigger_end; | |
1536a968 KM |
380 | break; |
381 | case SNDRV_PCM_TRIGGER_STOP: | |
690602fc | 382 | ret = rsnd_dai_call(stop, io, priv); |
cdaa3cdf KM |
383 | if (ret < 0) |
384 | goto dai_trigger_end; | |
385 | ||
690602fc | 386 | ret = rsnd_dai_call(quit, io, priv); |
cdaa3cdf KM |
387 | if (ret < 0) |
388 | goto dai_trigger_end; | |
389 | ||
3337744a KM |
390 | ret = rsnd_platform_call(priv, dai, stop, ssi_id); |
391 | if (ret < 0) | |
392 | goto dai_trigger_end; | |
1536a968 KM |
393 | break; |
394 | default: | |
395 | ret = -EINVAL; | |
396 | } | |
397 | ||
398 | dai_trigger_end: | |
399 | rsnd_unlock(priv, flags); | |
400 | ||
401 | return ret; | |
402 | } | |
403 | ||
404 | static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) | |
405 | { | |
406 | struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); | |
407 | ||
408 | /* set master/slave audio interface */ | |
409 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | |
410 | case SND_SOC_DAIFMT_CBM_CFM: | |
e1508289 | 411 | rdai->clk_master = 0; |
1536a968 KM |
412 | break; |
413 | case SND_SOC_DAIFMT_CBS_CFS: | |
e1508289 | 414 | rdai->clk_master = 1; /* codec is slave, cpu is master */ |
1536a968 KM |
415 | break; |
416 | default: | |
417 | return -EINVAL; | |
418 | } | |
419 | ||
1536a968 KM |
420 | /* set format */ |
421 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | |
422 | case SND_SOC_DAIFMT_I2S: | |
423 | rdai->sys_delay = 0; | |
424 | rdai->data_alignment = 0; | |
1a7889ca | 425 | rdai->frm_clk_inv = 0; |
1536a968 KM |
426 | break; |
427 | case SND_SOC_DAIFMT_LEFT_J: | |
428 | rdai->sys_delay = 1; | |
429 | rdai->data_alignment = 0; | |
1a7889ca | 430 | rdai->frm_clk_inv = 1; |
1536a968 KM |
431 | break; |
432 | case SND_SOC_DAIFMT_RIGHT_J: | |
433 | rdai->sys_delay = 1; | |
434 | rdai->data_alignment = 1; | |
1a7889ca KM |
435 | rdai->frm_clk_inv = 1; |
436 | break; | |
437 | } | |
438 | ||
439 | /* set clock inversion */ | |
440 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | |
441 | case SND_SOC_DAIFMT_NB_IF: | |
442 | rdai->bit_clk_inv = rdai->bit_clk_inv; | |
443 | rdai->frm_clk_inv = !rdai->frm_clk_inv; | |
444 | break; | |
445 | case SND_SOC_DAIFMT_IB_NF: | |
446 | rdai->bit_clk_inv = !rdai->bit_clk_inv; | |
447 | rdai->frm_clk_inv = rdai->frm_clk_inv; | |
448 | break; | |
449 | case SND_SOC_DAIFMT_IB_IF: | |
450 | rdai->bit_clk_inv = !rdai->bit_clk_inv; | |
451 | rdai->frm_clk_inv = !rdai->frm_clk_inv; | |
452 | break; | |
453 | case SND_SOC_DAIFMT_NB_NF: | |
454 | default: | |
1536a968 KM |
455 | break; |
456 | } | |
457 | ||
458 | return 0; | |
459 | } | |
460 | ||
461 | static const struct snd_soc_dai_ops rsnd_soc_dai_ops = { | |
462 | .trigger = rsnd_soc_dai_trigger, | |
463 | .set_fmt = rsnd_soc_dai_set_fmt, | |
464 | }; | |
465 | ||
739f9502 KM |
466 | #define rsnd_path_parse(priv, io, type) \ |
467 | ({ \ | |
468 | struct rsnd_mod *mod; \ | |
469 | int ret = 0; \ | |
470 | int id = -1; \ | |
471 | \ | |
472 | if (rsnd_is_enable_path(io, type)) { \ | |
473 | id = rsnd_info_id(priv, io, type); \ | |
474 | if (id >= 0) { \ | |
475 | mod = rsnd_##type##_mod_get(priv, id); \ | |
476 | ret = rsnd_dai_connect(mod, io); \ | |
477 | } \ | |
478 | } \ | |
479 | ret; \ | |
480 | }) | |
481 | ||
d3a76823 KM |
482 | #define rsnd_path_break(priv, io, type) \ |
483 | { \ | |
484 | struct rsnd_mod *mod; \ | |
485 | int id = -1; \ | |
486 | \ | |
487 | if (rsnd_is_enable_path(io, type)) { \ | |
488 | id = rsnd_info_id(priv, io, type); \ | |
489 | if (id >= 0) { \ | |
490 | mod = rsnd_##type##_mod_get(priv, id); \ | |
491 | rsnd_dai_disconnect(mod, io); \ | |
492 | } \ | |
493 | } \ | |
494 | } | |
495 | ||
9bfed6cf KM |
496 | static int rsnd_path_init(struct rsnd_priv *priv, |
497 | struct rsnd_dai *rdai, | |
498 | struct rsnd_dai_stream *io) | |
499 | { | |
9bfed6cf | 500 | int ret; |
9bfed6cf KM |
501 | |
502 | /* | |
503 | * Gen1 is created by SRU/SSI, and this SRU is base module of | |
504 | * Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU) | |
505 | * | |
506 | * Easy image is.. | |
507 | * Gen1 SRU = Gen2 SCU + SSIU + etc | |
508 | * | |
509 | * Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is | |
510 | * using fixed path. | |
9bfed6cf | 511 | */ |
9bfed6cf | 512 | |
ba9c949f | 513 | /* SRC */ |
739f9502 KM |
514 | ret = rsnd_path_parse(priv, io, src); |
515 | if (ret < 0) | |
516 | return ret; | |
9bfed6cf KM |
517 | |
518 | /* SSI */ | |
739f9502 KM |
519 | ret = rsnd_path_parse(priv, io, ssi); |
520 | if (ret < 0) | |
521 | return ret; | |
9bfed6cf | 522 | |
bff58ea4 KM |
523 | /* DVC */ |
524 | ret = rsnd_path_parse(priv, io, dvc); | |
525 | if (ret < 0) | |
526 | return ret; | |
9bfed6cf KM |
527 | |
528 | return ret; | |
529 | } | |
530 | ||
90e8e50f KM |
531 | static void rsnd_of_parse_dai(struct platform_device *pdev, |
532 | const struct rsnd_of_data *of_data, | |
533 | struct rsnd_priv *priv) | |
534 | { | |
535 | struct device_node *dai_node, *dai_np; | |
536 | struct device_node *ssi_node, *ssi_np; | |
537 | struct device_node *src_node, *src_np; | |
34cb6123 | 538 | struct device_node *dvc_node, *dvc_np; |
90e8e50f KM |
539 | struct device_node *playback, *capture; |
540 | struct rsnd_dai_platform_info *dai_info; | |
541 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); | |
542 | struct device *dev = &pdev->dev; | |
543 | int nr, i; | |
34cb6123 | 544 | int dai_i, ssi_i, src_i, dvc_i; |
90e8e50f KM |
545 | |
546 | if (!of_data) | |
547 | return; | |
548 | ||
549 | dai_node = of_get_child_by_name(dev->of_node, "rcar_sound,dai"); | |
550 | if (!dai_node) | |
551 | return; | |
552 | ||
553 | nr = of_get_child_count(dai_node); | |
554 | if (!nr) | |
555 | return; | |
556 | ||
557 | dai_info = devm_kzalloc(dev, | |
558 | sizeof(struct rsnd_dai_platform_info) * nr, | |
559 | GFP_KERNEL); | |
560 | if (!dai_info) { | |
561 | dev_err(dev, "dai info allocation error\n"); | |
562 | return; | |
563 | } | |
564 | ||
565 | info->dai_info_nr = nr; | |
566 | info->dai_info = dai_info; | |
567 | ||
568 | ssi_node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi"); | |
569 | src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src"); | |
34cb6123 | 570 | dvc_node = of_get_child_by_name(dev->of_node, "rcar_sound,dvc"); |
90e8e50f KM |
571 | |
572 | #define mod_parse(name) \ | |
573 | if (name##_node) { \ | |
574 | struct rsnd_##name##_platform_info *name##_info; \ | |
575 | \ | |
576 | name##_i = 0; \ | |
577 | for_each_child_of_node(name##_node, name##_np) { \ | |
578 | name##_info = info->name##_info + name##_i; \ | |
579 | \ | |
580 | if (name##_np == playback) \ | |
581 | dai_info->playback.name = name##_info; \ | |
582 | if (name##_np == capture) \ | |
583 | dai_info->capture.name = name##_info; \ | |
584 | \ | |
585 | name##_i++; \ | |
586 | } \ | |
587 | } | |
588 | ||
589 | /* | |
590 | * parse all dai | |
591 | */ | |
592 | dai_i = 0; | |
593 | for_each_child_of_node(dai_node, dai_np) { | |
594 | dai_info = info->dai_info + dai_i; | |
595 | ||
596 | for (i = 0;; i++) { | |
597 | ||
598 | playback = of_parse_phandle(dai_np, "playback", i); | |
599 | capture = of_parse_phandle(dai_np, "capture", i); | |
600 | ||
601 | if (!playback && !capture) | |
602 | break; | |
603 | ||
604 | mod_parse(ssi); | |
605 | mod_parse(src); | |
34cb6123 | 606 | mod_parse(dvc); |
90e8e50f | 607 | |
a493b6a6 JL |
608 | of_node_put(playback); |
609 | of_node_put(capture); | |
90e8e50f KM |
610 | } |
611 | ||
612 | dai_i++; | |
613 | } | |
614 | } | |
615 | ||
1536a968 | 616 | static int rsnd_dai_probe(struct platform_device *pdev, |
90e8e50f | 617 | const struct rsnd_of_data *of_data, |
1536a968 KM |
618 | struct rsnd_priv *priv) |
619 | { | |
620 | struct snd_soc_dai_driver *drv; | |
78f13d0c | 621 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
1536a968 | 622 | struct rsnd_dai *rdai; |
29e69fd2 | 623 | struct rsnd_ssi_platform_info *pmod, *cmod; |
1536a968 | 624 | struct device *dev = rsnd_priv_to_dev(priv); |
90e8e50f | 625 | int dai_nr; |
4b4dab82 KM |
626 | int i; |
627 | ||
90e8e50f KM |
628 | rsnd_of_parse_dai(pdev, of_data, priv); |
629 | ||
90e8e50f | 630 | dai_nr = info->dai_info_nr; |
4b4dab82 KM |
631 | if (!dai_nr) { |
632 | dev_err(dev, "no dai\n"); | |
633 | return -EIO; | |
634 | } | |
1536a968 KM |
635 | |
636 | drv = devm_kzalloc(dev, sizeof(*drv) * dai_nr, GFP_KERNEL); | |
637 | rdai = devm_kzalloc(dev, sizeof(*rdai) * dai_nr, GFP_KERNEL); | |
638 | if (!drv || !rdai) { | |
639 | dev_err(dev, "dai allocate failed\n"); | |
640 | return -ENOMEM; | |
641 | } | |
642 | ||
ecba9e72 | 643 | priv->rdai_nr = dai_nr; |
49848073 KM |
644 | priv->daidrv = drv; |
645 | priv->rdai = rdai; | |
646 | ||
1536a968 | 647 | for (i = 0; i < dai_nr; i++) { |
1536a968 | 648 | |
7c57d76f KM |
649 | pmod = info->dai_info[i].playback.ssi; |
650 | cmod = info->dai_info[i].capture.ssi; | |
1536a968 KM |
651 | |
652 | /* | |
653 | * init rsnd_dai | |
654 | */ | |
1536a968 | 655 | snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i); |
1b13d118 | 656 | rdai[i].priv = priv; |
1536a968 KM |
657 | |
658 | /* | |
659 | * init snd_soc_dai_driver | |
660 | */ | |
661 | drv[i].name = rdai[i].name; | |
662 | drv[i].ops = &rsnd_soc_dai_ops; | |
4b4dab82 | 663 | if (pmod) { |
f8c3c309 KM |
664 | snprintf(rdai[i].playback.name, RSND_DAI_NAME_SIZE, |
665 | "DAI%d Playback", i); | |
666 | ||
1536a968 KM |
667 | drv[i].playback.rates = RSND_RATES; |
668 | drv[i].playback.formats = RSND_FMTS; | |
669 | drv[i].playback.channels_min = 2; | |
670 | drv[i].playback.channels_max = 2; | |
f8c3c309 | 671 | drv[i].playback.stream_name = rdai[i].playback.name; |
389933d9 | 672 | |
29e69fd2 | 673 | rdai[i].playback.info = &info->dai_info[i].playback; |
54cb5562 | 674 | rdai[i].playback.rdai = rdai + i; |
9bfed6cf | 675 | rsnd_path_init(priv, &rdai[i], &rdai[i].playback); |
1536a968 | 676 | } |
4b4dab82 | 677 | if (cmod) { |
f8c3c309 KM |
678 | snprintf(rdai[i].capture.name, RSND_DAI_NAME_SIZE, |
679 | "DAI%d Capture", i); | |
680 | ||
1536a968 KM |
681 | drv[i].capture.rates = RSND_RATES; |
682 | drv[i].capture.formats = RSND_FMTS; | |
683 | drv[i].capture.channels_min = 2; | |
684 | drv[i].capture.channels_max = 2; | |
f8c3c309 | 685 | drv[i].capture.stream_name = rdai[i].capture.name; |
389933d9 | 686 | |
29e69fd2 | 687 | rdai[i].capture.info = &info->dai_info[i].capture; |
54cb5562 | 688 | rdai[i].capture.rdai = rdai + i; |
9bfed6cf | 689 | rsnd_path_init(priv, &rdai[i], &rdai[i].capture); |
1536a968 KM |
690 | } |
691 | ||
4b4dab82 KM |
692 | dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name, |
693 | pmod ? "play" : " -- ", | |
694 | cmod ? "capture" : " -- "); | |
1536a968 KM |
695 | } |
696 | ||
1536a968 KM |
697 | return 0; |
698 | } | |
699 | ||
1536a968 KM |
700 | /* |
701 | * pcm ops | |
702 | */ | |
703 | static struct snd_pcm_hardware rsnd_pcm_hardware = { | |
704 | .info = SNDRV_PCM_INFO_INTERLEAVED | | |
705 | SNDRV_PCM_INFO_MMAP | | |
706c6621 | 706 | SNDRV_PCM_INFO_MMAP_VALID, |
1536a968 KM |
707 | .buffer_bytes_max = 64 * 1024, |
708 | .period_bytes_min = 32, | |
709 | .period_bytes_max = 8192, | |
710 | .periods_min = 1, | |
711 | .periods_max = 32, | |
712 | .fifo_size = 256, | |
713 | }; | |
714 | ||
715 | static int rsnd_pcm_open(struct snd_pcm_substream *substream) | |
716 | { | |
717 | struct snd_pcm_runtime *runtime = substream->runtime; | |
718 | int ret = 0; | |
719 | ||
720 | snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware); | |
721 | ||
722 | ret = snd_pcm_hw_constraint_integer(runtime, | |
723 | SNDRV_PCM_HW_PARAM_PERIODS); | |
724 | ||
725 | return ret; | |
726 | } | |
727 | ||
728 | static int rsnd_hw_params(struct snd_pcm_substream *substream, | |
729 | struct snd_pcm_hw_params *hw_params) | |
730 | { | |
731 | return snd_pcm_lib_malloc_pages(substream, | |
732 | params_buffer_bytes(hw_params)); | |
733 | } | |
734 | ||
735 | static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream) | |
736 | { | |
737 | struct snd_pcm_runtime *runtime = substream->runtime; | |
738 | struct snd_soc_dai *dai = rsnd_substream_to_dai(substream); | |
739 | struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); | |
740 | struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream); | |
741 | ||
742 | return bytes_to_frames(runtime, io->byte_pos); | |
743 | } | |
744 | ||
745 | static struct snd_pcm_ops rsnd_pcm_ops = { | |
746 | .open = rsnd_pcm_open, | |
747 | .ioctl = snd_pcm_lib_ioctl, | |
748 | .hw_params = rsnd_hw_params, | |
749 | .hw_free = snd_pcm_lib_free_pages, | |
750 | .pointer = rsnd_pointer, | |
751 | }; | |
752 | ||
170a2497 KM |
753 | /* |
754 | * snd_kcontrol | |
755 | */ | |
756 | #define kcontrol_to_cfg(kctrl) ((struct rsnd_kctrl_cfg *)kctrl->private_value) | |
757 | static int rsnd_kctrl_info(struct snd_kcontrol *kctrl, | |
758 | struct snd_ctl_elem_info *uinfo) | |
759 | { | |
760 | struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl); | |
761 | ||
762 | if (cfg->texts) { | |
763 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
764 | uinfo->count = cfg->size; | |
765 | uinfo->value.enumerated.items = cfg->max; | |
766 | if (uinfo->value.enumerated.item >= cfg->max) | |
767 | uinfo->value.enumerated.item = cfg->max - 1; | |
768 | strlcpy(uinfo->value.enumerated.name, | |
769 | cfg->texts[uinfo->value.enumerated.item], | |
770 | sizeof(uinfo->value.enumerated.name)); | |
771 | } else { | |
772 | uinfo->count = cfg->size; | |
773 | uinfo->value.integer.min = 0; | |
774 | uinfo->value.integer.max = cfg->max; | |
775 | uinfo->type = (cfg->max == 1) ? | |
776 | SNDRV_CTL_ELEM_TYPE_BOOLEAN : | |
777 | SNDRV_CTL_ELEM_TYPE_INTEGER; | |
778 | } | |
779 | ||
780 | return 0; | |
781 | } | |
782 | ||
783 | static int rsnd_kctrl_get(struct snd_kcontrol *kctrl, | |
784 | struct snd_ctl_elem_value *uc) | |
785 | { | |
786 | struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl); | |
787 | int i; | |
788 | ||
789 | for (i = 0; i < cfg->size; i++) | |
790 | if (cfg->texts) | |
791 | uc->value.enumerated.item[i] = cfg->val[i]; | |
792 | else | |
793 | uc->value.integer.value[i] = cfg->val[i]; | |
794 | ||
795 | return 0; | |
796 | } | |
797 | ||
798 | static int rsnd_kctrl_put(struct snd_kcontrol *kctrl, | |
799 | struct snd_ctl_elem_value *uc) | |
800 | { | |
801 | struct rsnd_mod *mod = snd_kcontrol_chip(kctrl); | |
802 | struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl); | |
803 | int i, change = 0; | |
804 | ||
805 | for (i = 0; i < cfg->size; i++) { | |
806 | if (cfg->texts) { | |
807 | change |= (uc->value.enumerated.item[i] != cfg->val[i]); | |
808 | cfg->val[i] = uc->value.enumerated.item[i]; | |
809 | } else { | |
810 | change |= (uc->value.integer.value[i] != cfg->val[i]); | |
811 | cfg->val[i] = uc->value.integer.value[i]; | |
812 | } | |
813 | } | |
814 | ||
815 | if (change) | |
816 | cfg->update(mod); | |
817 | ||
818 | return change; | |
819 | } | |
820 | ||
821 | static int __rsnd_kctrl_new(struct rsnd_mod *mod, | |
170a2497 KM |
822 | struct snd_soc_pcm_runtime *rtd, |
823 | const unsigned char *name, | |
824 | struct rsnd_kctrl_cfg *cfg, | |
825 | void (*update)(struct rsnd_mod *mod)) | |
826 | { | |
827 | struct snd_card *card = rtd->card->snd_card; | |
828 | struct snd_kcontrol *kctrl; | |
829 | struct snd_kcontrol_new knew = { | |
830 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
831 | .name = name, | |
832 | .info = rsnd_kctrl_info, | |
833 | .get = rsnd_kctrl_get, | |
834 | .put = rsnd_kctrl_put, | |
835 | .private_value = (unsigned long)cfg, | |
836 | }; | |
837 | int ret; | |
838 | ||
839 | kctrl = snd_ctl_new1(&knew, mod); | |
840 | if (!kctrl) | |
841 | return -ENOMEM; | |
842 | ||
843 | ret = snd_ctl_add(card, kctrl); | |
d1f83d6e KM |
844 | if (ret < 0) { |
845 | snd_ctl_free_one(kctrl); | |
170a2497 | 846 | return ret; |
d1f83d6e | 847 | } |
170a2497 KM |
848 | |
849 | cfg->update = update; | |
d1f83d6e KM |
850 | cfg->card = card; |
851 | cfg->kctrl = kctrl; | |
170a2497 KM |
852 | |
853 | return 0; | |
854 | } | |
855 | ||
d1f83d6e KM |
856 | void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg) |
857 | { | |
858 | snd_ctl_remove(cfg->card, cfg->kctrl); | |
859 | } | |
860 | ||
170a2497 | 861 | int rsnd_kctrl_new_m(struct rsnd_mod *mod, |
170a2497 KM |
862 | struct snd_soc_pcm_runtime *rtd, |
863 | const unsigned char *name, | |
864 | void (*update)(struct rsnd_mod *mod), | |
865 | struct rsnd_kctrl_cfg_m *_cfg, | |
866 | u32 max) | |
867 | { | |
868 | _cfg->cfg.max = max; | |
869 | _cfg->cfg.size = RSND_DVC_CHANNELS; | |
870 | _cfg->cfg.val = _cfg->val; | |
f708d944 | 871 | return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update); |
170a2497 KM |
872 | } |
873 | ||
874 | int rsnd_kctrl_new_s(struct rsnd_mod *mod, | |
170a2497 KM |
875 | struct snd_soc_pcm_runtime *rtd, |
876 | const unsigned char *name, | |
877 | void (*update)(struct rsnd_mod *mod), | |
878 | struct rsnd_kctrl_cfg_s *_cfg, | |
879 | u32 max) | |
880 | { | |
881 | _cfg->cfg.max = max; | |
882 | _cfg->cfg.size = 1; | |
883 | _cfg->cfg.val = &_cfg->val; | |
f708d944 | 884 | return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update); |
170a2497 KM |
885 | } |
886 | ||
887 | int rsnd_kctrl_new_e(struct rsnd_mod *mod, | |
170a2497 KM |
888 | struct snd_soc_pcm_runtime *rtd, |
889 | const unsigned char *name, | |
890 | struct rsnd_kctrl_cfg_s *_cfg, | |
891 | void (*update)(struct rsnd_mod *mod), | |
892 | const char * const *texts, | |
893 | u32 max) | |
894 | { | |
895 | _cfg->cfg.max = max; | |
896 | _cfg->cfg.size = 1; | |
897 | _cfg->cfg.val = &_cfg->val; | |
898 | _cfg->cfg.texts = texts; | |
f708d944 | 899 | return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update); |
170a2497 KM |
900 | } |
901 | ||
1536a968 KM |
902 | /* |
903 | * snd_soc_platform | |
904 | */ | |
905 | ||
906 | #define PREALLOC_BUFFER (32 * 1024) | |
907 | #define PREALLOC_BUFFER_MAX (32 * 1024) | |
908 | ||
909 | static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd) | |
910 | { | |
7c63f3c0 KM |
911 | struct snd_soc_dai *dai = rtd->cpu_dai; |
912 | struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); | |
913 | int ret; | |
bff58ea4 | 914 | |
690602fc | 915 | ret = rsnd_dai_call(pcm_new, &rdai->playback, rtd); |
7c63f3c0 KM |
916 | if (ret) |
917 | return ret; | |
bff58ea4 | 918 | |
690602fc | 919 | ret = rsnd_dai_call(pcm_new, &rdai->capture, rtd); |
7c63f3c0 KM |
920 | if (ret) |
921 | return ret; | |
bff58ea4 | 922 | |
1536a968 KM |
923 | return snd_pcm_lib_preallocate_pages_for_all( |
924 | rtd->pcm, | |
925 | SNDRV_DMA_TYPE_DEV, | |
926 | rtd->card->snd_card->dev, | |
927 | PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); | |
928 | } | |
929 | ||
1536a968 KM |
930 | static struct snd_soc_platform_driver rsnd_soc_platform = { |
931 | .ops = &rsnd_pcm_ops, | |
932 | .pcm_new = rsnd_pcm_new, | |
1536a968 KM |
933 | }; |
934 | ||
935 | static const struct snd_soc_component_driver rsnd_soc_component = { | |
936 | .name = "rsnd", | |
937 | }; | |
938 | ||
d3a76823 | 939 | static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv, |
f708d944 | 940 | struct rsnd_dai_stream *io) |
d3a76823 | 941 | { |
d3a76823 KM |
942 | int ret; |
943 | ||
690602fc | 944 | ret = rsnd_dai_call(probe, io, priv); |
d3a76823 KM |
945 | if (ret == -EAGAIN) { |
946 | /* | |
947 | * Fallback to PIO mode | |
948 | */ | |
949 | ||
950 | /* | |
951 | * call "remove" for SSI/SRC/DVC | |
952 | * SSI will be switch to PIO mode if it was DMA mode | |
953 | * see | |
954 | * rsnd_dma_init() | |
97463e19 | 955 | * rsnd_ssi_fallback() |
d3a76823 | 956 | */ |
690602fc | 957 | rsnd_dai_call(remove, io, priv); |
d3a76823 KM |
958 | |
959 | /* | |
960 | * remove SRC/DVC from DAI, | |
961 | */ | |
962 | rsnd_path_break(priv, io, src); | |
963 | rsnd_path_break(priv, io, dvc); | |
964 | ||
97463e19 KM |
965 | /* |
966 | * fallback | |
967 | */ | |
690602fc | 968 | rsnd_dai_call(fallback, io, priv); |
97463e19 | 969 | |
d3a76823 KM |
970 | /* |
971 | * retry to "probe". | |
972 | * DAI has SSI which is PIO mode only now. | |
973 | */ | |
690602fc | 974 | ret = rsnd_dai_call(probe, io, priv); |
d3a76823 KM |
975 | } |
976 | ||
977 | return ret; | |
978 | } | |
979 | ||
1536a968 KM |
980 | /* |
981 | * rsnd probe | |
982 | */ | |
983 | static int rsnd_probe(struct platform_device *pdev) | |
984 | { | |
985 | struct rcar_snd_info *info; | |
986 | struct rsnd_priv *priv; | |
987 | struct device *dev = &pdev->dev; | |
7681f6ac | 988 | struct rsnd_dai *rdai; |
90e8e50f KM |
989 | const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev); |
990 | const struct rsnd_of_data *of_data; | |
d1ac970f | 991 | int (*probe_func[])(struct platform_device *pdev, |
90e8e50f | 992 | const struct rsnd_of_data *of_data, |
d1ac970f KM |
993 | struct rsnd_priv *priv) = { |
994 | rsnd_gen_probe, | |
288f392e | 995 | rsnd_dma_probe, |
d1ac970f | 996 | rsnd_ssi_probe, |
ba9c949f | 997 | rsnd_src_probe, |
bff58ea4 | 998 | rsnd_dvc_probe, |
d1ac970f KM |
999 | rsnd_adg_probe, |
1000 | rsnd_dai_probe, | |
1001 | }; | |
1002 | int ret, i; | |
1536a968 | 1003 | |
90e8e50f KM |
1004 | info = NULL; |
1005 | of_data = NULL; | |
1006 | if (of_id) { | |
1007 | info = devm_kzalloc(&pdev->dev, | |
1008 | sizeof(struct rcar_snd_info), GFP_KERNEL); | |
1009 | of_data = of_id->data; | |
1010 | } else { | |
1011 | info = pdev->dev.platform_data; | |
1012 | } | |
1013 | ||
1536a968 KM |
1014 | if (!info) { |
1015 | dev_err(dev, "driver needs R-Car sound information\n"); | |
1016 | return -ENODEV; | |
1017 | } | |
1018 | ||
1019 | /* | |
1020 | * init priv data | |
1021 | */ | |
1022 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | |
1023 | if (!priv) { | |
1024 | dev_err(dev, "priv allocate failed\n"); | |
1025 | return -ENODEV; | |
1026 | } | |
1027 | ||
9f464f8e | 1028 | priv->pdev = pdev; |
1536a968 KM |
1029 | priv->info = info; |
1030 | spin_lock_init(&priv->lock); | |
1031 | ||
1032 | /* | |
1033 | * init each module | |
1034 | */ | |
d1ac970f | 1035 | for (i = 0; i < ARRAY_SIZE(probe_func); i++) { |
90e8e50f | 1036 | ret = probe_func[i](pdev, of_data, priv); |
d1ac970f KM |
1037 | if (ret) |
1038 | return ret; | |
1039 | } | |
07539c1d | 1040 | |
7681f6ac | 1041 | for_each_rsnd_dai(rdai, priv, i) { |
f708d944 | 1042 | ret = rsnd_rdai_continuance_probe(priv, &rdai->playback); |
7681f6ac | 1043 | if (ret) |
d62a3dcd | 1044 | goto exit_snd_probe; |
dfc9403b | 1045 | |
f708d944 | 1046 | ret = rsnd_rdai_continuance_probe(priv, &rdai->capture); |
7681f6ac | 1047 | if (ret) |
d62a3dcd | 1048 | goto exit_snd_probe; |
7681f6ac | 1049 | } |
4b4dab82 | 1050 | |
1536a968 KM |
1051 | /* |
1052 | * asoc register | |
1053 | */ | |
1054 | ret = snd_soc_register_platform(dev, &rsnd_soc_platform); | |
1055 | if (ret < 0) { | |
1056 | dev_err(dev, "cannot snd soc register\n"); | |
1057 | return ret; | |
1058 | } | |
1059 | ||
1060 | ret = snd_soc_register_component(dev, &rsnd_soc_component, | |
ecba9e72 | 1061 | priv->daidrv, rsnd_rdai_nr(priv)); |
1536a968 KM |
1062 | if (ret < 0) { |
1063 | dev_err(dev, "cannot snd dai register\n"); | |
1064 | goto exit_snd_soc; | |
1065 | } | |
1066 | ||
1067 | dev_set_drvdata(dev, priv); | |
1068 | ||
1069 | pm_runtime_enable(dev); | |
1070 | ||
1071 | dev_info(dev, "probed\n"); | |
1072 | return ret; | |
1073 | ||
1074 | exit_snd_soc: | |
1075 | snd_soc_unregister_platform(dev); | |
d62a3dcd KM |
1076 | exit_snd_probe: |
1077 | for_each_rsnd_dai(rdai, priv, i) { | |
690602fc KM |
1078 | rsnd_dai_call(remove, &rdai->playback, priv); |
1079 | rsnd_dai_call(remove, &rdai->capture, priv); | |
d62a3dcd | 1080 | } |
1536a968 KM |
1081 | |
1082 | return ret; | |
1083 | } | |
1084 | ||
1085 | static int rsnd_remove(struct platform_device *pdev) | |
1086 | { | |
1087 | struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev); | |
7681f6ac | 1088 | struct rsnd_dai *rdai; |
2f78dd7f KM |
1089 | void (*remove_func[])(struct platform_device *pdev, |
1090 | struct rsnd_priv *priv) = { | |
1091 | rsnd_ssi_remove, | |
1092 | rsnd_src_remove, | |
1093 | rsnd_dvc_remove, | |
1094 | }; | |
d62a3dcd | 1095 | int ret = 0, i; |
1536a968 KM |
1096 | |
1097 | pm_runtime_disable(&pdev->dev); | |
1098 | ||
7681f6ac | 1099 | for_each_rsnd_dai(rdai, priv, i) { |
690602fc KM |
1100 | ret |= rsnd_dai_call(remove, &rdai->playback, priv); |
1101 | ret |= rsnd_dai_call(remove, &rdai->capture, priv); | |
7681f6ac | 1102 | } |
1536a968 | 1103 | |
2f78dd7f KM |
1104 | for (i = 0; i < ARRAY_SIZE(remove_func); i++) |
1105 | remove_func[i](pdev, priv); | |
1106 | ||
d7c42ff8 KM |
1107 | snd_soc_unregister_component(&pdev->dev); |
1108 | snd_soc_unregister_platform(&pdev->dev); | |
1109 | ||
d62a3dcd | 1110 | return ret; |
1536a968 KM |
1111 | } |
1112 | ||
1113 | static struct platform_driver rsnd_driver = { | |
1114 | .driver = { | |
1115 | .name = "rcar_sound", | |
90e8e50f | 1116 | .of_match_table = rsnd_of_match, |
1536a968 KM |
1117 | }, |
1118 | .probe = rsnd_probe, | |
1119 | .remove = rsnd_remove, | |
1120 | }; | |
1121 | module_platform_driver(rsnd_driver); | |
1122 | ||
1123 | MODULE_LICENSE("GPL"); | |
1124 | MODULE_DESCRIPTION("Renesas R-Car audio driver"); | |
1125 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); | |
1126 | MODULE_ALIAS("platform:rcar-pcm-audio"); |