1 // SPDX-License-Identifier: GPL-2.0 2 // 3 // soc-dai.c 4 // 5 // Copyright (C) 2019 Renesas Electronics Corp. 6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 7 // 8 9 #include <sound/soc.h> 10 #include <sound/soc-dai.h> 11 #include <sound/soc-link.h> 12 13 #define soc_dai_ret(dai, ret) _soc_dai_ret(dai, __func__, ret) 14 static inline int _soc_dai_ret(struct snd_soc_dai *dai, 15 const char *func, int ret) 16 { 17 /* Positive, Zero values are not errors */ 18 if (ret >= 0) 19 return ret; 20 21 /* Negative values might be errors */ 22 switch (ret) { 23 case -EPROBE_DEFER: 24 case -ENOTSUPP: 25 break; 26 default: 27 dev_err(dai->dev, 28 "ASoC: error at %s on %s: %d\n", 29 func, dai->name, ret); 30 } 31 32 return ret; 33 } 34 35 /* 36 * We might want to check substream by using list. 37 * In such case, we can update these macros. 38 */ 39 #define soc_dai_mark_push(dai, substream, tgt) ((dai)->mark_##tgt = substream) 40 #define soc_dai_mark_pop(dai, substream, tgt) ((dai)->mark_##tgt = NULL) 41 #define soc_dai_mark_match(dai, substream, tgt) ((dai)->mark_##tgt == substream) 42 43 /** 44 * snd_soc_dai_set_sysclk - configure DAI system or master clock. 45 * @dai: DAI 46 * @clk_id: DAI specific clock ID 47 * @freq: new clock frequency in Hz 48 * @dir: new clock direction - input/output. 49 * 50 * Configures the DAI master (MCLK) or system (SYSCLK) clocking. 51 */ 52 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 53 unsigned int freq, int dir) 54 { 55 int ret; 56 57 if (dai->driver->ops && 58 dai->driver->ops->set_sysclk) 59 ret = dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); 60 else 61 ret = snd_soc_component_set_sysclk(dai->component, clk_id, 0, 62 freq, dir); 63 64 return soc_dai_ret(dai, ret); 65 } 66 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); 67 68 /** 69 * snd_soc_dai_set_clkdiv - configure DAI clock dividers. 70 * @dai: DAI 71 * @div_id: DAI specific clock divider ID 72 * @div: new clock divisor. 73 * 74 * Configures the clock dividers. This is used to derive the best DAI bit and 75 * frame clocks from the system or master clock. It's best to set the DAI bit 76 * and frame clocks as low as possible to save system power. 77 */ 78 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 79 int div_id, int div) 80 { 81 int ret = -EINVAL; 82 83 if (dai->driver->ops && 84 dai->driver->ops->set_clkdiv) 85 ret = dai->driver->ops->set_clkdiv(dai, div_id, div); 86 87 return soc_dai_ret(dai, ret); 88 } 89 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); 90 91 /** 92 * snd_soc_dai_set_pll - configure DAI PLL. 93 * @dai: DAI 94 * @pll_id: DAI specific PLL ID 95 * @source: DAI specific source for the PLL 96 * @freq_in: PLL input clock frequency in Hz 97 * @freq_out: requested PLL output clock frequency in Hz 98 * 99 * Configures and enables PLL to generate output clock based on input clock. 100 */ 101 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 102 unsigned int freq_in, unsigned int freq_out) 103 { 104 int ret; 105 106 if (dai->driver->ops && 107 dai->driver->ops->set_pll) 108 ret = dai->driver->ops->set_pll(dai, pll_id, source, 109 freq_in, freq_out); 110 else 111 ret = snd_soc_component_set_pll(dai->component, pll_id, source, 112 freq_in, freq_out); 113 114 return soc_dai_ret(dai, ret); 115 } 116 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); 117 118 /** 119 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio. 120 * @dai: DAI 121 * @ratio: Ratio of BCLK to Sample rate. 122 * 123 * Configures the DAI for a preset BCLK to sample rate ratio. 124 */ 125 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) 126 { 127 int ret = -ENOTSUPP; 128 129 if (dai->driver->ops && 130 dai->driver->ops->set_bclk_ratio) 131 ret = dai->driver->ops->set_bclk_ratio(dai, ratio); 132 133 return soc_dai_ret(dai, ret); 134 } 135 EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio); 136 137 int snd_soc_dai_get_fmt_max_priority(struct snd_soc_pcm_runtime *rtd) 138 { 139 struct snd_soc_dai *dai; 140 int i, max = 0; 141 142 /* 143 * return max num if *ALL* DAIs have .auto_selectable_formats 144 */ 145 for_each_rtd_dais(rtd, i, dai) { 146 if (dai->driver->ops && 147 dai->driver->ops->num_auto_selectable_formats) 148 max = max(max, dai->driver->ops->num_auto_selectable_formats); 149 else 150 return 0; 151 } 152 153 return max; 154 } 155 156 /** 157 * snd_soc_dai_get_fmt - get supported audio format. 158 * @dai: DAI 159 * @priority: priority level of supported audio format. 160 * 161 * This should return only formats implemented with high 162 * quality by the DAI so that the core can configure a 163 * format which will work well with other devices. 164 * For example devices which don't support both edges of the 165 * LRCLK signal in I2S style formats should only list DSP 166 * modes. This will mean that sometimes fewer formats 167 * are reported here than are supported by set_fmt(). 168 */ 169 u64 snd_soc_dai_get_fmt(struct snd_soc_dai *dai, int priority) 170 { 171 const struct snd_soc_dai_ops *ops = dai->driver->ops; 172 u64 fmt = 0; 173 int i, max = 0, until = priority; 174 175 /* 176 * Collect auto_selectable_formats until priority 177 * 178 * ex) 179 * auto_selectable_formats[] = { A, B, C }; 180 * (A, B, C = SND_SOC_POSSIBLE_DAIFMT_xxx) 181 * 182 * priority = 1 : A 183 * priority = 2 : A | B 184 * priority = 3 : A | B | C 185 * priority = 4 : A | B | C 186 * ... 187 */ 188 if (ops) 189 max = ops->num_auto_selectable_formats; 190 191 if (max < until) 192 until = max; 193 194 for (i = 0; i < until; i++) 195 fmt |= ops->auto_selectable_formats[i]; 196 197 return fmt; 198 } 199 200 /** 201 * snd_soc_dai_set_fmt - configure DAI hardware audio format. 202 * @dai: DAI 203 * @fmt: SND_SOC_DAIFMT_* format value. 204 * 205 * Configures the DAI hardware format and clocking. 206 */ 207 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 208 { 209 int ret = -ENOTSUPP; 210 211 if (dai->driver->ops && dai->driver->ops->set_fmt) 212 ret = dai->driver->ops->set_fmt(dai, fmt); 213 214 return soc_dai_ret(dai, ret); 215 } 216 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); 217 218 /** 219 * snd_soc_xlate_tdm_slot_mask - generate tx/rx slot mask. 220 * @slots: Number of slots in use. 221 * @tx_mask: bitmask representing active TX slots. 222 * @rx_mask: bitmask representing active RX slots. 223 * 224 * Generates the TDM tx and rx slot default masks for DAI. 225 */ 226 static int snd_soc_xlate_tdm_slot_mask(unsigned int slots, 227 unsigned int *tx_mask, 228 unsigned int *rx_mask) 229 { 230 if (*tx_mask || *rx_mask) 231 return 0; 232 233 if (!slots) 234 return -EINVAL; 235 236 *tx_mask = (1 << slots) - 1; 237 *rx_mask = (1 << slots) - 1; 238 239 return 0; 240 } 241 242 /** 243 * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation 244 * @dai: The DAI to configure 245 * @tx_mask: bitmask representing active TX slots. 246 * @rx_mask: bitmask representing active RX slots. 247 * @slots: Number of slots in use. 248 * @slot_width: Width in bits for each slot. 249 * 250 * This function configures the specified DAI for TDM operation. @slot contains 251 * the total number of slots of the TDM stream and @slot_with the width of each 252 * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the 253 * active slots of the TDM stream for the specified DAI, i.e. which slots the 254 * DAI should write to or read from. If a bit is set the corresponding slot is 255 * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to 256 * the first slot, bit 1 to the second slot and so on. The first active slot 257 * maps to the first channel of the DAI, the second active slot to the second 258 * channel and so on. 259 * 260 * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask, 261 * @rx_mask and @slot_width will be ignored. 262 * 263 * Returns 0 on success, a negative error code otherwise. 264 */ 265 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 266 unsigned int tx_mask, unsigned int rx_mask, 267 int slots, int slot_width) 268 { 269 int ret = -ENOTSUPP; 270 int stream; 271 unsigned int *tdm_mask[] = { 272 &tx_mask, 273 &rx_mask, 274 }; 275 276 if (dai->driver->ops && 277 dai->driver->ops->xlate_tdm_slot_mask) 278 dai->driver->ops->xlate_tdm_slot_mask(slots, 279 &tx_mask, &rx_mask); 280 else 281 snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask); 282 283 for_each_pcm_streams(stream) 284 snd_soc_dai_tdm_mask_set(dai, stream, *tdm_mask[stream]); 285 286 if (dai->driver->ops && 287 dai->driver->ops->set_tdm_slot) 288 ret = dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 289 slots, slot_width); 290 return soc_dai_ret(dai, ret); 291 } 292 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 293 294 /** 295 * snd_soc_dai_set_channel_map - configure DAI audio channel map 296 * @dai: DAI 297 * @tx_num: how many TX channels 298 * @tx_slot: pointer to an array which imply the TX slot number channel 299 * 0~num-1 uses 300 * @rx_num: how many RX channels 301 * @rx_slot: pointer to an array which imply the RX slot number channel 302 * 0~num-1 uses 303 * 304 * configure the relationship between channel number and TDM slot number. 305 */ 306 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, 307 unsigned int tx_num, unsigned int *tx_slot, 308 unsigned int rx_num, unsigned int *rx_slot) 309 { 310 int ret = -ENOTSUPP; 311 312 if (dai->driver->ops && 313 dai->driver->ops->set_channel_map) 314 ret = dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, 315 rx_num, rx_slot); 316 return soc_dai_ret(dai, ret); 317 } 318 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); 319 320 /** 321 * snd_soc_dai_get_channel_map - Get DAI audio channel map 322 * @dai: DAI 323 * @tx_num: how many TX channels 324 * @tx_slot: pointer to an array which imply the TX slot number channel 325 * 0~num-1 uses 326 * @rx_num: how many RX channels 327 * @rx_slot: pointer to an array which imply the RX slot number channel 328 * 0~num-1 uses 329 */ 330 int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai, 331 unsigned int *tx_num, unsigned int *tx_slot, 332 unsigned int *rx_num, unsigned int *rx_slot) 333 { 334 int ret = -ENOTSUPP; 335 336 if (dai->driver->ops && 337 dai->driver->ops->get_channel_map) 338 ret = dai->driver->ops->get_channel_map(dai, tx_num, tx_slot, 339 rx_num, rx_slot); 340 return soc_dai_ret(dai, ret); 341 } 342 EXPORT_SYMBOL_GPL(snd_soc_dai_get_channel_map); 343 344 /** 345 * snd_soc_dai_set_tristate - configure DAI system or master clock. 346 * @dai: DAI 347 * @tristate: tristate enable 348 * 349 * Tristates the DAI so that others can use it. 350 */ 351 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 352 { 353 int ret = -EINVAL; 354 355 if (dai->driver->ops && 356 dai->driver->ops->set_tristate) 357 ret = dai->driver->ops->set_tristate(dai, tristate); 358 359 return soc_dai_ret(dai, ret); 360 } 361 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); 362 363 /** 364 * snd_soc_dai_digital_mute - configure DAI system or master clock. 365 * @dai: DAI 366 * @mute: mute enable 367 * @direction: stream to mute 368 * 369 * Mutes the DAI DAC. 370 */ 371 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, 372 int direction) 373 { 374 int ret = -ENOTSUPP; 375 376 /* 377 * ignore if direction was CAPTURE 378 * and it had .no_capture_mute flag 379 */ 380 if (dai->driver->ops && 381 dai->driver->ops->mute_stream && 382 (direction == SNDRV_PCM_STREAM_PLAYBACK || 383 !dai->driver->ops->no_capture_mute)) 384 ret = dai->driver->ops->mute_stream(dai, mute, direction); 385 386 return soc_dai_ret(dai, ret); 387 } 388 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); 389 390 int snd_soc_dai_hw_params(struct snd_soc_dai *dai, 391 struct snd_pcm_substream *substream, 392 struct snd_pcm_hw_params *params) 393 { 394 int ret = 0; 395 396 if (dai->driver->ops && 397 dai->driver->ops->hw_params) 398 ret = dai->driver->ops->hw_params(substream, params, dai); 399 400 /* mark substream if succeeded */ 401 if (ret == 0) 402 soc_dai_mark_push(dai, substream, hw_params); 403 404 return soc_dai_ret(dai, ret); 405 } 406 407 void snd_soc_dai_hw_free(struct snd_soc_dai *dai, 408 struct snd_pcm_substream *substream, 409 int rollback) 410 { 411 if (rollback && !soc_dai_mark_match(dai, substream, hw_params)) 412 return; 413 414 if (dai->driver->ops && 415 dai->driver->ops->hw_free) 416 dai->driver->ops->hw_free(substream, dai); 417 418 /* remove marked substream */ 419 soc_dai_mark_pop(dai, substream, hw_params); 420 } 421 422 int snd_soc_dai_startup(struct snd_soc_dai *dai, 423 struct snd_pcm_substream *substream) 424 { 425 int ret = 0; 426 427 if (!snd_soc_dai_stream_valid(dai, substream->stream)) 428 return 0; 429 430 if (dai->driver->ops && 431 dai->driver->ops->startup) 432 ret = dai->driver->ops->startup(substream, dai); 433 434 /* mark substream if succeeded */ 435 if (ret == 0) 436 soc_dai_mark_push(dai, substream, startup); 437 438 return soc_dai_ret(dai, ret); 439 } 440 441 void snd_soc_dai_shutdown(struct snd_soc_dai *dai, 442 struct snd_pcm_substream *substream, 443 int rollback) 444 { 445 if (!snd_soc_dai_stream_valid(dai, substream->stream)) 446 return; 447 448 if (rollback && !soc_dai_mark_match(dai, substream, startup)) 449 return; 450 451 if (dai->driver->ops && 452 dai->driver->ops->shutdown) 453 dai->driver->ops->shutdown(substream, dai); 454 455 /* remove marked substream */ 456 soc_dai_mark_pop(dai, substream, startup); 457 } 458 459 int snd_soc_dai_compress_new(struct snd_soc_dai *dai, 460 struct snd_soc_pcm_runtime *rtd, int num) 461 { 462 int ret = -ENOTSUPP; 463 if (dai->driver->compress_new) 464 ret = dai->driver->compress_new(rtd, num); 465 return soc_dai_ret(dai, ret); 466 } 467 468 /* 469 * snd_soc_dai_stream_valid() - check if a DAI supports the given stream 470 * 471 * Returns true if the DAI supports the indicated stream type. 472 */ 473 bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int dir) 474 { 475 struct snd_soc_pcm_stream *stream = snd_soc_dai_get_pcm_stream(dai, dir); 476 477 /* If the codec specifies any channels at all, it supports the stream */ 478 return stream->channels_min; 479 } 480 481 /* 482 * snd_soc_dai_link_set_capabilities() - set dai_link properties based on its DAIs 483 */ 484 void snd_soc_dai_link_set_capabilities(struct snd_soc_dai_link *dai_link) 485 { 486 bool supported[SNDRV_PCM_STREAM_LAST + 1]; 487 int direction; 488 489 for_each_pcm_streams(direction) { 490 struct snd_soc_dai_link_component *cpu; 491 struct snd_soc_dai_link_component *codec; 492 struct snd_soc_dai *dai; 493 bool supported_cpu = false; 494 bool supported_codec = false; 495 int i; 496 497 for_each_link_cpus(dai_link, i, cpu) { 498 dai = snd_soc_find_dai_with_mutex(cpu); 499 if (dai && snd_soc_dai_stream_valid(dai, direction)) { 500 supported_cpu = true; 501 break; 502 } 503 } 504 for_each_link_codecs(dai_link, i, codec) { 505 dai = snd_soc_find_dai_with_mutex(codec); 506 if (dai && snd_soc_dai_stream_valid(dai, direction)) { 507 supported_codec = true; 508 break; 509 } 510 } 511 supported[direction] = supported_cpu && supported_codec; 512 } 513 514 dai_link->dpcm_playback = supported[SNDRV_PCM_STREAM_PLAYBACK]; 515 dai_link->dpcm_capture = supported[SNDRV_PCM_STREAM_CAPTURE]; 516 } 517 EXPORT_SYMBOL_GPL(snd_soc_dai_link_set_capabilities); 518 519 void snd_soc_dai_action(struct snd_soc_dai *dai, 520 int stream, int action) 521 { 522 /* see snd_soc_dai_stream_active() */ 523 dai->stream[stream].active += action; 524 525 /* see snd_soc_component_active() */ 526 dai->component->active += action; 527 } 528 EXPORT_SYMBOL_GPL(snd_soc_dai_action); 529 530 int snd_soc_dai_active(struct snd_soc_dai *dai) 531 { 532 int stream, active; 533 534 active = 0; 535 for_each_pcm_streams(stream) 536 active += dai->stream[stream].active; 537 538 return active; 539 } 540 EXPORT_SYMBOL_GPL(snd_soc_dai_active); 541 542 int snd_soc_pcm_dai_probe(struct snd_soc_pcm_runtime *rtd, int order) 543 { 544 struct snd_soc_dai *dai; 545 int i; 546 547 for_each_rtd_dais(rtd, i, dai) { 548 if (dai->driver->probe_order != order) 549 continue; 550 551 if (dai->probed) 552 continue; 553 554 if (dai->driver->probe) { 555 int ret = dai->driver->probe(dai); 556 557 if (ret < 0) 558 return soc_dai_ret(dai, ret); 559 } 560 561 dai->probed = 1; 562 } 563 564 return 0; 565 } 566 567 int snd_soc_pcm_dai_remove(struct snd_soc_pcm_runtime *rtd, int order) 568 { 569 struct snd_soc_dai *dai; 570 int i, r, ret = 0; 571 572 for_each_rtd_dais(rtd, i, dai) { 573 if (dai->driver->remove_order != order) 574 continue; 575 576 if (dai->probed && 577 dai->driver->remove) { 578 r = dai->driver->remove(dai); 579 if (r < 0) 580 ret = r; /* use last error */ 581 } 582 583 dai->probed = 0; 584 } 585 586 return ret; 587 } 588 589 int snd_soc_pcm_dai_new(struct snd_soc_pcm_runtime *rtd) 590 { 591 struct snd_soc_dai *dai; 592 int i; 593 594 for_each_rtd_dais(rtd, i, dai) { 595 if (dai->driver->pcm_new) { 596 int ret = dai->driver->pcm_new(rtd, dai); 597 if (ret < 0) 598 return soc_dai_ret(dai, ret); 599 } 600 } 601 602 return 0; 603 } 604 605 int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream) 606 { 607 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 608 struct snd_soc_dai *dai; 609 int i, ret; 610 611 for_each_rtd_dais(rtd, i, dai) { 612 if (!snd_soc_dai_stream_valid(dai, substream->stream)) 613 continue; 614 if (dai->driver->ops && 615 dai->driver->ops->prepare) { 616 ret = dai->driver->ops->prepare(substream, dai); 617 if (ret < 0) 618 return soc_dai_ret(dai, ret); 619 } 620 } 621 622 return 0; 623 } 624 625 static int soc_dai_trigger(struct snd_soc_dai *dai, 626 struct snd_pcm_substream *substream, int cmd) 627 { 628 int ret = 0; 629 630 if (!snd_soc_dai_stream_valid(dai, substream->stream)) 631 return 0; 632 633 if (dai->driver->ops && 634 dai->driver->ops->trigger) 635 ret = dai->driver->ops->trigger(substream, cmd, dai); 636 637 return soc_dai_ret(dai, ret); 638 } 639 640 int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream, 641 int cmd, int rollback) 642 { 643 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 644 struct snd_soc_dai *dai; 645 int i, r, ret = 0; 646 647 switch (cmd) { 648 case SNDRV_PCM_TRIGGER_START: 649 case SNDRV_PCM_TRIGGER_RESUME: 650 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 651 for_each_rtd_dais(rtd, i, dai) { 652 ret = soc_dai_trigger(dai, substream, cmd); 653 if (ret < 0) 654 break; 655 soc_dai_mark_push(dai, substream, trigger); 656 } 657 break; 658 case SNDRV_PCM_TRIGGER_STOP: 659 case SNDRV_PCM_TRIGGER_SUSPEND: 660 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 661 for_each_rtd_dais(rtd, i, dai) { 662 if (rollback && !soc_dai_mark_match(dai, substream, trigger)) 663 continue; 664 665 r = soc_dai_trigger(dai, substream, cmd); 666 if (r < 0) 667 ret = r; /* use last ret */ 668 soc_dai_mark_pop(dai, substream, trigger); 669 } 670 } 671 672 return ret; 673 } 674 675 int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream, 676 int cmd) 677 { 678 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 679 struct snd_soc_dai *dai; 680 int i, ret; 681 682 for_each_rtd_dais(rtd, i, dai) { 683 if (dai->driver->ops && 684 dai->driver->ops->bespoke_trigger) { 685 ret = dai->driver->ops->bespoke_trigger(substream, 686 cmd, dai); 687 if (ret < 0) 688 return soc_dai_ret(dai, ret); 689 } 690 } 691 692 return 0; 693 } 694 695 void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream, 696 snd_pcm_sframes_t *cpu_delay, 697 snd_pcm_sframes_t *codec_delay) 698 { 699 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 700 struct snd_soc_dai *dai; 701 int i; 702 703 /* 704 * We're looking for the delay through the full audio path so it needs to 705 * be the maximum of the DAIs doing transmit and the maximum of the DAIs 706 * doing receive (ie, all CPUs and all CODECs) rather than just the maximum 707 * of all DAIs. 708 */ 709 710 /* for CPU */ 711 for_each_rtd_cpu_dais(rtd, i, dai) 712 if (dai->driver->ops && 713 dai->driver->ops->delay) 714 *cpu_delay = max(*cpu_delay, dai->driver->ops->delay(substream, dai)); 715 716 /* for Codec */ 717 for_each_rtd_codec_dais(rtd, i, dai) 718 if (dai->driver->ops && 719 dai->driver->ops->delay) 720 *codec_delay = max(*codec_delay, dai->driver->ops->delay(substream, dai)); 721 } 722 723 int snd_soc_dai_compr_startup(struct snd_soc_dai *dai, 724 struct snd_compr_stream *cstream) 725 { 726 int ret = 0; 727 728 if (dai->driver->cops && 729 dai->driver->cops->startup) 730 ret = dai->driver->cops->startup(cstream, dai); 731 732 /* mark cstream if succeeded */ 733 if (ret == 0) 734 soc_dai_mark_push(dai, cstream, compr_startup); 735 736 return soc_dai_ret(dai, ret); 737 } 738 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_startup); 739 740 void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai, 741 struct snd_compr_stream *cstream, 742 int rollback) 743 { 744 if (rollback && !soc_dai_mark_match(dai, cstream, compr_startup)) 745 return; 746 747 if (dai->driver->cops && 748 dai->driver->cops->shutdown) 749 dai->driver->cops->shutdown(cstream, dai); 750 751 /* remove marked cstream */ 752 soc_dai_mark_pop(dai, cstream, compr_startup); 753 } 754 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_shutdown); 755 756 int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai, 757 struct snd_compr_stream *cstream, int cmd) 758 { 759 int ret = 0; 760 761 if (dai->driver->cops && 762 dai->driver->cops->trigger) 763 ret = dai->driver->cops->trigger(cstream, cmd, dai); 764 765 return soc_dai_ret(dai, ret); 766 } 767 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_trigger); 768 769 int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai, 770 struct snd_compr_stream *cstream, 771 struct snd_compr_params *params) 772 { 773 int ret = 0; 774 775 if (dai->driver->cops && 776 dai->driver->cops->set_params) 777 ret = dai->driver->cops->set_params(cstream, params, dai); 778 779 return soc_dai_ret(dai, ret); 780 } 781 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_set_params); 782 783 int snd_soc_dai_compr_get_params(struct snd_soc_dai *dai, 784 struct snd_compr_stream *cstream, 785 struct snd_codec *params) 786 { 787 int ret = 0; 788 789 if (dai->driver->cops && 790 dai->driver->cops->get_params) 791 ret = dai->driver->cops->get_params(cstream, params, dai); 792 793 return soc_dai_ret(dai, ret); 794 } 795 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_get_params); 796 797 int snd_soc_dai_compr_ack(struct snd_soc_dai *dai, 798 struct snd_compr_stream *cstream, 799 size_t bytes) 800 { 801 int ret = 0; 802 803 if (dai->driver->cops && 804 dai->driver->cops->ack) 805 ret = dai->driver->cops->ack(cstream, bytes, dai); 806 807 return soc_dai_ret(dai, ret); 808 } 809 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_ack); 810 811 int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai, 812 struct snd_compr_stream *cstream, 813 struct snd_compr_tstamp *tstamp) 814 { 815 int ret = 0; 816 817 if (dai->driver->cops && 818 dai->driver->cops->pointer) 819 ret = dai->driver->cops->pointer(cstream, tstamp, dai); 820 821 return soc_dai_ret(dai, ret); 822 } 823 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_pointer); 824 825 int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai, 826 struct snd_compr_stream *cstream, 827 struct snd_compr_metadata *metadata) 828 { 829 int ret = 0; 830 831 if (dai->driver->cops && 832 dai->driver->cops->set_metadata) 833 ret = dai->driver->cops->set_metadata(cstream, metadata, dai); 834 835 return soc_dai_ret(dai, ret); 836 } 837 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_set_metadata); 838 839 int snd_soc_dai_compr_get_metadata(struct snd_soc_dai *dai, 840 struct snd_compr_stream *cstream, 841 struct snd_compr_metadata *metadata) 842 { 843 int ret = 0; 844 845 if (dai->driver->cops && 846 dai->driver->cops->get_metadata) 847 ret = dai->driver->cops->get_metadata(cstream, metadata, dai); 848 849 return soc_dai_ret(dai, ret); 850 } 851 EXPORT_SYMBOL_GPL(snd_soc_dai_compr_get_metadata); 852