summaryrefslogtreecommitdiff
path: root/sound/soc/soc-pcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/soc-pcm.c')
-rw-r--r--sound/soc/soc-pcm.c806
1 files changed, 338 insertions, 468 deletions
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 77ee103b7cd1..2c21fd528afd 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -30,42 +30,108 @@
static inline int _soc_pcm_ret(struct snd_soc_pcm_runtime *rtd,
const char *func, int ret)
{
- /* Positive, Zero values are not errors */
- if (ret >= 0)
- return ret;
+ return snd_soc_ret(rtd->dev, ret,
+ "at %s() on %s\n", func, rtd->dai_link->name);
+}
- /* Negative values might be errors */
- switch (ret) {
- case -EPROBE_DEFER:
- case -ENOTSUPP:
- case -EINVAL:
- break;
- default:
- dev_err(rtd->dev,
- "ASoC: error at %s on %s: %d\n",
- func, rtd->dai_link->name, ret);
+/* is the current PCM operation for this FE ? */
+#if 0
+static int snd_soc_dpcm_can_fe_update(struct snd_soc_pcm_runtime *fe, int stream)
+{
+ if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE)
+ return 1;
+ return 0;
+}
+#endif
+
+/* is the current PCM operation for this BE ? */
+static int snd_soc_dpcm_can_be_update(struct snd_soc_pcm_runtime *fe,
+ struct snd_soc_pcm_runtime *be, int stream)
+{
+ if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) ||
+ ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) &&
+ be->dpcm[stream].runtime_update))
+ return 1;
+ return 0;
+}
+
+static int snd_soc_dpcm_check_state(struct snd_soc_pcm_runtime *fe,
+ struct snd_soc_pcm_runtime *be,
+ int stream,
+ const enum snd_soc_dpcm_state *states,
+ int num_states)
+{
+ struct snd_soc_dpcm *dpcm;
+ int state;
+ int ret = 1;
+ int i;
+
+ for_each_dpcm_fe(be, stream, dpcm) {
+
+ if (dpcm->fe == fe)
+ continue;
+
+ state = dpcm->fe->dpcm[stream].state;
+ for (i = 0; i < num_states; i++) {
+ if (state == states[i]) {
+ ret = 0;
+ break;
+ }
+ }
}
+ /* it's safe to do this BE DAI */
return ret;
}
-static inline void snd_soc_dpcm_stream_lock_irq(struct snd_soc_pcm_runtime *rtd,
- int stream)
+/*
+ * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
+ * are not running, paused or suspended for the specified stream direction.
+ */
+static int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
+ struct snd_soc_pcm_runtime *be, int stream)
{
- snd_pcm_stream_lock_irq(snd_soc_dpcm_get_substream(rtd, stream));
-}
+ const enum snd_soc_dpcm_state state[] = {
+ SND_SOC_DPCM_STATE_START,
+ SND_SOC_DPCM_STATE_PAUSED,
+ SND_SOC_DPCM_STATE_SUSPEND,
+ };
-#define snd_soc_dpcm_stream_lock_irqsave_nested(rtd, stream, flags) \
- snd_pcm_stream_lock_irqsave_nested(snd_soc_dpcm_get_substream(rtd, stream), flags)
+ return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
+}
-static inline void snd_soc_dpcm_stream_unlock_irq(struct snd_soc_pcm_runtime *rtd,
- int stream)
+/*
+ * We can only change hw params a BE DAI if any of it's FE are not prepared,
+ * running, paused or suspended for the specified stream direction.
+ */
+static int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
+ struct snd_soc_pcm_runtime *be, int stream)
{
- snd_pcm_stream_unlock_irq(snd_soc_dpcm_get_substream(rtd, stream));
+ const enum snd_soc_dpcm_state state[] = {
+ SND_SOC_DPCM_STATE_START,
+ SND_SOC_DPCM_STATE_PAUSED,
+ SND_SOC_DPCM_STATE_SUSPEND,
+ SND_SOC_DPCM_STATE_PREPARE,
+ };
+
+ return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
}
-#define snd_soc_dpcm_stream_unlock_irqrestore(rtd, stream, flags) \
- snd_pcm_stream_unlock_irqrestore(snd_soc_dpcm_get_substream(rtd, stream), flags)
+/*
+ * We can only prepare a BE DAI if any of it's FE are not prepared,
+ * running or paused for the specified stream direction.
+ */
+static int snd_soc_dpcm_can_be_prepared(struct snd_soc_pcm_runtime *fe,
+ struct snd_soc_pcm_runtime *be, int stream)
+{
+ const enum snd_soc_dpcm_state state[] = {
+ SND_SOC_DPCM_STATE_START,
+ SND_SOC_DPCM_STATE_PAUSED,
+ SND_SOC_DPCM_STATE_PREPARE,
+ };
+
+ return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
+}
#define DPCM_MAX_BE_USERS 8
@@ -78,7 +144,6 @@ static inline const char *soc_codec_dai_name(struct snd_soc_pcm_runtime *rtd)
return (rtd)->dai_link->num_codecs == 1 ? snd_soc_rtd_to_codec(rtd, 0)->name : "multicodec";
}
-#ifdef CONFIG_DEBUG_FS
static const char *dpcm_state_string(enum snd_soc_dpcm_state state)
{
switch (state) {
@@ -107,6 +172,7 @@ static const char *dpcm_state_string(enum snd_soc_dpcm_state state)
return "unknown";
}
+#ifdef CONFIG_DEBUG_FS
static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
int stream, char *buf, size_t size)
{
@@ -172,11 +238,9 @@ static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,
int stream;
char *buf;
- if (fe->dai_link->num_cpus > 1) {
- dev_err(fe->dev,
+ if (fe->dai_link->num_cpus > 1)
+ return snd_soc_ret(fe->dev, -EINVAL,
"%s doesn't support Multi CPU yet\n", __func__);
- return -EINVAL;
- }
buf = kmalloc(out_count, GFP_KERNEL);
if (!buf)
@@ -222,7 +286,7 @@ static void dpcm_create_debugfs_state(struct snd_soc_dpcm *dpcm, int stream)
char *name;
name = kasprintf(GFP_KERNEL, "%s:%s", dpcm->be->dai_link->name,
- stream ? "capture" : "playback");
+ snd_pcm_direction_name(stream));
if (name) {
dpcm->debugfs_state = debugfs_create_dir(
name, dpcm->fe->debugfs_dpcm_root);
@@ -260,14 +324,14 @@ static void dpcm_set_fe_update_state(struct snd_soc_pcm_runtime *fe,
struct snd_pcm_substream *substream =
snd_soc_dpcm_get_substream(fe, stream);
- snd_soc_dpcm_stream_lock_irq(fe, stream);
+ snd_pcm_stream_lock_irq(substream);
if (state == SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pending) {
dpcm_fe_dai_do_trigger(substream,
fe->dpcm[stream].trigger_pending - 1);
fe->dpcm[stream].trigger_pending = 0;
}
fe->dpcm[stream].runtime_update = state;
- snd_soc_dpcm_stream_unlock_irq(fe, stream);
+ snd_pcm_stream_unlock_irq(substream);
}
static void dpcm_set_be_update_state(struct snd_soc_pcm_runtime *be,
@@ -315,44 +379,28 @@ EXPORT_SYMBOL_GPL(snd_soc_runtime_action);
* @rtd: The ASoC PCM runtime that should be checked.
*
* This function checks whether the power down delay should be ignored for a
- * specific PCM runtime. Returns true if the delay is 0, if it the DAI link has
+ * specific PCM runtime. Returns true if the delay is 0, if the DAI link has
* been configured to ignore the delay, or if none of the components benefits
* from having the delay.
*/
bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_component *component;
- bool ignore = true;
int i;
if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
return true;
for_each_rtd_components(rtd, i, component)
- ignore &= !component->driver->use_pmdown_time;
-
- return ignore;
-}
+ if (component->driver->use_pmdown_time)
+ /* No need to go through all components */
+ return false;
-/**
- * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
- * @substream: the pcm substream
- * @hw: the hardware parameters
- *
- * Sets the substream runtime hardware parameters.
- */
-int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
- const struct snd_pcm_hardware *hw)
-{
- substream->runtime->hw = *hw;
-
- return 0;
+ return true;
}
-EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
/* DPCM stream event, send event to FE and all active BEs. */
-int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
- int event)
+void dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir, int event)
{
struct snd_soc_dpcm *dpcm;
@@ -373,21 +421,19 @@ int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
}
snd_soc_dapm_stream_event(fe, dir, event);
-
- return 0;
}
static void soc_pcm_set_dai_params(struct snd_soc_dai *dai,
struct snd_pcm_hw_params *params)
{
if (params) {
- dai->rate = params_rate(params);
- dai->channels = params_channels(params);
- dai->sample_bits = snd_pcm_format_physical_width(params_format(params));
+ dai->symmetric_rate = params_rate(params);
+ dai->symmetric_channels = params_channels(params);
+ dai->symmetric_sample_bits = snd_pcm_format_physical_width(params_format(params));
} else {
- dai->rate = 0;
- dai->channels = 0;
- dai->sample_bits = 0;
+ dai->symmetric_rate = 0;
+ dai->symmetric_channels = 0;
+ dai->symmetric_sample_bits = 0;
}
}
@@ -401,20 +447,17 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
return 0;
#define __soc_pcm_apply_symmetry(name, NAME) \
- if (soc_dai->name && (soc_dai->driver->symmetric_##name || \
- rtd->dai_link->symmetric_##name)) { \
+ if (soc_dai->symmetric_##name && \
+ (soc_dai->driver->symmetric_##name || rtd->dai_link->symmetric_##name)) { \
dev_dbg(soc_dai->dev, "ASoC: Symmetry forces %s to %d\n",\
- #name, soc_dai->name); \
+ #name, soc_dai->symmetric_##name); \
\
ret = snd_pcm_hw_constraint_single(substream->runtime, \
SNDRV_PCM_HW_PARAM_##NAME,\
- soc_dai->name); \
- if (ret < 0) { \
- dev_err(soc_dai->dev, \
- "ASoC: Unable to apply %s constraint: %d\n",\
- #name, ret); \
- return ret; \
- } \
+ soc_dai->symmetric_##name); \
+ if (ret < 0) \
+ return snd_soc_ret(soc_dai->dev, ret, \
+ "Unable to apply %s constraint\n", #name); \
}
__soc_pcm_apply_symmetry(rate, RATE);
@@ -444,11 +487,12 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
if (symmetry) \
for_each_rtd_cpu_dais(rtd, i, cpu_dai) \
if (!snd_soc_dai_is_dummy(cpu_dai) && \
- cpu_dai->xxx && cpu_dai->xxx != d.xxx) { \
- dev_err(rtd->dev, "ASoC: unmatched %s symmetry: %s:%d - %s:%d\n", \
- #xxx, cpu_dai->name, cpu_dai->xxx, d.name, d.xxx); \
- return -EINVAL; \
- }
+ cpu_dai->symmetric_##xxx && \
+ cpu_dai->symmetric_##xxx != d.symmetric_##xxx) \
+ return snd_soc_ret(rtd->dev, -EINVAL, \
+ "unmatched %s symmetry: %s:%d - %s:%d\n", \
+ #xxx, cpu_dai->name, cpu_dai->symmetric_##xxx, \
+ d.name, d.symmetric_##xxx);
/* reject unmatched parameters when applying symmetry */
__soc_pcm_params_symmetry(rate);
@@ -503,7 +547,7 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
unsigned int bits = 0, cpu_bits = 0;
for_each_rtd_codec_dais(rtd, i, codec_dai) {
- struct snd_soc_pcm_stream *pcm_codec = snd_soc_dai_get_pcm_stream(codec_dai, stream);
+ const struct snd_soc_pcm_stream *pcm_codec = snd_soc_dai_get_pcm_stream(codec_dai, stream);
if (pcm_codec->sig_bits == 0) {
bits = 0;
@@ -513,7 +557,7 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
}
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
- struct snd_soc_pcm_stream *pcm_cpu = snd_soc_dai_get_pcm_stream(cpu_dai, stream);
+ const struct snd_soc_pcm_stream *pcm_cpu = snd_soc_dai_get_pcm_stream(cpu_dai, stream);
if (pcm_cpu->sig_bits == 0) {
cpu_bits = 0;
@@ -537,7 +581,7 @@ static void soc_pcm_hw_init(struct snd_pcm_hardware *hw)
}
static void soc_pcm_hw_update_rate(struct snd_pcm_hardware *hw,
- struct snd_soc_pcm_stream *p)
+ const struct snd_soc_pcm_stream *p)
{
hw->rates = snd_pcm_rate_mask_intersect(hw->rates, p->rates);
@@ -550,22 +594,17 @@ static void soc_pcm_hw_update_rate(struct snd_pcm_hardware *hw,
}
static void soc_pcm_hw_update_chan(struct snd_pcm_hardware *hw,
- struct snd_soc_pcm_stream *p)
+ const struct snd_soc_pcm_stream *p)
{
hw->channels_min = max(hw->channels_min, p->channels_min);
hw->channels_max = min(hw->channels_max, p->channels_max);
}
static void soc_pcm_hw_update_format(struct snd_pcm_hardware *hw,
- struct snd_soc_pcm_stream *p)
-{
- hw->formats &= p->formats;
-}
-
-static void soc_pcm_hw_update_subformat(struct snd_pcm_hardware *hw,
- struct snd_soc_pcm_stream *p)
+ const struct snd_soc_pcm_stream *p)
{
- hw->subformats &= p->subformats;
+ hw->formats &= p->formats;
+ hw->subformats &= p->subformats;
}
/**
@@ -582,8 +621,8 @@ int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
{
struct snd_soc_dai *codec_dai;
struct snd_soc_dai *cpu_dai;
- struct snd_soc_pcm_stream *codec_stream;
- struct snd_soc_pcm_stream *cpu_stream;
+ const struct snd_soc_pcm_stream *codec_stream;
+ const struct snd_soc_pcm_stream *cpu_stream;
unsigned int cpu_chan_min = 0, cpu_chan_max = UINT_MAX;
int i;
@@ -606,7 +645,6 @@ int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
soc_pcm_hw_update_chan(hw, cpu_stream);
soc_pcm_hw_update_rate(hw, cpu_stream);
soc_pcm_hw_update_format(hw, cpu_stream);
- soc_pcm_hw_update_subformat(hw, cpu_stream);
}
cpu_chan_min = hw->channels_min;
cpu_chan_max = hw->channels_max;
@@ -628,7 +666,6 @@ int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd,
soc_pcm_hw_update_chan(hw, codec_stream);
soc_pcm_hw_update_rate(hw, codec_stream);
soc_pcm_hw_update_format(hw, codec_stream);
- soc_pcm_hw_update_subformat(hw, codec_stream);
}
/* Verify both a valid CPU DAI and a valid CODEC DAI were found */
@@ -717,13 +754,12 @@ static int soc_pcm_clean(struct snd_soc_pcm_runtime *rtd,
/* Make sure DAI parameters cleared if the DAI becomes inactive */
for_each_rtd_dais(rtd, i, dai) {
- if (snd_soc_dai_active(dai) == 0 &&
- (dai->rate || dai->channels || dai->sample_bits))
+ if (snd_soc_dai_active(dai) == 0)
soc_pcm_set_dai_params(dai, NULL);
}
}
- for_each_rtd_dais(rtd, i, dai)
+ for_each_rtd_dais_reverse(rtd, i, dai)
snd_soc_dai_shutdown(dai, substream, rollback);
snd_soc_link_shutdown(substream, rollback);
@@ -794,9 +830,8 @@ static int soc_hw_sanity_check(struct snd_pcm_substream *substream)
return 0;
config_err:
- dev_err(dev, "ASoC: %s <-> %s No matching %s\n",
- name_codec, name_cpu, err_msg);
- return -EINVAL;
+ return snd_soc_ret(dev, -EINVAL,
+ "%s <-> %s No matching %s\n", name_codec, name_cpu, err_msg);
}
/*
@@ -914,12 +949,18 @@ static int __soc_pcm_prepare(struct snd_soc_pcm_runtime *rtd,
SND_SOC_DAPM_STREAM_START);
for_each_rtd_dais(rtd, i, dai) {
- if (dai->driver->ops && !dai->driver->ops->mute_unmute_on_trigger)
+ if (!snd_soc_dai_mute_is_ctrled_at_trigger(dai))
snd_soc_dai_digital_mute(dai, 0, substream->stream);
}
out:
- return soc_pcm_ret(rtd, ret);
+ /*
+ * Don't use soc_pcm_ret() on .prepare callback to lower error log severity
+ *
+ * We don't want to log an error since we do not want to give userspace a way to do a
+ * denial-of-service attack on the syslog / diskspace.
+ */
+ return ret;
}
/* PCM prepare ops for non-DPCM streams */
@@ -931,6 +972,13 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
snd_soc_dpcm_mutex_lock(rtd);
ret = __soc_pcm_prepare(rtd, substream);
snd_soc_dpcm_mutex_unlock(rtd);
+
+ /*
+ * Don't use soc_pcm_ret() on .prepare callback to lower error log severity
+ *
+ * We don't want to log an error since we do not want to give userspace a way to do a
+ * denial-of-service attack on the syslog / diskspace.
+ */
return ret;
}
@@ -959,7 +1007,7 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd,
soc_pcm_set_dai_params(dai, NULL);
if (snd_soc_dai_stream_active(dai, substream->stream) == 1) {
- if (dai->driver->ops && !dai->driver->ops->mute_unmute_on_trigger)
+ if (!snd_soc_dai_mute_is_ctrled_at_trigger(dai))
snd_soc_dai_digital_mute(dai, 1, substream->stream);
}
}
@@ -1007,10 +1055,10 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
* function can also be called multiple times and can allocate buffers
* (using snd_pcm_lib_* ). It's non-atomic.
*/
-static int __soc_pcm_hw_params(struct snd_soc_pcm_runtime *rtd,
- struct snd_pcm_substream *substream,
+static int __soc_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
+ struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai;
struct snd_soc_dai *codec_dai;
struct snd_pcm_hw_params tmp_params;
@@ -1116,7 +1164,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
int ret;
snd_soc_dpcm_mutex_lock(rtd);
- ret = __soc_pcm_hw_params(rtd, substream, params);
+ ret = __soc_pcm_hw_params(substream, params);
snd_soc_dpcm_mutex_unlock(rtd);
return ret;
}
@@ -1246,19 +1294,18 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
snd_soc_dpcm_mutex_assert_held(fe);
/* only add new dpcms */
- for_each_dpcm_be(fe, stream, dpcm) {
- if (dpcm->be == be && dpcm->fe == fe)
+ for_each_dpcm_be(fe, stream, dpcm)
+ if (dpcm->be == be)
return 0;
- }
fe_substream = snd_soc_dpcm_get_substream(fe, stream);
be_substream = snd_soc_dpcm_get_substream(be, stream);
- if (!fe_substream->pcm->nonatomic && be_substream->pcm->nonatomic) {
- dev_err(be->dev, "%s: FE is atomic but BE is nonatomic, invalid configuration\n",
- __func__);
- return -EINVAL;
- }
+ if (!fe_substream->pcm->nonatomic && be_substream->pcm->nonatomic)
+ return snd_soc_ret(be->dev, -EINVAL,
+ "%s: %s is atomic but %s is nonatomic, invalid configuration\n",
+ __func__, fe->dai_link->name, be->dai_link->name);
+
if (fe_substream->pcm->nonatomic && !be_substream->pcm->nonatomic) {
dev_dbg(be->dev, "FE is nonatomic but BE is not, forcing BE as nonatomic\n");
be_substream->pcm->nonatomic = 1;
@@ -1271,13 +1318,13 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
dpcm->be = be;
dpcm->fe = fe;
dpcm->state = SND_SOC_DPCM_LINK_STATE_NEW;
- snd_soc_dpcm_stream_lock_irq(fe, stream);
+ snd_pcm_stream_lock_irq(fe_substream);
list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients);
list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients);
- snd_soc_dpcm_stream_unlock_irq(fe, stream);
+ snd_pcm_stream_unlock_irq(fe_substream);
dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n",
- stream ? "capture" : "playback", fe->dai_link->name,
+ snd_pcm_direction_name(stream), fe->dai_link->name,
stream ? "<-" : "->", be->dai_link->name);
dpcm_create_debugfs_state(dpcm, stream);
@@ -1305,7 +1352,7 @@ static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
continue;
dev_dbg(fe->dev, "reparent %s path %s %s %s\n",
- stream ? "capture" : "playback",
+ snd_pcm_direction_name(stream),
dpcm->fe->dai_link->name,
stream ? "<-" : "->", dpcm->be->dai_link->name);
@@ -1319,21 +1366,22 @@ static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe,
void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
{
struct snd_soc_dpcm *dpcm, *d;
+ struct snd_pcm_substream *substream = snd_soc_dpcm_get_substream(fe, stream);
LIST_HEAD(deleted_dpcms);
snd_soc_dpcm_mutex_assert_held(fe);
- snd_soc_dpcm_stream_lock_irq(fe, stream);
+ snd_pcm_stream_lock_irq(substream);
for_each_dpcm_be_safe(fe, stream, dpcm, d) {
dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n",
- stream ? "capture" : "playback",
+ snd_pcm_direction_name(stream),
dpcm->be->dai_link->name);
if (dpcm->state != SND_SOC_DPCM_LINK_STATE_FREE)
continue;
dev_dbg(fe->dev, "freed DSP %s path %s %s %s\n",
- stream ? "capture" : "playback", fe->dai_link->name,
+ snd_pcm_direction_name(stream), fe->dai_link->name,
stream ? "<-" : "->", dpcm->be->dai_link->name);
/* BEs still alive need new FE */
@@ -1342,7 +1390,7 @@ void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
list_del(&dpcm->list_be);
list_move(&dpcm->list_fe, &deleted_dpcms);
}
- snd_soc_dpcm_stream_unlock_irq(fe, stream);
+ snd_pcm_stream_unlock_irq(substream);
while (!list_empty(&deleted_dpcms)) {
dpcm = list_first_entry(&deleted_dpcms, struct snd_soc_dpcm,
@@ -1427,11 +1475,9 @@ int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(fe, 0);
int paths;
- if (fe->dai_link->num_cpus > 1) {
- dev_err(fe->dev,
+ if (fe->dai_link->num_cpus > 1)
+ return snd_soc_ret(fe->dev, -EINVAL,
"%s doesn't support Multi CPU yet\n", __func__);
- return -EINVAL;
- }
/* get number of valid DAI paths and their widgets */
paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list,
@@ -1440,10 +1486,10 @@ int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
if (paths > 0)
dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths,
- stream ? "capture" : "playback");
+ snd_pcm_direction_name(stream));
else if (paths == 0)
dev_dbg(fe->dev, "ASoC: %s no valid %s path\n", fe->dai_link->name,
- stream ? "capture" : "playback");
+ snd_pcm_direction_name(stream));
return paths;
}
@@ -1486,7 +1532,7 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
continue;
dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n",
- stream ? "capture" : "playback",
+ snd_pcm_direction_name(stream),
dpcm->be->dai_link->name, fe->dai_link->name);
dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
dpcm_set_be_update_state(dpcm->be, stream, SND_SOC_DPCM_UPDATE_BE);
@@ -1497,8 +1543,8 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
return prune;
}
-static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
- struct snd_soc_dapm_widget_list **list_)
+int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
+ struct snd_soc_dapm_widget_list **list_)
{
struct snd_soc_card *card = fe->card;
struct snd_soc_dapm_widget_list *list = *list_;
@@ -1538,10 +1584,13 @@ static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
/*
* Filter for systems with 'component_chaining' enabled.
* This helps to avoid unnecessary re-configuration of an
- * already active BE on such systems.
+ * already active BE on such systems and ensures the BE DAI
+ * widget is powered ON after hw_params() BE DAI callback.
*/
if (fe->card->component_chaining &&
(be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
+ (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
+ (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
(be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
continue;
@@ -1563,19 +1612,6 @@ static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
return new;
}
-/*
- * Find the corresponding BE DAIs that source or sink audio to this
- * FE substream.
- */
-int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
- int stream, struct snd_soc_dapm_widget_list **list, int new)
-{
- if (new)
- return dpcm_add_paths(fe, stream, list);
- else
- return dpcm_prune_paths(fe, stream, list);
-}
-
void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
{
struct snd_soc_dpcm *dpcm;
@@ -1599,13 +1635,13 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
return;
/* is this op for this BE ? */
- if (!snd_soc_dpcm_be_can_update(fe, be, stream))
+ if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
if (be->dpcm[stream].users == 0) {
- dev_err(be->dev, "ASoC: no users %s at close - state %d\n",
- stream ? "capture" : "playback",
- be->dpcm[stream].state);
+ dev_err(be->dev, "ASoC: no users %s at close - state %s\n",
+ snd_pcm_direction_name(stream),
+ dpcm_state_string(be->dpcm[stream].state));
continue;
}
@@ -1644,19 +1680,19 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
if (!be_substream) {
dev_err(be->dev, "ASoC: no backend %s stream\n",
- stream ? "capture" : "playback");
+ snd_pcm_direction_name(stream));
continue;
}
/* is this op for this BE ? */
- if (!snd_soc_dpcm_be_can_update(fe, be, stream))
+ if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
/* first time the dpcm is open ? */
if (be->dpcm[stream].users == DPCM_MAX_BE_USERS) {
- dev_err(be->dev, "ASoC: too many users %s at open %d\n",
- stream ? "capture" : "playback",
- be->dpcm[stream].state);
+ dev_err(be->dev, "ASoC: too many users %s at open %s\n",
+ snd_pcm_direction_name(stream),
+ dpcm_state_string(be->dpcm[stream].state));
continue;
}
@@ -1668,16 +1704,16 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
continue;
dev_dbg(be->dev, "ASoC: open %s BE %s\n",
- stream ? "capture" : "playback", be->dai_link->name);
+ snd_pcm_direction_name(stream), be->dai_link->name);
be_substream->runtime = fe_substream->runtime;
err = __soc_pcm_open(be, be_substream);
if (err < 0) {
be->dpcm[stream].users--;
if (be->dpcm[stream].users < 0)
- dev_err(be->dev, "ASoC: no users %s at unwind %d\n",
- stream ? "capture" : "playback",
- be->dpcm[stream].state);
+ dev_err(be->dev, "ASoC: no users %s at unwind %s\n",
+ snd_pcm_direction_name(stream),
+ dpcm_state_string(be->dpcm[stream].state));
be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
goto unwind;
@@ -1711,7 +1747,7 @@ static void dpcm_runtime_setup_fe(struct snd_pcm_substream *substream)
hw->formats &= formats;
for_each_rtd_cpu_dais(fe, i, dai) {
- struct snd_soc_pcm_stream *cpu_stream;
+ const struct snd_soc_pcm_stream *cpu_stream;
/*
* Skip CPUs which don't support the current stream
@@ -1725,7 +1761,6 @@ static void dpcm_runtime_setup_fe(struct snd_pcm_substream *substream)
soc_pcm_hw_update_rate(hw, cpu_stream);
soc_pcm_hw_update_chan(hw, cpu_stream);
soc_pcm_hw_update_format(hw, cpu_stream);
- soc_pcm_hw_update_subformat(hw, cpu_stream);
}
}
@@ -1749,7 +1784,7 @@ static void dpcm_runtime_setup_be_format(struct snd_pcm_substream *substream)
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
- struct snd_soc_pcm_stream *codec_stream;
+ const struct snd_soc_pcm_stream *codec_stream;
int i;
for_each_rtd_codec_dais(be, i, dai) {
@@ -1763,7 +1798,6 @@ static void dpcm_runtime_setup_be_format(struct snd_pcm_substream *substream)
codec_stream = snd_soc_dai_get_pcm_stream(dai, stream);
soc_pcm_hw_update_format(hw, codec_stream);
- soc_pcm_hw_update_subformat(hw, codec_stream);
}
}
}
@@ -1786,7 +1820,7 @@ static void dpcm_runtime_setup_be_chan(struct snd_pcm_substream *substream)
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
- struct snd_soc_pcm_stream *cpu_stream;
+ const struct snd_soc_pcm_stream *cpu_stream;
struct snd_soc_dai *dai;
int i;
@@ -1808,7 +1842,7 @@ static void dpcm_runtime_setup_be_chan(struct snd_pcm_substream *substream)
* DAIs connected to a single CPU DAI, use CPU DAI's directly
*/
if (be->dai_link->num_codecs == 1) {
- struct snd_soc_pcm_stream *codec_stream = snd_soc_dai_get_pcm_stream(
+ const struct snd_soc_pcm_stream *codec_stream = snd_soc_dai_get_pcm_stream(
snd_soc_rtd_to_codec(be, 0), stream);
soc_pcm_hw_update_chan(hw, codec_stream);
@@ -1834,7 +1868,7 @@ static void dpcm_runtime_setup_be_rate(struct snd_pcm_substream *substream)
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
- struct snd_soc_pcm_stream *pcm;
+ const struct snd_soc_pcm_stream *pcm;
struct snd_soc_dai *dai;
int i;
@@ -1976,7 +2010,7 @@ void dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
snd_soc_dpcm_get_substream(be, stream);
/* is this op for this BE ? */
- if (!snd_soc_dpcm_be_can_update(fe, be, stream))
+ if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
/* only free hw when no longer used - check all FEs */
@@ -2042,7 +2076,7 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
be_substream = snd_soc_dpcm_get_substream(be, stream);
/* is this op for this BE ? */
- if (!snd_soc_dpcm_be_can_update(fe, be, stream))
+ if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
/* copy params for each dpcm */
@@ -2070,7 +2104,7 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
dev_dbg(be->dev, "ASoC: hw_params BE %s\n",
be->dai_link->name);
- ret = __soc_pcm_hw_params(be, be_substream, &hw_params);
+ ret = __soc_pcm_hw_params(be_substream, &hw_params);
if (ret < 0)
goto unwind;
@@ -2087,7 +2121,7 @@ unwind:
be = dpcm->be;
be_substream = snd_soc_dpcm_get_substream(be, stream);
- if (!snd_soc_dpcm_be_can_update(fe, be, stream))
+ if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
/* only allow hw_free() if no connected FEs are running */
@@ -2126,7 +2160,7 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
params_channels(params), params_format(params));
/* call hw_params on the frontend */
- ret = __soc_pcm_hw_params(fe, substream, params);
+ ret = __soc_pcm_hw_params(substream, params);
if (ret < 0)
dpcm_be_dai_hw_free(fe, stream);
else
@@ -2154,10 +2188,10 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
be = dpcm->be;
be_substream = snd_soc_dpcm_get_substream(be, stream);
- snd_soc_dpcm_stream_lock_irqsave_nested(be, stream, flags);
+ snd_pcm_stream_lock_irqsave_nested(be_substream, flags);
/* is this op for this BE ? */
- if (!snd_soc_dpcm_be_can_update(fe, be, stream))
+ if (!snd_soc_dpcm_can_be_update(fe, be, stream))
goto next;
dev_dbg(be->dev, "ASoC: trigger BE %s cmd %d\n",
@@ -2301,7 +2335,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
break;
}
next:
- snd_soc_dpcm_stream_unlock_irqrestore(be, stream, flags);
+ snd_pcm_stream_unlock_irqrestore(be_substream, flags);
if (ret)
break;
}
@@ -2322,23 +2356,23 @@ static int dpcm_dai_trigger_fe_be(struct snd_pcm_substream *substream,
ret = soc_pcm_trigger(substream, cmd);
if (ret < 0)
- return ret;
+ goto end;
ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
- return ret;
}
-
/* call trigger on the frontend after the backend. */
- ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
- if (ret < 0)
- return ret;
-
- dev_dbg(fe->dev, "ASoC: post trigger FE %s cmd %d\n",
- fe->dai_link->name, cmd);
+ else {
+ ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
+ if (ret < 0)
+ goto end;
- ret = soc_pcm_trigger(substream, cmd);
+ dev_dbg(fe->dev, "ASoC: post trigger FE %s cmd %d\n",
+ fe->dai_link->name, cmd);
- return ret;
+ ret = soc_pcm_trigger(substream, cmd);
+ }
+end:
+ return snd_soc_ret(fe->dev, ret, "trigger FE cmd: %d failed\n", cmd);
}
static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -2346,54 +2380,17 @@ static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd)
struct snd_soc_pcm_runtime *fe = snd_soc_substream_to_rtd(substream);
int stream = substream->stream;
int ret = 0;
+ int fe_first;
enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
switch (trigger) {
case SND_SOC_DPCM_TRIGGER_PRE:
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
- case SNDRV_PCM_TRIGGER_RESUME:
- case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- case SNDRV_PCM_TRIGGER_DRAIN:
- ret = dpcm_dai_trigger_fe_be(substream, cmd, true);
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- case SNDRV_PCM_TRIGGER_SUSPEND:
- case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- ret = dpcm_dai_trigger_fe_be(substream, cmd, false);
- break;
- default:
- ret = -EINVAL;
- break;
- }
+ fe_first = true;
break;
case SND_SOC_DPCM_TRIGGER_POST:
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
- case SNDRV_PCM_TRIGGER_RESUME:
- case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- case SNDRV_PCM_TRIGGER_DRAIN:
- ret = dpcm_dai_trigger_fe_be(substream, cmd, false);
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- case SNDRV_PCM_TRIGGER_SUSPEND:
- case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- ret = dpcm_dai_trigger_fe_be(substream, cmd, true);
- break;
- default:
- ret = -EINVAL;
- break;
- }
- break;
- case SND_SOC_DPCM_TRIGGER_BESPOKE:
- /* bespoke trigger() - handles both FE and BEs */
-
- dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd %d\n",
- fe->dai_link->name, cmd);
-
- ret = snd_soc_pcm_dai_bespoke_trigger(substream, cmd);
+ fe_first = false;
break;
default:
dev_err(fe->dev, "ASoC: invalid trigger cmd %d for %s\n", cmd,
@@ -2402,12 +2399,26 @@ static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd)
goto out;
}
- if (ret < 0) {
- dev_err(fe->dev, "ASoC: trigger FE cmd: %d failed: %d\n",
- cmd, ret);
- goto out;
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_RESUME:
+ case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+ case SNDRV_PCM_TRIGGER_DRAIN:
+ ret = dpcm_dai_trigger_fe_be(substream, cmd, fe_first);
+ break;
+ case SNDRV_PCM_TRIGGER_STOP:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
+ case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+ ret = dpcm_dai_trigger_fe_be(substream, cmd, !fe_first);
+ break;
+ default:
+ ret = -EINVAL;
+ break;
}
+ if (ret < 0)
+ goto out;
+
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
@@ -2457,7 +2468,7 @@ int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
snd_soc_dpcm_get_substream(be, stream);
/* is this op for this BE ? */
- if (!snd_soc_dpcm_be_can_update(fe, be, stream))
+ if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
if (!snd_soc_dpcm_can_be_prepared(fe, be, stream))
@@ -2479,7 +2490,13 @@ int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
}
- return soc_pcm_ret(fe, ret);
+ /*
+ * Don't use soc_pcm_ret() on .prepare callback to lower error log severity
+ *
+ * We don't want to log an error since we do not want to give userspace a way to do a
+ * denial-of-service attack on the syslog / diskspace.
+ */
+ return ret;
}
static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
@@ -2493,17 +2510,6 @@ static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
- /* there is no point preparing this FE if there are no BEs */
- if (list_empty(&fe->dpcm[stream].be_clients)) {
- /* dev_err_once() for visibility, dev_dbg() for debugging UCM profiles */
- dev_err_once(fe->dev, "ASoC: no backend DAIs enabled for %s, possibly missing ALSA mixer-based routing or UCM profile\n",
- fe->dai_link->name);
- dev_dbg(fe->dev, "ASoC: no backend DAIs enabled for %s\n",
- fe->dai_link->name);
- ret = -EINVAL;
- goto out;
- }
-
ret = dpcm_be_dai_prepare(fe, stream);
if (ret < 0)
goto out;
@@ -2519,31 +2525,23 @@ out:
dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
snd_soc_dpcm_mutex_unlock(fe);
- return soc_pcm_ret(fe, ret);
+ /*
+ * Don't use soc_pcm_ret() on .prepare callback to lower error log severity
+ *
+ * We don't want to log an error since we do not want to give userspace a way to do a
+ * denial-of-service attack on the syslog / diskspace.
+ */
+ return ret;
}
static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
{
- struct snd_pcm_substream *substream =
- snd_soc_dpcm_get_substream(fe, stream);
- enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
int err;
dev_dbg(fe->dev, "ASoC: runtime %s close on FE %s\n",
- stream ? "capture" : "playback", fe->dai_link->name);
+ snd_pcm_direction_name(stream), fe->dai_link->name);
- if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
- /* call bespoke trigger - FE takes care of all BE triggers */
- dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd stop\n",
- fe->dai_link->name);
-
- err = snd_soc_pcm_dai_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP);
- } else {
- dev_dbg(fe->dev, "ASoC: trigger FE %s cmd stop\n",
- fe->dai_link->name);
-
- err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
- }
+ err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
dpcm_be_dai_hw_free(fe, stream);
@@ -2557,20 +2555,17 @@ static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
{
- struct snd_pcm_substream *substream =
- snd_soc_dpcm_get_substream(fe, stream);
struct snd_soc_dpcm *dpcm;
- enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
int ret = 0;
dev_dbg(fe->dev, "ASoC: runtime %s open on FE %s\n",
- stream ? "capture" : "playback", fe->dai_link->name);
+ snd_pcm_direction_name(stream), fe->dai_link->name);
/* Only start the BE if the FE is ready */
if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE) {
- dev_err(fe->dev, "ASoC: FE %s is not ready %d\n",
- fe->dai_link->name, fe->dpcm[stream].state);
+ dev_err(fe->dev, "ASoC: FE %s is not ready %s\n",
+ fe->dai_link->name, dpcm_state_string(fe->dpcm[stream].state));
ret = -EINVAL;
goto disconnect;
}
@@ -2604,23 +2599,9 @@ static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
return 0;
- if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
- /* call trigger on the frontend - FE takes care of all BE triggers */
- dev_dbg(fe->dev, "ASoC: bespoke trigger FE %s cmd start\n",
- fe->dai_link->name);
-
- ret = snd_soc_pcm_dai_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START);
- if (ret < 0)
- goto hw_free;
- } else {
- dev_dbg(fe->dev, "ASoC: trigger FE %s cmd start\n",
- fe->dai_link->name);
-
- ret = dpcm_be_dai_trigger(fe, stream,
- SNDRV_PCM_TRIGGER_START);
- if (ret < 0)
- goto hw_free;
- }
+ ret = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_START);
+ if (ret < 0)
+ goto hw_free;
return 0;
@@ -2634,7 +2615,7 @@ disconnect:
struct snd_soc_pcm_runtime *be = dpcm->be;
/* is this op for this BE ? */
- if (!snd_soc_dpcm_be_can_update(fe, be, stream))
+ if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE ||
@@ -2654,11 +2635,9 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
if (!fe->dai_link->dynamic)
return 0;
- if (fe->dai_link->num_cpus > 1) {
- dev_err(fe->dev,
+ if (fe->dai_link->num_cpus > 1)
+ return snd_soc_ret(fe->dev, -EINVAL,
"%s doesn't support Multi CPU yet\n", __func__);
- return -EINVAL;
- }
/* only check active links */
if (!snd_soc_dai_active(snd_soc_rtd_to_cpu(fe, 0)))
@@ -2685,7 +2664,14 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
return paths;
/* update any playback/capture paths */
- count = dpcm_process_paths(fe, stream, &list, new);
+ /*
+ * Find the corresponding BE DAIs that source or sink audio to this
+ * FE substream.
+ */
+ if (new)
+ count = dpcm_add_paths(fe, stream, &list);
+ else
+ count = dpcm_prune_paths(fe, stream, &list);
if (count) {
dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
if (new)
@@ -2729,7 +2715,8 @@ int snd_soc_dpcm_runtime_update(struct snd_soc_card *card)
out:
snd_soc_dpcm_mutex_unlock(card);
- return ret;
+
+ return snd_soc_ret(card->dev, ret, "%s() failed\n", __func__);
}
EXPORT_SYMBOL_GPL(snd_soc_dpcm_runtime_update);
@@ -2776,13 +2763,25 @@ static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
goto open_end;
/* calculate valid and active FE <-> BE dpcms */
- dpcm_process_paths(fe, stream, &list, 1);
+ dpcm_add_paths(fe, stream, &list);
+
+ /* There is no point starting up this FE if there are no BEs. */
+ if (list_empty(&fe->dpcm[stream].be_clients)) {
+ /* dev_err_once() for visibility, dev_dbg() for debugging UCM profiles. */
+ dev_err_once(fe->dev, "ASoC: no backend DAIs enabled for %s, possibly missing ALSA mixer-based routing or UCM profile\n",
+ fe->dai_link->name);
+ dev_dbg(fe->dev, "ASoC: no backend DAIs enabled for %s\n", fe->dai_link->name);
+
+ ret = -EINVAL;
+ goto put_path;
+ }
ret = dpcm_fe_dai_startup(fe_substream);
if (ret < 0)
dpcm_fe_dai_cleanup(fe_substream);
dpcm_clear_pending_state(fe, stream);
+put_path:
dpcm_path_put(&list);
open_end:
snd_soc_dpcm_mutex_unlock(fe);
@@ -2794,74 +2793,51 @@ static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd,
{
struct snd_soc_dai_link *dai_link = rtd->dai_link;
struct snd_soc_dai *cpu_dai;
+ struct snd_soc_dai *codec_dai;
+ struct snd_soc_dai_link_ch_map *ch_maps;
+ struct snd_soc_dai *dummy_dai = snd_soc_find_dai(&snd_soc_dummy_dlc);
+ int cpu_capture;
+ int cpu_playback;
int has_playback = 0;
int has_capture = 0;
int i;
- if (dai_link->dynamic && dai_link->num_cpus > 1) {
- dev_err(rtd->dev, "DPCM doesn't support Multi CPU for Front-Ends yet\n");
- return -EINVAL;
- }
-
- if (dai_link->dynamic || dai_link->no_pcm) {
- int stream;
+ if (dai_link->dynamic && dai_link->num_cpus > 1)
+ return snd_soc_ret(rtd->dev, -EINVAL,
+ "DPCM doesn't support Multi CPU for Front-Ends yet\n");
- if (dai_link->dpcm_playback) {
- stream = SNDRV_PCM_STREAM_PLAYBACK;
-
- for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
- if (snd_soc_dai_stream_valid(cpu_dai, stream)) {
- has_playback = 1;
- break;
- }
- }
- if (!has_playback) {
- dev_err(rtd->card->dev,
- "No CPU DAIs support playback for stream %s\n",
- dai_link->stream_name);
- return -EINVAL;
- }
- }
- if (dai_link->dpcm_capture) {
- stream = SNDRV_PCM_STREAM_CAPTURE;
-
- for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
- if (snd_soc_dai_stream_valid(cpu_dai, stream)) {
- has_capture = 1;
- break;
- }
- }
+ /* Adapt stream for codec2codec links */
+ cpu_capture = snd_soc_get_stream_cpu(dai_link, SNDRV_PCM_STREAM_CAPTURE);
+ cpu_playback = snd_soc_get_stream_cpu(dai_link, SNDRV_PCM_STREAM_PLAYBACK);
- if (!has_capture) {
- dev_err(rtd->card->dev,
- "No CPU DAIs support capture for stream %s\n",
- dai_link->stream_name);
- return -EINVAL;
- }
- }
- } else {
- struct snd_soc_dai_link_ch_map *ch_maps;
- struct snd_soc_dai *codec_dai;
-
- /* Adapt stream for codec2codec links */
- int cpu_capture = snd_soc_get_stream_cpu(dai_link, SNDRV_PCM_STREAM_CAPTURE);
- int cpu_playback = snd_soc_get_stream_cpu(dai_link, SNDRV_PCM_STREAM_PLAYBACK);
+ /*
+ * see
+ * soc.h :: [dai_link->ch_maps Image sample]
+ */
+ for_each_rtd_ch_maps(rtd, i, ch_maps) {
+ cpu_dai = snd_soc_rtd_to_cpu(rtd, ch_maps->cpu);
+ codec_dai = snd_soc_rtd_to_codec(rtd, ch_maps->codec);
/*
- * see
- * soc.h :: [dai_link->ch_maps Image sample]
+ * FIXME
+ *
+ * DPCM Codec has been no checked before.
+ * It should be checked, but it breaks compatibility.
+ *
+ * For example there is a case that CPU have loopback capabilities which is used
+ * for tests on boards where the Codec has no capture capabilities. In this case,
+ * Codec capture validation check will be fail, but system should allow capture
+ * capabilities. We have no solution for it today.
*/
- for_each_rtd_ch_maps(rtd, i, ch_maps) {
- cpu_dai = snd_soc_rtd_to_cpu(rtd, ch_maps->cpu);
- codec_dai = snd_soc_rtd_to_codec(rtd, ch_maps->codec);
-
- if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
- snd_soc_dai_stream_valid(cpu_dai, cpu_playback))
- has_playback = 1;
- if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
- snd_soc_dai_stream_valid(cpu_dai, cpu_capture))
- has_capture = 1;
- }
+ if (dai_link->dynamic || dai_link->no_pcm)
+ codec_dai = dummy_dai;
+
+ if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
+ snd_soc_dai_stream_valid(cpu_dai, cpu_playback))
+ has_playback = 1;
+ if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
+ snd_soc_dai_stream_valid(cpu_dai, cpu_capture))
+ has_capture = 1;
}
if (dai_link->playback_only)
@@ -2870,12 +2846,9 @@ static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd,
if (dai_link->capture_only)
has_playback = 0;
- if (!has_playback && !has_capture) {
- dev_err(rtd->dev, "substream %s has no playback, no capture\n",
- dai_link->stream_name);
-
- return -EINVAL;
- }
+ if (!has_playback && !has_capture)
+ return snd_soc_ret(rtd->dev, -EINVAL,
+ "substream %s has no playback, no capture\n", dai_link->stream_name);
*playback = has_playback;
*capture = has_capture;
@@ -2885,7 +2858,7 @@ static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd,
static int soc_create_pcm(struct snd_pcm **pcm,
struct snd_soc_pcm_runtime *rtd,
- int playback, int capture, int num)
+ int playback, int capture)
{
char new_name[64];
int ret;
@@ -2895,13 +2868,13 @@ static int soc_create_pcm(struct snd_pcm **pcm,
snprintf(new_name, sizeof(new_name), "codec2codec(%s)",
rtd->dai_link->stream_name);
- ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
+ ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, rtd->id,
playback, capture, pcm);
} else if (rtd->dai_link->no_pcm) {
snprintf(new_name, sizeof(new_name), "(%s)",
rtd->dai_link->stream_name);
- ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
+ ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, rtd->id,
playback, capture, pcm);
} else {
if (rtd->dai_link->dynamic)
@@ -2910,23 +2883,22 @@ static int soc_create_pcm(struct snd_pcm **pcm,
else
snprintf(new_name, sizeof(new_name), "%s %s-%d",
rtd->dai_link->stream_name,
- soc_codec_dai_name(rtd), num);
+ soc_codec_dai_name(rtd), rtd->id);
- ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
+ ret = snd_pcm_new(rtd->card->snd_card, new_name, rtd->id, playback,
capture, pcm);
}
- if (ret < 0) {
- dev_err(rtd->card->dev, "ASoC: can't create pcm %s for dailink %s: %d\n",
- new_name, rtd->dai_link->name, ret);
- return ret;
- }
- dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name);
+ if (ret < 0)
+ return snd_soc_ret(rtd->dev, ret,
+ "can't create pcm %s for dailink %s\n", new_name, rtd->dai_link->name);
+
+ dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n", rtd->id, new_name);
return 0;
}
/* create a new pcm */
-int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
+int soc_new_pcm(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_component *component;
struct snd_pcm *pcm;
@@ -2937,7 +2909,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
if (ret < 0)
return ret;
- ret = soc_create_pcm(&pcm, rtd, playback, capture, num);
+ ret = soc_create_pcm(&pcm, rtd, playback, capture);
if (ret < 0)
return ret;
@@ -3015,27 +2987,6 @@ out:
return ret;
}
-/* is the current PCM operation for this FE ? */
-int snd_soc_dpcm_fe_can_update(struct snd_soc_pcm_runtime *fe, int stream)
-{
- if (fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE)
- return 1;
- return 0;
-}
-EXPORT_SYMBOL_GPL(snd_soc_dpcm_fe_can_update);
-
-/* is the current PCM operation for this BE ? */
-int snd_soc_dpcm_be_can_update(struct snd_soc_pcm_runtime *fe,
- struct snd_soc_pcm_runtime *be, int stream)
-{
- if ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_FE) ||
- ((fe->dpcm[stream].runtime_update == SND_SOC_DPCM_UPDATE_BE) &&
- be->dpcm[stream].runtime_update))
- return 1;
- return 0;
-}
-EXPORT_SYMBOL_GPL(snd_soc_dpcm_be_can_update);
-
/* get the substream for this BE */
struct snd_pcm_substream *
snd_soc_dpcm_get_substream(struct snd_soc_pcm_runtime *be, int stream)
@@ -3043,84 +2994,3 @@ struct snd_pcm_substream *
return be->pcm->streams[stream].substream;
}
EXPORT_SYMBOL_GPL(snd_soc_dpcm_get_substream);
-
-static int snd_soc_dpcm_check_state(struct snd_soc_pcm_runtime *fe,
- struct snd_soc_pcm_runtime *be,
- int stream,
- const enum snd_soc_dpcm_state *states,
- int num_states)
-{
- struct snd_soc_dpcm *dpcm;
- int state;
- int ret = 1;
- int i;
-
- for_each_dpcm_fe(be, stream, dpcm) {
-
- if (dpcm->fe == fe)
- continue;
-
- state = dpcm->fe->dpcm[stream].state;
- for (i = 0; i < num_states; i++) {
- if (state == states[i]) {
- ret = 0;
- break;
- }
- }
- }
-
- /* it's safe to do this BE DAI */
- return ret;
-}
-
-/*
- * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
- * are not running, paused or suspended for the specified stream direction.
- */
-int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
- struct snd_soc_pcm_runtime *be, int stream)
-{
- const enum snd_soc_dpcm_state state[] = {
- SND_SOC_DPCM_STATE_START,
- SND_SOC_DPCM_STATE_PAUSED,
- SND_SOC_DPCM_STATE_SUSPEND,
- };
-
- return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
-}
-EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
-
-/*
- * We can only change hw params a BE DAI if any of it's FE are not prepared,
- * running, paused or suspended for the specified stream direction.
- */
-int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
- struct snd_soc_pcm_runtime *be, int stream)
-{
- const enum snd_soc_dpcm_state state[] = {
- SND_SOC_DPCM_STATE_START,
- SND_SOC_DPCM_STATE_PAUSED,
- SND_SOC_DPCM_STATE_SUSPEND,
- SND_SOC_DPCM_STATE_PREPARE,
- };
-
- return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
-}
-EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);
-
-/*
- * We can only prepare a BE DAI if any of it's FE are not prepared,
- * running or paused for the specified stream direction.
- */
-int snd_soc_dpcm_can_be_prepared(struct snd_soc_pcm_runtime *fe,
- struct snd_soc_pcm_runtime *be, int stream)
-{
- const enum snd_soc_dpcm_state state[] = {
- SND_SOC_DPCM_STATE_START,
- SND_SOC_DPCM_STATE_PAUSED,
- SND_SOC_DPCM_STATE_PREPARE,
- };
-
- return snd_soc_dpcm_check_state(fe, be, stream, state, ARRAY_SIZE(state));
-}
-EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_prepared);