]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: qcom: sc7280: make use of common helpers
authorSrinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Wed, 22 Oct 2025 14:33:49 +0000 (15:33 +0100)
committerMark Brown <broonie@kernel.org>
Wed, 29 Oct 2025 14:54:40 +0000 (14:54 +0000)
sc7280 machine driver can make use of common sdw functions to do most of
the soundwire related operations. Remove such redundant code from sc7280
driver.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Tested-by: Steev Klimaszewski <threeway@gmail.com> # Thinkpad X13s
Link: https://patch.msgid.link/20251022143349.1081513-5-srinivas.kandagatla@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/qcom/sc7280.c
sound/soc/qcom/sdw.c

index c444dae563c75dbf662e9c3af9ecb0c963c247c5..abdd58c1d0a4cfda71b15046d26a35c03e9cc0db 100644 (file)
@@ -31,7 +31,6 @@
 
 struct sc7280_snd_data {
        struct snd_soc_card card;
-       struct sdw_stream_runtime *sruntime[LPASS_MAX_PORTS];
        u32 pri_mi2s_clk_count;
        struct snd_soc_jack hs_jack;
        struct snd_soc_jack hdmi_jack;
@@ -207,32 +206,12 @@ static int sc7280_snd_hw_params(struct snd_pcm_substream *substream,
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
-       struct snd_soc_dai *codec_dai;
-       const struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
-       struct sc7280_snd_data *pdata = snd_soc_card_get_drvdata(rtd->card);
-       struct sdw_stream_runtime *sruntime;
-       int i;
 
        if (!rtd->dai_link->no_pcm) {
                snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2);
                snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE, 48000, 48000);
        }
 
-       switch (cpu_dai->id) {
-       case LPASS_CDC_DMA_TX3:
-       case LPASS_CDC_DMA_RX0:
-       case RX_CODEC_DMA_RX_0:
-       case SECONDARY_MI2S_RX:
-       case TX_CODEC_DMA_TX_3:
-       case VA_CODEC_DMA_TX_0:
-               for_each_rtd_codec_dais(rtd, i, codec_dai) {
-                       sruntime = snd_soc_dai_get_stream(codec_dai, substream->stream);
-                       if (sruntime != ERR_PTR(-ENOTSUPP))
-                               pdata->sruntime[cpu_dai->id] = sruntime;
-               }
-               break;
-       }
-
        return 0;
 }
 
@@ -241,30 +220,8 @@ static int sc7280_snd_swr_prepare(struct snd_pcm_substream *substream)
        struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
        const struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
        struct sc7280_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
-       struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];
-       int ret;
 
-       if (!sruntime)
-               return 0;
-
-       if (data->stream_prepared[cpu_dai->id]) {
-               sdw_disable_stream(sruntime);
-               sdw_deprepare_stream(sruntime);
-               data->stream_prepared[cpu_dai->id] = false;
-       }
-
-       ret = sdw_prepare_stream(sruntime);
-       if (ret)
-               return ret;
-
-       ret = sdw_enable_stream(sruntime);
-       if (ret) {
-               sdw_deprepare_stream(sruntime);
-               return ret;
-       }
-       data->stream_prepared[cpu_dai->id] = true;
-
-       return ret;
+       return qcom_snd_sdw_prepare(substream, &data->stream_prepared[cpu_dai->id]);
 }
 
 static int sc7280_snd_prepare(struct snd_pcm_substream *substream)
@@ -291,24 +248,8 @@ static int sc7280_snd_hw_free(struct snd_pcm_substream *substream)
        struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
        struct sc7280_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
        const struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
-       struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];
 
-       switch (cpu_dai->id) {
-       case LPASS_CDC_DMA_RX0:
-       case LPASS_CDC_DMA_TX3:
-       case RX_CODEC_DMA_RX_0:
-       case TX_CODEC_DMA_TX_3:
-       case VA_CODEC_DMA_TX_0:
-               if (sruntime && data->stream_prepared[cpu_dai->id]) {
-                       sdw_disable_stream(sruntime);
-                       sdw_deprepare_stream(sruntime);
-                       data->stream_prepared[cpu_dai->id] = false;
-               }
-               break;
-       default:
-               break;
-       }
-       return 0;
+       return qcom_snd_sdw_hw_free(substream, &data->stream_prepared[cpu_dai->id]);
 }
 
 static void sc7280_snd_shutdown(struct snd_pcm_substream *substream)
@@ -317,7 +258,6 @@ static void sc7280_snd_shutdown(struct snd_pcm_substream *substream)
        struct snd_soc_card *card = rtd->card;
        struct sc7280_snd_data *data = snd_soc_card_get_drvdata(card);
        struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
-       struct sdw_stream_runtime *sruntime = qcom_snd_sdw_get_stream(substream);
 
        switch (cpu_dai->id) {
        case MI2S_PRIMARY:
@@ -336,8 +276,7 @@ static void sc7280_snd_shutdown(struct snd_pcm_substream *substream)
                break;
        }
 
-       data->sruntime[cpu_dai->id] = NULL;
-       sdw_release_stream(sruntime);
+       qcom_snd_sdw_shutdown(substream);
 }
 
 static int sc7280_snd_startup(struct snd_pcm_substream *substream)
index c44659deea01ae0e951630d06e473f93f01c883b..6576b47a4c8c354e18037f0d38bad4302b5f6441 100644 (file)
@@ -2,6 +2,7 @@
 // Copyright (c) 2018-2023, Linaro Limited.
 // Copyright (c) 2018, The Linux Foundation. All rights reserved.
 
+#include <dt-bindings/sound/qcom,lpass.h>
 #include <dt-bindings/sound/qcom,q6afe.h>
 #include <linux/module.h>
 #include <sound/soc.h>
@@ -35,6 +36,16 @@ static bool qcom_snd_is_sdw_dai(int id)
                break;
        }
 
+       /* DSP Bypass usecase, cpu dai index overlaps with DSP dai ids,
+        * DO NOT MERGE into top switch case */
+       switch (id) {
+       case LPASS_CDC_DMA_TX3:
+       case LPASS_CDC_DMA_RX0:
+               return true;
+       default:
+               break;
+       }
+
        return false;
 }