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.c123
1 files changed, 42 insertions, 81 deletions
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 4c9d4cd8cf0b..dcab9527ba3d 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -609,68 +609,41 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)
static int soc_pcm_components_open(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
- struct snd_soc_component *last = NULL;
struct snd_soc_component *component;
int i, ret = 0;
for_each_rtd_components(rtd, i, component) {
- last = component;
-
- ret = snd_soc_component_module_get_when_open(component);
- if (ret < 0) {
- dev_err(component->dev,
- "ASoC: can't get module %s\n",
- component->name);
+ ret = snd_soc_component_module_get_when_open(component, substream);
+ if (ret < 0)
break;
- }
ret = snd_soc_component_open(component, substream);
- if (ret < 0) {
- snd_soc_component_module_put_when_close(component);
- dev_err(component->dev,
- "ASoC: can't open component %s: %d\n",
- component->name, ret);
+ if (ret < 0)
break;
- }
- }
-
- if (ret < 0) {
- /* rollback on error */
- for_each_rtd_components(rtd, i, component) {
- if (component == last)
- break;
-
- snd_soc_component_close(component, substream);
- snd_soc_component_module_put_when_close(component);
- }
}
return ret;
}
-static int soc_pcm_components_close(struct snd_pcm_substream *substream)
+static int soc_pcm_components_close(struct snd_pcm_substream *substream,
+ int rollback)
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_component *component;
int i, r, ret = 0;
for_each_rtd_components(rtd, i, component) {
- r = snd_soc_component_close(component, substream);
+ r = snd_soc_component_close(component, substream, rollback);
if (r < 0)
ret = r; /* use last ret */
- snd_soc_component_module_put_when_close(component);
+ snd_soc_component_module_put_when_close(component, substream, rollback);
}
return ret;
}
-/*
- * Called by ALSA when a PCM substream is closed. Private data can be
- * freed here. The cpu DAI, codec DAI, machine and components are also
- * shutdown.
- */
-static int soc_pcm_close(struct snd_pcm_substream *substream)
+static int soc_pcm_clean(struct snd_pcm_substream *substream, int rollback)
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_component *component;
@@ -679,23 +652,22 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
- snd_soc_runtime_deactivate(rtd, substream->stream);
+ if (!rollback)
+ snd_soc_runtime_deactivate(rtd, substream->stream);
for_each_rtd_dais(rtd, i, dai)
- snd_soc_dai_shutdown(dai, substream);
+ snd_soc_dai_shutdown(dai, substream, rollback);
- snd_soc_link_shutdown(substream);
+ snd_soc_link_shutdown(substream, rollback);
- soc_pcm_components_close(substream);
+ soc_pcm_components_close(substream, rollback);
- snd_soc_dapm_stream_stop(rtd, substream->stream);
+ if (!rollback)
+ snd_soc_dapm_stream_stop(rtd, substream->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);
- }
+ snd_soc_pcm_component_pm_runtime_put(rtd, substream, rollback);
for_each_rtd_components(rtd, i, component)
if (!snd_soc_component_active(component))
@@ -705,6 +677,16 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
}
/*
+ * Called by ALSA when a PCM substream is closed. Private data can be
+ * freed here. The cpu DAI, codec DAI, machine and components are also
+ * shutdown.
+ */
+static int soc_pcm_close(struct snd_pcm_substream *substream)
+{
+ return soc_pcm_clean(substream, 0);
+}
+
+/*
* Called by ALSA when a PCM substream is opened, the runtime->hw record is
* then initialized and any private data can be allocated. This also calls
* startup for the cpu DAI, component, machine and codec DAI.
@@ -722,28 +704,25 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
for_each_rtd_components(rtd, i, component)
pinctrl_pm_select_default_state(component->dev);
- for_each_rtd_components(rtd, i, component)
- pm_runtime_get_sync(component->dev);
+ ret = snd_soc_pcm_component_pm_runtime_get(rtd, substream);
+ if (ret < 0)
+ goto pm_err;
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
ret = soc_pcm_components_open(substream);
if (ret < 0)
- goto component_err;
+ goto err;
ret = snd_soc_link_startup(substream);
if (ret < 0)
- goto rtd_startup_err;
+ goto err;
/* startup the audio subsystem */
for_each_rtd_dais(rtd, i, dai) {
ret = snd_soc_dai_startup(dai, substream);
- if (ret < 0) {
- dev_err(dai->dev,
- "ASoC: can't open DAI %s: %d\n",
- dai->name, ret);
- goto config_err;
- }
+ if (ret < 0)
+ goto err;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
dai->tx_mask = 0;
@@ -771,18 +750,18 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
if (!runtime->hw.rates) {
printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n",
codec_dai_name, cpu_dai_name);
- goto config_err;
+ goto err;
}
if (!runtime->hw.formats) {
printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n",
codec_dai_name, cpu_dai_name);
- goto config_err;
+ goto err;
}
if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
runtime->hw.channels_min > runtime->hw.channels_max) {
printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n",
codec_dai_name, cpu_dai_name);
- goto config_err;
+ goto err;
}
soc_pcm_apply_msb(substream);
@@ -792,7 +771,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
if (snd_soc_dai_active(dai)) {
ret = soc_pcm_apply_symmetry(substream, dai);
if (ret != 0)
- goto config_err;
+ goto err;
}
}
@@ -803,32 +782,14 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
runtime->hw.channels_max);
pr_debug("ASoC: min rate %d max rate %d\n", runtime->hw.rate_min,
runtime->hw.rate_max);
-
dynamic:
-
snd_soc_runtime_activate(rtd, substream->stream);
-
+ ret = 0;
+err:
mutex_unlock(&rtd->card->pcm_mutex);
- return 0;
-
-config_err:
- for_each_rtd_dais_rollback(rtd, i, dai)
- snd_soc_dai_shutdown(dai, substream);
-
- snd_soc_link_shutdown(substream);
-rtd_startup_err:
- soc_pcm_components_close(substream);
-component_err:
- 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);
- }
-
- for_each_rtd_components(rtd, i, component)
- if (!snd_soc_component_active(component))
- pinctrl_pm_select_sleep_state(component->dev);
+pm_err:
+ if (ret < 0)
+ soc_pcm_clean(substream, 1);
return ret;
}