diff --git a/sound/soc/sof/intel/hda-loader.c b/sound/soc/sof/intel/hda-loader.c index 796d772a6a8d30..d423f751ade3c3 100644 --- a/sound/soc/sof/intel/hda-loader.c +++ b/sound/soc/sof/intel/hda-loader.c @@ -44,7 +44,7 @@ static int cl_stream_prepare(struct snd_sof_dev *sdev, unsigned int format, int ret; if (direction == SNDRV_PCM_STREAM_PLAYBACK) { - stream = hda_dsp_stream_get_pstream(sdev); + stream = hda_dsp_stream_get(sdev, direction, FALSE); } else { dev_err(sdev->dev, "error: code loading DMA is playback only\n"); return -EINVAL; @@ -77,7 +77,8 @@ static int cl_stream_prepare(struct snd_sof_dev *sdev, unsigned int format, return hstream->stream_tag; error: - hda_dsp_stream_put_pstream(sdev, hstream->stream_tag); + hda_dsp_stream_put(sdev, SNDRV_PCM_STREAM_PLAYBACK, + hstream->stream_tag); snd_dma_free_pages(dmab); return ret; } diff --git a/sound/soc/sof/intel/hda-pcm.c b/sound/soc/sof/intel/hda-pcm.c index d5a09dcceeee4d..07a85a409de363 100644 --- a/sound/soc/sof/intel/hda-pcm.c +++ b/sound/soc/sof/intel/hda-pcm.c @@ -212,11 +212,7 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev, { struct hdac_ext_stream *stream; - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - stream = hda_dsp_stream_get_pstream(sdev); - else - stream = hda_dsp_stream_get_cstream(sdev); - + stream = hda_dsp_stream_get(sdev, substream->stream, FALSE); if (!stream) { dev_err(sdev->dev, "error: no stream available\n"); return -ENODEV; @@ -233,10 +229,8 @@ int hda_dsp_pcm_close(struct snd_sof_dev *sdev, struct hdac_stream *hstream = substream->runtime->private_data; int ret; - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - ret = hda_dsp_stream_put_pstream(sdev, hstream->stream_tag); - else - ret = hda_dsp_stream_put_cstream(sdev, hstream->stream_tag); + ret = hda_dsp_stream_put(sdev, substream->stream, + hstream->stream_tag); if (ret) { dev_dbg(sdev->dev, "stream %s not opened!\n", substream->name); diff --git a/sound/soc/sof/intel/hda-stream.c b/sound/soc/sof/intel/hda-stream.c index a9189058f5dfc4..2547bb50fe815e 100644 --- a/sound/soc/sof/intel/hda-stream.c +++ b/sound/soc/sof/intel/hda-stream.c @@ -165,18 +165,28 @@ int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev, /* get next unused stream */ struct hdac_ext_stream * -hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction) +hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, int reverse) { struct hdac_bus *bus = sof_to_bus(sdev); struct hdac_ext_stream *stream = NULL; struct hdac_stream *s; - /* get an unused playback stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == direction && !s->opened) { - s->opened = true; - stream = stream_to_hdac_ext_stream(s); - break; + /* get an unused stream */ + if (reverse) { + list_for_each_entry_reverse(s, &bus->stream_list, list) { + if (s->direction == direction && !s->opened) { + s->opened = true; + stream = stream_to_hdac_ext_stream(s); + break; + } + } + } else { + list_for_each_entry(s, &bus->stream_list, list) { + if (s->direction == direction && !s->opened) { + s->opened = true; + stream = stream_to_hdac_ext_stream(s); + break; + } } } @@ -189,56 +199,6 @@ hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction) return stream; } -/* get next unused playback stream */ -struct hdac_ext_stream * -hda_dsp_stream_get_pstream(struct snd_sof_dev *sdev) -{ - struct hdac_bus *bus = sof_to_bus(sdev); - struct hdac_ext_stream *stream = NULL; - struct hdac_stream *s; - - /* get an unused playback stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == SNDRV_PCM_STREAM_PLAYBACK - && !s->opened) { - s->opened = true; - stream = stream_to_hdac_ext_stream(s); - break; - } - } - - /* stream found ? */ - if (!stream) - dev_err(sdev->dev, "error: no free playback streams\n"); - - return stream; -} - -/* get next unused capture stream */ -struct hdac_ext_stream * -hda_dsp_stream_get_cstream(struct snd_sof_dev *sdev) -{ - struct hdac_bus *bus = sof_to_bus(sdev); - struct hdac_ext_stream *stream = NULL; - struct hdac_stream *s; - - /* get an unused capture stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == SNDRV_PCM_STREAM_CAPTURE - && !s->opened) { - s->opened = true; - stream = stream_to_hdac_ext_stream(s); - break; - } - } - - /* stream found ? */ - if (!stream) - dev_err(sdev->dev, "error: no free capture streams\n"); - - return stream; -} - /* free a stream */ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int tag) { @@ -258,44 +218,6 @@ int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int tag) return -ENODEV; } -/* free playback stream */ -int hda_dsp_stream_put_pstream(struct snd_sof_dev *sdev, int tag) -{ - struct hdac_bus *bus = sof_to_bus(sdev); - struct hdac_stream *s; - - /* find used playback stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == SNDRV_PCM_STREAM_PLAYBACK - && s->opened && s->stream_tag == tag) { - s->opened = false; - return 0; - } - } - - dev_dbg(sdev->dev, "tag %d not opened!\n", tag); - return -ENODEV; -} - -/* free capture stream */ -int hda_dsp_stream_put_cstream(struct snd_sof_dev *sdev, int tag) -{ - struct hdac_bus *bus = sof_to_bus(sdev); - struct hdac_stream *s; - - /* find used capture stream */ - list_for_each_entry(s, &bus->stream_list, list) { - if (s->direction == SNDRV_PCM_STREAM_CAPTURE - && s->opened && s->stream_tag == tag) { - s->opened = false; - return 0; - } - } - - dev_dbg(sdev->dev, "tag %d not opened!\n", tag); - return -ENODEV; -} - int hda_dsp_stream_trigger(struct snd_sof_dev *sdev, struct hdac_ext_stream *stream, int cmd) { diff --git a/sound/soc/sof/intel/hda-trace.c b/sound/soc/sof/intel/hda-trace.c index a1c9f1b45dca14..d2464564ed22dd 100644 --- a/sound/soc/sof/intel/hda-trace.c +++ b/sound/soc/sof/intel/hda-trace.c @@ -52,7 +52,12 @@ static int hda_dsp_trace_prepare(struct snd_sof_dev *sdev) int hda_dsp_trace_init(struct snd_sof_dev *sdev, u32 *tag) { - sdev->hda->dtrace_stream = hda_dsp_stream_get_cstream(sdev); + /* get last capture stream for dma trace, this make FW easier + * to manage dma channels just from index 0 + */ + sdev->hda->dtrace_stream = hda_dsp_stream_get(sdev, + SNDRV_PCM_STREAM_CAPTURE, + TRUE); if (!sdev->hda->dtrace_stream) { dev_err(sdev->dev, @@ -76,8 +81,9 @@ int hda_dsp_trace_release(struct snd_sof_dev *sdev) if (sdev->hda->dtrace_stream) { hstream = &sdev->hda->dtrace_stream->hstream; hstream->opened = false; - hda_dsp_stream_put_cstream(sdev, - hstream->stream_tag); + hda_dsp_stream_put(sdev, + SNDRV_PCM_STREAM_CAPTURE, + hstream->stream_tag); sdev->hda->dtrace_stream = NULL; return 0; } diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h index 5e27345022a86d..32a1bd680eadff 100644 --- a/sound/soc/sof/intel/hda.h +++ b/sound/soc/sof/intel/hda.h @@ -451,14 +451,9 @@ int hda_dsp_stream_setup_bdl(struct snd_sof_dev *sdev, struct hdac_stream *stream); struct hdac_ext_stream * - hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction); -struct hdac_ext_stream * - hda_dsp_stream_get_cstream(struct snd_sof_dev *sdev); -struct hdac_ext_stream * - hda_dsp_stream_get_pstream(struct snd_sof_dev *sdev); + hda_dsp_stream_get(struct snd_sof_dev *sdev, int direction, + int reverse); int hda_dsp_stream_put(struct snd_sof_dev *sdev, int direction, int stream_tag); -int hda_dsp_stream_put_pstream(struct snd_sof_dev *sdev, int stream_tag); -int hda_dsp_stream_put_cstream(struct snd_sof_dev *sdev, int stream_tag); int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev, struct hdac_ext_stream *stream, int enable, u32 size);