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