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 5/8] ASoC: soc-pcm: add soc_hw_sanity_check()
Date: 02 Mar 2021 10:48:12 +0900	[thread overview]
Message-ID: <87mtvmqqar.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87tupuqqc8.wl-kuninori.morimoto.gx@renesas.com>


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

Current soc_pcm_open() is checking runtime->hw parameters, but having
such function is very helpful for reading code.

This patch adds new soc_hw_sanity_check() and checks runtime->hw
parameters there. And print its debug message there, too.

Debug message print out timing is exchanged after this patch,
but it is not a big deal, because it is for debug.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-pcm.c | 67 +++++++++++++++++++++++++++------------------
 1 file changed, 40 insertions(+), 27 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 76c7f04cfd1a..aa1f26ccb0dc 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -685,6 +685,44 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
 	return soc_pcm_clean(substream, 0);
 }
 
+static int soc_hw_sanity_check(struct snd_pcm_substream *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+	struct snd_pcm_hardware *hw = &substream->runtime->hw;
+	const char *name_cpu = soc_cpu_dai_name(rtd);
+	const char *name_codec = soc_codec_dai_name(rtd);
+	const char *err_msg;
+	struct device *dev = rtd->dev;
+
+	err_msg = "rates";
+	if (!hw->rates)
+		goto config_err;
+
+	err_msg = "formats";
+	if (!hw->formats)
+		goto config_err;
+
+	err_msg = "channels";
+	if (!hw->channels_min || !hw->channels_max ||
+	     hw->channels_min  >  hw->channels_max)
+		goto config_err;
+
+	dev_dbg(dev, "ASoC: %s <-> %s info:\n",		name_codec,
+							name_cpu);
+	dev_dbg(dev, "ASoC: rate mask 0x%x\n",		hw->rates);
+	dev_dbg(dev, "ASoC: ch   min %d max %d\n",	hw->channels_min,
+							hw->channels_max);
+	dev_dbg(dev, "ASoC: rate min %d max %d\n",	hw->rate_min,
+							hw->rate_max);
+
+	return 0;
+
+config_err:
+	dev_err(dev, "ASoC: %s <-> %s No matching %s\n",
+		name_codec, name_cpu, err_msg);
+	return -EINVAL;
+}
+
 /*
  * 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
@@ -693,11 +731,8 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
 static int soc_pcm_open(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
-	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_soc_component *component;
 	struct snd_soc_dai *dai;
-	const char *codec_dai_name = soc_codec_dai_name(rtd);
-	const char *cpu_dai_name = soc_cpu_dai_name(rtd);
 	int i, ret = 0;
 
 	for_each_rtd_components(rtd, i, component)
@@ -738,23 +773,9 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 
 	soc_pcm_care_symmetry(substream);
 
-	ret = -EINVAL;
-	if (!runtime->hw.rates) {
-		printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n",
-			codec_dai_name, cpu_dai_name);
-		goto err;
-	}
-	if (!runtime->hw.formats) {
-		printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n",
-			codec_dai_name, cpu_dai_name);
-		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);
+	ret = soc_hw_sanity_check(substream);
+	if (ret < 0)
 		goto err;
-	}
 
 	soc_pcm_apply_msb(substream);
 
@@ -764,14 +785,6 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 		if (ret != 0)
 			goto err;
 	}
-
-	pr_debug("ASoC: %s <-> %s info:\n",
-		 codec_dai_name, cpu_dai_name);
-	pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates);
-	pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min,
-		 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;
-- 
2.25.1


  parent reply	other threads:[~2021-03-02  1:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02  1:47 [PATCH 0/8] ASoC: soc-pcm: cleanup each functions Kuninori Morimoto
2021-03-02  1:47 ` [PATCH 1/8] ASoC: soc-pcm: check DAI activity under soc_pcm_apply_symmetry() Kuninori Morimoto
2021-03-02  1:47 ` [PATCH 2/8] ASoC: soc-pcm: add soc_cpu/codec_dai_name() macro Kuninori Morimoto
2021-03-02 13:04   ` Mark Brown
2021-03-04 22:04     ` Kuninori Morimoto
2021-03-02  1:48 ` [PATCH 3/8] ASoC: soc-pcm: direct copy at snd_soc_set_runtime_hwparams() Kuninori Morimoto
2021-03-02  1:48 ` [PATCH 4/8] ASoC: soc-pcm: add soc_pcm_care_symmetry() Kuninori Morimoto
2021-03-02 13:10   ` Mark Brown
2021-03-04 22:06     ` Kuninori Morimoto
2021-03-02  1:48 ` Kuninori Morimoto [this message]
2021-03-02  1:48 ` [PATCH 6/8] ASoC: soc-pcm: fixup dpcm_be_dai_startup() user count Kuninori Morimoto
2021-03-02  1:48 ` [PATCH 7/8] ASoC: soc-pcm: remove unneeded !rtd->dai_link check Kuninori Morimoto
2021-03-02  1:48 ` [PATCH 8/8] ASoC: soc-pcm: share DPCM BE DAI stop operation Kuninori Morimoto
2021-03-05  0:59 [PATCH v2 0/8] ASoC: soc-pcm: cleanup each functions Kuninori Morimoto
2021-03-05  1:00 ` [PATCH 5/8] ASoC: soc-pcm: add soc_hw_sanity_check() Kuninori Morimoto

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=87mtvmqqar.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.