Skip to contentSkip to conversation

ASoC: SOF: ipc4: upport multiple configs for BE DAIs

PATCH In review Peter Ujfalusi 2 participants 4 messages Mar 16, 2023 – Mar 17, 2023

Subsystems (3)
lore
Share & tools
lore

Peter Ujfalusi

author maintainer
#0 lore raw

cover ASoC: SOF: ipc4: upport multiple configs for BE DAIs

Hi,

Backend DAIs may support multiple audio formats. Modify pipeline setup to select a suitable configuration based on topology and frontend DAI runtime configuration.

The prime use case is BT offload support where we need the abality to select different configuration on the BE side.

Regards,
Peter
--
Kai Vehmanen (2):
ASoC: SOF: ipc4-pcm: support multiple configs for BE DAIs
ASoC: SOF: ipc4-topology: use common helper function in copier prepare

 sound/soc/sof/ipc4-pcm.c      | 66 ++++++++++++++++++++++---
 sound/soc/sof/ipc4-topology.c | 92 ++++++++++++++++++++++++++---------
 2 files changed, 128 insertions(+), 30 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 1/2 ASoC: SOF: ipc4-pcm: support multiple configs for BE DAIs

From: Kai Vehmanen <[email protected]>

Backend DAIs may support multiple audio formats. Modify pipeline setup to select a suitable configuration based on topology and frontend DAI runtime configuration.

For sampling rate, if one of the BE DAI configurations has a sampling rate matching that of FE DAI, configure BE DAI to this rate.

For sample format, the current code hardcodes DAI copier sample format to 32bit for both playback and capture pipelines. This is not always desired, so lift the limitation and set the sample format based on topology definitions for the copiers. For capture pipelines, we want to set the BE DAI pipeline format based on topology instead of using the FE DAI format. This covers the common use-case where BE DAI outputs data at a higher sample precision and sample width is reduced later in the pipeline. Instead of hardcoding to 32bit, use the BE DAI copier output format defined in topology.

---
 sound/soc/sof/ipc4-pcm.c      | 66 +++++++++++++++++++++++++++----
 sound/soc/sof/ipc4-topology.c | 74 +++++++++++++++++++++++++++++++----
 2 files changed, 125 insertions(+), 15 deletions(-)
sound/soc/sof/ipc4-pcm.c +58 -8
index 701da5ee4e4e..4598057b7f28 100644
@@ -362,15 +362,68 @@ static void ipc4_ssp_dai_config_pcm_params_match(struct snd_sof_dev *sdev, const
 	}
 }
 
+/*
+ * Fixup DAI link parameters for sampling rate based on
+ * DAI copier configuration.
+ */
+static int sof_ipc4_pcm_dai_link_fixup_rate(struct snd_sof_dev *sdev,
+					    struct snd_pcm_hw_params *params,
+					    struct sof_ipc4_copier *ipc4_copier)
+{
+	struct sof_ipc4_pin_format *pin_fmts = ipc4_copier->available_fmt.input_pin_fmts;
+	struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+	int num_input_formats = ipc4_copier->available_fmt.num_input_formats;
+	unsigned int fe_rate = params_rate(params);
+	bool fe_be_rate_match = false;
+	bool single_be_rate = true;
+	unsigned int be_rate;
+	int i;
+
+	/*
+	 * Copier does not change sampling rate, so we
+	 * need to only consider the input pin information.
+	 */
+	for (i = 0; i < num_input_formats; i++) {
+		unsigned int val = pin_fmts[i].audio_fmt.sampling_frequency;
+
+		if (i == 0)
+			be_rate = val;
+		else if (val != be_rate)
+			single_be_rate = false;
+
+		if (val == fe_rate) {
+			fe_be_rate_match = true;
+			break;
+		}
+	}
+
+	/*
+	 * If rate is different than FE rate, topology must
+	 * contain an SRC. But we do require topology to
+	 * define a single rate in the DAI copier config in
+	 * this case (FE rate may be variable).
+	 */
+	if (!fe_be_rate_match) {
+		if (!single_be_rate) {
+			dev_err(sdev->dev, "Unable to select sampling rate for DAI link\n");
+			return -EINVAL;
+		}
+
+		rate->min = be_rate;
+		rate->max = rate->min;
+	}
+
+	return 0;
+}
+
 static int sof_ipc4_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
 				       struct snd_pcm_hw_params *params)
 {
 	struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
 	struct snd_sof_dai *dai = snd_sof_find_dai(component, rtd->dai_link->name);
-	struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
-	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
 	struct sof_ipc4_copier *ipc4_copier;
+	int ret;
 
 	if (!dai) {
 		dev_err(component->dev, "%s: No DAI found with name %s\n", __func__,
@@ -385,12 +438,9 @@ static int sof_ipc4_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
 		return -EINVAL;
 	}
 
-	/* always set BE format to 32-bits for both playback and capture */
-	snd_mask_none(fmt);
-	snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
-
-	rate->min = ipc4_copier->available_fmt.input_pin_fmts->audio_fmt.sampling_frequency;
-	rate->max = rate->min;
+	ret = sof_ipc4_pcm_dai_link_fixup_rate(sdev, params, ipc4_copier);
+	if (ret)
+		return ret;
 
 	switch (ipc4_copier->dai_type) {
 	case SOF_DAI_INTEL_SSP:
sound/soc/sof/ipc4-topology.c +67 -7

86 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH 2/2 ASoC: SOF: ipc4-topology: use common helper function in copier prepare

In reply to Peter Ujfalusi

From: Kai Vehmanen <[email protected]>

Use the ipc4_set_fmt_mask() helper function instead of open-coding the logic in multiple places.

---
 sound/soc/sof/ipc4-topology.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
sound/soc/sof/ipc4-topology.c +3 -15
index cf438f32b4ed..4fba8ada9a06 100644
@@ -1363,21 +1363,9 @@ sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
 	out_sample_valid_bits =
 		SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(copier_data->out_format.fmt_cfg);
 	snd_mask_none(fmt);
-	switch (out_sample_valid_bits) {
-	case 16:
-		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
-		break;
-	case 24:
-		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
-		break;
-	case 32:
-		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
-		break;
-	default:
-		dev_err(sdev->dev, "invalid sample frame format %d\n",
-			params_format(pipeline_params));
-		return -EINVAL;
-	}
+	ret = ipc4_set_fmt_mask(fmt, out_sample_valid_bits);
+	if (ret)
+		return ret;
 
 	/*
 	 * Set the gateway dma_buffer_size to 2ms buffer size to meet the FW expectation. In the
Signature · 1 line
2.39.2
maintainer
#3 lore raw
In reply to Peter Ujfalusi
Quoted 6 lines · Peter Ujfalusi

Backend DAIs may support multiple audio formats. Modify pipeline setup to select a suitable configuration based on topology and frontend DAI runtime configuration.

The prime use case is BT offload support where we need the abality to select different configuration on the BE side.

Quoted 8 lines

Regards,
Peter
--
Kai Vehmanen (2):
ASoC: SOF: ipc4-pcm: support multiple configs for BE DAIs
ASoC: SOF: ipc4-topology: use common helper function in copier prepare

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: SOF: ipc4-pcm: support multiple configs for BE DAIs

      commit: 279e52d6b9f366f9930a0f90ee84e7d0a6a27b26
[2/2] ASoC: SOF: ipc4-topology: use common helper function in copier prepare
      commit: 37ec7ab49f951ef8c38102328b84d3dc7155dc68

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark