summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles Keepax <ckeepax@opensource.cirrus.com>2019-02-05 11:18:13 +0000
committerMark Brown <broonie@kernel.org>2019-02-06 15:51:04 +0000
commit4ef0ecb80e348f1888b0c7ebfa8f7c1ec3ed9006 (patch)
tree39da67607132053654ccd382b7c12d2eef47ba1d
parent52cadf1fdbe87a3a3eee11d9cc4873796903c934 (diff)
downloadlinux-stable-4ef0ecb80e348f1888b0c7ebfa8f7c1ec3ed9006.tar.gz
linux-stable-4ef0ecb80e348f1888b0c7ebfa8f7c1ec3ed9006.tar.bz2
linux-stable-4ef0ecb80e348f1888b0c7ebfa8f7c1ec3ed9006.zip
ASoC: compress: Add helper functions for component trigger/set_params
The trigger and set_params callbacks are called from 3 and 2 separate loops respectively, tidy up the code a little by factoring these out into helper functions. Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/soc-compress.c117
1 files changed, 54 insertions, 63 deletions
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index fc8742383b23..03d5b9ccd3fc 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -345,17 +345,13 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
return 0;
}
-static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
+static int soc_compr_components_trigger(struct snd_compr_stream *cstream,
+ int cmd)
{
-
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component;
struct snd_soc_rtdcom_list *rtdcom;
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- int ret = 0;
-
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
+ int ret;
for_each_rtdcom(rtd, rtdcom) {
component = rtdcom->component;
@@ -366,9 +362,25 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
ret = component->driver->compr_ops->trigger(cstream, cmd);
if (ret < 0)
- goto out;
+ return ret;
}
+ return 0;
+}
+
+static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
+{
+ struct snd_soc_pcm_runtime *rtd = cstream->private_data;
+ struct snd_soc_dai *codec_dai = rtd->codec_dai;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ int ret;
+
+ mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
+
+ ret = soc_compr_components_trigger(cstream, cmd);
+ if (ret < 0)
+ goto out;
+
if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger)
cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai);
@@ -389,28 +401,12 @@ out:
static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
{
struct snd_soc_pcm_runtime *fe = cstream->private_data;
- struct snd_soc_component *component;
- struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_dai *cpu_dai = fe->cpu_dai;
int ret, stream;
if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
- cmd == SND_COMPR_TRIGGER_DRAIN) {
-
- for_each_rtdcom(fe, rtdcom) {
- component = rtdcom->component;
-
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->trigger)
- continue;
-
- ret = component->driver->compr_ops->trigger(cstream,
- cmd);
- if (ret < 0)
- return ret;
- }
- return ret;
- }
+ cmd == SND_COMPR_TRIGGER_DRAIN)
+ return soc_compr_components_trigger(cstream, cmd);
if (cstream->direction == SND_COMPRESS_PLAYBACK)
stream = SNDRV_PCM_STREAM_PLAYBACK;
@@ -425,17 +421,9 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
goto out;
}
- for_each_rtdcom(fe, rtdcom) {
- component = rtdcom->component;
-
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->trigger)
- continue;
-
- ret = component->driver->compr_ops->trigger(cstream, cmd);
- if (ret < 0)
- goto out;
- }
+ ret = soc_compr_components_trigger(cstream, cmd);
+ if (ret < 0)
+ goto out;
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
@@ -462,12 +450,33 @@ out:
return ret;
}
-static int soc_compr_set_params(struct snd_compr_stream *cstream,
- struct snd_compr_params *params)
+static int soc_compr_components_set_params(struct snd_compr_stream *cstream,
+ struct snd_compr_params *params)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component;
struct snd_soc_rtdcom_list *rtdcom;
+ int ret;
+
+ for_each_rtdcom(rtd, rtdcom) {
+ component = rtdcom->component;
+
+ if (!component->driver->compr_ops ||
+ !component->driver->compr_ops->set_params)
+ continue;
+
+ ret = component->driver->compr_ops->set_params(cstream, params);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int soc_compr_set_params(struct snd_compr_stream *cstream,
+ struct snd_compr_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
int ret;
@@ -486,17 +495,9 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
goto err;
}
- for_each_rtdcom(rtd, rtdcom) {
- component = rtdcom->component;
-
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->set_params)
- continue;
-
- ret = component->driver->compr_ops->set_params(cstream, params);
- if (ret < 0)
- goto err;
- }
+ ret = soc_compr_components_set_params(cstream, params);
+ if (ret < 0)
+ goto err;
if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) {
ret = rtd->dai_link->compr_ops->set_params(cstream);
@@ -530,8 +531,6 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
struct snd_soc_pcm_runtime *fe = cstream->private_data;
struct snd_pcm_substream *fe_substream =
fe->pcm->streams[cstream->direction].substream;
- struct snd_soc_component *component;
- struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_dai *cpu_dai = fe->cpu_dai;
int ret, stream;
@@ -566,17 +565,9 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
goto out;
}
- for_each_rtdcom(fe, rtdcom) {
- component = rtdcom->component;
-
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->set_params)
- continue;
-
- ret = component->driver->compr_ops->set_params(cstream, params);
- if (ret < 0)
- goto out;
- }
+ ret = soc_compr_components_set_params(cstream, params);
+ if (ret < 0)
+ goto out;
if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) {
ret = fe->dai_link->compr_ops->set_params(cstream);