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>
14 #include <linux/bitops.h>
16 #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret, -1)
17 #define soc_component_ret_reg_rw(dai, ret, reg) _soc_component_ret(dai, __func__, ret, reg)
18 static inline int _soc_component_ret(struct snd_soc_component *component,
19 const char *func, int ret, int reg)
21 /* Positive/Zero values are not errors */
25 /* Negative values might be errors */
32 dev_err(component->dev,
33 "ASoC: error at %s on %s: %d\n",
34 func, component->name, ret);
36 dev_err(component->dev,
37 "ASoC: error at %s on %s for register: [0x%08x] %d\n",
38 func, component->name, reg, ret);
44 static inline int soc_component_field_shift(struct snd_soc_component *component,
48 dev_err(component->dev, "ASoC: error field mask is zero for %s\n",
53 return (ffs(mask) - 1);
57 * We might want to check substream by using list.
58 * In such case, we can update these macros.
60 #define soc_component_mark_push(component, substream, tgt) ((component)->mark_##tgt = substream)
61 #define soc_component_mark_pop(component, substream, tgt) ((component)->mark_##tgt = NULL)
62 #define soc_component_mark_match(component, substream, tgt) ((component)->mark_##tgt == substream)
64 void snd_soc_component_set_aux(struct snd_soc_component *component,
65 struct snd_soc_aux_dev *aux)
67 component->init = (aux) ? aux->init : NULL;
70 int snd_soc_component_init(struct snd_soc_component *component)
75 ret = component->init(component);
77 return soc_component_ret(component, ret);
81 * snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
82 * @component: COMPONENT
83 * @clk_id: DAI specific clock ID
84 * @source: Source for the clock
85 * @freq: new clock frequency in Hz
86 * @dir: new clock direction - input/output.
88 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
90 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
91 int clk_id, int source, unsigned int freq,
96 if (component->driver->set_sysclk)
97 ret = component->driver->set_sysclk(component, clk_id, source,
100 return soc_component_ret(component, ret);
102 EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
105 * snd_soc_component_set_pll - configure component PLL.
106 * @component: COMPONENT
107 * @pll_id: DAI specific PLL ID
108 * @source: DAI specific source for the PLL
109 * @freq_in: PLL input clock frequency in Hz
110 * @freq_out: requested PLL output clock frequency in Hz
112 * Configures and enables PLL to generate output clock based on input clock.
114 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
115 int source, unsigned int freq_in,
116 unsigned int freq_out)
120 if (component->driver->set_pll)
121 ret = component->driver->set_pll(component, pll_id, source,
124 return soc_component_ret(component, ret);
126 EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
128 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
129 enum snd_soc_dapm_type type, int subseq)
131 if (component->driver->seq_notifier)
132 component->driver->seq_notifier(component, type, subseq);
135 int snd_soc_component_stream_event(struct snd_soc_component *component,
140 if (component->driver->stream_event)
141 ret = component->driver->stream_event(component, event);
143 return soc_component_ret(component, ret);
146 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
147 enum snd_soc_bias_level level)
151 if (component->driver->set_bias_level)
152 ret = component->driver->set_bias_level(component, level);
154 return soc_component_ret(component, ret);
157 int snd_soc_component_enable_pin(struct snd_soc_component *component,
160 struct snd_soc_dapm_context *dapm =
161 snd_soc_component_get_dapm(component);
162 return snd_soc_dapm_enable_pin(dapm, pin);
164 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
166 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
169 struct snd_soc_dapm_context *dapm =
170 snd_soc_component_get_dapm(component);
171 return snd_soc_dapm_enable_pin_unlocked(dapm, pin);
173 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
175 int snd_soc_component_disable_pin(struct snd_soc_component *component,
178 struct snd_soc_dapm_context *dapm =
179 snd_soc_component_get_dapm(component);
180 return snd_soc_dapm_disable_pin(dapm, pin);
182 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
184 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
187 struct snd_soc_dapm_context *dapm =
188 snd_soc_component_get_dapm(component);
189 return snd_soc_dapm_disable_pin_unlocked(dapm, pin);
191 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
193 int snd_soc_component_nc_pin(struct snd_soc_component *component,
196 struct snd_soc_dapm_context *dapm =
197 snd_soc_component_get_dapm(component);
198 return snd_soc_dapm_nc_pin(dapm, pin);
200 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
202 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
205 struct snd_soc_dapm_context *dapm =
206 snd_soc_component_get_dapm(component);
207 return snd_soc_dapm_nc_pin_unlocked(dapm, pin);
209 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
211 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
214 struct snd_soc_dapm_context *dapm =
215 snd_soc_component_get_dapm(component);
216 return snd_soc_dapm_get_pin_status(dapm, pin);
218 EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
220 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
223 struct snd_soc_dapm_context *dapm =
224 snd_soc_component_get_dapm(component);
225 return snd_soc_dapm_force_enable_pin(dapm, pin);
227 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
229 int snd_soc_component_force_enable_pin_unlocked(
230 struct snd_soc_component *component,
233 struct snd_soc_dapm_context *dapm =
234 snd_soc_component_get_dapm(component);
235 return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
237 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
240 * snd_soc_component_set_jack - configure component jack.
241 * @component: COMPONENTs
242 * @jack: structure to use for the jack
243 * @data: can be used if codec driver need extra data for configuring jack
245 * Configures and enables jack detection function.
247 int snd_soc_component_set_jack(struct snd_soc_component *component,
248 struct snd_soc_jack *jack, void *data)
252 if (component->driver->set_jack)
253 ret = component->driver->set_jack(component, jack, data);
255 return soc_component_ret(component, ret);
257 EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
259 int snd_soc_component_module_get(struct snd_soc_component *component,
260 void *mark, int upon_open)
264 if (component->driver->module_get_upon_open == !!upon_open &&
265 !try_module_get(component->dev->driver->owner))
268 /* mark module if succeeded */
270 soc_component_mark_push(component, mark, module);
272 return soc_component_ret(component, ret);
275 void snd_soc_component_module_put(struct snd_soc_component *component,
276 void *mark, int upon_open, int rollback)
278 if (rollback && !soc_component_mark_match(component, mark, module))
281 if (component->driver->module_get_upon_open == !!upon_open)
282 module_put(component->dev->driver->owner);
284 /* remove the mark from module */
285 soc_component_mark_pop(component, mark, module);
288 int snd_soc_component_open(struct snd_soc_component *component,
289 struct snd_pcm_substream *substream)
293 if (component->driver->open)
294 ret = component->driver->open(component, substream);
296 /* mark substream if succeeded */
298 soc_component_mark_push(component, substream, open);
300 return soc_component_ret(component, ret);
303 int snd_soc_component_close(struct snd_soc_component *component,
304 struct snd_pcm_substream *substream,
309 if (rollback && !soc_component_mark_match(component, substream, open))
312 if (component->driver->close)
313 ret = component->driver->close(component, substream);
315 /* remove marked substream */
316 soc_component_mark_pop(component, substream, open);
318 return soc_component_ret(component, ret);
321 void snd_soc_component_suspend(struct snd_soc_component *component)
323 if (component->driver->suspend)
324 component->driver->suspend(component);
325 component->suspended = 1;
328 void snd_soc_component_resume(struct snd_soc_component *component)
330 if (component->driver->resume)
331 component->driver->resume(component);
332 component->suspended = 0;
335 int snd_soc_component_is_suspended(struct snd_soc_component *component)
337 return component->suspended;
340 int snd_soc_component_probe(struct snd_soc_component *component)
344 if (component->driver->probe)
345 ret = component->driver->probe(component);
347 return soc_component_ret(component, ret);
350 void snd_soc_component_remove(struct snd_soc_component *component)
352 if (component->driver->remove)
353 component->driver->remove(component);
356 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
357 struct device_node *ep)
361 if (component->driver->of_xlate_dai_id)
362 ret = component->driver->of_xlate_dai_id(component, ep);
364 return soc_component_ret(component, ret);
367 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
368 const struct of_phandle_args *args,
369 const char **dai_name)
371 if (component->driver->of_xlate_dai_name)
372 return component->driver->of_xlate_dai_name(component,
375 * Don't use soc_component_ret here because we may not want to report
376 * the error just yet. If a device has more than one component, the
377 * first may not match and we don't want spam the log with this.
382 void snd_soc_component_setup_regmap(struct snd_soc_component *component)
384 int val_bytes = regmap_get_val_bytes(component->regmap);
386 /* Errors are legitimate for non-integer byte multiples */
388 component->val_bytes = val_bytes;
394 * snd_soc_component_init_regmap() - Initialize regmap instance for the
396 * @component: The component for which to initialize the regmap instance
397 * @regmap: The regmap instance that should be used by the component
399 * This function allows deferred assignment of the regmap instance that is
400 * associated with the component. Only use this if the regmap instance is not
401 * yet ready when the component is registered. The function must also be called
402 * before the first IO attempt of the component.
404 void snd_soc_component_init_regmap(struct snd_soc_component *component,
405 struct regmap *regmap)
407 component->regmap = regmap;
408 snd_soc_component_setup_regmap(component);
410 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
413 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the
415 * @component: The component for which to de-initialize the regmap instance
417 * Calls regmap_exit() on the regmap instance associated to the component and
418 * removes the regmap instance from the component.
420 * This function should only be used if snd_soc_component_init_regmap() was used
421 * to initialize the regmap instance.
423 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
425 regmap_exit(component->regmap);
426 component->regmap = NULL;
428 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
432 int snd_soc_component_compr_open(struct snd_soc_component *component,
433 struct snd_compr_stream *cstream)
437 if (component->driver->compress_ops &&
438 component->driver->compress_ops->open)
439 ret = component->driver->compress_ops->open(component, cstream);
441 /* mark substream if succeeded */
443 soc_component_mark_push(component, cstream, compr_open);
445 return soc_component_ret(component, ret);
447 EXPORT_SYMBOL_GPL(snd_soc_component_compr_open);
449 void snd_soc_component_compr_free(struct snd_soc_component *component,
450 struct snd_compr_stream *cstream,
453 if (rollback && !soc_component_mark_match(component, cstream, compr_open))
456 if (component->driver->compress_ops &&
457 component->driver->compress_ops->free)
458 component->driver->compress_ops->free(component, cstream);
460 /* remove marked substream */
461 soc_component_mark_pop(component, cstream, compr_open);
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 int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
660 struct snd_compr_metadata *metadata)
662 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
663 struct snd_soc_component *component;
666 for_each_rtd_components(rtd, i, component) {
667 if (component->driver->compress_ops &&
668 component->driver->compress_ops->get_metadata) {
669 ret = component->driver->compress_ops->get_metadata(
670 component, cstream, metadata);
671 return soc_component_ret(component, ret);
677 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_metadata);
679 static unsigned int soc_component_read_no_lock(
680 struct snd_soc_component *component,
684 unsigned int val = 0;
686 if (component->regmap)
687 ret = regmap_read(component->regmap, reg, &val);
688 else if (component->driver->read) {
690 val = component->driver->read(component, reg);
696 return soc_component_ret_reg_rw(component, ret, reg);
702 * snd_soc_component_read() - Read register value
703 * @component: Component to read from
704 * @reg: Register to read
708 unsigned int snd_soc_component_read(struct snd_soc_component *component,
713 mutex_lock(&component->io_mutex);
714 val = soc_component_read_no_lock(component, reg);
715 mutex_unlock(&component->io_mutex);
719 EXPORT_SYMBOL_GPL(snd_soc_component_read);
721 static int soc_component_write_no_lock(
722 struct snd_soc_component *component,
723 unsigned int reg, unsigned int val)
727 if (component->regmap)
728 ret = regmap_write(component->regmap, reg, val);
729 else if (component->driver->write)
730 ret = component->driver->write(component, reg, val);
732 return soc_component_ret_reg_rw(component, ret, reg);
736 * snd_soc_component_write() - Write register value
737 * @component: Component to write to
738 * @reg: Register to write
739 * @val: Value to write to the register
741 * Return: 0 on success, a negative error code otherwise.
743 int snd_soc_component_write(struct snd_soc_component *component,
744 unsigned int reg, unsigned int val)
748 mutex_lock(&component->io_mutex);
749 ret = soc_component_write_no_lock(component, reg, val);
750 mutex_unlock(&component->io_mutex);
754 EXPORT_SYMBOL_GPL(snd_soc_component_write);
756 static int snd_soc_component_update_bits_legacy(
757 struct snd_soc_component *component, unsigned int reg,
758 unsigned int mask, unsigned int val, bool *change)
760 unsigned int old, new;
763 mutex_lock(&component->io_mutex);
765 old = soc_component_read_no_lock(component, reg);
767 new = (old & ~mask) | (val & mask);
768 *change = old != new;
770 ret = soc_component_write_no_lock(component, reg, new);
772 mutex_unlock(&component->io_mutex);
774 return soc_component_ret_reg_rw(component, ret, reg);
778 * snd_soc_component_update_bits() - Perform read/modify/write cycle
779 * @component: Component to update
780 * @reg: Register to update
781 * @mask: Mask that specifies which bits to update
782 * @val: New value for the bits specified by mask
784 * Return: 1 if the operation was successful and the value of the register
785 * changed, 0 if the operation was successful, but the value did not change.
786 * Returns a negative error code otherwise.
788 int snd_soc_component_update_bits(struct snd_soc_component *component,
789 unsigned int reg, unsigned int mask, unsigned int val)
794 if (component->regmap)
795 ret = regmap_update_bits_check(component->regmap, reg, mask,
798 ret = snd_soc_component_update_bits_legacy(component, reg,
802 return soc_component_ret_reg_rw(component, ret, reg);
805 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
808 * snd_soc_component_update_bits_async() - Perform asynchronous
809 * read/modify/write cycle
810 * @component: Component to update
811 * @reg: Register to update
812 * @mask: Mask that specifies which bits to update
813 * @val: New value for the bits specified by mask
815 * This function is similar to snd_soc_component_update_bits(), but the update
816 * operation is scheduled asynchronously. This means it may not be completed
817 * when the function returns. To make sure that all scheduled updates have been
818 * completed snd_soc_component_async_complete() must be called.
820 * Return: 1 if the operation was successful and the value of the register
821 * changed, 0 if the operation was successful, but the value did not change.
822 * Returns a negative error code otherwise.
824 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
825 unsigned int reg, unsigned int mask, unsigned int val)
830 if (component->regmap)
831 ret = regmap_update_bits_check_async(component->regmap, reg,
834 ret = snd_soc_component_update_bits_legacy(component, reg,
838 return soc_component_ret_reg_rw(component, ret, reg);
841 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
844 * snd_soc_component_read_field() - Read register field value
845 * @component: Component to read from
846 * @reg: Register to read
847 * @mask: mask of the register field
849 * Return: read value of register field.
851 unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
852 unsigned int reg, unsigned int mask)
856 val = snd_soc_component_read(component, reg);
858 val = (val & mask) >> soc_component_field_shift(component, mask);
862 EXPORT_SYMBOL_GPL(snd_soc_component_read_field);
865 * snd_soc_component_write_field() - write to register field
866 * @component: Component to write to
867 * @reg: Register to write
868 * @mask: mask of the register field to update
869 * @val: value of the field to write
871 * Return: 1 for change, otherwise 0.
873 int snd_soc_component_write_field(struct snd_soc_component *component,
874 unsigned int reg, unsigned int mask,
878 val = (val << soc_component_field_shift(component, mask)) & mask;
880 return snd_soc_component_update_bits(component, reg, mask, val);
882 EXPORT_SYMBOL_GPL(snd_soc_component_write_field);
885 * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
886 * @component: Component for which to wait
888 * This function blocks until all asynchronous I/O which has previously been
889 * scheduled using snd_soc_component_update_bits_async() has completed.
891 void snd_soc_component_async_complete(struct snd_soc_component *component)
893 if (component->regmap)
894 regmap_async_complete(component->regmap);
896 EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
899 * snd_soc_component_test_bits - Test register for change
900 * @component: component
901 * @reg: Register to test
902 * @mask: Mask that specifies which bits to test
903 * @value: Value to test against
905 * Tests a register with a new value and checks if the new value is
906 * different from the old value.
908 * Return: 1 for change, otherwise 0.
910 int snd_soc_component_test_bits(struct snd_soc_component *component,
911 unsigned int reg, unsigned int mask, unsigned int value)
913 unsigned int old, new;
915 old = snd_soc_component_read(component, reg);
916 new = (old & ~mask) | value;
919 EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);
921 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
923 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
924 struct snd_soc_component *component;
927 /* FIXME: use 1st pointer */
928 for_each_rtd_components(rtd, i, component)
929 if (component->driver->pointer)
930 return component->driver->pointer(component, substream);
935 static bool snd_soc_component_is_codec_on_rtd(struct snd_soc_pcm_runtime *rtd,
936 struct snd_soc_component *component)
938 struct snd_soc_dai *dai;
941 for_each_rtd_codec_dais(rtd, i, dai) {
942 if (dai->component == component)
949 void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream,
950 snd_pcm_sframes_t *cpu_delay,
951 snd_pcm_sframes_t *codec_delay)
953 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
954 struct snd_soc_component *component;
955 snd_pcm_sframes_t delay;
959 * We're looking for the delay through the full audio path so it needs to
960 * be the maximum of the Components doing transmit and the maximum of the
961 * Components doing receive (ie, all CPUs and all CODECs) rather than
962 * just the maximum of all Components.
964 for_each_rtd_components(rtd, i, component) {
965 if (!component->driver->delay)
968 delay = component->driver->delay(component, substream);
970 if (snd_soc_component_is_codec_on_rtd(rtd, component))
971 *codec_delay = max(*codec_delay, delay);
973 *cpu_delay = max(*cpu_delay, delay);
977 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
978 unsigned int cmd, void *arg)
980 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
981 struct snd_soc_component *component;
984 /* FIXME: use 1st ioctl */
985 for_each_rtd_components(rtd, i, component)
986 if (component->driver->ioctl)
987 return soc_component_ret(
989 component->driver->ioctl(component,
990 substream, cmd, arg));
992 return snd_pcm_lib_ioctl(substream, cmd, arg);
995 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream)
997 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
998 struct snd_soc_component *component;
1001 for_each_rtd_components(rtd, i, component) {
1002 if (component->driver->sync_stop) {
1003 ret = component->driver->sync_stop(component,
1006 return soc_component_ret(component, ret);
1013 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
1014 int channel, unsigned long pos,
1015 void __user *buf, unsigned long bytes)
1017 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1018 struct snd_soc_component *component;
1021 /* FIXME. it returns 1st copy now */
1022 for_each_rtd_components(rtd, i, component)
1023 if (component->driver->copy_user)
1024 return soc_component_ret(
1026 component->driver->copy_user(
1027 component, substream, channel,
1033 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
1034 unsigned long offset)
1036 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1037 struct snd_soc_component *component;
1041 /* FIXME. it returns 1st page now */
1042 for_each_rtd_components(rtd, i, component) {
1043 if (component->driver->page) {
1044 page = component->driver->page(component,
1054 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
1055 struct vm_area_struct *vma)
1057 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1058 struct snd_soc_component *component;
1061 /* FIXME. it returns 1st mmap now */
1062 for_each_rtd_components(rtd, i, component)
1063 if (component->driver->mmap)
1064 return soc_component_ret(
1066 component->driver->mmap(component,
1072 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd)
1074 struct snd_soc_component *component;
1078 for_each_rtd_components(rtd, i, component) {
1079 if (component->driver->pcm_construct) {
1080 ret = component->driver->pcm_construct(component, rtd);
1082 return soc_component_ret(component, ret);
1089 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd)
1091 struct snd_soc_component *component;
1097 for_each_rtd_components(rtd, i, component)
1098 if (component->driver->pcm_destruct)
1099 component->driver->pcm_destruct(component, rtd->pcm);
1102 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream)
1104 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1105 struct snd_soc_component *component;
1108 for_each_rtd_components(rtd, i, component) {
1109 if (component->driver->prepare) {
1110 ret = component->driver->prepare(component, substream);
1112 return soc_component_ret(component, ret);
1119 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
1120 struct snd_pcm_hw_params *params)
1122 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1123 struct snd_soc_component *component;
1126 for_each_rtd_components(rtd, i, component) {
1127 if (component->driver->hw_params) {
1128 ret = component->driver->hw_params(component,
1131 return soc_component_ret(component, ret);
1133 /* mark substream if succeeded */
1134 soc_component_mark_push(component, substream, hw_params);
1140 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
1143 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1144 struct snd_soc_component *component;
1147 for_each_rtd_components(rtd, i, component) {
1148 if (rollback && !soc_component_mark_match(component, substream, hw_params))
1151 if (component->driver->hw_free) {
1152 ret = component->driver->hw_free(component, substream);
1154 soc_component_ret(component, ret);
1157 /* remove marked substream */
1158 soc_component_mark_pop(component, substream, hw_params);
1162 static int soc_component_trigger(struct snd_soc_component *component,
1163 struct snd_pcm_substream *substream,
1168 if (component->driver->trigger)
1169 ret = component->driver->trigger(component, substream, cmd);
1171 return soc_component_ret(component, ret);
1174 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
1175 int cmd, int rollback)
1177 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1178 struct snd_soc_component *component;
1182 case SNDRV_PCM_TRIGGER_START:
1183 case SNDRV_PCM_TRIGGER_RESUME:
1184 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1185 for_each_rtd_components(rtd, i, component) {
1186 ret = soc_component_trigger(component, substream, cmd);
1189 soc_component_mark_push(component, substream, trigger);
1192 case SNDRV_PCM_TRIGGER_STOP:
1193 case SNDRV_PCM_TRIGGER_SUSPEND:
1194 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1195 for_each_rtd_components(rtd, i, component) {
1196 if (rollback && !soc_component_mark_match(component, substream, trigger))
1199 r = soc_component_trigger(component, substream, cmd);
1201 ret = r; /* use last ret */
1202 soc_component_mark_pop(component, substream, trigger);
1209 int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
1212 struct snd_soc_component *component;
1215 for_each_rtd_components(rtd, i, component) {
1216 int ret = pm_runtime_get_sync(component->dev);
1217 if (ret < 0 && ret != -EACCES) {
1218 pm_runtime_put_noidle(component->dev);
1219 return soc_component_ret(component, ret);
1221 /* mark stream if succeeded */
1222 soc_component_mark_push(component, stream, pm);
1228 void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
1229 void *stream, int rollback)
1231 struct snd_soc_component *component;
1234 for_each_rtd_components(rtd, i, component) {
1235 if (rollback && !soc_component_mark_match(component, stream, pm))
1238 pm_runtime_mark_last_busy(component->dev);
1239 pm_runtime_put_autosuspend(component->dev);
1241 /* remove marked stream */
1242 soc_component_mark_pop(component, stream, pm);
1246 int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream)
1248 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1249 struct snd_soc_component *component;
1252 /* FIXME: use 1st pointer */
1253 for_each_rtd_components(rtd, i, component)
1254 if (component->driver->ack)
1255 return component->driver->ack(component, substream);