ASoC: fsl: fsl_qmc_audio: Introduce qmc_dai_constraints_interleaved()
authorHerve Codina <herve.codina@bootlin.com>
Mon, 1 Jul 2024 11:30:33 +0000 (13:30 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 4 Jul 2024 11:24:57 +0000 (12:24 +0100)
Constraints are set by qmc_dai_startup(). These constraints are specific
to the interleaved mode.

With the future introduction of support for non-interleaved mode, a new
set of constraints will be set. To make the code clear and keep
qmc_dai_startup() simple, extract the current interleaved mode
constraints settings to a specific function.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Link: https://patch.msgid.link/20240701113038.55144-7-herve.codina@bootlin.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/fsl/fsl_qmc_audio.c

index 36145f1ddbf1af654f2e9ce20f4865b29f6d202b..f70c6c8eec4a882af152580550f60dc50e22eef6 100644 (file)
@@ -436,24 +436,14 @@ static int qmc_dai_hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *
        return qmc_dai_hw_rule_format_by_channels(qmc_dai, params, qmc_dai->nb_rx_ts);
 }
 
-static int qmc_dai_startup(struct snd_pcm_substream *substream,
-                          struct snd_soc_dai *dai)
+static int qmc_dai_constraints_interleaved(struct snd_pcm_substream *substream,
+                                          struct qmc_dai *qmc_dai)
 {
-       struct qmc_dai_prtd *prtd = substream->runtime->private_data;
        snd_pcm_hw_rule_func_t hw_rule_channels_by_format;
        snd_pcm_hw_rule_func_t hw_rule_format_by_channels;
-       struct qmc_dai *qmc_dai;
        unsigned int frame_bits;
        int ret;
 
-       qmc_dai = qmc_dai_get_data(dai);
-       if (!qmc_dai) {
-               dev_err(dai->dev, "Invalid dai\n");
-               return -EINVAL;
-       }
-
-       prtd->qmc_dai = qmc_dai;
-
        if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
                hw_rule_channels_by_format = qmc_dai_hw_rule_capture_channels_by_format;
                hw_rule_format_by_channels = qmc_dai_hw_rule_capture_format_by_channels;
@@ -468,7 +458,7 @@ static int qmc_dai_startup(struct snd_pcm_substream *substream,
                                  hw_rule_channels_by_format, qmc_dai,
                                  SNDRV_PCM_HW_PARAM_FORMAT, -1);
        if (ret) {
-               dev_err(dai->dev, "Failed to add channels rule (%d)\n", ret);
+               dev_err(qmc_dai->dev, "Failed to add channels rule (%d)\n", ret);
                return ret;
        }
 
@@ -476,7 +466,7 @@ static int qmc_dai_startup(struct snd_pcm_substream *substream,
                                  hw_rule_format_by_channels, qmc_dai,
                                  SNDRV_PCM_HW_PARAM_CHANNELS, -1);
        if (ret) {
-               dev_err(dai->dev, "Failed to add format rule (%d)\n", ret);
+               dev_err(qmc_dai->dev, "Failed to add format rule (%d)\n", ret);
                return ret;
        }
 
@@ -484,13 +474,30 @@ static int qmc_dai_startup(struct snd_pcm_substream *substream,
                                           SNDRV_PCM_HW_PARAM_FRAME_BITS,
                                           frame_bits);
        if (ret < 0) {
-               dev_err(dai->dev, "Failed to add frame_bits constraint (%d)\n", ret);
+               dev_err(qmc_dai->dev, "Failed to add frame_bits constraint (%d)\n", ret);
                return ret;
        }
 
        return 0;
 }
 
+static int qmc_dai_startup(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai)
+{
+       struct qmc_dai_prtd *prtd = substream->runtime->private_data;
+       struct qmc_dai *qmc_dai;
+
+       qmc_dai = qmc_dai_get_data(dai);
+       if (!qmc_dai) {
+               dev_err(dai->dev, "Invalid dai\n");
+               return -EINVAL;
+       }
+
+       prtd->qmc_dai = qmc_dai;
+
+       return qmc_dai_constraints_interleaved(substream, qmc_dai);
+}
+
 static int qmc_dai_hw_params(struct snd_pcm_substream *substream,
                             struct snd_pcm_hw_params *params,
                             struct snd_soc_dai *dai)