]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: simple-card-utils: add sysclk ordering support
authorStefano Radaelli <stefano.r@variscite.com>
Fri, 13 Feb 2026 15:03:55 +0000 (16:03 +0100)
committerMark Brown <broonie@kernel.org>
Sun, 22 Feb 2026 23:52:23 +0000 (23:52 +0000)
When simple-audio-card programs sysclk for CPU and codec DAIs during
hw_params, the ordering of these calls may matter on some platforms.

Some CPU DAIs finalize or adjust the MCLK rate as part of their
set_sysclk() callback (for example by calling clk_set_rate()). If the
codec sysclk is configured before the CPU DAI applies the final MCLK
rate, the codec may configure its internal clocking based on a
non-final MCLK value.

Such situations can arise depending on the clock provider/consumer
relationship between the CPU DAI and the codec.

Introduce an explicit sysclk ordering enum in simple-card-utils and use
it to control the order of snd_soc_dai_set_sysclk() calls in the mclk-fs
handling path. The default behaviour remains unchanged (codec-first)
to avoid regressions.

Signed-off-by: Stefano Radaelli <stefano.r@variscite.com>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://patch.msgid.link/20260213150355.442609-1-stefano.r@variscite.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/simple_card_utils.h
sound/soc/generic/simple-card-utils.c

index 69a9c9c4d0e9cd4575ad2ea2caae7caafa627336..915e6ae5f68d7d79db4eb7750f139e004e4ee614 100644 (file)
@@ -54,6 +54,11 @@ struct prop_nums {
        int platforms;
 };
 
+enum simple_util_sysclk_order {
+       SIMPLE_SYSCLK_ORDER_CODEC_FIRST = 0,
+       SIMPLE_SYSCLK_ORDER_CPU_FIRST,
+};
+
 struct simple_util_priv {
        struct snd_soc_card snd_card;
        struct simple_dai_props {
@@ -63,6 +68,7 @@ struct simple_util_priv {
                struct snd_soc_codec_conf *codec_conf;
                struct prop_nums num;
                unsigned int mclk_fs;
+               enum simple_util_sysclk_order sysclk_order;
        } *dai_props;
        struct simple_util_jack hp_jack;
        struct simple_util_jack mic_jack;
index bdc02e85b089fe208812f612f1c659e3bad5cdf1..fdd8b76f2914f35c4c110d98df7866e4bc2eaee5 100644 (file)
@@ -468,6 +468,7 @@ int simple_util_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_dai *sdai;
        struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card);
        struct simple_dai_props *props = runtime_simple_priv_to_props(priv, rtd);
+       enum simple_util_sysclk_order order = props->sysclk_order;
        unsigned int mclk, mclk_fs = 0;
        int i, ret;
 
@@ -501,18 +502,36 @@ int simple_util_hw_params(struct snd_pcm_substream *substream,
                                goto end;
                }
 
-               for_each_rtd_codec_dais(rtd, i, sdai) {
-                       pdai = simple_props_to_dai_codec(props, i);
-                       ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
-                       if (ret && ret != -ENOTSUPP)
-                               goto end;
-               }
+               if (order == SIMPLE_SYSCLK_ORDER_CPU_FIRST) {
+                       /* CPU first */
+                       for_each_rtd_cpu_dais(rtd, i, sdai) {
+                               pdai = simple_props_to_dai_cpu(props, i);
+                               ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+                               if (ret && ret != -ENOTSUPP)
+                                       goto end;
+                       }
 
-               for_each_rtd_cpu_dais(rtd, i, sdai) {
-                       pdai = simple_props_to_dai_cpu(props, i);
-                       ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
-                       if (ret && ret != -ENOTSUPP)
-                               goto end;
+                       for_each_rtd_codec_dais(rtd, i, sdai) {
+                               pdai = simple_props_to_dai_codec(props, i);
+                               ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+                               if (ret && ret != -ENOTSUPP)
+                                       goto end;
+                       }
+               } else {
+                       /* default: codec first */
+                       for_each_rtd_codec_dais(rtd, i, sdai) {
+                               pdai = simple_props_to_dai_codec(props, i);
+                               ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+                               if (ret && ret != -ENOTSUPP)
+                                       goto end;
+                       }
+
+                       for_each_rtd_cpu_dais(rtd, i, sdai) {
+                               pdai = simple_props_to_dai_cpu(props, i);
+                               ret = snd_soc_dai_set_sysclk(sdai, 0, mclk, pdai->clk_direction);
+                               if (ret && ret != -ENOTSUPP)
+                                       goto end;
+                       }
                }
        }