Commit 4ef0ecb8 authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown

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: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 52cadf1f
...@@ -345,17 +345,13 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) ...@@ -345,17 +345,13 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
return 0; 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_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component; struct snd_soc_component *component;
struct snd_soc_rtdcom_list *rtdcom; struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_dai *codec_dai = rtd->codec_dai; int ret;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
int ret = 0;
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
for_each_rtdcom(rtd, rtdcom) { for_each_rtdcom(rtd, rtdcom) {
component = rtdcom->component; component = rtdcom->component;
...@@ -366,9 +362,25 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) ...@@ -366,9 +362,25 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
ret = component->driver->compr_ops->trigger(cstream, cmd); ret = component->driver->compr_ops->trigger(cstream, cmd);
if (ret < 0) 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) if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger)
cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai);
...@@ -389,28 +401,12 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) ...@@ -389,28 +401,12 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) 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_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; struct snd_soc_dai *cpu_dai = fe->cpu_dai;
int ret, stream; int ret, stream;
if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
cmd == SND_COMPR_TRIGGER_DRAIN) { cmd == SND_COMPR_TRIGGER_DRAIN)
return soc_compr_components_trigger(cstream, cmd);
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;
}
if (cstream->direction == SND_COMPRESS_PLAYBACK) if (cstream->direction == SND_COMPRESS_PLAYBACK)
stream = SNDRV_PCM_STREAM_PLAYBACK; stream = SNDRV_PCM_STREAM_PLAYBACK;
...@@ -425,17 +421,9 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) ...@@ -425,17 +421,9 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
goto out; goto out;
} }
for_each_rtdcom(fe, rtdcom) { ret = soc_compr_components_trigger(cstream, cmd);
component = rtdcom->component; if (ret < 0)
goto out;
if (!component->driver->compr_ops ||
!component->driver->compr_ops->trigger)
continue;
ret = component->driver->compr_ops->trigger(cstream, cmd);
if (ret < 0)
goto out;
}
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
...@@ -462,12 +450,33 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) ...@@ -462,12 +450,33 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
return ret; return ret;
} }
static int soc_compr_set_params(struct snd_compr_stream *cstream, static int soc_compr_components_set_params(struct snd_compr_stream *cstream,
struct snd_compr_params *params) struct snd_compr_params *params)
{ {
struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component; struct snd_soc_component *component;
struct snd_soc_rtdcom_list *rtdcom; 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; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
int ret; int ret;
...@@ -486,17 +495,9 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream, ...@@ -486,17 +495,9 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
goto err; goto err;
} }
for_each_rtdcom(rtd, rtdcom) { ret = soc_compr_components_set_params(cstream, params);
component = rtdcom->component; if (ret < 0)
goto err;
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;
}
if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) { if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) {
ret = rtd->dai_link->compr_ops->set_params(cstream); 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, ...@@ -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_soc_pcm_runtime *fe = cstream->private_data;
struct snd_pcm_substream *fe_substream = struct snd_pcm_substream *fe_substream =
fe->pcm->streams[cstream->direction].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; struct snd_soc_dai *cpu_dai = fe->cpu_dai;
int ret, stream; int ret, stream;
...@@ -566,17 +565,9 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, ...@@ -566,17 +565,9 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
goto out; goto out;
} }
for_each_rtdcom(fe, rtdcom) { ret = soc_compr_components_set_params(cstream, params);
component = rtdcom->component; if (ret < 0)
goto out;
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;
}
if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) { if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) {
ret = fe->dai_link->compr_ops->set_params(cstream); ret = fe->dai_link->compr_ops->set_params(cstream);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment