Commit 2b39123b authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-pcm: add soc_create_pcm() and simplify soc_new_pcm()

soc_new_pcm() implementation is very long / verbose / complex,
thus, it is very difficult to read.
If we read it carefully, we can notice that it is consisted by

	int soc_new_pcm(...)
	{
		(1) judging playback/caputre part
		(2) creating the PCM part
		(3) setup pcm/rtd part
	}

This patch adds new soc_create_pcm() for (2) part
and offload it from snd_pcm_new().
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/875z3paigi.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 7fc6bebd
...@@ -2719,18 +2719,12 @@ static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd, ...@@ -2719,18 +2719,12 @@ static int soc_get_playback_capture(struct snd_soc_pcm_runtime *rtd,
return 0; return 0;
} }
/* create a new pcm */ static int soc_create_pcm(struct snd_pcm **pcm,
int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) struct snd_soc_pcm_runtime *rtd,
int playback, int capture, int num)
{ {
struct snd_soc_component *component;
struct snd_pcm *pcm;
char new_name[64]; char new_name[64];
int ret = 0, playback = 0, capture = 0; int ret;
int i;
ret = soc_get_playback_capture(rtd, &playback, &capture);
if (ret < 0)
return ret;
/* create the PCM */ /* create the PCM */
if (rtd->dai_link->params) { if (rtd->dai_link->params) {
...@@ -2738,13 +2732,13 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) ...@@ -2738,13 +2732,13 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
rtd->dai_link->stream_name); rtd->dai_link->stream_name);
ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
playback, capture, &pcm); playback, capture, pcm);
} else if (rtd->dai_link->no_pcm) { } else if (rtd->dai_link->no_pcm) {
snprintf(new_name, sizeof(new_name), "(%s)", snprintf(new_name, sizeof(new_name), "(%s)",
rtd->dai_link->stream_name); rtd->dai_link->stream_name);
ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num, ret = snd_pcm_new_internal(rtd->card->snd_card, new_name, num,
playback, capture, &pcm); playback, capture, pcm);
} else { } else {
if (rtd->dai_link->dynamic) if (rtd->dai_link->dynamic)
snprintf(new_name, sizeof(new_name), "%s (*)", snprintf(new_name, sizeof(new_name), "%s (*)",
...@@ -2756,7 +2750,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) ...@@ -2756,7 +2750,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
"multicodec" : asoc_rtd_to_codec(rtd, 0)->name, num); "multicodec" : asoc_rtd_to_codec(rtd, 0)->name, num);
ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback, ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
capture, &pcm); capture, pcm);
} }
if (ret < 0) { if (ret < 0) {
dev_err(rtd->card->dev, "ASoC: can't create pcm %s for dailink %s: %d\n", dev_err(rtd->card->dev, "ASoC: can't create pcm %s for dailink %s: %d\n",
...@@ -2765,6 +2759,25 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) ...@@ -2765,6 +2759,25 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
} }
dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name); dev_dbg(rtd->card->dev, "ASoC: registered pcm #%d %s\n",num, new_name);
return 0;
}
/* create a new pcm */
int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
{
struct snd_soc_component *component;
struct snd_pcm *pcm;
int ret = 0, playback = 0, capture = 0;
int i;
ret = soc_get_playback_capture(rtd, &playback, &capture);
if (ret < 0)
return ret;
ret = soc_create_pcm(&pcm, rtd, playback, capture, num);
if (ret < 0)
return ret;
/* DAPM dai link stream work */ /* DAPM dai link stream work */
if (rtd->dai_link->params) if (rtd->dai_link->params)
rtd->close_delayed_work_func = codec2codec_close_delayed_work; rtd->close_delayed_work_func = codec2codec_close_delayed_work;
...@@ -2825,8 +2838,8 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) ...@@ -2825,8 +2838,8 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
ret = snd_soc_pcm_component_new(rtd); ret = snd_soc_pcm_component_new(rtd);
if (ret < 0) { if (ret < 0) {
dev_err(rtd->dev, "ASoC: pcm %s constructor failed for dailink %s: %d\n", dev_err(rtd->dev, "ASoC: pcm constructor failed for dailink %s: %d\n",
new_name, rtd->dai_link->name, ret); rtd->dai_link->name, ret);
return ret; return ret;
} }
......
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