1 // SPDX-License-Identifier: GPL-2.0 2 // 3 // soc-component.c 4 // 5 // Copyright 2009-2011 Wolfson Microelectronics PLC. 6 // Copyright (C) 2019 Renesas Electronics Corp. 7 // 8 // Mark Brown <broonie@opensource.wolfsonmicro.com> 9 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 10 // 11 #include <linux/module.h> 12 #include <sound/soc.h> 13 14 #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret) 15 static inline int _soc_component_ret(struct snd_soc_component *component, 16 const char *func, int ret) 17 { 18 /* Positive/Zero values are not errors */ 19 if (ret >= 0) 20 return ret; 21 22 /* Negative values might be errors */ 23 switch (ret) { 24 case -EPROBE_DEFER: 25 case -ENOTSUPP: 26 break; 27 default: 28 dev_err(component->dev, 29 "ASoC: error at %s on %s: %d\n", 30 func, component->name, ret); 31 } 32 33 return ret; 34 } 35 36 int snd_soc_component_initialize(struct snd_soc_component *component, 37 const struct snd_soc_component_driver *driver, 38 struct device *dev, const char *name) 39 { 40 INIT_LIST_HEAD(&component->dai_list); 41 INIT_LIST_HEAD(&component->dobj_list); 42 INIT_LIST_HEAD(&component->card_list); 43 mutex_init(&component->io_mutex); 44 45 component->name = name; 46 component->dev = dev; 47 component->driver = driver; 48 49 return 0; 50 } 51 52 void snd_soc_component_set_aux(struct snd_soc_component *component, 53 struct snd_soc_aux_dev *aux) 54 { 55 component->init = (aux) ? aux->init : NULL; 56 } 57 58 int snd_soc_component_init(struct snd_soc_component *component) 59 { 60 int ret = 0; 61 62 if (component->init) 63 ret = component->init(component); 64 65 return soc_component_ret(component, ret); 66 } 67 68 /** 69 * snd_soc_component_set_sysclk - configure COMPONENT system or master clock. 70 * @component: COMPONENT 71 * @clk_id: DAI specific clock ID 72 * @source: Source for the clock 73 * @freq: new clock frequency in Hz 74 * @dir: new clock direction - input/output. 75 * 76 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. 77 */ 78 int snd_soc_component_set_sysclk(struct snd_soc_component *component, 79 int clk_id, int source, unsigned int freq, 80 int dir) 81 { 82 int ret = -ENOTSUPP; 83 84 if (component->driver->set_sysclk) 85 ret = component->driver->set_sysclk(component, clk_id, source, 86 freq, dir); 87 88 return soc_component_ret(component, ret); 89 } 90 EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk); 91 92 /* 93 * snd_soc_component_set_pll - configure component PLL. 94 * @component: COMPONENT 95 * @pll_id: DAI specific PLL ID 96 * @source: DAI specific source for the PLL 97 * @freq_in: PLL input clock frequency in Hz 98 * @freq_out: requested PLL output clock frequency in Hz 99 * 100 * Configures and enables PLL to generate output clock based on input clock. 101 */ 102 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, 103 int source, unsigned int freq_in, 104 unsigned int freq_out) 105 { 106 int ret = -EINVAL; 107 108 if (component->driver->set_pll) 109 ret = component->driver->set_pll(component, pll_id, source, 110 freq_in, freq_out); 111 112 return soc_component_ret(component, ret); 113 } 114 EXPORT_SYMBOL_GPL(snd_soc_component_set_pll); 115 116 void snd_soc_component_seq_notifier(struct snd_soc_component *component, 117 enum snd_soc_dapm_type type, int subseq) 118 { 119 if (component->driver->seq_notifier) 120 component->driver->seq_notifier(component, type, subseq); 121 } 122 123 int snd_soc_component_stream_event(struct snd_soc_component *component, 124 int event) 125 { 126 int ret = 0; 127 128 if (component->driver->stream_event) 129 ret = component->driver->stream_event(component, event); 130 131 return soc_component_ret(component, ret); 132 } 133 134 int snd_soc_component_set_bias_level(struct snd_soc_component *component, 135 enum snd_soc_bias_level level) 136 { 137 int ret = 0; 138 139 if (component->driver->set_bias_level) 140 ret = component->driver->set_bias_level(component, level); 141 142 return soc_component_ret(component, ret); 143 } 144 145 static int soc_component_pin(struct snd_soc_component *component, 146 const char *pin, 147 int (*pin_func)(struct snd_soc_dapm_context *dapm, 148 const char *pin)) 149 { 150 struct snd_soc_dapm_context *dapm = 151 snd_soc_component_get_dapm(component); 152 char *full_name; 153 int ret; 154 155 if (!component->name_prefix) { 156 ret = pin_func(dapm, pin); 157 goto end; 158 } 159 160 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); 161 if (!full_name) { 162 ret = -ENOMEM; 163 goto end; 164 } 165 166 ret = pin_func(dapm, full_name); 167 kfree(full_name); 168 end: 169 return soc_component_ret(component, ret); 170 } 171 172 int snd_soc_component_enable_pin(struct snd_soc_component *component, 173 const char *pin) 174 { 175 return soc_component_pin(component, pin, snd_soc_dapm_enable_pin); 176 } 177 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin); 178 179 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component, 180 const char *pin) 181 { 182 return soc_component_pin(component, pin, snd_soc_dapm_enable_pin_unlocked); 183 } 184 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked); 185 186 int snd_soc_component_disable_pin(struct snd_soc_component *component, 187 const char *pin) 188 { 189 return soc_component_pin(component, pin, snd_soc_dapm_disable_pin); 190 } 191 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin); 192 193 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component, 194 const char *pin) 195 { 196 return soc_component_pin(component, pin, snd_soc_dapm_disable_pin_unlocked); 197 } 198 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked); 199 200 int snd_soc_component_nc_pin(struct snd_soc_component *component, 201 const char *pin) 202 { 203 return soc_component_pin(component, pin, snd_soc_dapm_nc_pin); 204 } 205 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin); 206 207 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component, 208 const char *pin) 209 { 210 return soc_component_pin(component, pin, snd_soc_dapm_nc_pin_unlocked); 211 } 212 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked); 213 214 int snd_soc_component_get_pin_status(struct snd_soc_component *component, 215 const char *pin) 216 { 217 return soc_component_pin(component, pin, snd_soc_dapm_get_pin_status); 218 } 219 EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status); 220 221 int snd_soc_component_force_enable_pin(struct snd_soc_component *component, 222 const char *pin) 223 { 224 return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin); 225 } 226 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin); 227 228 int snd_soc_component_force_enable_pin_unlocked( 229 struct snd_soc_component *component, 230 const char *pin) 231 { 232 return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin_unlocked); 233 } 234 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked); 235 236 /** 237 * snd_soc_component_set_jack - configure component jack. 238 * @component: COMPONENTs 239 * @jack: structure to use for the jack 240 * @data: can be used if codec driver need extra data for configuring jack 241 * 242 * Configures and enables jack detection function. 243 */ 244 int snd_soc_component_set_jack(struct snd_soc_component *component, 245 struct snd_soc_jack *jack, void *data) 246 { 247 int ret = -ENOTSUPP; 248 249 if (component->driver->set_jack) 250 ret = component->driver->set_jack(component, jack, data); 251 252 return soc_component_ret(component, ret); 253 } 254 EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); 255 256 int snd_soc_component_module_get(struct snd_soc_component *component, 257 int upon_open) 258 { 259 int ret = 0; 260 261 if (component->driver->module_get_upon_open == !!upon_open && 262 !try_module_get(component->dev->driver->owner)) 263 ret = -ENODEV; 264 265 return soc_component_ret(component, ret); 266 } 267 268 void snd_soc_component_module_put(struct snd_soc_component *component, 269 int upon_open) 270 { 271 if (component->driver->module_get_upon_open == !!upon_open) 272 module_put(component->dev->driver->owner); 273 } 274 275 int snd_soc_component_open(struct snd_soc_component *component, 276 struct snd_pcm_substream *substream) 277 { 278 int ret = 0; 279 280 if (component->driver->open) 281 ret = component->driver->open(component, substream); 282 283 return soc_component_ret(component, ret); 284 } 285 286 int snd_soc_component_close(struct snd_soc_component *component, 287 struct snd_pcm_substream *substream) 288 { 289 int ret = 0; 290 291 if (component->driver->close) 292 ret = component->driver->close(component, substream); 293 294 return soc_component_ret(component, ret); 295 } 296 297 void snd_soc_component_suspend(struct snd_soc_component *component) 298 { 299 if (component->driver->suspend) 300 component->driver->suspend(component); 301 component->suspended = 1; 302 } 303 304 void snd_soc_component_resume(struct snd_soc_component *component) 305 { 306 if (component->driver->resume) 307 component->driver->resume(component); 308 component->suspended = 0; 309 } 310 311 int snd_soc_component_is_suspended(struct snd_soc_component *component) 312 { 313 return component->suspended; 314 } 315 316 int snd_soc_component_probe(struct snd_soc_component *component) 317 { 318 int ret = 0; 319 320 if (component->driver->probe) 321 ret = component->driver->probe(component); 322 323 return soc_component_ret(component, ret); 324 } 325 326 void snd_soc_component_remove(struct snd_soc_component *component) 327 { 328 if (component->driver->remove) 329 component->driver->remove(component); 330 } 331 332 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, 333 struct device_node *ep) 334 { 335 int ret = -ENOTSUPP; 336 337 if (component->driver->of_xlate_dai_id) 338 ret = component->driver->of_xlate_dai_id(component, ep); 339 340 return soc_component_ret(component, ret); 341 } 342 343 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, 344 struct of_phandle_args *args, 345 const char **dai_name) 346 { 347 if (component->driver->of_xlate_dai_name) 348 return component->driver->of_xlate_dai_name(component, 349 args, dai_name); 350 /* 351 * Don't use soc_component_ret here because we may not want to report 352 * the error just yet. If a device has more than one component, the 353 * first may not match and we don't want spam the log with this. 354 */ 355 return -ENOTSUPP; 356 } 357 358 void snd_soc_component_setup_regmap(struct snd_soc_component *component) 359 { 360 int val_bytes = regmap_get_val_bytes(component->regmap); 361 362 /* Errors are legitimate for non-integer byte multiples */ 363 if (val_bytes > 0) 364 component->val_bytes = val_bytes; 365 } 366 367 #ifdef CONFIG_REGMAP 368 369 /** 370 * snd_soc_component_init_regmap() - Initialize regmap instance for the 371 * component 372 * @component: The component for which to initialize the regmap instance 373 * @regmap: The regmap instance that should be used by the component 374 * 375 * This function allows deferred assignment of the regmap instance that is 376 * associated with the component. Only use this if the regmap instance is not 377 * yet ready when the component is registered. The function must also be called 378 * before the first IO attempt of the component. 379 */ 380 void snd_soc_component_init_regmap(struct snd_soc_component *component, 381 struct regmap *regmap) 382 { 383 component->regmap = regmap; 384 snd_soc_component_setup_regmap(component); 385 } 386 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); 387 388 /** 389 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the 390 * component 391 * @component: The component for which to de-initialize the regmap instance 392 * 393 * Calls regmap_exit() on the regmap instance associated to the component and 394 * removes the regmap instance from the component. 395 * 396 * This function should only be used if snd_soc_component_init_regmap() was used 397 * to initialize the regmap instance. 398 */ 399 void snd_soc_component_exit_regmap(struct snd_soc_component *component) 400 { 401 regmap_exit(component->regmap); 402 component->regmap = NULL; 403 } 404 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); 405 406 #endif 407 408 static unsigned int soc_component_read_no_lock( 409 struct snd_soc_component *component, 410 unsigned int reg) 411 { 412 int ret; 413 unsigned int val = 0; 414 415 if (component->regmap) 416 ret = regmap_read(component->regmap, reg, &val); 417 else if (component->driver->read) { 418 ret = 0; 419 val = component->driver->read(component, reg); 420 } 421 else 422 ret = -EIO; 423 424 if (ret < 0) 425 soc_component_ret(component, ret); 426 427 return val; 428 } 429 430 /** 431 * snd_soc_component_read() - Read register value 432 * @component: Component to read from 433 * @reg: Register to read 434 * 435 * Return: read value 436 */ 437 unsigned int snd_soc_component_read(struct snd_soc_component *component, 438 unsigned int reg) 439 { 440 unsigned int val; 441 442 mutex_lock(&component->io_mutex); 443 val = soc_component_read_no_lock(component, reg); 444 mutex_unlock(&component->io_mutex); 445 446 return val; 447 } 448 EXPORT_SYMBOL_GPL(snd_soc_component_read); 449 450 static int soc_component_write_no_lock( 451 struct snd_soc_component *component, 452 unsigned int reg, unsigned int val) 453 { 454 int ret = -EIO; 455 456 if (component->regmap) 457 ret = regmap_write(component->regmap, reg, val); 458 else if (component->driver->write) 459 ret = component->driver->write(component, reg, val); 460 461 return soc_component_ret(component, ret); 462 } 463 464 /** 465 * snd_soc_component_write() - Write register value 466 * @component: Component to write to 467 * @reg: Register to write 468 * @val: Value to write to the register 469 * 470 * Return: 0 on success, a negative error code otherwise. 471 */ 472 int snd_soc_component_write(struct snd_soc_component *component, 473 unsigned int reg, unsigned int val) 474 { 475 int ret; 476 477 mutex_lock(&component->io_mutex); 478 ret = soc_component_write_no_lock(component, reg, val); 479 mutex_unlock(&component->io_mutex); 480 481 return ret; 482 } 483 EXPORT_SYMBOL_GPL(snd_soc_component_write); 484 485 static int snd_soc_component_update_bits_legacy( 486 struct snd_soc_component *component, unsigned int reg, 487 unsigned int mask, unsigned int val, bool *change) 488 { 489 unsigned int old, new; 490 int ret = 0; 491 492 mutex_lock(&component->io_mutex); 493 494 old = soc_component_read_no_lock(component, reg); 495 496 new = (old & ~mask) | (val & mask); 497 *change = old != new; 498 if (*change) 499 ret = soc_component_write_no_lock(component, reg, new); 500 501 mutex_unlock(&component->io_mutex); 502 503 return soc_component_ret(component, ret); 504 } 505 506 /** 507 * snd_soc_component_update_bits() - Perform read/modify/write cycle 508 * @component: Component to update 509 * @reg: Register to update 510 * @mask: Mask that specifies which bits to update 511 * @val: New value for the bits specified by mask 512 * 513 * Return: 1 if the operation was successful and the value of the register 514 * changed, 0 if the operation was successful, but the value did not change. 515 * Returns a negative error code otherwise. 516 */ 517 int snd_soc_component_update_bits(struct snd_soc_component *component, 518 unsigned int reg, unsigned int mask, unsigned int val) 519 { 520 bool change; 521 int ret; 522 523 if (component->regmap) 524 ret = regmap_update_bits_check(component->regmap, reg, mask, 525 val, &change); 526 else 527 ret = snd_soc_component_update_bits_legacy(component, reg, 528 mask, val, &change); 529 530 if (ret < 0) 531 return soc_component_ret(component, ret); 532 return change; 533 } 534 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits); 535 536 /** 537 * snd_soc_component_update_bits_async() - Perform asynchronous 538 * read/modify/write cycle 539 * @component: Component to update 540 * @reg: Register to update 541 * @mask: Mask that specifies which bits to update 542 * @val: New value for the bits specified by mask 543 * 544 * This function is similar to snd_soc_component_update_bits(), but the update 545 * operation is scheduled asynchronously. This means it may not be completed 546 * when the function returns. To make sure that all scheduled updates have been 547 * completed snd_soc_component_async_complete() must be called. 548 * 549 * Return: 1 if the operation was successful and the value of the register 550 * changed, 0 if the operation was successful, but the value did not change. 551 * Returns a negative error code otherwise. 552 */ 553 int snd_soc_component_update_bits_async(struct snd_soc_component *component, 554 unsigned int reg, unsigned int mask, unsigned int val) 555 { 556 bool change; 557 int ret; 558 559 if (component->regmap) 560 ret = regmap_update_bits_check_async(component->regmap, reg, 561 mask, val, &change); 562 else 563 ret = snd_soc_component_update_bits_legacy(component, reg, 564 mask, val, &change); 565 566 if (ret < 0) 567 return soc_component_ret(component, ret); 568 return change; 569 } 570 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async); 571 572 /** 573 * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed 574 * @component: Component for which to wait 575 * 576 * This function blocks until all asynchronous I/O which has previously been 577 * scheduled using snd_soc_component_update_bits_async() has completed. 578 */ 579 void snd_soc_component_async_complete(struct snd_soc_component *component) 580 { 581 if (component->regmap) 582 regmap_async_complete(component->regmap); 583 } 584 EXPORT_SYMBOL_GPL(snd_soc_component_async_complete); 585 586 /** 587 * snd_soc_component_test_bits - Test register for change 588 * @component: component 589 * @reg: Register to test 590 * @mask: Mask that specifies which bits to test 591 * @value: Value to test against 592 * 593 * Tests a register with a new value and checks if the new value is 594 * different from the old value. 595 * 596 * Return: 1 for change, otherwise 0. 597 */ 598 int snd_soc_component_test_bits(struct snd_soc_component *component, 599 unsigned int reg, unsigned int mask, unsigned int value) 600 { 601 unsigned int old, new; 602 603 old = snd_soc_component_read(component, reg); 604 new = (old & ~mask) | value; 605 return old != new; 606 } 607 EXPORT_SYMBOL_GPL(snd_soc_component_test_bits); 608 609 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream) 610 { 611 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 612 struct snd_soc_component *component; 613 int i; 614 615 /* FIXME: use 1st pointer */ 616 for_each_rtd_components(rtd, i, component) 617 if (component->driver->pointer) 618 return component->driver->pointer(component, substream); 619 620 return 0; 621 } 622 623 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, 624 unsigned int cmd, void *arg) 625 { 626 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 627 struct snd_soc_component *component; 628 int i; 629 630 /* FIXME: use 1st ioctl */ 631 for_each_rtd_components(rtd, i, component) 632 if (component->driver->ioctl) 633 return soc_component_ret( 634 component, 635 component->driver->ioctl(component, 636 substream, cmd, arg)); 637 638 return snd_pcm_lib_ioctl(substream, cmd, arg); 639 } 640 641 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream) 642 { 643 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 644 struct snd_soc_component *component; 645 int i, ret; 646 647 for_each_rtd_components(rtd, i, component) { 648 if (component->driver->sync_stop) { 649 ret = component->driver->sync_stop(component, 650 substream); 651 if (ret < 0) 652 return soc_component_ret(component, ret); 653 } 654 } 655 656 return 0; 657 } 658 659 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, 660 int channel, unsigned long pos, 661 void __user *buf, unsigned long bytes) 662 { 663 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 664 struct snd_soc_component *component; 665 int i; 666 667 /* FIXME. it returns 1st copy now */ 668 for_each_rtd_components(rtd, i, component) 669 if (component->driver->copy_user) 670 return soc_component_ret( 671 component, 672 component->driver->copy_user( 673 component, substream, channel, 674 pos, buf, bytes)); 675 676 return -EINVAL; 677 } 678 679 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, 680 unsigned long offset) 681 { 682 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 683 struct snd_soc_component *component; 684 struct page *page; 685 int i; 686 687 /* FIXME. it returns 1st page now */ 688 for_each_rtd_components(rtd, i, component) { 689 if (component->driver->page) { 690 page = component->driver->page(component, 691 substream, offset); 692 if (page) 693 return page; 694 } 695 } 696 697 return NULL; 698 } 699 700 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, 701 struct vm_area_struct *vma) 702 { 703 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 704 struct snd_soc_component *component; 705 int i; 706 707 /* FIXME. it returns 1st mmap now */ 708 for_each_rtd_components(rtd, i, component) 709 if (component->driver->mmap) 710 return soc_component_ret( 711 component, 712 component->driver->mmap(component, 713 substream, vma)); 714 715 return -EINVAL; 716 } 717 718 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd) 719 { 720 struct snd_soc_component *component; 721 int ret; 722 int i; 723 724 for_each_rtd_components(rtd, i, component) { 725 if (component->driver->pcm_construct) { 726 ret = component->driver->pcm_construct(component, rtd); 727 if (ret < 0) 728 return soc_component_ret(component, ret); 729 } 730 } 731 732 return 0; 733 } 734 735 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd) 736 { 737 struct snd_soc_component *component; 738 int i; 739 740 if (!rtd->pcm) 741 return; 742 743 for_each_rtd_components(rtd, i, component) 744 if (component->driver->pcm_destruct) 745 component->driver->pcm_destruct(component, rtd->pcm); 746 } 747 748 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream) 749 { 750 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 751 struct snd_soc_component *component; 752 int i, ret; 753 754 for_each_rtd_components(rtd, i, component) { 755 if (component->driver->prepare) { 756 ret = component->driver->prepare(component, substream); 757 if (ret < 0) 758 return soc_component_ret(component, ret); 759 } 760 } 761 762 return 0; 763 } 764 765 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream, 766 struct snd_pcm_hw_params *params, 767 struct snd_soc_component **last) 768 { 769 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 770 struct snd_soc_component *component; 771 int i, ret; 772 773 for_each_rtd_components(rtd, i, component) { 774 if (component->driver->hw_params) { 775 ret = component->driver->hw_params(component, 776 substream, params); 777 if (ret < 0) { 778 *last = component; 779 return soc_component_ret(component, ret); 780 } 781 } 782 } 783 784 *last = NULL; 785 return 0; 786 } 787 788 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream, 789 struct snd_soc_component *last) 790 { 791 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 792 struct snd_soc_component *component; 793 int i, ret; 794 795 for_each_rtd_components(rtd, i, component) { 796 if (component == last) 797 break; 798 799 if (component->driver->hw_free) { 800 ret = component->driver->hw_free(component, substream); 801 if (ret < 0) 802 soc_component_ret(component, ret); 803 } 804 } 805 } 806 807 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream, 808 int cmd) 809 { 810 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 811 struct snd_soc_component *component; 812 int i, ret; 813 814 for_each_rtd_components(rtd, i, component) { 815 if (component->driver->trigger) { 816 ret = component->driver->trigger(component, substream, cmd); 817 if (ret < 0) 818 return soc_component_ret(component, ret); 819 } 820 } 821 822 return 0; 823 } 824