Skip to content

Commit d420caa

Browse files
committed
ASoC: SOF: Intel: hda-loader: use hda_dma_prepare/cleanup helpers
Use the common hda_dma_prepare/cleanup helpers. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 4d0f336 commit d420caa

1 file changed

Lines changed: 3 additions & 91 deletions

File tree

sound/soc/sof/intel/hda-loader.c

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -53,65 +53,8 @@ hda_cl_prepare(struct device *dev, unsigned int format, unsigned int size,
5353
struct snd_dma_buffer *dmab, bool persistent_buffer, int direction,
5454
bool is_iccmax)
5555
{
56-
struct snd_sof_dev *sdev = dev_get_drvdata(dev);
57-
struct hdac_ext_stream *hext_stream;
58-
struct hdac_stream *hstream;
59-
int ret;
60-
61-
hext_stream = hda_dsp_stream_get(sdev, direction, 0);
62-
63-
if (!hext_stream) {
64-
dev_err(sdev->dev, "error: no stream available\n");
65-
return ERR_PTR(-ENODEV);
66-
}
67-
hstream = &hext_stream->hstream;
68-
hstream->substream = NULL;
69-
70-
/*
71-
* Allocate DMA buffer if it is temporary or if the buffer is intended
72-
* to be persistent but not yet allocated.
73-
* We cannot rely solely on !dmab->area as caller might use a struct on
74-
* stack (when it is temporary) without clearing it to 0.
75-
*/
76-
if (!persistent_buffer || !dmab->area) {
77-
ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, dev, size, dmab);
78-
if (ret < 0) {
79-
dev_err(sdev->dev, "%s: memory alloc failed: %d\n",
80-
__func__, ret);
81-
goto out_put;
82-
}
83-
}
84-
85-
hstream->period_bytes = 0;/* initialize period_bytes */
86-
hstream->format_val = format;
87-
hstream->bufsize = size;
88-
89-
if (is_iccmax) {
90-
ret = hda_dsp_iccmax_stream_hw_params(sdev, hext_stream, dmab, NULL);
91-
if (ret < 0) {
92-
dev_err(sdev->dev, "error: iccmax stream prepare failed: %d\n", ret);
93-
goto out_free;
94-
}
95-
} else {
96-
ret = hda_dsp_stream_hw_params(sdev, hext_stream, dmab, NULL);
97-
if (ret < 0) {
98-
dev_err(sdev->dev, "error: hdac prepare failed: %d\n", ret);
99-
goto out_free;
100-
}
101-
hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_ENABLE, size);
102-
}
103-
104-
return hext_stream;
105-
106-
out_free:
107-
snd_dma_free_pages(dmab);
108-
dmab->area = NULL;
109-
dmab->bytes = 0;
110-
hstream->bufsize = 0;
111-
hstream->format_val = 0;
112-
out_put:
113-
hda_dsp_stream_put(sdev, direction, hstream->stream_tag);
114-
return ERR_PTR(ret);
56+
return hda_dma_prepare(dev, format, size, dmab, persistent_buffer,
57+
direction, is_iccmax, false);
11558
}
11659
EXPORT_SYMBOL_NS(hda_cl_prepare, "SND_SOC_SOF_INTEL_HDA_COMMON");
11760

@@ -275,38 +218,7 @@ EXPORT_SYMBOL_NS(hda_cl_trigger, "SND_SOC_SOF_INTEL_HDA_COMMON");
275218
int hda_cl_cleanup(struct device *dev, struct snd_dma_buffer *dmab,
276219
bool persistent_buffer, struct hdac_ext_stream *hext_stream)
277220
{
278-
struct snd_sof_dev *sdev = dev_get_drvdata(dev);
279-
struct hdac_stream *hstream = &hext_stream->hstream;
280-
int sd_offset = SOF_STREAM_SD_OFFSET(hstream);
281-
int ret = 0;
282-
283-
if (hstream->direction == SNDRV_PCM_STREAM_PLAYBACK)
284-
ret = hda_dsp_stream_spib_config(sdev, hext_stream, HDA_DSP_SPIB_DISABLE, 0);
285-
else
286-
snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, sd_offset,
287-
SOF_HDA_SD_CTL_DMA_START, 0);
288-
289-
hda_dsp_stream_put(sdev, hstream->direction, hstream->stream_tag);
290-
hstream->running = 0;
291-
hstream->substream = NULL;
292-
293-
/* reset BDL address */
294-
snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
295-
sd_offset + SOF_HDA_ADSP_REG_SD_BDLPL, 0);
296-
snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
297-
sd_offset + SOF_HDA_ADSP_REG_SD_BDLPU, 0);
298-
299-
snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, sd_offset, 0);
300-
301-
if (!persistent_buffer) {
302-
snd_dma_free_pages(dmab);
303-
dmab->area = NULL;
304-
dmab->bytes = 0;
305-
hstream->bufsize = 0;
306-
hstream->format_val = 0;
307-
}
308-
309-
return ret;
221+
return hda_dma_cleanup(dev, dmab, persistent_buffer, hext_stream, false);
310222
}
311223
EXPORT_SYMBOL_NS(hda_cl_cleanup, "SND_SOC_SOF_INTEL_HDA_COMMON");
312224

0 commit comments

Comments
 (0)