All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
To: Mark Brown <broonie@kernel.org>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: [PATCH 02/14] ASoC: simple-card-utils: share dummy DAI and reduce memory
Date: 01 Apr 2021 13:15:33 +0900	[thread overview]
Message-ID: <87tuoqod22.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87wntmod33.wl-kuninori.morimoto.gx@renesas.com>

From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Current simple-card / audio-graph creates 1xCPU + 1xCodec + 1xPlatform
for all dai_link, but some of them is not needed.
For example Platform is not needed for DPCM BE case.
Moreover, we can share snd-soc-dummy DAI for CPU-dummy / dummy-Codec
in DPCM.

This patch adds dummy DAI and share it when DPCM case,
I beliave it can contribute to reduce memory.

By this patch, CPU-dummy / dummy-CPU are set at asoc_simple_init_priv(),
thus, its settings are no longer needed at DPCM detecting timing
on simple-card / audio-graph.
Moreover, we can remove triky Platform settings code for DPCM BE,
because un-needed Platform is not created.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/simple_card_utils.h     |  1 +
 sound/soc/generic/audio-graph-card.c  | 12 +----------
 sound/soc/generic/simple-card-utils.c | 30 ++++++++++++++++++++-------
 sound/soc/generic/simple-card.c       | 12 +----------
 4 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index 475f8cb14492..6635283a8160 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -62,6 +62,7 @@ struct asoc_simple_priv {
 	struct snd_soc_dai_link *dai_link;
 	struct asoc_simple_dai *dais;
 	struct snd_soc_dai_link_component *dlcs;
+	struct snd_soc_dai_link_component dummy;
 	struct snd_soc_codec_conf *codec_conf;
 	struct gpio_desc *pa_gpio;
 	const struct snd_soc_ops *ops;
diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index a3ca9a99fccd..49d37964e40a 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -240,9 +240,6 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 		int is_single_links = 0;
 
 		/* Codec is dummy */
-		codecs->of_node		= NULL;
-		codecs->dai_name	= "snd-soc-dummy-dai";
-		codecs->name		= "snd-soc-dummy";
 
 		/* FE settings */
 		dai_link->dynamic		= 1;
@@ -281,13 +278,11 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 
 		/* card->num_links includes Codec */
 		asoc_simple_canonicalize_cpu(dai_link, is_single_links);
+		asoc_simple_canonicalize_platform(dai_link);
 	} else {
 		struct snd_soc_codec_conf *cconf;
 
 		/* CPU is dummy */
-		cpus->of_node		= NULL;
-		cpus->dai_name		= "snd-soc-dummy-dai";
-		cpus->name		= "snd-soc-dummy";
 
 		/* BE settings */
 		dai_link->no_pcm		= 1;
@@ -328,8 +323,6 @@ static int graph_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 	graph_parse_convert(dev, ep, &dai_props->adata);
 	graph_parse_mclk_fs(top, ep, dai_props);
 
-	asoc_simple_canonicalize_platform(dai_link);
-
 	ret = asoc_simple_parse_tdm(ep, dai);
 	if (ret)
 		goto out_put_node;
@@ -659,15 +652,12 @@ static int graph_count_dpcm(struct asoc_simple_priv *priv,
 
 	if (li->cpu) {
 		li->num[li->link].cpus		= 1;
-		li->num[li->link].codecs	= 1;
 		li->num[li->link].platforms	= 1;
 
 		li->link++; /* 1xCPU-dummy */
 		li->dais++; /* 1xCPU */
 	} else {
-		li->num[li->link].cpus		= 1;
 		li->num[li->link].codecs	= 1;
-		li->num[li->link].platforms	= 1;
 
 		li->link++; /* 1xdummy-Codec */
 		li->conf++; /* 1xdummy-Codec */
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 1606b9bc6b71..64b1ff5bafda 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -404,13 +404,6 @@ void asoc_simple_canonicalize_platform(struct snd_soc_dai_link *dai_link)
 	/* Assumes platform == cpu */
 	if (!dai_link->platforms->of_node)
 		dai_link->platforms->of_node = dai_link->cpus->of_node;
-
-	/*
-	 * DPCM BE can be no platform.
-	 * Alloced memory will be waste, but not leak.
-	 */
-	if (!dai_link->platforms->of_node)
-		dai_link->num_platforms = 0;
 }
 EXPORT_SYMBOL_GPL(asoc_simple_canonicalize_platform);
 
@@ -633,6 +626,11 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
 			return -ENOMEM;
 	}
 
+	/* dummy CPU/Codec */
+	priv->dummy.of_node	= NULL;
+	priv->dummy.dai_name	= "snd-soc-dummy-dai";
+	priv->dummy.name	= "snd-soc-dummy";
+
 	priv->dai_props		= dai_props;
 	priv->dai_link		= dai_link;
 	priv->dais		= dais;
@@ -653,6 +651,12 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
 			dai_link[i].num_cpus	= li->num[i].cpus;
 
 			dlcs += li->num[i].cpus;
+		} else {
+			/* DPCM Be's CPU = dummy */
+			dai_props[i].cpus	=
+			dai_link[i].cpus	= &priv->dummy;
+			dai_props[i].num.cpus	=
+			dai_link[i].num_cpus	= 1;
 		}
 
 		if (li->num[i].codecs) {
@@ -663,6 +667,12 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
 			dai_link[i].num_codecs	= li->num[i].codecs;
 
 			dlcs += li->num[i].codecs;
+		} else {
+			/* DPCM Fe's Codec = dummy */
+			dai_props[i].codecs	=
+			dai_link[i].codecs	= &priv->dummy;
+			dai_props[i].num.codecs	=
+			dai_link[i].num_codecs	= 1;
 		}
 
 		if (li->num[i].platforms) {
@@ -673,6 +683,12 @@ int asoc_simple_init_priv(struct asoc_simple_priv *priv,
 			dai_link[i].num_platforms	= li->num[i].platforms;
 
 			dlcs += li->num[i].platforms;
+		} else {
+			/* Doesn't have Platform */
+			dai_props[i].platforms		=
+			dai_link[i].platforms		= NULL;
+			dai_props[i].num.platforms	=
+			dai_link[i].num_platforms	= 0;
 		}
 	}
 
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index f60e809d723b..542180a19a06 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -141,9 +141,6 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 		int is_single_links = 0;
 
 		/* Codec is dummy */
-		codecs->of_node		= NULL;
-		codecs->dai_name	= "snd-soc-dummy-dai";
-		codecs->name		= "snd-soc-dummy";
 
 		/* FE settings */
 		dai_link->dynamic		= 1;
@@ -167,13 +164,11 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 			goto out_put_node;
 
 		asoc_simple_canonicalize_cpu(dai_link, is_single_links);
+		asoc_simple_canonicalize_platform(dai_link);
 	} else {
 		struct snd_soc_codec_conf *cconf;
 
 		/* CPU is dummy */
-		cpus->of_node		= NULL;
-		cpus->dai_name		= "snd-soc-dummy-dai";
-		cpus->name		= "snd-soc-dummy";
 
 		/* BE settings */
 		dai_link->no_pcm		= 1;
@@ -211,8 +206,6 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
 	simple_parse_convert(dev, np, &dai_props->adata);
 	simple_parse_mclk_fs(top, np, codec, dai_props, prefix);
 
-	asoc_simple_canonicalize_platform(dai_link);
-
 	ret = asoc_simple_parse_tdm(np, dai);
 	if (ret)
 		goto out_put_node;
@@ -530,15 +523,12 @@ static int simple_count_dpcm(struct asoc_simple_priv *priv,
 
 	if (li->cpu) {
 		li->num[li->link].cpus		= 1;
-		li->num[li->link].codecs	= 1;
 		li->num[li->link].platforms	= 1;
 
 		li->link++; /* CPU-dummy */
 		li->dais++;
 	} else {
-		li->num[li->link].cpus		= 1;
 		li->num[li->link].codecs	= 1;
-		li->num[li->link].platforms	= 1;
 
 		li->link++; /* dummy-Codec */
 		li->dais++;
-- 
2.25.1


  parent reply	other threads:[~2021-04-01  4:17 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01  4:14 [PATCH 00/14] ASoC: simple-card-utils: prepare for multi support Kuninori Morimoto
2021-04-01  4:15 ` [PATCH 01/14] ASoC: simple-card-utils: enable flexible CPU/Codec/Platform Kuninori Morimoto
2021-04-15 18:01   ` Thierry Reding
2021-04-15 18:01     ` Thierry Reding
2021-04-15 18:14     ` Mark Brown
2021-04-15 18:14       ` Mark Brown
2021-04-15 18:25       ` Thierry Reding
2021-04-15 18:25         ` Thierry Reding
2021-04-15 18:31         ` Mark Brown
2021-04-15 18:31           ` Mark Brown
2021-04-01  4:15 ` Kuninori Morimoto [this message]
2021-04-01  4:15 ` [PATCH 03/14] ASoC: simple-card-utils: setup dai_props cpu_dai/codec_dai at initial timing Kuninori Morimoto
2021-04-08 14:16   ` Mark Brown
2021-04-01  4:15 ` [PATCH 04/14] ASoC: simple-card-utils: remove li->dais/li->conf Kuninori Morimoto
2021-04-01  4:15 ` [PATCH 05/14] ASoC: simple-card-utils: use for_each_prop_xxx() Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 06/14] ASoC: simple-card-utils: remove asoc_simple_parse_xxx() Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 07/14] ASoC: simple-card-utils: care multi DAI at asoc_simple_clean_reference() Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 08/14] ASoC: simple-card-utils: indicate dai_fmt if exist Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 09/14] ASoC: simple-card-utils: indicate missing CPU/Codec numbers for debug Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 10/14] ASoC: simple-card-utils: add simple_props_to_xxx() macro Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 11/14] ASoC: simple-card-utils: multi support at asoc_simple_canonicalize_cpu/platform() Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 12/14] ASoC: simple-card-utils: tidyup debug info for clock Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 13/14] ASoC: simple-card-utils: tidyup dev_dbg() to use 1 line Kuninori Morimoto
2021-04-01  4:16 ` [PATCH 14/14] ASoC: simple-card-utils: tidyup asoc_simple_parse_convert() Kuninori Morimoto
2021-04-08 16:54 ` [PATCH 00/14] ASoC: simple-card-utils: prepare for multi support Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tuoqod22.wl-kuninori.morimoto.gx@renesas.com \
    --to=kuninori.morimoto.gx@renesas.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.