ASoC: Intel: avs: Relocate HDA BE DAI specific operations
authorCezary Rojewski <cezary.rojewski@intel.com>
Fri, 26 Apr 2024 09:57:27 +0000 (11:57 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 29 Apr 2024 15:09:47 +0000 (00:09 +0900)
DAI's startup()/shutdown() shall deal with allocation and freeing of
resources needed to facilitate streaming over it. Currently for HDAudio
BE DAIs some of that task is done in component->open()/close(). Relocate
the relevant pieces to address that.

Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
Link: https://lore.kernel.org/r/20240426095733.3946951-3-cezary.rojewski@intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/avs/pcm.c

index 77a7e8f9395158f79bea0e9d77d400ddaf858ba3..f3cd54f355ef82bd6d7dc0a11dc854d94eef24ce 100644 (file)
@@ -277,12 +277,36 @@ static const struct snd_soc_dai_ops avs_dai_hda_be_ops;
 
 static int avs_dai_hda_be_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
 {
-       return avs_dai_startup(substream, dai, false, &avs_dai_hda_be_ops);
+       struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+       struct hdac_ext_stream *link_stream;
+       struct hda_codec *codec;
+       int ret;
+
+       ret = avs_dai_startup(substream, dai, false, &avs_dai_hda_be_ops);
+       if (ret)
+               return ret;
+
+       codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev);
+       link_stream = snd_hdac_ext_stream_assign(&codec->bus->core, substream,
+                                                HDAC_EXT_STREAM_TYPE_LINK);
+       if (!link_stream) {
+               avs_dai_nonhda_be_shutdown(substream, dai);
+               return -EBUSY;
+       }
+
+       substream->runtime->private_data = link_stream;
+       return 0;
 }
 
 static void avs_dai_hda_be_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
 {
-       return avs_dai_nonhda_be_shutdown(substream, dai);
+       struct hdac_ext_stream *link_stream;
+
+       link_stream = substream->runtime->private_data;
+       snd_hdac_ext_stream_release(link_stream, HDAC_EXT_STREAM_TYPE_LINK);
+       substream->runtime->private_data = NULL;
+
+       avs_dai_nonhda_be_shutdown(substream, dai);
 }
 
 static int avs_dai_hda_be_hw_params(struct snd_pcm_substream *substream,
@@ -1576,8 +1600,6 @@ static int avs_component_hda_open(struct snd_soc_component *component,
                                  struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
-       struct hdac_ext_stream *link_stream;
-       struct hda_codec *codec;
 
        if (!rtd->dai_link->no_pcm) {
                struct snd_pcm_hardware hwparams = avs_pcm_hardware;
@@ -1609,30 +1631,6 @@ static int avs_component_hda_open(struct snd_soc_component *component,
                return snd_soc_set_runtime_hwparams(substream, &hwparams);
        }
 
-       codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev);
-       link_stream = snd_hdac_ext_stream_assign(&codec->bus->core, substream,
-                                            HDAC_EXT_STREAM_TYPE_LINK);
-       if (!link_stream)
-               return -EBUSY;
-
-       substream->runtime->private_data = link_stream;
-       return 0;
-}
-
-static int avs_component_hda_close(struct snd_soc_component *component,
-                                  struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
-       struct hdac_ext_stream *link_stream;
-
-       /* only BE DAI links are handled here */
-       if (!rtd->dai_link->no_pcm)
-               return 0;
-
-       link_stream = substream->runtime->private_data;
-       snd_hdac_ext_stream_release(link_stream, HDAC_EXT_STREAM_TYPE_LINK);
-       substream->runtime->private_data = NULL;
-
        return 0;
 }
 
@@ -1643,7 +1641,6 @@ static const struct snd_soc_component_driver avs_hda_component_driver = {
        .suspend                = avs_component_suspend,
        .resume                 = avs_component_resume,
        .open                   = avs_component_hda_open,
-       .close                  = avs_component_hda_close,
        .pointer                = avs_component_pointer,
        .mmap                   = avs_component_mmap,
        .pcm_construct          = avs_component_construct,