ASoC: SOF: Intel: hda-dai-ops: only allocate/release streams for first CPU DAI
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Mon, 7 Aug 2023 21:09:51 +0000 (16:09 -0500)
committerMark Brown <broonie@kernel.org>
Mon, 7 Aug 2023 22:09:41 +0000 (23:09 +0100)
When we have multiple CPU DAIs in a dailink, typically for SoundWire
aggregated solutions with amplifiers on multiple links, we only want
to allocate one HDaudio stream_tag. The simplest solution is to
allocate the hext_stream/stream_tag for the DAI with index 0 in the
dailink, and reuse the same stream for all other CPU DAIs.

This assumption relies on serialization of DAIs by the ASoC core,
where all CPU DAIs are handled in a loop.

The stream release follows the same idea of releasing the tag for the
first DAI only. Ideally we would want the loop to be handled in
reverse-order to summetry, but there is no risk of reusing a
stream_tag which is no longer valid.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Link: https://lore.kernel.org/r/20230807210959.506849-13-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/intel/hda-dai-ops.c

index b668862..9a6d995 100644 (file)
@@ -145,9 +145,17 @@ static struct hdac_ext_stream *hda_assign_hext_stream(struct snd_sof_dev *sdev,
                                                      struct snd_soc_dai *cpu_dai,
                                                      struct snd_pcm_substream *substream)
 {
+       struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+       struct snd_soc_dai *dai;
        struct hdac_ext_stream *hext_stream;
 
-       hext_stream = hda_link_stream_assign(sof_to_bus(sdev), substream);
+       /* only allocate a stream_tag for the first DAI in the dailink */
+       dai = asoc_rtd_to_cpu(rtd, 0);
+       if (dai == cpu_dai)
+               hext_stream = hda_link_stream_assign(sof_to_bus(sdev), substream);
+       else
+               hext_stream = snd_soc_dai_get_dma_data(dai, substream);
+
        if (!hext_stream)
                return NULL;
 
@@ -160,9 +168,14 @@ static void hda_release_hext_stream(struct snd_sof_dev *sdev, struct snd_soc_dai
                                    struct snd_pcm_substream *substream)
 {
        struct hdac_ext_stream *hext_stream = hda_get_hext_stream(sdev, cpu_dai, substream);
+       struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+       struct snd_soc_dai *dai;
 
+       /* only release a stream_tag for the first DAI in the dailink */
+       dai = asoc_rtd_to_cpu(rtd, 0);
+       if (dai == cpu_dai)
+               snd_hdac_ext_stream_release(hext_stream, HDAC_EXT_STREAM_TYPE_LINK);
        snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
-       snd_hdac_ext_stream_release(hext_stream, HDAC_EXT_STREAM_TYPE_LINK);
 }
 
 static void hda_setup_hext_stream(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_stream,