All of lore.kernel.org
 help / color / mirror / Atom feed
From: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
To: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org>
Cc: <perex@perex.cz>, <tiwai@suse.com>, <lgirdwood@gmail.com>,
	<broonie@kernel.org>, <mirq-linux@rere.qmqm.pl>,
	<gustavoars@kernel.org>,
	Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Subject: [RFC PATCH 3/3] ASoC: soc-pcm: apply BE HW constraint rules
Date: Tue, 23 Mar 2021 13:43:27 +0200	[thread overview]
Message-ID: <20210323114327.3969072-4-codrin.ciubotariu@microchip.com> (raw)
In-Reply-To: <20210323114327.3969072-1-codrin.ciubotariu@microchip.com>

Apply the HW constraint rules added by the BE DAIs. The constraint rules
are applied after the fixup is called for the HW parameters. This way, if
the HW parameters do not correspond with the HW capabilities, the
constraint rules will return an error. The mask and the interval
constraints are the same as the ones used for FE. The DAI link
dpcm_merged_* flags are used to check if the FE and BE must share the same
HW parameters.

Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
 include/sound/pcm.h     |  2 ++
 sound/core/pcm_native.c | 17 +++++++++++++----
 sound/soc/soc-pcm.c     | 30 ++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 198d37d04d78..b56a4435439a 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -987,6 +987,8 @@ int snd_pcm_hw_rule_div(struct snd_pcm_hw_params *params,
 			struct snd_pcm_hw_rule *rule);
 
 int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
+int constrain_params_by_rules(struct snd_pcm_substream *substream,
+			      struct snd_pcm_hw_params *params);
 
 int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
 				 u_int64_t mask);
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index d6f14162bce5..2ff6e182c7f5 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -22,6 +22,7 @@
 #include <sound/pcm_params.h>
 #include <sound/timer.h>
 #include <sound/minors.h>
+#include <sound/soc.h>
 #include <linux/uio.h>
 #include <linux/delay.h>
 
@@ -326,11 +327,10 @@ static int constrain_interval_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-static int constrain_params_by_rules(struct snd_pcm_substream *substream,
-				     struct snd_pcm_hw_params *params)
+int constrain_params_by_rules(struct snd_pcm_substream *substream,
+			      struct snd_pcm_hw_params *params)
 {
-	struct snd_pcm_hw_constraints *constrs =
-					&substream->runtime->hw_constraints;
+	struct snd_pcm_hw_constraints *constrs;
 	unsigned int k;
 	unsigned int *rstamps;
 	unsigned int vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1];
@@ -342,6 +342,14 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
 	bool again;
 	int changed, err = 0;
 
+	if (substream->pcm->internal) {
+		struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+
+		constrs = &rtd->dpcm[substream->stream].hw_constraints;
+	} else {
+		constrs = &substream->runtime->hw_constraints;
+	}
+
 	/*
 	 * Each application of rule has own sequence number.
 	 *
@@ -446,6 +454,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
 	kfree(rstamps);
 	return err;
 }
+EXPORT_SYMBOL(constrain_params_by_rules);
 
 static int fixup_unreferenced_params(struct snd_pcm_substream *substream,
 				     struct snd_pcm_hw_params *params)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index dae246918e0d..5bd71d48c0de 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1934,11 +1934,25 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
 		memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params,
 				sizeof(struct snd_pcm_hw_params));
 
+		/* copy FE mask and interval constraints */
+		memcpy(&be->dpcm[stream].hw_constraints.masks,
+		       &be_substream->runtime->hw_constraints.masks,
+		       sizeof(be_substream->runtime->hw_constraints.masks));
+		memcpy(&be->dpcm[stream].hw_constraints.intervals,
+		       &be_substream->runtime->hw_constraints.intervals,
+		       sizeof(be_substream->runtime->hw_constraints.intervals));
+
 		/* perform any hw_params fixups */
 		ret = snd_soc_link_be_hw_params_fixup(be, &dpcm->hw_params);
 		if (ret < 0)
 			goto unwind;
 
+		/* apply constrain rules */
+		dpcm->hw_params.rmask = ~0U;
+		ret = constrain_params_by_rules(be_substream, &dpcm->hw_params);
+		if (ret < 0)
+			goto unwind;
+
 		/* copy the fixed-up hw params for BE dai */
 		memcpy(&be->dpcm[stream].hw_params, &dpcm->hw_params,
 		       sizeof(struct snd_pcm_hw_params));
@@ -2002,6 +2016,22 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
 
 	memcpy(&fe->dpcm[stream].hw_params, params,
 			sizeof(struct snd_pcm_hw_params));
+	if (!fe->dai_link->dpcm_merged_format) {
+		snd_mask_any(hw_param_mask(&fe->dpcm[stream].hw_params,
+					   SNDRV_PCM_HW_PARAM_FORMAT));
+		snd_interval_any(hw_param_interval(&fe->dpcm[stream].hw_params,
+						   SNDRV_PCM_HW_PARAM_SAMPLE_BITS));
+		snd_interval_any(hw_param_interval(&fe->dpcm[stream].hw_params,
+						   SNDRV_PCM_HW_PARAM_FRAME_BITS));
+	}
+	if (!fe->dai_link->dpcm_merged_chan) {
+		snd_interval_any(hw_param_interval(&fe->dpcm[stream].hw_params,
+						   SNDRV_PCM_HW_PARAM_CHANNELS));
+	}
+	if (!fe->dai_link->dpcm_merged_rate) {
+		snd_interval_any(hw_param_interval(&fe->dpcm[stream].hw_params,
+						   SNDRV_PCM_HW_PARAM_RATE));
+	}
 	ret = dpcm_be_dai_hw_params(fe, stream);
 	if (ret < 0)
 		goto out;
-- 
2.27.0


WARNING: multiple messages have this Message-ID (diff)
From: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
To: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org>
Cc: gustavoars@kernel.org, tiwai@suse.com, lgirdwood@gmail.com,
	mirq-linux@rere.qmqm.pl, broonie@kernel.org,
	Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Subject: [RFC PATCH 3/3] ASoC: soc-pcm: apply BE HW constraint rules
Date: Tue, 23 Mar 2021 13:43:27 +0200	[thread overview]
Message-ID: <20210323114327.3969072-4-codrin.ciubotariu@microchip.com> (raw)
In-Reply-To: <20210323114327.3969072-1-codrin.ciubotariu@microchip.com>

Apply the HW constraint rules added by the BE DAIs. The constraint rules
are applied after the fixup is called for the HW parameters. This way, if
the HW parameters do not correspond with the HW capabilities, the
constraint rules will return an error. The mask and the interval
constraints are the same as the ones used for FE. The DAI link
dpcm_merged_* flags are used to check if the FE and BE must share the same
HW parameters.

Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
 include/sound/pcm.h     |  2 ++
 sound/core/pcm_native.c | 17 +++++++++++++----
 sound/soc/soc-pcm.c     | 30 ++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 198d37d04d78..b56a4435439a 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -987,6 +987,8 @@ int snd_pcm_hw_rule_div(struct snd_pcm_hw_params *params,
 			struct snd_pcm_hw_rule *rule);
 
 int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
+int constrain_params_by_rules(struct snd_pcm_substream *substream,
+			      struct snd_pcm_hw_params *params);
 
 int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
 				 u_int64_t mask);
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index d6f14162bce5..2ff6e182c7f5 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -22,6 +22,7 @@
 #include <sound/pcm_params.h>
 #include <sound/timer.h>
 #include <sound/minors.h>
+#include <sound/soc.h>
 #include <linux/uio.h>
 #include <linux/delay.h>
 
@@ -326,11 +327,10 @@ static int constrain_interval_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-static int constrain_params_by_rules(struct snd_pcm_substream *substream,
-				     struct snd_pcm_hw_params *params)
+int constrain_params_by_rules(struct snd_pcm_substream *substream,
+			      struct snd_pcm_hw_params *params)
 {
-	struct snd_pcm_hw_constraints *constrs =
-					&substream->runtime->hw_constraints;
+	struct snd_pcm_hw_constraints *constrs;
 	unsigned int k;
 	unsigned int *rstamps;
 	unsigned int vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1];
@@ -342,6 +342,14 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
 	bool again;
 	int changed, err = 0;
 
+	if (substream->pcm->internal) {
+		struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+
+		constrs = &rtd->dpcm[substream->stream].hw_constraints;
+	} else {
+		constrs = &substream->runtime->hw_constraints;
+	}
+
 	/*
 	 * Each application of rule has own sequence number.
 	 *
@@ -446,6 +454,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
 	kfree(rstamps);
 	return err;
 }
+EXPORT_SYMBOL(constrain_params_by_rules);
 
 static int fixup_unreferenced_params(struct snd_pcm_substream *substream,
 				     struct snd_pcm_hw_params *params)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index dae246918e0d..5bd71d48c0de 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1934,11 +1934,25 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
 		memcpy(&dpcm->hw_params, &fe->dpcm[stream].hw_params,
 				sizeof(struct snd_pcm_hw_params));
 
+		/* copy FE mask and interval constraints */
+		memcpy(&be->dpcm[stream].hw_constraints.masks,
+		       &be_substream->runtime->hw_constraints.masks,
+		       sizeof(be_substream->runtime->hw_constraints.masks));
+		memcpy(&be->dpcm[stream].hw_constraints.intervals,
+		       &be_substream->runtime->hw_constraints.intervals,
+		       sizeof(be_substream->runtime->hw_constraints.intervals));
+
 		/* perform any hw_params fixups */
 		ret = snd_soc_link_be_hw_params_fixup(be, &dpcm->hw_params);
 		if (ret < 0)
 			goto unwind;
 
+		/* apply constrain rules */
+		dpcm->hw_params.rmask = ~0U;
+		ret = constrain_params_by_rules(be_substream, &dpcm->hw_params);
+		if (ret < 0)
+			goto unwind;
+
 		/* copy the fixed-up hw params for BE dai */
 		memcpy(&be->dpcm[stream].hw_params, &dpcm->hw_params,
 		       sizeof(struct snd_pcm_hw_params));
@@ -2002,6 +2016,22 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
 
 	memcpy(&fe->dpcm[stream].hw_params, params,
 			sizeof(struct snd_pcm_hw_params));
+	if (!fe->dai_link->dpcm_merged_format) {
+		snd_mask_any(hw_param_mask(&fe->dpcm[stream].hw_params,
+					   SNDRV_PCM_HW_PARAM_FORMAT));
+		snd_interval_any(hw_param_interval(&fe->dpcm[stream].hw_params,
+						   SNDRV_PCM_HW_PARAM_SAMPLE_BITS));
+		snd_interval_any(hw_param_interval(&fe->dpcm[stream].hw_params,
+						   SNDRV_PCM_HW_PARAM_FRAME_BITS));
+	}
+	if (!fe->dai_link->dpcm_merged_chan) {
+		snd_interval_any(hw_param_interval(&fe->dpcm[stream].hw_params,
+						   SNDRV_PCM_HW_PARAM_CHANNELS));
+	}
+	if (!fe->dai_link->dpcm_merged_rate) {
+		snd_interval_any(hw_param_interval(&fe->dpcm[stream].hw_params,
+						   SNDRV_PCM_HW_PARAM_RATE));
+	}
 	ret = dpcm_be_dai_hw_params(fe, stream);
 	if (ret < 0)
 		goto out;
-- 
2.27.0


  parent reply	other threads:[~2021-03-23 11:44 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 11:43 [RFC PATCH 0/3] Separate BE DAI HW constraints from FE ones Codrin Ciubotariu
2021-03-23 11:43 ` Codrin Ciubotariu
2021-03-23 11:43 ` [RFC PATCH 1/3] pcm: use substream instead of runtime in snd_pcm_hw_rule_add() Codrin Ciubotariu
2021-03-23 11:43   ` Codrin Ciubotariu
2021-03-23 11:43 ` [RFC PATCH 2/3] ASoC: soc-pcm: add hw_constraints for BE DAI links Codrin Ciubotariu
2021-03-23 11:43   ` Codrin Ciubotariu
2021-03-23 11:43 ` Codrin Ciubotariu [this message]
2021-03-23 11:43   ` [RFC PATCH 3/3] ASoC: soc-pcm: apply BE HW constraint rules Codrin Ciubotariu
2021-03-23 12:15 ` [RFC PATCH 0/3] Separate BE DAI HW constraints from FE ones Jaroslav Kysela
2021-03-23 12:15   ` Jaroslav Kysela
2021-03-23 14:18   ` Codrin.Ciubotariu
2021-03-23 14:18     ` Codrin.Ciubotariu
2021-04-14 14:58     ` Codrin.Ciubotariu
2021-04-14 14:58       ` Codrin.Ciubotariu
2021-04-15 16:17       ` Mark Brown
2021-04-15 16:17         ` Mark Brown
2021-04-15 16:56         ` Codrin.Ciubotariu
2021-04-15 16:56           ` Codrin.Ciubotariu
2021-04-15 17:25           ` Mark Brown
2021-04-15 17:25             ` Mark Brown
2021-04-16 16:03             ` Codrin.Ciubotariu
2021-04-16 16:03               ` Codrin.Ciubotariu
2021-04-16 16:31               ` Mark Brown
2021-04-16 16:31                 ` Mark Brown
2021-04-16 16:47                 ` Pierre-Louis Bossart
2021-04-16 16:47                   ` Pierre-Louis Bossart
2021-04-16 18:55                   ` Mark Brown
2021-04-16 18:55                     ` Mark Brown
2021-04-16 19:39                     ` Pierre-Louis Bossart
2021-04-16 19:39                       ` Pierre-Louis Bossart
2021-04-19 15:07                       ` Mark Brown
2021-04-19 15:07                         ` Mark Brown
2021-04-16 17:39                 ` Codrin.Ciubotariu
2021-04-16 17:39                   ` Codrin.Ciubotariu
2021-03-23 19:25 ` Pierre-Louis Bossart
2021-03-23 19:25   ` Pierre-Louis Bossart
2021-03-24  9:51   ` Codrin.Ciubotariu
2021-03-24  9:51     ` Codrin.Ciubotariu
2021-03-24 15:28     ` Pierre-Louis Bossart
2021-03-24 15:28       ` Pierre-Louis Bossart
2021-03-24 17:12       ` Codrin.Ciubotariu
2021-03-24 17:12         ` Codrin.Ciubotariu

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=20210323114327.3969072-4-codrin.ciubotariu@microchip.com \
    --to=codrin.ciubotariu@microchip.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /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.