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