aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-compress.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sound/soc/soc-compress.c625
1 files changed, 190 insertions, 435 deletions
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 392a1c5b15d3..870f13e1d389 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -19,118 +19,114 @@
#include <sound/soc.h>
#include <sound/initval.h>
#include <sound/soc-dpcm.h>
+#include <sound/soc-link.h>
#include <linux/pm_runtime.h>
-static int soc_compr_components_open(struct snd_compr_stream *cstream,
- struct snd_soc_component **last)
+static int snd_soc_compr_components_open(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component;
- int i, ret;
+ int ret = 0;
+ int i;
for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->open)
- continue;
-
- ret = component->driver->compr_ops->open(cstream);
- if (ret < 0) {
- dev_err(component->dev,
- "Compress ASoC: can't open platform %s: %d\n",
- component->name, ret);
+ ret = snd_soc_component_module_get_when_open(component, cstream);
+ if (ret < 0)
+ break;
- *last = component;
- return ret;
- }
+ ret = snd_soc_component_compr_open(component, cstream);
+ if (ret < 0)
+ break;
}
- *last = NULL;
- return 0;
+ return ret;
}
-static int soc_compr_components_free(struct snd_compr_stream *cstream,
- struct snd_soc_component *last)
+static void snd_soc_compr_components_free(struct snd_compr_stream *cstream,
+ int rollback)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component;
int i;
for_each_rtd_components(rtd, i, component) {
- if (component == last)
- break;
-
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->free)
- continue;
-
- component->driver->compr_ops->free(cstream);
+ snd_soc_component_compr_free(component, cstream, rollback);
+ snd_soc_component_module_put_when_close(component, cstream, rollback);
}
-
- return 0;
}
-static int soc_compr_open(struct snd_compr_stream *cstream)
+static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component, *save = NULL;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- int ret, i;
-
- for_each_rtd_components(rtd, i, component) {
- ret = pm_runtime_get_sync(component->dev);
- if (ret < 0 && ret != -EACCES) {
- pm_runtime_put_noidle(component->dev);
- save = component;
- goto pm_err;
- }
- }
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+ int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) {
- ret = cpu_dai->driver->cops->startup(cstream, cpu_dai);
- if (ret < 0) {
- dev_err(cpu_dai->dev,
- "Compress ASoC: can't open interface %s: %d\n",
- cpu_dai->name, ret);
- goto out;
- }
- }
+ if (!rollback)
+ snd_soc_runtime_deactivate(rtd, stream);
- ret = soc_compr_components_open(cstream, &component);
- if (ret < 0)
- goto machine_err;
+ snd_soc_dai_digital_mute(codec_dai, 1, stream);
- if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) {
- ret = rtd->dai_link->compr_ops->startup(cstream);
- if (ret < 0) {
- dev_err(rtd->dev,
- "Compress ASoC: %s startup failed: %d\n",
- rtd->dai_link->name, ret);
- goto machine_err;
- }
- }
+ if (!snd_soc_dai_active(cpu_dai))
+ cpu_dai->rate = 0;
+
+ if (!snd_soc_dai_active(codec_dai))
+ codec_dai->rate = 0;
+
+ snd_soc_link_compr_shutdown(cstream, rollback);
- snd_soc_runtime_activate(rtd, cstream->direction);
+ snd_soc_compr_components_free(cstream, rollback);
+
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream, rollback);
+
+ if (!rollback)
+ snd_soc_dapm_stream_stop(rtd, stream);
mutex_unlock(&rtd->card->pcm_mutex);
+ snd_soc_pcm_component_pm_runtime_put(rtd, cstream, rollback);
+
return 0;
+}
-machine_err:
- soc_compr_components_free(cstream, component);
+static int soc_compr_free(struct snd_compr_stream *cstream)
+{
+ return soc_compr_clean(cstream, 0);
+}
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
- cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
-out:
+static int soc_compr_open(struct snd_compr_stream *cstream)
+{
+ struct snd_soc_pcm_runtime *rtd = cstream->private_data;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+ int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
+ int ret;
+
+ ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream);
+ if (ret < 0)
+ goto err_no_lock;
+
+ mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
+
+ ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
+ if (ret < 0)
+ goto err;
+
+ ret = snd_soc_compr_components_open(cstream);
+ if (ret < 0)
+ goto err;
+
+ ret = snd_soc_link_compr_startup(cstream);
+ if (ret < 0)
+ goto err;
+
+ snd_soc_runtime_activate(rtd, stream);
+err:
mutex_unlock(&rtd->card->pcm_mutex);
-pm_err:
- for_each_rtd_components(rtd, i, component) {
- if (component == save)
- break;
- pm_runtime_mark_last_busy(component->dev);
- pm_runtime_put_autosuspend(component->dev);
- }
+err_no_lock:
+ if (ret < 0)
+ soc_compr_clean(cstream, 1);
return ret;
}
@@ -140,27 +136,19 @@ static int soc_compr_open_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_dai *cpu_dai = fe->cpu_dai;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
struct snd_soc_dpcm *dpcm;
struct snd_soc_dapm_widget_list *list;
- int stream;
+ int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
int ret;
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- stream = SNDRV_PCM_STREAM_PLAYBACK;
- else
- stream = SNDRV_PCM_STREAM_CAPTURE;
-
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
fe->dpcm[stream].runtime = fe_substream->runtime;
ret = dpcm_path_get(fe, stream, &list);
if (ret < 0)
goto be_err;
- else if (ret == 0)
- dev_dbg(fe->dev, "Compress ASoC: %s no valid %s route\n",
- fe->dai_link->name, stream ? "capture" : "playback");
+
/* calculate valid and active FE <-> BE dpcms */
dpcm_process_paths(fe, stream, &list, 1);
fe->dpcm[stream].runtime = fe_substream->runtime;
@@ -178,28 +166,17 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
goto out;
}
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) {
- ret = cpu_dai->driver->cops->startup(cstream, cpu_dai);
- if (ret < 0) {
- dev_err(cpu_dai->dev,
- "Compress ASoC: can't open interface %s: %d\n",
- cpu_dai->name, ret);
- goto out;
- }
- }
+ ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
+ if (ret < 0)
+ goto out;
- ret = soc_compr_components_open(cstream, &component);
+ ret = snd_soc_compr_components_open(cstream);
if (ret < 0)
goto open_err;
- if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) {
- ret = fe->dai_link->compr_ops->startup(cstream);
- if (ret < 0) {
- pr_err("Compress ASoC: %s startup failed: %d\n",
- fe->dai_link->name, ret);
- goto machine_err;
- }
- }
+ ret = snd_soc_link_compr_startup(cstream);
+ if (ret < 0)
+ goto machine_err;
dpcm_clear_pending_state(fe, stream);
dpcm_path_put(&list);
@@ -207,17 +184,18 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
+ mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
snd_soc_runtime_activate(fe, stream);
+ mutex_unlock(&fe->card->pcm_mutex);
mutex_unlock(&fe->card->mutex);
return 0;
machine_err:
- soc_compr_components_free(cstream, component);
+ snd_soc_compr_components_free(cstream, 1);
open_err:
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
- cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
out:
dpcm_path_put(&list);
be_err:
@@ -226,74 +204,24 @@ be_err:
return ret;
}
-static int soc_compr_free(struct snd_compr_stream *cstream)
-{
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
- int stream, i;
-
- mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
-
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- stream = SNDRV_PCM_STREAM_PLAYBACK;
- else
- stream = SNDRV_PCM_STREAM_CAPTURE;
-
- snd_soc_runtime_deactivate(rtd, stream);
-
- snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
-
- if (!cpu_dai->active)
- cpu_dai->rate = 0;
-
- if (!codec_dai->active)
- codec_dai->rate = 0;
-
- if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown)
- rtd->dai_link->compr_ops->shutdown(cstream);
-
- soc_compr_components_free(cstream, NULL);
-
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
- cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
-
- snd_soc_dapm_stream_stop(rtd, stream);
-
- mutex_unlock(&rtd->card->pcm_mutex);
-
- for_each_rtd_components(rtd, i, component) {
- pm_runtime_mark_last_busy(component->dev);
- pm_runtime_put_autosuspend(component->dev);
- }
-
- return 0;
-}
-
static int soc_compr_free_fe(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *fe = cstream->private_data;
- struct snd_soc_dai *cpu_dai = fe->cpu_dai;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
struct snd_soc_dpcm *dpcm;
- int stream, ret;
+ int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- stream = SNDRV_PCM_STREAM_PLAYBACK;
- else
- stream = SNDRV_PCM_STREAM_CAPTURE;
-
+ mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
snd_soc_runtime_deactivate(fe, stream);
+ mutex_unlock(&fe->card->pcm_mutex);
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
- ret = dpcm_be_dai_hw_free(fe, stream);
- if (ret < 0)
- dev_err(fe->dev, "Compressed ASoC: hw_free failed: %d\n", ret);
+ dpcm_be_dai_hw_free(fe, stream);
- ret = dpcm_be_dai_shutdown(fe, stream);
+ dpcm_be_dai_shutdown(fe, stream);
/* mark FE's links ready to prune */
for_each_dpcm_be(fe, stream, dpcm)
@@ -308,60 +236,40 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
fe->dpcm[stream].runtime = NULL;
- if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
- fe->dai_link->compr_ops->shutdown(cstream);
+ snd_soc_link_compr_shutdown(cstream, 0);
- soc_compr_components_free(cstream, NULL);
+ snd_soc_compr_components_free(cstream, 0);
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
- cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0);
mutex_unlock(&fe->card->mutex);
return 0;
}
-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;
- int i, ret;
-
- for_each_rtd_components(rtd, i, 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 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;
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+ int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
int ret;
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
- ret = soc_compr_components_trigger(cstream, cmd);
+ ret = snd_soc_component_compr_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);
+ ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
+ if (ret < 0)
+ goto out;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
- snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction);
+ snd_soc_dai_digital_mute(codec_dai, 0, stream);
break;
case SNDRV_PCM_TRIGGER_STOP:
- snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
+ snd_soc_dai_digital_mute(codec_dai, 1, stream);
break;
}
@@ -373,27 +281,21 @@ 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_dai *cpu_dai = fe->cpu_dai;
- int ret, stream;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
+ int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
+ int ret;
if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
cmd == SND_COMPR_TRIGGER_DRAIN)
- return soc_compr_components_trigger(cstream, cmd);
-
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- stream = SNDRV_PCM_STREAM_PLAYBACK;
- else
- stream = SNDRV_PCM_STREAM_CAPTURE;
+ return snd_soc_component_compr_trigger(cstream, cmd);
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) {
- ret = cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai);
- if (ret < 0)
- goto out;
- }
+ ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
+ if (ret < 0)
+ goto out;
- ret = soc_compr_components_trigger(cstream, cmd);
+ ret = snd_soc_component_compr_trigger(cstream, cmd);
if (ret < 0)
goto out;
@@ -422,31 +324,12 @@ out:
return ret;
}
-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;
- int i, ret;
-
- for_each_rtd_components(rtd, i, 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 = asoc_rtd_to_cpu(rtd, 0);
+ int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
int ret;
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
@@ -458,28 +341,19 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
* that these callbacks will configure everything for this compress
* path, like configuring a PCM port for a CODEC.
*/
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) {
- ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai);
- if (ret < 0)
- goto err;
- }
+ ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
+ if (ret < 0)
+ goto err;
- ret = soc_compr_components_set_params(cstream, params);
+ ret = snd_soc_component_compr_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);
- if (ret < 0)
- goto err;
- }
+ ret = snd_soc_link_compr_set_params(cstream);
+ if (ret < 0)
+ goto err;
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
- SND_SOC_DAPM_STREAM_START);
- else
- snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE,
- SND_SOC_DAPM_STREAM_START);
+ snd_soc_dapm_stream_event(rtd, stream, SND_SOC_DAPM_STREAM_START);
/* cancel any delayed stream shutdown that is pending */
rtd->pop_wait = 0;
@@ -500,13 +374,9 @@ 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_dai *cpu_dai = fe->cpu_dai;
- int ret, stream;
-
- if (cstream->direction == SND_COMPRESS_PLAYBACK)
- stream = SNDRV_PCM_STREAM_PLAYBACK;
- else
- stream = SNDRV_PCM_STREAM_CAPTURE;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0);
+ int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
+ int ret;
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
@@ -528,21 +398,17 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
if (ret < 0)
goto out;
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_params) {
- ret = cpu_dai->driver->cops->set_params(cstream, params, cpu_dai);
- if (ret < 0)
- goto out;
- }
+ ret = snd_soc_dai_compr_set_params(cpu_dai, cstream, params);
+ if (ret < 0)
+ goto out;
- ret = soc_compr_components_set_params(cstream, params);
+ ret = snd_soc_component_compr_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);
- if (ret < 0)
- goto out;
- }
+ ret = snd_soc_link_compr_set_params(cstream);
+ if (ret < 0)
+ goto out;
dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
@@ -557,102 +423,34 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
struct snd_codec *params)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- int i, ret = 0;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+ int ret = 0;
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_params) {
- ret = cpu_dai->driver->cops->get_params(cstream, params, cpu_dai);
- if (ret < 0)
- goto err;
- }
-
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->get_params)
- continue;
-
- ret = component->driver->compr_ops->get_params(cstream, params);
- break;
- }
+ ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params);
+ if (ret < 0)
+ goto err;
+ ret = snd_soc_component_compr_get_params(cstream, params);
err:
mutex_unlock(&rtd->card->pcm_mutex);
return ret;
}
-static int soc_compr_get_caps(struct snd_compr_stream *cstream,
- struct snd_compr_caps *caps)
-{
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- int i, ret = 0;
-
- mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
-
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->get_caps)
- continue;
-
- ret = component->driver->compr_ops->get_caps(cstream, caps);
- break;
- }
-
- mutex_unlock(&rtd->card->pcm_mutex);
- return ret;
-}
-
-static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream,
- struct snd_compr_codec_caps *codec)
-{
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- int i, ret = 0;
-
- mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
-
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->get_codec_caps)
- continue;
-
- ret = component->driver->compr_ops->get_codec_caps(cstream,
- codec);
- break;
- }
-
- mutex_unlock(&rtd->card->pcm_mutex);
- return ret;
-}
-
static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- int i, ret = 0;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+ int ret;
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->ack) {
- ret = cpu_dai->driver->cops->ack(cstream, bytes, cpu_dai);
- if (ret < 0)
- goto err;
- }
-
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->ack)
- continue;
-
- ret = component->driver->compr_ops->ack(cstream, bytes);
- if (ret < 0)
- goto err;
- }
+ ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes);
+ if (ret < 0)
+ goto err;
+ ret = snd_soc_component_compr_ack(cstream, bytes);
err:
mutex_unlock(&rtd->card->pcm_mutex);
return ret;
@@ -662,46 +460,17 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
struct snd_compr_tstamp *tstamp)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- int i, ret = 0;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-
- mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
-
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer)
- cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai);
-
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->pointer)
- continue;
-
- ret = component->driver->compr_ops->pointer(cstream, tstamp);
- break;
- }
-
- mutex_unlock(&rtd->card->pcm_mutex);
- return ret;
-}
-
-static int soc_compr_copy(struct snd_compr_stream *cstream,
- char __user *buf, size_t count)
-{
- struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- int i, ret = 0;
+ int ret;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->copy)
- continue;
-
- ret = component->driver->compr_ops->copy(cstream, buf, count);
- break;
- }
+ ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp);
+ if (ret < 0)
+ goto out;
+ ret = snd_soc_component_compr_pointer(cstream, tstamp);
+out:
mutex_unlock(&rtd->card->pcm_mutex);
return ret;
}
@@ -710,54 +479,28 @@ static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
struct snd_compr_metadata *metadata)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- int i, ret;
-
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_metadata) {
- ret = cpu_dai->driver->cops->set_metadata(cstream, metadata, cpu_dai);
- if (ret < 0)
- return ret;
- }
-
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->set_metadata)
- continue;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+ int ret;
- ret = component->driver->compr_ops->set_metadata(cstream,
- metadata);
- if (ret < 0)
- return ret;
- }
+ ret = snd_soc_dai_compr_set_metadata(cpu_dai, cstream, metadata);
+ if (ret < 0)
+ return ret;
- return 0;
+ return snd_soc_component_compr_set_metadata(cstream, metadata);
}
static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
struct snd_compr_metadata *metadata)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- int i, ret;
-
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_metadata) {
- ret = cpu_dai->driver->cops->get_metadata(cstream, metadata, cpu_dai);
- if (ret < 0)
- return ret;
- }
-
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->get_metadata)
- continue;
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
+ int ret;
- return component->driver->compr_ops->get_metadata(cstream,
- metadata);
- }
+ ret = snd_soc_dai_compr_get_metadata(cpu_dai, cstream, metadata);
+ if (ret < 0)
+ return ret;
- return 0;
+ return snd_soc_component_compr_get_metadata(cstream, metadata);
}
/* ASoC Compress operations */
@@ -771,8 +514,8 @@ static struct snd_compr_ops soc_compr_ops = {
.trigger = soc_compr_trigger,
.pointer = soc_compr_pointer,
.ack = soc_compr_ack,
- .get_caps = soc_compr_get_caps,
- .get_codec_caps = soc_compr_get_codec_caps
+ .get_caps = snd_soc_component_compr_get_caps,
+ .get_codec_caps = snd_soc_component_compr_get_codec_caps,
};
/* ASoC Dynamic Compress operations */
@@ -786,8 +529,8 @@ static struct snd_compr_ops soc_compr_dyn_ops = {
.trigger = soc_compr_trigger_fe,
.pointer = soc_compr_pointer,
.ack = soc_compr_ack,
- .get_caps = soc_compr_get_caps,
- .get_codec_caps = soc_compr_get_codec_caps
+ .get_caps = snd_soc_component_compr_get_caps,
+ .get_codec_caps = snd_soc_component_compr_get_codec_caps,
};
/**
@@ -801,8 +544,8 @@ static struct snd_compr_ops soc_compr_dyn_ops = {
int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
{
struct snd_soc_component *component;
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
struct snd_compr *compr;
struct snd_pcm *be_pcm;
char new_name[64];
@@ -810,9 +553,22 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
int playback = 0, capture = 0;
int i;
- if (rtd->num_codecs > 1) {
+ /*
+ * make sure these are same value,
+ * and then use these as equally
+ */
+ BUILD_BUG_ON((int)SNDRV_PCM_STREAM_PLAYBACK != (int)SND_COMPRESS_PLAYBACK);
+ BUILD_BUG_ON((int)SNDRV_PCM_STREAM_CAPTURE != (int)SND_COMPRESS_CAPTURE);
+
+ if (rtd->dai_link->num_cpus > 1 ||
+ rtd->dai_link->num_codecs > 1) {
dev_err(rtd->card->dev,
- "Compress ASoC: Multicodec not supported\n");
+ "Compress ASoC: Multi CPU/Codec not supported\n");
+ return -EINVAL;
+ }
+
+ if (!codec_dai) {
+ dev_err(rtd->card->dev, "Missing codec\n");
return -EINVAL;
}
@@ -878,19 +634,18 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
}
for_each_rtd_components(rtd, i, component) {
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->copy)
+ if (!component->driver->compress_ops ||
+ !component->driver->compress_ops->copy)
continue;
- compr->ops->copy = soc_compr_copy;
+ compr->ops->copy = snd_soc_component_compr_copy;
break;
}
- mutex_init(&compr->lock);
ret = snd_compress_new(rtd->card->snd_card, num, direction,
new_name, compr);
if (ret < 0) {
- component = rtd->codec_dai->component;
+ component = asoc_rtd_to_codec(rtd, 0)->component;
dev_err(component->dev,
"Compress ASoC: can't create compress for codec %s: %d\n",
component->name, ret);
@@ -903,8 +658,8 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
rtd->compr = compr;
compr->private_data = rtd;
- dev_info(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n",
- codec_dai->name, cpu_dai->name);
+ dev_dbg(rtd->card->dev, "Compress ASoC: %s <-> %s mapping ok\n",
+ codec_dai->name, cpu_dai->name);
return 0;
}