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 static int soc_component_pin(struct snd_soc_component *component,
153 int (*pin_func)(struct snd_soc_dapm_context *dapm,
156 struct snd_soc_dapm_context *dapm =
157 snd_soc_component_get_dapm(component);
161 if (!component->name_prefix) {
162 ret = pin_func(dapm, pin);
166 full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
172 ret = pin_func(dapm, full_name);
175 return soc_component_ret(component, ret);
178 int snd_soc_component_enable_pin(struct snd_soc_component *component,
181 return soc_component_pin(component, pin, snd_soc_dapm_enable_pin);
183 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
185 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
188 return soc_component_pin(component, pin, snd_soc_dapm_enable_pin_unlocked);
190 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
192 int snd_soc_component_disable_pin(struct snd_soc_component *component,
195 return soc_component_pin(component, pin, snd_soc_dapm_disable_pin);
197 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
199 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
202 return soc_component_pin(component, pin, snd_soc_dapm_disable_pin_unlocked);
204 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
206 int snd_soc_component_nc_pin(struct snd_soc_component *component,
209 return soc_component_pin(component, pin, snd_soc_dapm_nc_pin);
211 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
213 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
216 return soc_component_pin(component, pin, snd_soc_dapm_nc_pin_unlocked);
218 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
220 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
223 return soc_component_pin(component, pin, snd_soc_dapm_get_pin_status);
225 EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
227 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
230 return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin);
232 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
234 int snd_soc_component_force_enable_pin_unlocked(
235 struct snd_soc_component *component,
238 return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin_unlocked);
240 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
243 * snd_soc_component_set_jack - configure component jack.
244 * @component: COMPONENTs
245 * @jack: structure to use for the jack
246 * @data: can be used if codec driver need extra data for configuring jack
248 * Configures and enables jack detection function.
250 int snd_soc_component_set_jack(struct snd_soc_component *component,
251 struct snd_soc_jack *jack, void *data)
255 if (component->driver->set_jack)
256 ret = component->driver->set_jack(component, jack, data);
258 return soc_component_ret(component, ret);
260 EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
262 int snd_soc_component_module_get(struct snd_soc_component *component,
263 struct snd_pcm_substream *substream,
268 if (component->driver->module_get_upon_open == !!upon_open &&
269 !try_module_get(component->dev->driver->owner))
272 /* mark substream if succeeded */
274 soc_component_mark_push(component, substream, module);
276 return soc_component_ret(component, ret);
279 void snd_soc_component_module_put(struct snd_soc_component *component,
280 struct snd_pcm_substream *substream,
281 int upon_open, int rollback)
283 if (rollback && !soc_component_mark_match(component, substream, module))
286 if (component->driver->module_get_upon_open == !!upon_open)
287 module_put(component->dev->driver->owner);
289 /* remove marked substream */
290 soc_component_mark_pop(component, substream, module);
293 int snd_soc_component_open(struct snd_soc_component *component,
294 struct snd_pcm_substream *substream)
298 if (component->driver->open)
299 ret = component->driver->open(component, substream);
301 /* mark substream if succeeded */
303 soc_component_mark_push(component, substream, open);
305 return soc_component_ret(component, ret);
308 int snd_soc_component_close(struct snd_soc_component *component,
309 struct snd_pcm_substream *substream,
314 if (rollback && !soc_component_mark_match(component, substream, open))
317 if (component->driver->close)
318 ret = component->driver->close(component, substream);
320 /* remove marked substream */
321 soc_component_mark_pop(component, substream, open);
323 return soc_component_ret(component, ret);
326 void snd_soc_component_suspend(struct snd_soc_component *component)
328 if (component->driver->suspend)
329 component->driver->suspend(component);
330 component->suspended = 1;
333 void snd_soc_component_resume(struct snd_soc_component *component)
335 if (component->driver->resume)
336 component->driver->resume(component);
337 component->suspended = 0;
340 int snd_soc_component_is_suspended(struct snd_soc_component *component)
342 return component->suspended;
345 int snd_soc_component_probe(struct snd_soc_component *component)
349 if (component->driver->probe)
350 ret = component->driver->probe(component);
352 return soc_component_ret(component, ret);
355 void snd_soc_component_remove(struct snd_soc_component *component)
357 if (component->driver->remove)
358 component->driver->remove(component);
361 int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
362 struct device_node *ep)
366 if (component->driver->of_xlate_dai_id)
367 ret = component->driver->of_xlate_dai_id(component, ep);
369 return soc_component_ret(component, ret);
372 int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
373 struct of_phandle_args *args,
374 const char **dai_name)
376 if (component->driver->of_xlate_dai_name)
377 return component->driver->of_xlate_dai_name(component,
380 * Don't use soc_component_ret here because we may not want to report
381 * the error just yet. If a device has more than one component, the
382 * first may not match and we don't want spam the log with this.
387 void snd_soc_component_setup_regmap(struct snd_soc_component *component)
389 int val_bytes = regmap_get_val_bytes(component->regmap);
391 /* Errors are legitimate for non-integer byte multiples */
393 component->val_bytes = val_bytes;
399 * snd_soc_component_init_regmap() - Initialize regmap instance for the
401 * @component: The component for which to initialize the regmap instance
402 * @regmap: The regmap instance that should be used by the component
404 * This function allows deferred assignment of the regmap instance that is
405 * associated with the component. Only use this if the regmap instance is not
406 * yet ready when the component is registered. The function must also be called
407 * before the first IO attempt of the component.
409 void snd_soc_component_init_regmap(struct snd_soc_component *component,
410 struct regmap *regmap)
412 component->regmap = regmap;
413 snd_soc_component_setup_regmap(component);
415 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
418 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the
420 * @component: The component for which to de-initialize the regmap instance
422 * Calls regmap_exit() on the regmap instance associated to the component and
423 * removes the regmap instance from the component.
425 * This function should only be used if snd_soc_component_init_regmap() was used
426 * to initialize the regmap instance.
428 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
430 regmap_exit(component->regmap);
431 component->regmap = NULL;
433 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
437 int snd_soc_component_compr_open(struct snd_compr_stream *cstream)
439 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
440 struct snd_soc_component *component;
443 for_each_rtd_components(rtd, i, component) {
444 if (component->driver->compress_ops &&
445 component->driver->compress_ops->open) {
446 ret = component->driver->compress_ops->open(component, cstream);
448 return soc_component_ret(component, ret);
450 soc_component_mark_push(component, cstream, compr_open);
455 EXPORT_SYMBOL_GPL(snd_soc_component_compr_open);
457 void snd_soc_component_compr_free(struct snd_compr_stream *cstream,
460 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
461 struct snd_soc_component *component;
464 for_each_rtd_components(rtd, i, component) {
465 if (rollback && !soc_component_mark_match(component, cstream, compr_open))
468 if (component->driver->compress_ops &&
469 component->driver->compress_ops->free)
470 component->driver->compress_ops->free(component, cstream);
472 soc_component_mark_pop(component, cstream, compr_open);
475 EXPORT_SYMBOL_GPL(snd_soc_component_compr_free);
477 int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd)
479 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
480 struct snd_soc_component *component;
483 for_each_rtd_components(rtd, i, component) {
484 if (component->driver->compress_ops &&
485 component->driver->compress_ops->trigger) {
486 ret = component->driver->compress_ops->trigger(
487 component, cstream, cmd);
489 return soc_component_ret(component, ret);
495 EXPORT_SYMBOL_GPL(snd_soc_component_compr_trigger);
497 int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
498 struct snd_compr_params *params)
500 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
501 struct snd_soc_component *component;
504 for_each_rtd_components(rtd, i, component) {
505 if (component->driver->compress_ops &&
506 component->driver->compress_ops->set_params) {
507 ret = component->driver->compress_ops->set_params(
508 component, cstream, params);
510 return soc_component_ret(component, ret);
516 EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_params);
518 int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
519 struct snd_codec *params)
521 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
522 struct snd_soc_component *component;
525 for_each_rtd_components(rtd, i, component) {
526 if (component->driver->compress_ops &&
527 component->driver->compress_ops->get_params) {
528 ret = component->driver->compress_ops->get_params(
529 component, cstream, params);
530 return soc_component_ret(component, ret);
536 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_params);
538 int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
539 struct snd_compr_caps *caps)
541 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
542 struct snd_soc_component *component;
545 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
547 for_each_rtd_components(rtd, i, component) {
548 if (component->driver->compress_ops &&
549 component->driver->compress_ops->get_caps) {
550 ret = component->driver->compress_ops->get_caps(
551 component, cstream, caps);
556 mutex_unlock(&rtd->card->pcm_mutex);
558 return soc_component_ret(component, ret);
560 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_caps);
562 int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
563 struct snd_compr_codec_caps *codec)
565 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
566 struct snd_soc_component *component;
569 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
571 for_each_rtd_components(rtd, i, component) {
572 if (component->driver->compress_ops &&
573 component->driver->compress_ops->get_codec_caps) {
574 ret = component->driver->compress_ops->get_codec_caps(
575 component, cstream, codec);
580 mutex_unlock(&rtd->card->pcm_mutex);
582 return soc_component_ret(component, ret);
584 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_codec_caps);
586 int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
588 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
589 struct snd_soc_component *component;
592 for_each_rtd_components(rtd, i, component) {
593 if (component->driver->compress_ops &&
594 component->driver->compress_ops->ack) {
595 ret = component->driver->compress_ops->ack(
596 component, cstream, bytes);
598 return soc_component_ret(component, ret);
604 EXPORT_SYMBOL_GPL(snd_soc_component_compr_ack);
606 int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
607 struct snd_compr_tstamp *tstamp)
609 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
610 struct snd_soc_component *component;
613 for_each_rtd_components(rtd, i, component) {
614 if (component->driver->compress_ops &&
615 component->driver->compress_ops->pointer) {
616 ret = component->driver->compress_ops->pointer(
617 component, cstream, tstamp);
618 return soc_component_ret(component, ret);
624 EXPORT_SYMBOL_GPL(snd_soc_component_compr_pointer);
626 int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
627 char __user *buf, size_t count)
629 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
630 struct snd_soc_component *component;
633 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
635 for_each_rtd_components(rtd, i, component) {
636 if (component->driver->compress_ops &&
637 component->driver->compress_ops->copy) {
638 ret = component->driver->compress_ops->copy(
639 component, cstream, buf, count);
644 mutex_unlock(&rtd->card->pcm_mutex);
646 return soc_component_ret(component, ret);
648 EXPORT_SYMBOL_GPL(snd_soc_component_compr_copy);
650 int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
651 struct snd_compr_metadata *metadata)
653 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
654 struct snd_soc_component *component;
657 for_each_rtd_components(rtd, i, component) {
658 if (component->driver->compress_ops &&
659 component->driver->compress_ops->set_metadata) {
660 ret = component->driver->compress_ops->set_metadata(
661 component, cstream, metadata);
663 return soc_component_ret(component, ret);
669 EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_metadata);
671 int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
672 struct snd_compr_metadata *metadata)
674 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
675 struct snd_soc_component *component;
678 for_each_rtd_components(rtd, i, component) {
679 if (component->driver->compress_ops &&
680 component->driver->compress_ops->get_metadata) {
681 ret = component->driver->compress_ops->get_metadata(
682 component, cstream, metadata);
683 return soc_component_ret(component, ret);
689 EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_metadata);
691 static unsigned int soc_component_read_no_lock(
692 struct snd_soc_component *component,
696 unsigned int val = 0;
698 if (component->regmap)
699 ret = regmap_read(component->regmap, reg, &val);
700 else if (component->driver->read) {
702 val = component->driver->read(component, reg);
708 return soc_component_ret(component, ret);
714 * snd_soc_component_read() - Read register value
715 * @component: Component to read from
716 * @reg: Register to read
720 unsigned int snd_soc_component_read(struct snd_soc_component *component,
725 mutex_lock(&component->io_mutex);
726 val = soc_component_read_no_lock(component, reg);
727 mutex_unlock(&component->io_mutex);
731 EXPORT_SYMBOL_GPL(snd_soc_component_read);
733 static int soc_component_write_no_lock(
734 struct snd_soc_component *component,
735 unsigned int reg, unsigned int val)
739 if (component->regmap)
740 ret = regmap_write(component->regmap, reg, val);
741 else if (component->driver->write)
742 ret = component->driver->write(component, reg, val);
744 return soc_component_ret(component, ret);
748 * snd_soc_component_write() - Write register value
749 * @component: Component to write to
750 * @reg: Register to write
751 * @val: Value to write to the register
753 * Return: 0 on success, a negative error code otherwise.
755 int snd_soc_component_write(struct snd_soc_component *component,
756 unsigned int reg, unsigned int val)
760 mutex_lock(&component->io_mutex);
761 ret = soc_component_write_no_lock(component, reg, val);
762 mutex_unlock(&component->io_mutex);
766 EXPORT_SYMBOL_GPL(snd_soc_component_write);
768 static int snd_soc_component_update_bits_legacy(
769 struct snd_soc_component *component, unsigned int reg,
770 unsigned int mask, unsigned int val, bool *change)
772 unsigned int old, new;
775 mutex_lock(&component->io_mutex);
777 old = soc_component_read_no_lock(component, reg);
779 new = (old & ~mask) | (val & mask);
780 *change = old != new;
782 ret = soc_component_write_no_lock(component, reg, new);
784 mutex_unlock(&component->io_mutex);
786 return soc_component_ret(component, ret);
790 * snd_soc_component_update_bits() - Perform read/modify/write cycle
791 * @component: Component to update
792 * @reg: Register to update
793 * @mask: Mask that specifies which bits to update
794 * @val: New value for the bits specified by mask
796 * Return: 1 if the operation was successful and the value of the register
797 * changed, 0 if the operation was successful, but the value did not change.
798 * Returns a negative error code otherwise.
800 int snd_soc_component_update_bits(struct snd_soc_component *component,
801 unsigned int reg, unsigned int mask, unsigned int val)
806 if (component->regmap)
807 ret = regmap_update_bits_check(component->regmap, reg, mask,
810 ret = snd_soc_component_update_bits_legacy(component, reg,
814 return soc_component_ret(component, ret);
817 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
820 * snd_soc_component_update_bits_async() - Perform asynchronous
821 * read/modify/write cycle
822 * @component: Component to update
823 * @reg: Register to update
824 * @mask: Mask that specifies which bits to update
825 * @val: New value for the bits specified by mask
827 * This function is similar to snd_soc_component_update_bits(), but the update
828 * operation is scheduled asynchronously. This means it may not be completed
829 * when the function returns. To make sure that all scheduled updates have been
830 * completed snd_soc_component_async_complete() must be called.
832 * Return: 1 if the operation was successful and the value of the register
833 * changed, 0 if the operation was successful, but the value did not change.
834 * Returns a negative error code otherwise.
836 int snd_soc_component_update_bits_async(struct snd_soc_component *component,
837 unsigned int reg, unsigned int mask, unsigned int val)
842 if (component->regmap)
843 ret = regmap_update_bits_check_async(component->regmap, reg,
846 ret = snd_soc_component_update_bits_legacy(component, reg,
850 return soc_component_ret(component, ret);
853 EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
856 * snd_soc_component_read_field() - Read register field value
857 * @component: Component to read from
858 * @reg: Register to read
859 * @mask: mask of the register field
861 * Return: read value of register field.
863 unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
864 unsigned int reg, unsigned int mask)
868 val = snd_soc_component_read(component, reg);
870 val = (val & mask) >> soc_component_field_shift(component, mask);
874 EXPORT_SYMBOL_GPL(snd_soc_component_read_field);
877 * snd_soc_component_write_field() - write to register field
878 * @component: Component to write to
879 * @reg: Register to write
880 * @mask: mask of the register field to update
881 * @val: value of the field to write
883 * Return: 1 for change, otherwise 0.
885 int snd_soc_component_write_field(struct snd_soc_component *component,
886 unsigned int reg, unsigned int mask,
890 val = (val << soc_component_field_shift(component, mask)) & mask;
892 return snd_soc_component_update_bits(component, reg, mask, val);
894 EXPORT_SYMBOL_GPL(snd_soc_component_write_field);
897 * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
898 * @component: Component for which to wait
900 * This function blocks until all asynchronous I/O which has previously been
901 * scheduled using snd_soc_component_update_bits_async() has completed.
903 void snd_soc_component_async_complete(struct snd_soc_component *component)
905 if (component->regmap)
906 regmap_async_complete(component->regmap);
908 EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
911 * snd_soc_component_test_bits - Test register for change
912 * @component: component
913 * @reg: Register to test
914 * @mask: Mask that specifies which bits to test
915 * @value: Value to test against
917 * Tests a register with a new value and checks if the new value is
918 * different from the old value.
920 * Return: 1 for change, otherwise 0.
922 int snd_soc_component_test_bits(struct snd_soc_component *component,
923 unsigned int reg, unsigned int mask, unsigned int value)
925 unsigned int old, new;
927 old = snd_soc_component_read(component, reg);
928 new = (old & ~mask) | value;
931 EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);
933 int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
935 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
936 struct snd_soc_component *component;
939 /* FIXME: use 1st pointer */
940 for_each_rtd_components(rtd, i, component)
941 if (component->driver->pointer)
942 return component->driver->pointer(component, substream);
947 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
948 unsigned int cmd, void *arg)
950 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
951 struct snd_soc_component *component;
954 /* FIXME: use 1st ioctl */
955 for_each_rtd_components(rtd, i, component)
956 if (component->driver->ioctl)
957 return soc_component_ret(
959 component->driver->ioctl(component,
960 substream, cmd, arg));
962 return snd_pcm_lib_ioctl(substream, cmd, arg);
965 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream)
967 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
968 struct snd_soc_component *component;
971 for_each_rtd_components(rtd, i, component) {
972 if (component->driver->sync_stop) {
973 ret = component->driver->sync_stop(component,
976 return soc_component_ret(component, ret);
983 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
984 int channel, unsigned long pos,
985 void __user *buf, unsigned long bytes)
987 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
988 struct snd_soc_component *component;
991 /* FIXME. it returns 1st copy now */
992 for_each_rtd_components(rtd, i, component)
993 if (component->driver->copy_user)
994 return soc_component_ret(
996 component->driver->copy_user(
997 component, substream, channel,
1003 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
1004 unsigned long offset)
1006 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1007 struct snd_soc_component *component;
1011 /* FIXME. it returns 1st page now */
1012 for_each_rtd_components(rtd, i, component) {
1013 if (component->driver->page) {
1014 page = component->driver->page(component,
1024 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
1025 struct vm_area_struct *vma)
1027 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1028 struct snd_soc_component *component;
1031 /* FIXME. it returns 1st mmap now */
1032 for_each_rtd_components(rtd, i, component)
1033 if (component->driver->mmap)
1034 return soc_component_ret(
1036 component->driver->mmap(component,
1042 int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd)
1044 struct snd_soc_component *component;
1048 for_each_rtd_components(rtd, i, component) {
1049 if (component->driver->pcm_construct) {
1050 ret = component->driver->pcm_construct(component, rtd);
1052 return soc_component_ret(component, ret);
1059 void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd)
1061 struct snd_soc_component *component;
1067 for_each_rtd_components(rtd, i, component)
1068 if (component->driver->pcm_destruct)
1069 component->driver->pcm_destruct(component, rtd->pcm);
1072 int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream)
1074 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1075 struct snd_soc_component *component;
1078 for_each_rtd_components(rtd, i, component) {
1079 if (component->driver->prepare) {
1080 ret = component->driver->prepare(component, substream);
1082 return soc_component_ret(component, ret);
1089 int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
1090 struct snd_pcm_hw_params *params)
1092 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1093 struct snd_soc_component *component;
1096 for_each_rtd_components(rtd, i, component) {
1097 if (component->driver->hw_params) {
1098 ret = component->driver->hw_params(component,
1101 return soc_component_ret(component, ret);
1103 /* mark substream if succeeded */
1104 soc_component_mark_push(component, substream, hw_params);
1110 void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
1113 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1114 struct snd_soc_component *component;
1117 for_each_rtd_components(rtd, i, component) {
1118 if (rollback && !soc_component_mark_match(component, substream, hw_params))
1121 if (component->driver->hw_free) {
1122 ret = component->driver->hw_free(component, substream);
1124 soc_component_ret(component, ret);
1127 /* remove marked substream */
1128 soc_component_mark_pop(component, substream, hw_params);
1132 static int soc_component_trigger(struct snd_soc_component *component,
1133 struct snd_pcm_substream *substream,
1138 if (component->driver->trigger)
1139 ret = component->driver->trigger(component, substream, cmd);
1141 return soc_component_ret(component, ret);
1144 int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
1145 int cmd, int rollback)
1147 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1148 struct snd_soc_component *component;
1152 case SNDRV_PCM_TRIGGER_START:
1153 case SNDRV_PCM_TRIGGER_RESUME:
1154 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1155 for_each_rtd_components(rtd, i, component) {
1156 ret = soc_component_trigger(component, substream, cmd);
1159 soc_component_mark_push(component, substream, trigger);
1162 case SNDRV_PCM_TRIGGER_STOP:
1163 case SNDRV_PCM_TRIGGER_SUSPEND:
1164 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1165 for_each_rtd_components(rtd, i, component) {
1166 if (rollback && !soc_component_mark_match(component, substream, trigger))
1169 r = soc_component_trigger(component, substream, cmd);
1171 ret = r; /* use last ret */
1172 soc_component_mark_pop(component, substream, trigger);
1179 int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
1182 struct snd_soc_component *component;
1185 for_each_rtd_components(rtd, i, component) {
1186 ret = pm_runtime_get_sync(component->dev);
1187 if (ret < 0 && ret != -EACCES) {
1188 pm_runtime_put_noidle(component->dev);
1189 return soc_component_ret(component, ret);
1191 /* mark stream if succeeded */
1192 soc_component_mark_push(component, stream, pm);
1198 void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
1199 void *stream, int rollback)
1201 struct snd_soc_component *component;
1204 for_each_rtd_components(rtd, i, component) {
1205 if (rollback && !soc_component_mark_match(component, stream, pm))
1208 pm_runtime_mark_last_busy(component->dev);
1209 pm_runtime_put_autosuspend(component->dev);
1211 /* remove marked stream */
1212 soc_component_mark_pop(component, stream, pm);