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)
17 static inline int _soc_component_ret(struct snd_soc_component *component,
18 const char *func, int ret)
20 /* Positive/Zero values are not errors */
24 /* Negative values might be errors */
30 dev_err(component->dev,
31 "ASoC: error at %s on %s: %d\n",
32 func, component->name, ret);
38 static inline int soc_component_field_shift(struct snd_soc_component *component,
42 dev_err(component->dev, "ASoC: error field mask is zero for %s\n",
47 return (ffs(mask) - 1);
51 * We might want to check substream by using list.
52 * In such case, we can update these macros.
54 #define soc_component_mark_push(component, substream, tgt) ((component)->mark_##tgt = substream)
55 #define soc_component_mark_pop(component, substream, tgt) ((component)->mark_##tgt = NULL)
56 #define soc_component_mark_match(component, substream, tgt) ((component)->mark_##tgt == substream)
58 void snd_soc_component_set_aux(struct snd_soc_component *component,
59 struct snd_soc_aux_dev *aux)
61 component->init = (aux) ? aux->init : NULL;
64 int snd_soc_component_init(struct snd_soc_component *component)
69 ret = component->init(component);
71 return soc_component_ret(component, ret);
75 * snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
76 * @component: COMPONENT
77 * @clk_id: DAI specific clock ID
78 * @source: Source for the clock
79 * @freq: new clock frequency in Hz
80 * @dir: new clock direction - input/output.
82 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
84 int snd_soc_component_set_sysclk(struct snd_soc_component *component,
85 int clk_id, int source, unsigned int freq,
90 if (component->driver->set_sysclk)
91 ret = component->driver->set_sysclk(component, clk_id, source,
94 return soc_component_ret(component, ret);
96 EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
99 * snd_soc_component_set_pll - configure component PLL.
100 * @component: COMPONENT
101 * @pll_id: DAI specific PLL ID
102 * @source: DAI specific source for the PLL
103 * @freq_in: PLL input clock frequency in Hz
104 * @freq_out: requested PLL output clock frequency in Hz
106 * Configures and enables PLL to generate output clock based on input clock.
108 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
109 int source, unsigned int freq_in,
110 unsigned int freq_out)
114 if (component->driver->set_pll)
115 ret = component->driver->set_pll(component, pll_id, source,
118 return soc_component_ret(component, ret);
120 EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
122 void snd_soc_component_seq_notifier(struct snd_soc_component *component,
123 enum snd_soc_dapm_type type, int subseq)
125 if (component->driver->seq_notifier)
126 component->driver->seq_notifier(component, type, subseq);
129 int snd_soc_component_stream_event(struct snd_soc_component *component,
134 if (component->driver->stream_event)
135 ret = component->driver->stream_event(component, event);
137 return soc_component_ret(component, ret);
140 int snd_soc_component_set_bias_level(struct snd_soc_component *component,
141 enum snd_soc_bias_level level)
145 if (component->driver->set_bias_level)
146 ret = component->driver->set_bias_level(component, level);
148 return soc_component_ret(component, ret);
151 int snd_soc_component_enable_pin(struct snd_soc_component *component,
154 struct snd_soc_dapm_context *dapm =
155 snd_soc_component_get_dapm(component);
156 return snd_soc_dapm_enable_pin(dapm, pin);
158 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
160 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
163 struct snd_soc_dapm_context *dapm =
164 snd_soc_component_get_dapm(component);
165 return snd_soc_dapm_enable_pin_unlocked(dapm, pin);
167 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
169 int snd_soc_component_disable_pin(struct snd_soc_component *component,
172 struct snd_soc_dapm_context *dapm =
173 snd_soc_component_get_dapm(component);
174 return snd_soc_dapm_disable_pin(dapm, pin);
176 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
178 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
181 struct snd_soc_dapm_context *dapm =
182 snd_soc_component_get_dapm(component);
183 return snd_soc_dapm_disable_pin_unlocked(dapm, pin);
185 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
187 int snd_soc_component_nc_pin(struct snd_soc_component *component,
190 struct snd_soc_dapm_context *dapm =
191 snd_soc_component_get_dapm(component);
192 return snd_soc_dapm_nc_pin(dapm, pin);
194 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
196 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
199 struct snd_soc_dapm_context *dapm =
200 snd_soc_component_get_dapm(component);
201 return snd_soc_dapm_nc_pin_unlocked(dapm, pin);
203 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
205 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
208 struct snd_soc_dapm_context *dapm =
209 snd_soc_component_get_dapm(component);
210 return snd_soc_dapm_get_pin_status(dapm, pin);
212 EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
214 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
217 struct snd_soc_dapm_context *dapm =
218 snd_soc_component_get_dapm(component);
219 return snd_soc_dapm_force_enable_pin(dapm, pin);
221 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
223 int snd_soc_component_force_enable_pin_unlocked(
224 struct snd_soc_component *component,
227 struct snd_soc_dapm_context *dapm =
228 snd_soc_component_get_dapm(component);
229 return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
231 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
234 * snd_soc_component_set_jack - configure component jack.
235 * @component: COMPONENTs
236 * @jack: structure to use for the jack
237 * @data: can be used if codec driver need extra data for configuring jack
239 * Configures and enables jack detection function.
241 int snd_soc_component_set_jack(struct snd_soc_component *component,
242 struct snd_soc_jack *jack, void *data)
246 if (component->driver->set_jack)
247 ret = component->driver->set_jack(component, jack, data);
249 return soc_component_ret(component, ret);
251 EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
253 int snd_soc_component_module_get(struct snd_soc_component *component,
254 struct snd_pcm_substream *substream,
259 if (component->driver->module_get_upon_open == !!upon_open &&
260 !try_module_get(component->dev->driver->owner))
263 /* mark substream if succeeded */
265 soc_component_mark_push(component, substream, module);
267 return soc_component_ret(component, ret);
270 void snd_soc_component_module_put(struct snd_soc_component *component,
271 struct snd_pcm_substream *substream,
272 int upon_open, int rollback)
274 if (rollback && !soc_component_mark_match(component, substream, module))
277 if (component->driver->module_get_upon_open == !!upon_open)
278 module_put(component->dev->driver->owner);
280 /* remove marked substream */
281 soc_component_mark_pop(component, substream, module);
284 int snd_soc_component_open(struct snd_soc_component *component,
285 struct snd_pcm_substream *substream)
289 if (component->driver->open)
290 ret = component->driver->open(component, substream);
292 /* mark substream if succeeded */
294 soc_component_mark_push(component, substream, open);
296 return soc_component_ret(component, ret);
299 int snd_soc_component_close(struct snd_soc_component *component,
300 struct snd_pcm_substream *substream,
305 if (rollback && !soc_component_mark_match(component, substream, open))
308 if (component->driver->close)
309 ret = component->driver->close(component, substream);
311 /* remove marked substream */
312 soc_component_mark_pop(component, substream, open);
314 return soc_component_ret(component, ret);
317 void snd_soc_component_suspend(struct snd_soc_component *component)
319 if (component->driver->suspend)
320 component->driver->suspend(component);
321 component->suspended = 1;
324 void snd_soc_component_resume(struct snd_soc_component *component)
326 if (component->driver->resume)
327 component->driver->resume(component);
328 component->suspended = 0;
331 int snd_soc_component_is_suspended(struct snd_soc_component *component)
333 return component->suspended;
336 int snd_soc_component_probe(struct snd_soc_component *component)
340 if (component->driver->probe)
341 ret = component->driver->probe(component);
343 return soc_component_ret(component, ret);
346 void snd_soc_component_remove(struct snd_soc_component *component)
348 if (component->driver->remove)
349 component->driver->remove(component);
352 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
353 struct device_node *ep)
357 if (component->driver->of_xlate_dai_id)
358 ret = component->driver->of_xlate_dai_id(component, ep);
360 return soc_component_ret(component, ret);
363 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
364 const struct of_phandle_args *args,
365 const char **dai_name)
367 if (component->driver->of_xlate_dai_name)
368 return component->driver->of_xlate_dai_name(component,
371 * Don't use soc_component_ret here because we may not want to report
372 * the error just yet. If a device has more than one component, the
373 * first may not match and we don't want spam the log with this.
378 void snd_soc_component_setup_regmap(struct snd_soc_component *component)
380 int val_bytes = regmap_get_val_bytes(component->regmap);
382 /* Errors are legitimate for non-integer byte multiples */
384 component->val_bytes = val_bytes;
390 * snd_soc_component_init_regmap() - Initialize regmap instance for the
392 * @component: The component for which to initialize the regmap instance
393 * @regmap: The regmap instance that should be used by the component
395 * This function allows deferred assignment of the regmap instance that is
396 * associated with the component. Only use this if the regmap instance is not
397 * yet ready when the component is registered. The function must also be called
398 * before the first IO attempt of the component.
400 void snd_soc_component_init_regmap(struct snd_soc_component *component,
401 struct regmap *regmap)
403 component->regmap = regmap;
404 snd_soc_component_setup_regmap(component);
406 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
409 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the
411 * @component: The component for which to de-initialize the regmap instance
413 * Calls regmap_exit() on the regmap instance associated to the component and
414 * removes the regmap instance from the component.
416 * This function should only be used if snd_soc_component_init_regmap() was used
417 * to initialize the regmap instance.
419 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
421 regmap_exit(component->regmap);
422 component->regmap = NULL;
424 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
428 int snd_soc_component_compr_open(struct snd_compr_stream *cstream)
430 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
431 struct snd_soc_component *component;
434 for_each_rtd_components(rtd, i, component) {
435 if (component->driver->compress_ops &&
436 component->driver->compress_ops->open) {
437 ret = component->driver->compress_ops->open(component, cstream);
439 return soc_component_ret(component, ret);
441 soc_component_mark_push(component, cstream, compr_open);
446 EXPORT_SYMBOL_GPL(snd_soc_component_compr_open);
448 void snd_soc_component_compr_free(struct snd_compr_stream *cstream,
451 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
452 struct snd_soc_component *component;
455 for_each_rtd_components(rtd, i, component) {
456 if (rollback && !soc_component_mark_match(component, cstream, compr_open))
459 if (component->driver->compress_ops &&
460 component->driver->compress_ops->free)
461 component->driver->compress_ops->free(component, cstream);
463 soc_component_mark_pop(component, cstream, compr_open);
466 EXPORT_SYMBOL_GPL(snd_soc_component_compr_free);
468 int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd)
470 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
471 struct snd_soc_component *component;
474 for_each_rtd_components(rtd, i, component) {
475 if (component->driver->compress_ops &&
476 component->driver->compress_ops->trigger) {
477 ret = component->driver->compress_ops->trigger(
478 component, cstream, cmd);
480 return soc_component_ret(component, ret);
486 EXPORT_SYMBOL_GPL(snd_soc_component_compr_trigger);
488 int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
489 struct snd_compr_params *params)
491 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
492 struct snd_soc_component *component;
495 for_each_rtd_components(rtd, i, component) {
496 if (component->driver->compress_ops &&
497 component->driver->compress_ops->set_params) {
498 ret = component->driver->compress_ops->set_params(
499 component, cstream, params);
501 return soc_component_ret(component, ret);
507 EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_params);
509 int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
510 struct snd_codec *params)
512 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
513 struct snd_soc_component *component;
516 for_each_rtd_components(rtd, i, component) {
517 if (component->driver->compress_ops &&
518 component->driver->compress_ops->get_params) {
519 ret = component->driver->compress_ops->get_params(
520 component, cstream, params);
521 return soc_component_ret(component, ret);
527 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_params);
529 int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
530 struct snd_compr_caps *caps)
532 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
533 struct snd_soc_component *component;
536 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
538 for_each_rtd_components(rtd, i, component) {
539 if (component->driver->compress_ops &&
540 component->driver->compress_ops->get_caps) {
541 ret = component->driver->compress_ops->get_caps(
542 component, cstream, caps);
547 mutex_unlock(&rtd->card->pcm_mutex);
549 return soc_component_ret(component, ret);
551 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_caps);
553 int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
554 struct snd_compr_codec_caps *codec)
556 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
557 struct snd_soc_component *component;
560 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
562 for_each_rtd_components(rtd, i, component) {
563 if (component->driver->compress_ops &&
564 component->driver->compress_ops->get_codec_caps) {
565 ret = component->driver->compress_ops->get_codec_caps(
566 component, cstream, codec);
571 mutex_unlock(&rtd->card->pcm_mutex);
573 return soc_component_ret(component, ret);
575 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_codec_caps);
577 int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
579 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
580 struct snd_soc_component *component;
583 for_each_rtd_components(rtd, i, component) {
584 if (component->driver->compress_ops &&
585 component->driver->compress_ops->ack) {
586 ret = component->driver->compress_ops->ack(
587 component, cstream, bytes);
589 return soc_component_ret(component, ret);
595 EXPORT_SYMBOL_GPL(snd_soc_component_compr_ack);
597 int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
598 struct snd_compr_tstamp *tstamp)
600 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
601 struct snd_soc_component *component;
604 for_each_rtd_components(rtd, i, component) {
605 if (component->driver->compress_ops &&
606 component->driver->compress_ops->pointer) {
607 ret = component->driver->compress_ops->pointer(
608 component, cstream, tstamp);
609 return soc_component_ret(component, ret);
615 EXPORT_SYMBOL_GPL(snd_soc_component_compr_pointer);
617 int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
618 char __user *buf, size_t count)
620 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
621 struct snd_soc_component *component;
624 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
626 for_each_rtd_components(rtd, i, component) {
627 if (component->driver->compress_ops &&
628 component->driver->compress_ops->copy) {
629 ret = component->driver->compress_ops->copy(
630 component, cstream, buf, count);
635 mutex_unlock(&rtd->card->pcm_mutex);
637 return soc_component_ret(component, ret);
639 EXPORT_SYMBOL_GPL(snd_soc_component_compr_copy);
641 int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
642 struct snd_compr_metadata *metadata)
644 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
645 struct snd_soc_component *component;
648 for_each_rtd_components(rtd, i, component) {
649 if (component->driver->compress_ops &&
650 component->driver->compress_ops->set_metadata) {
651 ret = component->driver->compress_ops->set_metadata(
652 component, cstream, metadata);
654 return soc_component_ret(component, ret);
660 EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_metadata);
662 int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
663 struct snd_compr_metadata *metadata)
665 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
666 struct snd_soc_component *component;
669 for_each_rtd_components(rtd, i, component) {
670 if (component->driver->compress_ops &&
671 component->driver->compress_ops->get_metadata) {
672 ret = component->driver->compress_ops->get_metadata(
673 component, cstream, metadata);
674 return soc_component_ret(component, ret);
680 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_metadata);
682 static unsigned int soc_component_read_no_lock(
683 struct snd_soc_component *component,
687 unsigned int val = 0;
689 if (component->regmap)
690 ret = regmap_read(component->regmap, reg, &val);
691 else if (component->driver->read) {
693 val = component->driver->read(component, reg);
699 return soc_component_ret(component, ret);
705 * snd_soc_component_read() - Read register value
706 * @component: Component to read from
707 * @reg: Register to read
711 unsigned int snd_soc_component_read(struct snd_soc_component *component,
716 mutex_lock(&component->io_mutex);
717 val = soc_component_read_no_lock(component, reg);
718 mutex_unlock(&component->io_mutex);
722 EXPORT_SYMBOL_GPL(snd_soc_component_read);
724 static int soc_component_write_no_lock(
725 struct snd_soc_component *component,
726 unsigned int reg, unsigned int val)
730 if (component->regmap)
731 ret = regmap_write(component->regmap, reg, val);
732 else if (component->driver->write)
733 ret = component->driver->write(component, reg, val);
735 return soc_component_ret(component, ret);
739 * snd_soc_component_write() - Write register value
740 * @component: Component to write to
741 * @reg: Register to write
742 * @val: Value to write to the register
744 * Return: 0 on success, a negative error code otherwise.
746 int snd_soc_component_write(struct snd_soc_component *component,
747 unsigned int reg, unsigned int val)
751 mutex_lock(&component->io_mutex);
752 ret = soc_component_write_no_lock(component, reg, val);
753 mutex_unlock(&component->io_mutex);
757 EXPORT_SYMBOL_GPL(snd_soc_component_write);
759 static int snd_soc_component_update_bits_legacy(
760 struct snd_soc_component *component, unsigned int reg,
761 unsigned int mask, unsigned int val, bool *change)
763 unsigned int old, new;
766 mutex_lock(&component->io_mutex);
768 old = soc_component_read_no_lock(component, reg);
770 new = (old & ~mask) | (val & mask);
771 *change = old != new;
773 ret = soc_component_write_no_lock(component, reg, new);
775 mutex_unlock(&component->io_mutex);
777 return soc_component_ret(component, ret);
781 * snd_soc_component_update_bits() - Perform read/modify/write cycle
782 * @component: Component to update
783 * @reg: Register to update
784 * @mask: Mask that specifies which bits to update
785 * @val: New value for the bits specified by mask
787 * Return: 1 if the operation was successful and the value of the register
788 * changed, 0 if the operation was successful, but the value did not change.
789 * Returns a negative error code otherwise.
791 int snd_soc_component_update_bits(struct snd_soc_component *component,
792 unsigned int reg, unsigned int mask, unsigned int val)
797 if (component->regmap)
798 ret = regmap_update_bits_check(component->regmap, reg, mask,
801 ret = snd_soc_component_update_bits_legacy(component, reg,
805 return soc_component_ret(component, ret);
808 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
811 * snd_soc_component_update_bits_async() - Perform asynchronous
812 * read/modify/write cycle
813 * @component: Component to update
814 * @reg: Register to update
815 * @mask: Mask that specifies which bits to update
816 * @val: New value for the bits specified by mask
818 * This function is similar to snd_soc_component_update_bits(), but the update
819 * operation is scheduled asynchronously. This means it may not be completed
820 * when the function returns. To make sure that all scheduled updates have been
821 * completed snd_soc_component_async_complete() must be called.
823 * Return: 1 if the operation was successful and the value of the register
824 * changed, 0 if the operation was successful, but the value did not change.
825 * Returns a negative error code otherwise.
827 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
828 unsigned int reg, unsigned int mask, unsigned int val)
833 if (component->regmap)
834 ret = regmap_update_bits_check_async(component->regmap, reg,
837 ret = snd_soc_component_update_bits_legacy(component, reg,
841 return soc_component_ret(component, ret);
844 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
847 * snd_soc_component_read_field() - Read register field value
848 * @component: Component to read from
849 * @reg: Register to read
850 * @mask: mask of the register field
852 * Return: read value of register field.
854 unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
855 unsigned int reg, unsigned int mask)
859 val = snd_soc_component_read(component, reg);
861 val = (val & mask) >> soc_component_field_shift(component, mask);
865 EXPORT_SYMBOL_GPL(snd_soc_component_read_field);
868 * snd_soc_component_write_field() - write to register field
869 * @component: Component to write to
870 * @reg: Register to write
871 * @mask: mask of the register field to update
872 * @val: value of the field to write
874 * Return: 1 for change, otherwise 0.
876 int snd_soc_component_write_field(struct snd_soc_component *component,
877 unsigned int reg, unsigned int mask,
881 val = (val << soc_component_field_shift(component, mask)) & mask;
883 return snd_soc_component_update_bits(component, reg, mask, val);
885 EXPORT_SYMBOL_GPL(snd_soc_component_write_field);
888 * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
889 * @component: Component for which to wait
891 * This function blocks until all asynchronous I/O which has previously been
892 * scheduled using snd_soc_component_update_bits_async() has completed.
894 void snd_soc_component_async_complete(struct snd_soc_component *component)
896 if (component->regmap)
897 regmap_async_complete(component->regmap);
899 EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
902 * snd_soc_component_test_bits - Test register for change
903 * @component: component
904 * @reg: Register to test
905 * @mask: Mask that specifies which bits to test
906 * @value: Value to test against
908 * Tests a register with a new value and checks if the new value is
909 * different from the old value.
911 * Return: 1 for change, otherwise 0.
913 int snd_soc_component_test_bits(struct snd_soc_component *component,
914 unsigned int reg, unsigned int mask, unsigned int value)
916 unsigned int old, new;
918 old = snd_soc_component_read(component, reg);
919 new = (old & ~mask) | value;
922 EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);
924 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
926 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
927 struct snd_soc_component *component;
930 /* FIXME: use 1st pointer */
931 for_each_rtd_components(rtd, i, component)
932 if (component->driver->pointer)
933 return component->driver->pointer(component, substream);
938 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
939 unsigned int cmd, void *arg)
941 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
942 struct snd_soc_component *component;
945 /* FIXME: use 1st ioctl */
946 for_each_rtd_components(rtd, i, component)
947 if (component->driver->ioctl)
948 return soc_component_ret(
950 component->driver->ioctl(component,
951 substream, cmd, arg));
953 return snd_pcm_lib_ioctl(substream, cmd, arg);
956 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream)
958 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
959 struct snd_soc_component *component;
962 for_each_rtd_components(rtd, i, component) {
963 if (component->driver->sync_stop) {
964 ret = component->driver->sync_stop(component,
967 return soc_component_ret(component, ret);
974 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
975 int channel, unsigned long pos,
976 void __user *buf, unsigned long bytes)
978 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
979 struct snd_soc_component *component;
982 /* FIXME. it returns 1st copy now */
983 for_each_rtd_components(rtd, i, component)
984 if (component->driver->copy_user)
985 return soc_component_ret(
987 component->driver->copy_user(
988 component, substream, channel,
994 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
995 unsigned long offset)
997 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
998 struct snd_soc_component *component;
1002 /* FIXME. it returns 1st page now */
1003 for_each_rtd_components(rtd, i, component) {
1004 if (component->driver->page) {
1005 page = component->driver->page(component,
1015 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
1016 struct vm_area_struct *vma)
1018 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1019 struct snd_soc_component *component;
1022 /* FIXME. it returns 1st mmap now */
1023 for_each_rtd_components(rtd, i, component)
1024 if (component->driver->mmap)
1025 return soc_component_ret(
1027 component->driver->mmap(component,
1033 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd)
1035 struct snd_soc_component *component;
1039 for_each_rtd_components(rtd, i, component) {
1040 if (component->driver->pcm_construct) {
1041 ret = component->driver->pcm_construct(component, rtd);
1043 return soc_component_ret(component, ret);
1050 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd)
1052 struct snd_soc_component *component;
1058 for_each_rtd_components(rtd, i, component)
1059 if (component->driver->pcm_destruct)
1060 component->driver->pcm_destruct(component, rtd->pcm);
1063 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream)
1065 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1066 struct snd_soc_component *component;
1069 for_each_rtd_components(rtd, i, component) {
1070 if (component->driver->prepare) {
1071 ret = component->driver->prepare(component, substream);
1073 return soc_component_ret(component, ret);
1080 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
1081 struct snd_pcm_hw_params *params)
1083 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1084 struct snd_soc_component *component;
1087 for_each_rtd_components(rtd, i, component) {
1088 if (component->driver->hw_params) {
1089 ret = component->driver->hw_params(component,
1092 return soc_component_ret(component, ret);
1094 /* mark substream if succeeded */
1095 soc_component_mark_push(component, substream, hw_params);
1101 void snd_soc_pcm_component_hw_free(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 (rollback && !soc_component_mark_match(component, substream, hw_params))
1112 if (component->driver->hw_free) {
1113 ret = component->driver->hw_free(component, substream);
1115 soc_component_ret(component, ret);
1118 /* remove marked substream */
1119 soc_component_mark_pop(component, substream, hw_params);
1123 static int soc_component_trigger(struct snd_soc_component *component,
1124 struct snd_pcm_substream *substream,
1129 if (component->driver->trigger)
1130 ret = component->driver->trigger(component, substream, cmd);
1132 return soc_component_ret(component, ret);
1135 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
1136 int cmd, int rollback)
1138 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1139 struct snd_soc_component *component;
1143 case SNDRV_PCM_TRIGGER_START:
1144 case SNDRV_PCM_TRIGGER_RESUME:
1145 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1146 for_each_rtd_components(rtd, i, component) {
1147 ret = soc_component_trigger(component, substream, cmd);
1150 soc_component_mark_push(component, substream, trigger);
1153 case SNDRV_PCM_TRIGGER_STOP:
1154 case SNDRV_PCM_TRIGGER_SUSPEND:
1155 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1156 for_each_rtd_components(rtd, i, component) {
1157 if (rollback && !soc_component_mark_match(component, substream, trigger))
1160 r = soc_component_trigger(component, substream, cmd);
1162 ret = r; /* use last ret */
1163 soc_component_mark_pop(component, substream, trigger);
1170 int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
1173 struct snd_soc_component *component;
1176 for_each_rtd_components(rtd, i, component) {
1177 int ret = pm_runtime_get_sync(component->dev);
1178 if (ret < 0 && ret != -EACCES) {
1179 pm_runtime_put_noidle(component->dev);
1180 return soc_component_ret(component, ret);
1182 /* mark stream if succeeded */
1183 soc_component_mark_push(component, stream, pm);
1189 void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
1190 void *stream, int rollback)
1192 struct snd_soc_component *component;
1195 for_each_rtd_components(rtd, i, component) {
1196 if (rollback && !soc_component_mark_match(component, stream, pm))
1199 pm_runtime_mark_last_busy(component->dev);
1200 pm_runtime_put_autosuspend(component->dev);
1202 /* remove marked stream */
1203 soc_component_mark_pop(component, stream, pm);
1207 int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream)
1209 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1210 struct snd_soc_component *component;
1213 /* FIXME: use 1st pointer */
1214 for_each_rtd_components(rtd, i, component)
1215 if (component->driver->ack)
1216 return component->driver->ack(component, substream);