Commit a72706ed authored by Jerome Brunet's avatar Jerome Brunet Committed by Mark Brown

ASoC: codec2codec: remove ephemeral variables

Now that codec to codec links struct snd_soc_pcm_runtime have lasting pcm
and substreams, let's use them. Alsa allocate and keep the
struct snd_pcm_runtime as long as the link is powered.
Signed-off-by: default avatarJerome Brunet <jbrunet@baylibre.com>
Link: https://lore.kernel.org/r/20190725165949.29699-6-jbrunet@baylibre.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent a342031c
...@@ -3775,6 +3775,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3775,6 +3775,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_pcm_hw_params *params = NULL; struct snd_pcm_hw_params *params = NULL;
const struct snd_soc_pcm_stream *config = NULL; const struct snd_soc_pcm_stream *config = NULL;
struct snd_pcm_runtime *runtime = NULL;
unsigned int fmt; unsigned int fmt;
int ret = 0; int ret = 0;
...@@ -3782,6 +3783,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3782,6 +3783,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
if (!params) if (!params)
return -ENOMEM; return -ENOMEM;
runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
if (!runtime) {
ret = -ENOMEM;
goto out;
}
substream->runtime = runtime;
substream->stream = SNDRV_PCM_STREAM_CAPTURE; substream->stream = SNDRV_PCM_STREAM_CAPTURE;
snd_soc_dapm_widget_for_each_source_path(w, path) { snd_soc_dapm_widget_for_each_source_path(w, path) {
source = path->source->priv; source = path->source->priv;
...@@ -3808,6 +3817,8 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3808,6 +3817,8 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
sink->active++; sink->active++;
} }
substream->hw_opened = 1;
/* /*
* Note: getting the config after .startup() gives a chance to * Note: getting the config after .startup() gives a chance to
* either party on the link to alter the configuration if * either party on the link to alter the configuration if
...@@ -3864,6 +3875,9 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3864,6 +3875,9 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
} }
out: out:
if (ret < 0)
kfree(runtime);
kfree(params); kfree(params);
return ret; return ret;
} }
...@@ -3873,29 +3887,16 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, ...@@ -3873,29 +3887,16 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
{ {
struct snd_soc_dapm_path *path; struct snd_soc_dapm_path *path;
struct snd_soc_dai *source, *sink; struct snd_soc_dai *source, *sink;
struct snd_soc_pcm_runtime *rtd = w->priv; struct snd_pcm_substream *substream = w->priv;
struct snd_pcm_substream substream; int ret = 0, saved_stream = substream->stream;
struct snd_pcm_runtime *runtime = NULL;
int ret = 0;
if (WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) || if (WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) ||
list_empty(&w->edges[SND_SOC_DAPM_DIR_IN]))) list_empty(&w->edges[SND_SOC_DAPM_DIR_IN])))
return -EINVAL; return -EINVAL;
memset(&substream, 0, sizeof(substream));
/* Allocate a dummy snd_pcm_runtime for startup() and other ops() */
runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
if (!runtime) {
ret = -ENOMEM;
goto out;
}
substream.runtime = runtime;
substream.private_data = rtd;
switch (event) { switch (event) {
case SND_SOC_DAPM_PRE_PMU: case SND_SOC_DAPM_PRE_PMU:
ret = snd_soc_dai_link_event_pre_pmu(w, &substream); ret = snd_soc_dai_link_event_pre_pmu(w, substream);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -3926,40 +3927,45 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, ...@@ -3926,40 +3927,45 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
ret = 0; ret = 0;
} }
substream.stream = SNDRV_PCM_STREAM_CAPTURE; substream->stream = SNDRV_PCM_STREAM_CAPTURE;
snd_soc_dapm_widget_for_each_source_path(w, path) { snd_soc_dapm_widget_for_each_source_path(w, path) {
source = path->source->priv; source = path->source->priv;
snd_soc_dai_hw_free(source, &substream); snd_soc_dai_hw_free(source, substream);
} }
substream.stream = SNDRV_PCM_STREAM_PLAYBACK; substream->stream = SNDRV_PCM_STREAM_PLAYBACK;
snd_soc_dapm_widget_for_each_sink_path(w, path) { snd_soc_dapm_widget_for_each_sink_path(w, path) {
sink = path->sink->priv; sink = path->sink->priv;
snd_soc_dai_hw_free(sink, &substream); snd_soc_dai_hw_free(sink, substream);
} }
substream.stream = SNDRV_PCM_STREAM_CAPTURE; substream->stream = SNDRV_PCM_STREAM_CAPTURE;
snd_soc_dapm_widget_for_each_source_path(w, path) { snd_soc_dapm_widget_for_each_source_path(w, path) {
source = path->source->priv; source = path->source->priv;
source->active--; source->active--;
snd_soc_dai_shutdown(source, &substream); snd_soc_dai_shutdown(source, substream);
} }
substream.stream = SNDRV_PCM_STREAM_PLAYBACK; substream->stream = SNDRV_PCM_STREAM_PLAYBACK;
snd_soc_dapm_widget_for_each_sink_path(w, path) { snd_soc_dapm_widget_for_each_sink_path(w, path) {
sink = path->sink->priv; sink = path->sink->priv;
sink->active--; sink->active--;
snd_soc_dai_shutdown(sink, &substream); snd_soc_dai_shutdown(sink, substream);
} }
break; break;
case SND_SOC_DAPM_POST_PMD:
kfree(substream->runtime);
break;
default: default:
WARN(1, "Unknown event %d\n", event); WARN(1, "Unknown event %d\n", event);
ret = -EINVAL; ret = -EINVAL;
} }
out: out:
kfree(runtime); /* Restore the substream direction */
substream->stream = saved_stream;
return ret; return ret;
} }
...@@ -4082,9 +4088,11 @@ snd_soc_dapm_alloc_kcontrol(struct snd_soc_card *card, ...@@ -4082,9 +4088,11 @@ snd_soc_dapm_alloc_kcontrol(struct snd_soc_card *card,
} }
static struct snd_soc_dapm_widget * static struct snd_soc_dapm_widget *
snd_soc_dapm_new_dai(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd, snd_soc_dapm_new_dai(struct snd_soc_card *card,
struct snd_pcm_substream *substream,
char *id) char *id)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dapm_widget template; struct snd_soc_dapm_widget template;
struct snd_soc_dapm_widget *w; struct snd_soc_dapm_widget *w;
const char **w_param_text; const char **w_param_text;
...@@ -4103,7 +4111,7 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd, ...@@ -4103,7 +4111,7 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd,
template.name = link_name; template.name = link_name;
template.event = snd_soc_dai_link_event; template.event = snd_soc_dai_link_event;
template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
SND_SOC_DAPM_PRE_PMD; SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD;
template.kcontrol_news = NULL; template.kcontrol_news = NULL;
/* allocate memory for control, only in case of multiple configs */ /* allocate memory for control, only in case of multiple configs */
...@@ -4138,7 +4146,7 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd, ...@@ -4138,7 +4146,7 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd,
goto outfree_kcontrol_news; goto outfree_kcontrol_news;
} }
w->priv = rtd; w->priv = substream;
return w; return w;
...@@ -4260,6 +4268,8 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card, ...@@ -4260,6 +4268,8 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
struct snd_soc_dai *codec_dai; struct snd_soc_dai *codec_dai;
struct snd_soc_dapm_widget *playback = NULL, *capture = NULL; struct snd_soc_dapm_widget *playback = NULL, *capture = NULL;
struct snd_soc_dapm_widget *codec, *playback_cpu, *capture_cpu; struct snd_soc_dapm_widget *codec, *playback_cpu, *capture_cpu;
struct snd_pcm_substream *substream;
struct snd_pcm_str *streams = rtd->pcm->streams;
int i; int i;
if (rtd->dai_link->params) { if (rtd->dai_link->params) {
...@@ -4278,7 +4288,8 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card, ...@@ -4278,7 +4288,8 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
if (playback_cpu && codec) { if (playback_cpu && codec) {
if (!playback) { if (!playback) {
playback = snd_soc_dapm_new_dai(card, rtd, substream = streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
playback = snd_soc_dapm_new_dai(card, substream,
"playback"); "playback");
if (IS_ERR(playback)) { if (IS_ERR(playback)) {
dev_err(rtd->dev, dev_err(rtd->dev,
...@@ -4307,7 +4318,8 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card, ...@@ -4307,7 +4318,8 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
if (codec && capture_cpu) { if (codec && capture_cpu) {
if (!capture) { if (!capture) {
capture = snd_soc_dapm_new_dai(card, rtd, substream = streams[SNDRV_PCM_STREAM_CAPTURE].substream;
capture = snd_soc_dapm_new_dai(card, substream,
"capture"); "capture");
if (IS_ERR(capture)) { if (IS_ERR(capture)) {
dev_err(rtd->dev, dev_err(rtd->dev,
......
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