OSDN Git Service

ASoC: SOF: Intel: Refactor code for HDA stream creation
authorChao Song <chao.song@linux.intel.com>
Mon, 14 Aug 2023 23:15:19 +0000 (18:15 -0500)
committerMark Brown <broonie@kernel.org>
Tue, 15 Aug 2023 12:54:56 +0000 (13:54 +0100)
Existing HDA stream creation is split into two
for loops for capture and playback, but most of
the code in the two for loops are duplicated.

This patch refactors HDA stream creation with a
single for loop, thus remove code duplication.

No functional change in this patch.

Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Chao Song <chao.song@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20230814231519.79051-1-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/intel/hda-stream.c

index b13acb9..0b0087a 100644 (file)
@@ -869,8 +869,8 @@ int hda_dsp_stream_init(struct snd_sof_dev *sdev)
                return -ENOMEM;
        }
 
-       /* create capture streams */
-       for (i = 0; i < num_capture; i++) {
+       /* create capture and playback streams */
+       for (i = 0; i < num_total; i++) {
                struct sof_intel_hda_stream *hda_stream;
 
                hda_stream = devm_kzalloc(sdev->dev, sizeof(*hda_stream),
@@ -909,69 +909,17 @@ int hda_dsp_stream_init(struct snd_sof_dev *sdev)
                hstream->index = i;
                sd_offset = SOF_STREAM_SD_OFFSET(hstream);
                hstream->sd_addr = sdev->bar[HDA_DSP_HDA_BAR] + sd_offset;
-               hstream->stream_tag = i + 1;
                hstream->opened = false;
                hstream->running = false;
-               hstream->direction = SNDRV_PCM_STREAM_CAPTURE;
 
-               /* memory alloc for stream BDL */
-               ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev,
-                                         HDA_DSP_BDL_SIZE, &hstream->bdl);
-               if (ret < 0) {
-                       dev_err(sdev->dev, "error: stream bdl dma alloc failed\n");
-                       return -ENOMEM;
-               }
-               hstream->posbuf = (__le32 *)(bus->posbuf.area +
-                       (hstream->index) * 8);
-
-               list_add_tail(&hstream->list, &bus->stream_list);
-       }
-
-       /* create playback streams */
-       for (i = num_capture; i < num_total; i++) {
-               struct sof_intel_hda_stream *hda_stream;
-
-               hda_stream = devm_kzalloc(sdev->dev, sizeof(*hda_stream),
-                                         GFP_KERNEL);
-               if (!hda_stream)
-                       return -ENOMEM;
-
-               hda_stream->sdev = sdev;
-
-               hext_stream = &hda_stream->hext_stream;
-
-               if (sdev->bar[HDA_DSP_PP_BAR]) {
-                       hext_stream->pphc_addr = sdev->bar[HDA_DSP_PP_BAR] +
-                               SOF_HDA_PPHC_BASE + SOF_HDA_PPHC_INTERVAL * i;
-
-                       hext_stream->pplc_addr = sdev->bar[HDA_DSP_PP_BAR] +
-                               SOF_HDA_PPLC_BASE + SOF_HDA_PPLC_MULTI * num_total +
-                               SOF_HDA_PPLC_INTERVAL * i;
-               }
-
-               hstream = &hext_stream->hstream;
-
-               /* do we support SPIB */
-               if (sdev->bar[HDA_DSP_SPIB_BAR]) {
-                       hstream->spib_addr = sdev->bar[HDA_DSP_SPIB_BAR] +
-                               SOF_HDA_SPIB_BASE + SOF_HDA_SPIB_INTERVAL * i +
-                               SOF_HDA_SPIB_SPIB;
-
-                       hstream->fifo_addr = sdev->bar[HDA_DSP_SPIB_BAR] +
-                               SOF_HDA_SPIB_BASE + SOF_HDA_SPIB_INTERVAL * i +
-                               SOF_HDA_SPIB_MAXFIFO;
+               if (i < num_capture) {
+                       hstream->stream_tag = i + 1;
+                       hstream->direction = SNDRV_PCM_STREAM_CAPTURE;
+               } else {
+                       hstream->stream_tag = i - num_capture + 1;
+                       hstream->direction = SNDRV_PCM_STREAM_PLAYBACK;
                }
 
-               hstream->bus = bus;
-               hstream->sd_int_sta_mask = 1 << i;
-               hstream->index = i;
-               sd_offset = SOF_STREAM_SD_OFFSET(hstream);
-               hstream->sd_addr = sdev->bar[HDA_DSP_HDA_BAR] + sd_offset;
-               hstream->stream_tag = i - num_capture + 1;
-               hstream->opened = false;
-               hstream->running = false;
-               hstream->direction = SNDRV_PCM_STREAM_PLAYBACK;
-
                /* mem alloc for stream BDL */
                ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev,
                                          HDA_DSP_BDL_SIZE, &hstream->bdl);