Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Fabio Estevam <festevam@gmail.com>
To: broonie@kernel.org
Cc: shengjiu.wang@gmail.com, linux-sound@vger.kernel.org,
	Fabio Estevam <festevam@gmail.com>
Subject: [PATCH 2/3] ASoC: fsl_sai: Stop BCLK after the last stream is freed
Date: Mon, 19 Oct 2026 19:28:26 -0300	[thread overview]
Message-ID: <20261019222827.131120-2-festevam@gmail.com> (raw)
In-Reply-To: <20261019222827.131120-1-festevam@gmail.com>

On i.MX8MP, trigger stop leaves BCE set so MCLK remains available to
a codec. When the final stream is freed, hw_free disables MCLK, but
TERE and BCE can keep BCLK running from the newly selected clock
source, including an unconfigured bus clock.

Clear TERE and BCE once no configured or active stream needs the
clock. This preserves MCLK between trigger stop and hw_free.

The premature clock output was reproduced on a custom i.MX8MP board.

Fixes: 197c53c8ecb3 ("ASoC: fsl_sai: Don't disable bitclock for i.MX8MP")
Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 sound/soc/fsl/fsl_sai.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index 51779d7f8bf8..a135b3da37cf 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -851,6 +851,16 @@ static int fsl_sai_hw_free(struct snd_pcm_substream *substream,
 		}
 	}
 
+	/*
+	 * Keep MCLK available until the last stream is freed, as it may be
+	 * needed by a codec. Once no stream uses it, stop TERE and BCE too;
+	 * otherwise BCLK can continue from the clock source selected later.
+	 */
+	if (sai->soc_data->mclk_with_tere && sai->mclk_direction_output &&
+	    !sai->mclk_streams && snd_soc_dai_active(cpu_dai) <= 1)
+		regmap_update_bits(sai->regmap, FSL_SAI_TCSR(ofs),
+				   FSL_SAI_CSR_TERE | FSL_SAI_CSR_BCE, 0);
+
 	return 0;
 }
 
-- 
2.43.0


  reply	other threads:[~2026-10-19 22:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 22:28 [PATCH 1/3] ASoC: fsl_sai: Defer TERE until stream setup Fabio Estevam
2026-10-19 22:28 ` Fabio Estevam [this message]
2026-10-19 22:28 ` [PATCH 3/3] ASoC: fsl_sai: Select sleep pinctrl state during runtime suspend Fabio Estevam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261019222827.131120-2-festevam@gmail.com \
    --to=festevam@gmail.com \
    --cc=broonie@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=shengjiu.wang@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox