1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright 2009-2011 Wolfson Microelectronics PLC.
6 // Copyright (C) 2019 Renesas Electronics Corp.
8 // Mark Brown <broonie@opensource.wolfsonmicro.com>
9 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
11 #include <linux/module.h>
12 #include <linux/pm_runtime.h>
13 #include <sound/soc.h>
15 #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret)
16 static inline int _soc_component_ret(struct snd_soc_component *component,
17 const char *func, int ret)
19 /* Positive/Zero values are not errors */
23 /* Negative values might be errors */
29 dev_err(component->dev,
30 "ASoC: error at %s on %s: %d\n",
31 func, component->name, ret);
38 * We might want to check substream by using list.
39 * In such case, we can update these macros.
41 #define soc_component_mark_push(component, substream, tgt) ((component)->mark_##tgt = substream)
42 #define soc_component_mark_pop(component, substream, tgt) ((component)->mark_##tgt = NULL)
43 #define soc_component_mark_match(component, substream, tgt) ((component)->mark_##tgt == substream)
45 void snd_soc_component_set_aux(struct snd_soc_component *component,
46 struct snd_soc_aux_dev *aux)
48 component->init = (aux) ? aux->init : NULL;
51 int snd_soc_component_init(struct snd_soc_component *component)
56 ret = component->init(component);
58 return soc_component_ret(component, ret);
62 * snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
63 * @component: COMPONENT
64 * @clk_id: DAI specific clock ID
65 * @source: Source for the clock
66 * @freq: new clock frequency in Hz
67 * @dir: new clock direction - input/output.
69 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
71 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
72 int clk_id, int source, unsigned int freq,
77 if (component->driver->set_sysclk)
78 ret = component->driver->set_sysclk(component, clk_id, source,
81 return soc_component_ret(component, ret);
83 EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
86 * snd_soc_component_set_pll - configure component PLL.
87 * @component: COMPONENT
88 * @pll_id: DAI specific PLL ID
89 * @source: DAI specific source for the PLL
90 * @freq_in: PLL input clock frequency in Hz
91 * @freq_out: requested PLL output clock frequency in Hz
93 * Configures and enables PLL to generate output clock based on input clock.
95 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
96 int source, unsigned int freq_in,
97 unsigned int freq_out)
101 if (component->driver->set_pll)
102 ret = component->driver->set_pll(component, pll_id, source,
105 return soc_component_ret(component, ret);
107 EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
109 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
110 enum snd_soc_dapm_type type, int subseq)
112 if (component->driver->seq_notifier)
113 component->driver->seq_notifier(component, type, subseq);
116 int snd_soc_component_stream_event(struct snd_soc_component *component,
121 if (component->driver->stream_event)
122 ret = component->driver->stream_event(component, event);
124 return soc_component_ret(component, ret);
127 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
128 enum snd_soc_bias_level level)
132 if (component->driver->set_bias_level)
133 ret = component->driver->set_bias_level(component, level);
135 return soc_component_ret(component, ret);
138 static int soc_component_pin(struct snd_soc_component *component,
140 int (*pin_func)(struct snd_soc_dapm_context *dapm,
143 struct snd_soc_dapm_context *dapm =
144 snd_soc_component_get_dapm(component);
148 if (!component->name_prefix) {
149 ret = pin_func(dapm, pin);
153 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
159 ret = pin_func(dapm, full_name);
162 return soc_component_ret(component, ret);
165 int snd_soc_component_enable_pin(struct snd_soc_component *component,
168 return soc_component_pin(component, pin, snd_soc_dapm_enable_pin);
170 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
172 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
175 return soc_component_pin(component, pin, snd_soc_dapm_enable_pin_unlocked);
177 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
179 int snd_soc_component_disable_pin(struct snd_soc_component *component,
182 return soc_component_pin(component, pin, snd_soc_dapm_disable_pin);
184 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
186 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
189 return soc_component_pin(component, pin, snd_soc_dapm_disable_pin_unlocked);
191 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
193 int snd_soc_component_nc_pin(struct snd_soc_component *component,
196 return soc_component_pin(component, pin, snd_soc_dapm_nc_pin);
198 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
200 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
203 return soc_component_pin(component, pin, snd_soc_dapm_nc_pin_unlocked);
205 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
207 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
210 return soc_component_pin(component, pin, snd_soc_dapm_get_pin_status);
212 EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
214 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
217 return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin);
219 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
221 int snd_soc_component_force_enable_pin_unlocked(
222 struct snd_soc_component *component,
225 return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin_unlocked);
227 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
230 * snd_soc_component_set_jack - configure component jack.
231 * @component: COMPONENTs
232 * @jack: structure to use for the jack
233 * @data: can be used if codec driver need extra data for configuring jack
235 * Configures and enables jack detection function.
237 int snd_soc_component_set_jack(struct snd_soc_component *component,
238 struct snd_soc_jack *jack, void *data)
242 if (component->driver->set_jack)
243 ret = component->driver->set_jack(component, jack, data);
245 return soc_component_ret(component, ret);
247 EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
249 int snd_soc_component_module_get(struct snd_soc_component *component,
250 struct snd_pcm_substream *substream,
255 if (component->driver->module_get_upon_open == !!upon_open &&
256 !try_module_get(component->dev->driver->owner))
259 /* mark substream if succeeded */
261 soc_component_mark_push(component, substream, module);
263 return soc_component_ret(component, ret);
266 void snd_soc_component_module_put(struct snd_soc_component *component,
267 struct snd_pcm_substream *substream,
268 int upon_open, int rollback)
270 if (rollback && !soc_component_mark_match(component, substream, module))
273 if (component->driver->module_get_upon_open == !!upon_open)
274 module_put(component->dev->driver->owner);
276 /* remove marked substream */
277 soc_component_mark_pop(component, substream, module);
280 int snd_soc_component_open(struct snd_soc_component *component,
281 struct snd_pcm_substream *substream)
285 if (component->driver->open)
286 ret = component->driver->open(component, substream);
288 /* mark substream if succeeded */
290 soc_component_mark_push(component, substream, open);
292 return soc_component_ret(component, ret);
295 int snd_soc_component_close(struct snd_soc_component *component,
296 struct snd_pcm_substream *substream,
301 if (rollback && !soc_component_mark_match(component, substream, open))
304 if (component->driver->close)
305 ret = component->driver->close(component, substream);
307 /* remove marked substream */
308 soc_component_mark_pop(component, substream, open);
310 return soc_component_ret(component, ret);
313 void snd_soc_component_suspend(struct snd_soc_component *component)
315 if (component->driver->suspend)
316 component->driver->suspend(component);
317 component->suspended = 1;
320 void snd_soc_component_resume(struct snd_soc_component *component)
322 if (component->driver->resume)
323 component->driver->resume(component);
324 component->suspended = 0;
327 int snd_soc_component_is_suspended(struct snd_soc_component *component)
329 return component->suspended;
332 int snd_soc_component_probe(struct snd_soc_component *component)
336 if (component->driver->probe)
337 ret = component->driver->probe(component);
339 return soc_component_ret(component, ret);
342 void snd_soc_component_remove(struct snd_soc_component *component)
344 if (component->driver->remove)
345 component->driver->remove(component);
348 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
349 struct device_node *ep)
353 if (component->driver->of_xlate_dai_id)
354 ret = component->driver->of_xlate_dai_id(component, ep);
356 return soc_component_ret(component, ret);
359 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
360 struct of_phandle_args *args,
361 const char **dai_name)
363 if (component->driver->of_xlate_dai_name)
364 return component->driver->of_xlate_dai_name(component,
367 * Don't use soc_component_ret here because we may not want to report
368 * the error just yet. If a device has more than one component, the
369 * first may not match and we don't want spam the log with this.
374 void snd_soc_component_setup_regmap(struct snd_soc_component *component)
376 int val_bytes = regmap_get_val_bytes(component->regmap);
378 /* Errors are legitimate for non-integer byte multiples */
380 component->val_bytes = val_bytes;
386 * snd_soc_component_init_regmap() - Initialize regmap instance for the
388 * @component: The component for which to initialize the regmap instance
389 * @regmap: The regmap instance that should be used by the component
391 * This function allows deferred assignment of the regmap instance that is
392 * associated with the component. Only use this if the regmap instance is not
393 * yet ready when the component is registered. The function must also be called
394 * before the first IO attempt of the component.
396 void snd_soc_component_init_regmap(struct snd_soc_component *component,
397 struct regmap *regmap)
399 component->regmap = regmap;
400 snd_soc_component_setup_regmap(component);
402 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
405 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the
407 * @component: The component for which to de-initialize the regmap instance
409 * Calls regmap_exit() on the regmap instance associated to the component and
410 * removes the regmap instance from the component.
412 * This function should only be used if snd_soc_component_init_regmap() was used
413 * to initialize the regmap instance.
415 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
417 regmap_exit(component->regmap);
418 component->regmap = NULL;
420 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
424 int snd_soc_component_compr_open(struct snd_compr_stream *cstream,
425 struct snd_soc_component **last)
427 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
428 struct snd_soc_component *component;
431 for_each_rtd_components(rtd, i, component) {
432 if (component->driver->compress_ops &&
433 component->driver->compress_ops->open) {
434 ret = component->driver->compress_ops->open(component, cstream);
437 return soc_component_ret(component, ret);
445 EXPORT_SYMBOL_GPL(snd_soc_component_compr_open);
447 void snd_soc_component_compr_free(struct snd_compr_stream *cstream,
448 struct snd_soc_component *last)
450 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
451 struct snd_soc_component *component;
454 for_each_rtd_components(rtd, i, component) {
455 if (component == last)
458 if (component->driver->compress_ops &&
459 component->driver->compress_ops->free)
460 component->driver->compress_ops->free(component, cstream);
463 EXPORT_SYMBOL_GPL(snd_soc_component_compr_free);
465 int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd)
467 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
468 struct snd_soc_component *component;
471 for_each_rtd_components(rtd, i, component) {
472 if (component->driver->compress_ops &&
473 component->driver->compress_ops->trigger) {
474 ret = component->driver->compress_ops->trigger(
475 component, cstream, cmd);
477 return soc_component_ret(component, ret);
483 EXPORT_SYMBOL_GPL(snd_soc_component_compr_trigger);
485 int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
486 struct snd_compr_params *params)
488 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
489 struct snd_soc_component *component;
492 for_each_rtd_components(rtd, i, component) {
493 if (component->driver->compress_ops &&
494 component->driver->compress_ops->set_params) {
495 ret = component->driver->compress_ops->set_params(
496 component, cstream, params);
498 return soc_component_ret(component, ret);
504 EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_params);
506 int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
507 struct snd_codec *params)
509 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
510 struct snd_soc_component *component;
513 for_each_rtd_components(rtd, i, component) {
514 if (component->driver->compress_ops &&
515 component->driver->compress_ops->get_params) {
516 ret = component->driver->compress_ops->get_params(
517 component, cstream, params);
518 return soc_component_ret(component, ret);
524 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_params);
526 int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
527 struct snd_compr_caps *caps)
529 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
530 struct snd_soc_component *component;
533 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
535 for_each_rtd_components(rtd, i, component) {
536 if (component->driver->compress_ops &&
537 component->driver->compress_ops->get_caps) {
538 ret = component->driver->compress_ops->get_caps(
539 component, cstream, caps);
544 mutex_unlock(&rtd->card->pcm_mutex);
546 return soc_component_ret(component, ret);
548 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_caps);
550 int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
551 struct snd_compr_codec_caps *codec)
553 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
554 struct snd_soc_component *component;
557 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
559 for_each_rtd_components(rtd, i, component) {
560 if (component->driver->compress_ops &&
561 component->driver->compress_ops->get_codec_caps) {
562 ret = component->driver->compress_ops->get_codec_caps(
563 component, cstream, codec);
568 mutex_unlock(&rtd->card->pcm_mutex);
570 return soc_component_ret(component, ret);
572 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_codec_caps);
574 int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
576 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
577 struct snd_soc_component *component;
580 for_each_rtd_components(rtd, i, component) {
581 if (component->driver->compress_ops &&
582 component->driver->compress_ops->ack) {
583 ret = component->driver->compress_ops->ack(
584 component, cstream, bytes);
586 return soc_component_ret(component, ret);
592 EXPORT_SYMBOL_GPL(snd_soc_component_compr_ack);
594 int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
595 struct snd_compr_tstamp *tstamp)
597 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
598 struct snd_soc_component *component;
601 for_each_rtd_components(rtd, i, component) {
602 if (component->driver->compress_ops &&
603 component->driver->compress_ops->pointer) {
604 ret = component->driver->compress_ops->pointer(
605 component, cstream, tstamp);
606 return soc_component_ret(component, ret);
612 EXPORT_SYMBOL_GPL(snd_soc_component_compr_pointer);
614 int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
615 char __user *buf, size_t count)
617 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
618 struct snd_soc_component *component;
621 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
623 for_each_rtd_components(rtd, i, component) {
624 if (component->driver->compress_ops &&
625 component->driver->compress_ops->copy) {
626 ret = component->driver->compress_ops->copy(
627 component, cstream, buf, count);
632 mutex_unlock(&rtd->card->pcm_mutex);
634 return soc_component_ret(component, ret);
636 EXPORT_SYMBOL_GPL(snd_soc_component_compr_copy);
638 int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
639 struct snd_compr_metadata *metadata)
641 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
642 struct snd_soc_component *component;
645 for_each_rtd_components(rtd, i, component) {
646 if (component->driver->compress_ops &&
647 component->driver->compress_ops->set_metadata) {
648 ret = component->driver->compress_ops->set_metadata(
649 component, cstream, metadata);
651 return soc_component_ret(component, ret);
657 EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_metadata);
659 static unsigned int soc_component_read_no_lock(
660 struct snd_soc_component *component,
664 unsigned int val = 0;
666 if (component->regmap)
667 ret = regmap_read(component->regmap, reg, &val);
668 else if (component->driver->read) {
670 val = component->driver->read(component, reg);
676 return soc_component_ret(component, ret);
682 * snd_soc_component_read() - Read register value
683 * @component: Component to read from
684 * @reg: Register to read
688 unsigned int snd_soc_component_read(struct snd_soc_component *component,
693 mutex_lock(&component->io_mutex);
694 val = soc_component_read_no_lock(component, reg);
695 mutex_unlock(&component->io_mutex);
699 EXPORT_SYMBOL_GPL(snd_soc_component_read);
701 static int soc_component_write_no_lock(
702 struct snd_soc_component *component,
703 unsigned int reg, unsigned int val)
707 if (component->regmap)
708 ret = regmap_write(component->regmap, reg, val);
709 else if (component->driver->write)
710 ret = component->driver->write(component, reg, val);
712 return soc_component_ret(component, ret);
716 * snd_soc_component_write() - Write register value
717 * @component: Component to write to
718 * @reg: Register to write
719 * @val: Value to write to the register
721 * Return: 0 on success, a negative error code otherwise.
723 int snd_soc_component_write(struct snd_soc_component *component,
724 unsigned int reg, unsigned int val)
728 mutex_lock(&component->io_mutex);
729 ret = soc_component_write_no_lock(component, reg, val);
730 mutex_unlock(&component->io_mutex);
734 EXPORT_SYMBOL_GPL(snd_soc_component_write);
736 static int snd_soc_component_update_bits_legacy(
737 struct snd_soc_component *component, unsigned int reg,
738 unsigned int mask, unsigned int val, bool *change)
740 unsigned int old, new;
743 mutex_lock(&component->io_mutex);
745 old = soc_component_read_no_lock(component, reg);
747 new = (old & ~mask) | (val & mask);
748 *change = old != new;
750 ret = soc_component_write_no_lock(component, reg, new);
752 mutex_unlock(&component->io_mutex);
754 return soc_component_ret(component, ret);
758 * snd_soc_component_update_bits() - Perform read/modify/write cycle
759 * @component: Component to update
760 * @reg: Register to update
761 * @mask: Mask that specifies which bits to update
762 * @val: New value for the bits specified by mask
764 * Return: 1 if the operation was successful and the value of the register
765 * changed, 0 if the operation was successful, but the value did not change.
766 * Returns a negative error code otherwise.
768 int snd_soc_component_update_bits(struct snd_soc_component *component,
769 unsigned int reg, unsigned int mask, unsigned int val)
774 if (component->regmap)
775 ret = regmap_update_bits_check(component->regmap, reg, mask,
778 ret = snd_soc_component_update_bits_legacy(component, reg,
782 return soc_component_ret(component, ret);
785 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
788 * snd_soc_component_update_bits_async() - Perform asynchronous
789 * read/modify/write cycle
790 * @component: Component to update
791 * @reg: Register to update
792 * @mask: Mask that specifies which bits to update
793 * @val: New value for the bits specified by mask
795 * This function is similar to snd_soc_component_update_bits(), but the update
796 * operation is scheduled asynchronously. This means it may not be completed
797 * when the function returns. To make sure that all scheduled updates have been
798 * completed snd_soc_component_async_complete() must be called.
800 * Return: 1 if the operation was successful and the value of the register
801 * changed, 0 if the operation was successful, but the value did not change.
802 * Returns a negative error code otherwise.
804 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
805 unsigned int reg, unsigned int mask, unsigned int val)
810 if (component->regmap)
811 ret = regmap_update_bits_check_async(component->regmap, reg,
814 ret = snd_soc_component_update_bits_legacy(component, reg,
818 return soc_component_ret(component, ret);
821 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
824 * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
825 * @component: Component for which to wait
827 * This function blocks until all asynchronous I/O which has previously been
828 * scheduled using snd_soc_component_update_bits_async() has completed.
830 void snd_soc_component_async_complete(struct snd_soc_component *component)
832 if (component->regmap)
833 regmap_async_complete(component->regmap);
835 EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
838 * snd_soc_component_test_bits - Test register for change
839 * @component: component
840 * @reg: Register to test
841 * @mask: Mask that specifies which bits to test
842 * @value: Value to test against
844 * Tests a register with a new value and checks if the new value is
845 * different from the old value.
847 * Return: 1 for change, otherwise 0.
849 int snd_soc_component_test_bits(struct snd_soc_component *component,
850 unsigned int reg, unsigned int mask, unsigned int value)
852 unsigned int old, new;
854 old = snd_soc_component_read(component, reg);
855 new = (old & ~mask) | value;
858 EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);
860 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
862 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
863 struct snd_soc_component *component;
866 /* FIXME: use 1st pointer */
867 for_each_rtd_components(rtd, i, component)
868 if (component->driver->pointer)
869 return component->driver->pointer(component, substream);
874 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
875 unsigned int cmd, void *arg)
877 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
878 struct snd_soc_component *component;
881 /* FIXME: use 1st ioctl */
882 for_each_rtd_components(rtd, i, component)
883 if (component->driver->ioctl)
884 return soc_component_ret(
886 component->driver->ioctl(component,
887 substream, cmd, arg));
889 return snd_pcm_lib_ioctl(substream, cmd, arg);
892 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream)
894 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
895 struct snd_soc_component *component;
898 for_each_rtd_components(rtd, i, component) {
899 if (component->driver->sync_stop) {
900 ret = component->driver->sync_stop(component,
903 return soc_component_ret(component, ret);
910 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
911 int channel, unsigned long pos,
912 void __user *buf, unsigned long bytes)
914 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
915 struct snd_soc_component *component;
918 /* FIXME. it returns 1st copy now */
919 for_each_rtd_components(rtd, i, component)
920 if (component->driver->copy_user)
921 return soc_component_ret(
923 component->driver->copy_user(
924 component, substream, channel,
930 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
931 unsigned long offset)
933 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
934 struct snd_soc_component *component;
938 /* FIXME. it returns 1st page now */
939 for_each_rtd_components(rtd, i, component) {
940 if (component->driver->page) {
941 page = component->driver->page(component,
951 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
952 struct vm_area_struct *vma)
954 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
955 struct snd_soc_component *component;
958 /* FIXME. it returns 1st mmap now */
959 for_each_rtd_components(rtd, i, component)
960 if (component->driver->mmap)
961 return soc_component_ret(
963 component->driver->mmap(component,
969 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd)
971 struct snd_soc_component *component;
975 for_each_rtd_components(rtd, i, component) {
976 if (component->driver->pcm_construct) {
977 ret = component->driver->pcm_construct(component, rtd);
979 return soc_component_ret(component, ret);
986 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd)
988 struct snd_soc_component *component;
994 for_each_rtd_components(rtd, i, component)
995 if (component->driver->pcm_destruct)
996 component->driver->pcm_destruct(component, rtd->pcm);
999 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream)
1001 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1002 struct snd_soc_component *component;
1005 for_each_rtd_components(rtd, i, component) {
1006 if (component->driver->prepare) {
1007 ret = component->driver->prepare(component, substream);
1009 return soc_component_ret(component, ret);
1016 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
1017 struct snd_pcm_hw_params *params)
1019 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1020 struct snd_soc_component *component;
1023 for_each_rtd_components(rtd, i, component) {
1024 if (component->driver->hw_params) {
1025 ret = component->driver->hw_params(component,
1028 return soc_component_ret(component, ret);
1030 /* mark substream if succeeded */
1031 soc_component_mark_push(component, substream, hw_params);
1037 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
1040 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1041 struct snd_soc_component *component;
1044 for_each_rtd_components(rtd, i, component) {
1045 if (rollback && !soc_component_mark_match(component, substream, hw_params))
1048 if (component->driver->hw_free) {
1049 ret = component->driver->hw_free(component, substream);
1051 soc_component_ret(component, ret);
1054 /* remove marked substream */
1055 soc_component_mark_pop(component, substream, hw_params);
1059 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
1062 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1063 struct snd_soc_component *component;
1066 for_each_rtd_components(rtd, i, component) {
1067 if (component->driver->trigger) {
1068 ret = component->driver->trigger(component, substream, cmd);
1070 return soc_component_ret(component, ret);
1077 int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
1080 struct snd_soc_component *component;
1083 for_each_rtd_components(rtd, i, component) {
1084 ret = pm_runtime_get_sync(component->dev);
1085 if (ret < 0 && ret != -EACCES) {
1086 pm_runtime_put_noidle(component->dev);
1087 return soc_component_ret(component, ret);
1089 /* mark stream if succeeded */
1090 soc_component_mark_push(component, stream, pm);
1096 void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
1097 void *stream, int rollback)
1099 struct snd_soc_component *component;
1102 for_each_rtd_components(rtd, i, component) {
1103 if (rollback && !soc_component_mark_match(component, stream, pm))
1106 pm_runtime_mark_last_busy(component->dev);
1107 pm_runtime_put_autosuspend(component->dev);
1109 /* remove marked stream */
1110 soc_component_mark_pop(component, stream, pm);