[PATCH 5/9] ASoC: apple: mca: Factor out mca_be_get_fe

From: James Calligeros
Date: Sun May 18 2025 - 06:52:56 EST


From: Martin Povišer <povik+lin@xxxxxxxxxxx>

This is a function that we also want to use from within mca_be_shutdown,
so factor it out.

Signed-off-by: Martin Povišer <povik+lin@xxxxxxxxxxx>
Signed-off-by: James Calligeros <jcalligeros99@xxxxxxxxx>
---
sound/soc/apple/mca.c | 31 ++++++++++++++-----------
1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/sound/soc/apple/mca.c b/sound/soc/apple/mca.c
index 39713c378ba10910b0a3ac3d804844b25dfa2c94..7c3e1eae8b963ff593fdcf54e4a1f2e5f64a63c1 100644
--- a/sound/soc/apple/mca.c
+++ b/sound/soc/apple/mca.c
@@ -702,30 +702,35 @@ static bool mca_be_clk_started(struct mca_cluster *cl)
return false;
}

-static int mca_be_startup(struct snd_pcm_substream *substream,
- struct snd_soc_dai *dai)
+static struct snd_soc_pcm_runtime *mca_be_get_fe(struct snd_soc_pcm_runtime *be,
+ int stream)
{
- struct snd_soc_pcm_runtime *be = snd_soc_substream_to_rtd(substream);
- struct snd_soc_pcm_runtime *fe;
- struct mca_cluster *cl = mca_dai_to_cluster(dai);
- struct mca_cluster *fe_cl;
- struct mca_data *mca = cl->host;
+ struct snd_soc_pcm_runtime *fe = NULL;
struct snd_soc_dpcm *dpcm;

- fe = NULL;
-
- for_each_dpcm_fe(be, substream->stream, dpcm) {
+ for_each_dpcm_fe(be, stream, dpcm) {
if (fe && dpcm->fe != fe) {
- dev_err(mca->dev, "many FE per one BE unsupported\n");
- return -EINVAL;
+ dev_err(be->dev, "many FE per one BE unsupported\n");
+ return NULL;
}

fe = dpcm->fe;
}

+ return fe;
+}
+
+static int mca_be_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_pcm_runtime *be = snd_soc_substream_to_rtd(substream);
+ struct snd_soc_pcm_runtime *fe = mca_be_get_fe(be, substream->stream);
+ struct mca_cluster *cl = mca_dai_to_cluster(dai);
+ struct mca_cluster *fe_cl;
+ struct mca_data *mca = cl->host;
+
if (!fe)
return -EINVAL;
-
fe_cl = mca_dai_to_cluster(snd_soc_rtd_to_cpu(fe, 0));

if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {

--
2.49.0