ASoC: fsl_micfil: Switch to common sample rate constraint function
authorChancel Liu <chancel.liu@nxp.com>
Tue, 26 Nov 2024 11:54:38 +0000 (20:54 +0900)
committerMark Brown <broonie@kernel.org>
Mon, 9 Dec 2024 13:11:10 +0000 (13:11 +0000)
fsl_asoc_constrain_rates() is a common function to constrain rates.
Let's switch to this function.

Signed-off-by: Chancel Liu <chancel.liu@nxp.com>
Link: https://patch.msgid.link/20241126115440.3929061-3-chancel.liu@nxp.com
Acked-by: Shengjiu Wang <shengjiu.wang@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/fsl/fsl_micfil.c

index 8c15389c9a04bca86dace0672ef2bf02f9d5d529..e908cfb594ab5f2a7ab8e5ee68d276f5474f87a4 100644 (file)
 #define MICFIL_AUDIO_PLL2      1
 #define MICFIL_CLK_EXT3                2
 
+static const unsigned int fsl_micfil_rates[] = {
+       8000, 11025, 16000, 22050, 32000, 44100, 48000,
+};
+
+static const struct snd_pcm_hw_constraint_list fsl_micfil_rate_constraints = {
+       .count = ARRAY_SIZE(fsl_micfil_rates),
+       .list = fsl_micfil_rates,
+};
+
 enum quality {
        QUALITY_HIGH,
        QUALITY_MEDIUM,
@@ -486,29 +495,12 @@ static int fsl_micfil_startup(struct snd_pcm_substream *substream,
                              struct snd_soc_dai *dai)
 {
        struct fsl_micfil *micfil = snd_soc_dai_get_drvdata(dai);
-       unsigned int rates[MICFIL_NUM_RATES] = {8000, 11025, 16000, 22050, 32000, 44100, 48000};
-       int i, j, k = 0;
-       u64 clk_rate;
 
        if (!micfil) {
                dev_err(dai->dev, "micfil dai priv_data not set\n");
                return -EINVAL;
        }
 
-       micfil->constraint_rates.list = micfil->constraint_rates_list;
-       micfil->constraint_rates.count = 0;
-
-       for (j = 0; j < MICFIL_NUM_RATES; j++) {
-               for (i = 0; i < MICFIL_CLK_SRC_NUM; i++) {
-                       clk_rate = clk_get_rate(micfil->clk_src[i]);
-                       if (clk_rate != 0 && do_div(clk_rate, rates[j]) == 0) {
-                               micfil->constraint_rates_list[k++] = rates[j];
-                               micfil->constraint_rates.count++;
-                               break;
-                       }
-               }
-       }
-
        if (micfil->constraint_rates.count > 0)
                snd_pcm_hw_constraint_list(substream->runtime, 0,
                                           SNDRV_PCM_HW_PARAM_RATE,
@@ -1239,6 +1231,13 @@ static int fsl_micfil_probe(struct platform_device *pdev)
        if (IS_ERR(micfil->clk_src[MICFIL_CLK_EXT3]))
                micfil->clk_src[MICFIL_CLK_EXT3] = NULL;
 
+       fsl_asoc_constrain_rates(&micfil->constraint_rates,
+                                &fsl_micfil_rate_constraints,
+                                micfil->clk_src[MICFIL_AUDIO_PLL1],
+                                micfil->clk_src[MICFIL_AUDIO_PLL2],
+                                micfil->clk_src[MICFIL_CLK_EXT3],
+                                micfil->constraint_rates_list);
+
        /* init regmap */
        regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
        if (IS_ERR(regs))