[PATCH 2/6] ASoC: es8316: Get sysclk rate from MCLK clock when not explicitly set

From: Hongyang Zhao

Date: Thu Mar 05 2026 - 00:49:39 EST


When the sysclk has not been set via set_sysclk(), try to get the clock
rate from the MCLK clock provider. This is useful when the codec's MCLK
is managed by an external clock controller and the machine driver does
not explicitly call set_sysclk().

Signed-off-by: Hongyang Zhao <hongyang.zhao@xxxxxxxxxxxxxxx>
---
sound/soc/codecs/es8316.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 9245c33700de..fdde7e4f7365 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -477,9 +477,20 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream,
u8 bclk_divider;
u16 lrck_divider;
int i;
- unsigned int clk = es8316->sysclk / 2;
+ unsigned int clk;
bool clk_valid = false;

+ if (es8316->sysclk == 0 && es8316->mclk) {
+ /* If the sysclk has not been set, try to get it from the MCLK */
+ es8316->sysclk = clk_get_rate(es8316->mclk);
+ if (es8316->sysclk == 0) {
+ dev_err(component->dev, "unable to get mclk rate\n");
+ return -EINVAL;
+ }
+ }
+
+ clk = es8316->sysclk / 2;
+
/* We will start with halved sysclk and see if we can use it
* for proper clocking. This is to minimise the risk of running
* the CODEC with a too high frequency. We have an SKU where

--
2.43.0