1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
8 // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9 // Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
10 // Rander Wang <rander.wang@intel.com>
11 // Keyon Jie <yang.jie@linux.intel.com>
15 * Hardware interface for generic Intel audio DSP HDA IP
18 #include <linux/pm_runtime.h>
19 #include <sound/hdaudio_ext.h>
20 #include <sound/hda_register.h>
21 #include <sound/sof.h>
26 * set up one of BDL entries for a stream
28 static int hda_setup_bdle(struct snd_sof_dev
*sdev
,
29 struct snd_dma_buffer
*dmab
,
30 struct hdac_stream
*stream
,
31 struct sof_intel_dsp_bdl
**bdlp
,
32 int offset
, int size
, int ioc
)
34 struct hdac_bus
*bus
= sof_to_bus(sdev
);
35 struct sof_intel_dsp_bdl
*bdl
= *bdlp
;
41 if (stream
->frags
>= HDA_DSP_MAX_BDL_ENTRIES
) {
42 dev_err(sdev
->dev
, "error: stream frags exceeded\n");
46 addr
= snd_sgbuf_get_addr(dmab
, offset
);
47 /* program BDL addr */
48 bdl
->addr_l
= cpu_to_le32(lower_32_bits(addr
));
49 bdl
->addr_h
= cpu_to_le32(upper_32_bits(addr
));
50 /* program BDL size */
51 chunk
= snd_sgbuf_get_chunk_size(dmab
, offset
, size
);
52 /* one BDLE should not cross 4K boundary */
53 if (bus
->align_bdle_4k
) {
54 u32 remain
= 0x1000 - (offset
& 0xfff);
59 bdl
->size
= cpu_to_le32(chunk
);
60 /* only program IOC when the whole segment is processed */
62 bdl
->ioc
= (size
|| !ioc
) ? 0 : cpu_to_le32(0x01);
67 dev_vdbg(sdev
->dev
, "bdl, frags:%d, chunk size:0x%x;\n",
68 stream
->frags
, chunk
);
76 * set up Buffer Descriptor List (BDL) for host memory transfer
77 * BDL describes the location of the individual buffers and is little endian.
79 int hda_dsp_stream_setup_bdl(struct snd_sof_dev
*sdev
,
80 struct snd_dma_buffer
*dmab
,
81 struct hdac_stream
*stream
)
83 struct sof_intel_hda_dev
*hda
= sdev
->pdata
->hw_pdata
;
84 struct sof_intel_dsp_bdl
*bdl
;
85 int i
, offset
, period_bytes
, periods
;
88 period_bytes
= stream
->period_bytes
;
89 dev_dbg(sdev
->dev
, "period_bytes:0x%x\n", period_bytes
);
91 period_bytes
= stream
->bufsize
;
93 periods
= stream
->bufsize
/ period_bytes
;
95 dev_dbg(sdev
->dev
, "periods:%d\n", periods
);
97 remain
= stream
->bufsize
% period_bytes
;
101 /* program the initial BDL entries */
102 bdl
= (struct sof_intel_dsp_bdl
*)stream
->bdl
.area
;
107 * set IOC if don't use position IPC
108 * and period_wakeup needed.
110 ioc
= hda
->no_ipc_position
?
111 !stream
->no_period_wakeup
: 0;
113 for (i
= 0; i
< periods
; i
++) {
114 if (i
== (periods
- 1) && remain
)
115 /* set the last small entry */
116 offset
= hda_setup_bdle(sdev
, dmab
,
117 stream
, &bdl
, offset
,
120 offset
= hda_setup_bdle(sdev
, dmab
,
121 stream
, &bdl
, offset
,
128 int hda_dsp_stream_spib_config(struct snd_sof_dev
*sdev
,
129 struct hdac_ext_stream
*stream
,
130 int enable
, u32 size
)
132 struct hdac_stream
*hstream
= &stream
->hstream
;
135 if (!sdev
->bar
[HDA_DSP_SPIB_BAR
]) {
136 dev_err(sdev
->dev
, "error: address of spib capability is NULL\n");
140 mask
= (1 << hstream
->index
);
142 /* enable/disable SPIB for the stream */
143 snd_sof_dsp_update_bits(sdev
, HDA_DSP_SPIB_BAR
,
144 SOF_HDA_ADSP_REG_CL_SPBFIFO_SPBFCCTL
, mask
,
145 enable
<< hstream
->index
);
147 /* set the SPIB value */
148 sof_io_write(sdev
, stream
->spib_addr
, size
);
153 /* get next unused stream */
154 struct hdac_ext_stream
*
155 hda_dsp_stream_get(struct snd_sof_dev
*sdev
, int direction
)
157 struct hdac_bus
*bus
= sof_to_bus(sdev
);
158 struct sof_intel_hda_stream
*hda_stream
;
159 struct hdac_ext_stream
*stream
= NULL
;
160 struct hdac_stream
*s
;
162 spin_lock_irq(&bus
->reg_lock
);
164 /* get an unused stream */
165 list_for_each_entry(s
, &bus
->stream_list
, list
) {
166 if (s
->direction
== direction
&& !s
->opened
) {
167 stream
= stream_to_hdac_ext_stream(s
);
168 hda_stream
= container_of(stream
,
169 struct sof_intel_hda_stream
,
171 /* check if the host DMA channel is reserved */
172 if (hda_stream
->host_reserved
)
180 spin_unlock_irq(&bus
->reg_lock
);
184 dev_err(sdev
->dev
, "error: no free %s streams\n",
185 direction
== SNDRV_PCM_STREAM_PLAYBACK
?
186 "playback" : "capture");
189 * Disable DMI Link L1 entry when capture stream is opened.
190 * Workaround to address a known issue with host DMA that results
191 * in xruns during pause/release in capture scenarios.
193 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_ALWAYS_ENABLE_DMI_L1
))
194 if (stream
&& direction
== SNDRV_PCM_STREAM_CAPTURE
)
195 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
,
197 HDA_VS_INTEL_EM2_L1SEN
, 0);
203 int hda_dsp_stream_put(struct snd_sof_dev
*sdev
, int direction
, int stream_tag
)
205 struct hdac_bus
*bus
= sof_to_bus(sdev
);
206 struct hdac_stream
*s
;
207 bool active_capture_stream
= false;
210 spin_lock_irq(&bus
->reg_lock
);
213 * close stream matching the stream tag
214 * and check if there are any open capture streams.
216 list_for_each_entry(s
, &bus
->stream_list
, list
) {
220 if (s
->direction
== direction
&& s
->stream_tag
== stream_tag
) {
223 } else if (s
->direction
== SNDRV_PCM_STREAM_CAPTURE
) {
224 active_capture_stream
= true;
228 spin_unlock_irq(&bus
->reg_lock
);
230 /* Enable DMI L1 entry if there are no capture streams open */
231 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_ALWAYS_ENABLE_DMI_L1
))
232 if (!active_capture_stream
)
233 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
,
235 HDA_VS_INTEL_EM2_L1SEN
,
236 HDA_VS_INTEL_EM2_L1SEN
);
239 dev_dbg(sdev
->dev
, "stream_tag %d not opened!\n", stream_tag
);
246 int hda_dsp_stream_trigger(struct snd_sof_dev
*sdev
,
247 struct hdac_ext_stream
*stream
, int cmd
)
249 struct hdac_stream
*hstream
= &stream
->hstream
;
250 int sd_offset
= SOF_STREAM_SD_OFFSET(hstream
);
251 u32 dma_start
= SOF_HDA_SD_CTL_DMA_START
;
255 /* cmd must be for audio stream */
257 case SNDRV_PCM_TRIGGER_RESUME
:
258 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
259 case SNDRV_PCM_TRIGGER_START
:
260 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
, SOF_HDA_INTCTL
,
262 1 << hstream
->index
);
264 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
,
266 SOF_HDA_SD_CTL_DMA_START
|
267 SOF_HDA_CL_DMA_SD_INT_MASK
,
268 SOF_HDA_SD_CTL_DMA_START
|
269 SOF_HDA_CL_DMA_SD_INT_MASK
);
271 ret
= snd_sof_dsp_read_poll_timeout(sdev
,
274 ((run
& dma_start
) == dma_start
),
275 HDA_DSP_REG_POLL_INTERVAL_US
,
276 HDA_DSP_STREAM_RUN_TIMEOUT
);
281 hstream
->running
= true;
283 case SNDRV_PCM_TRIGGER_SUSPEND
:
284 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
285 case SNDRV_PCM_TRIGGER_STOP
:
286 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
,
288 SOF_HDA_SD_CTL_DMA_START
|
289 SOF_HDA_CL_DMA_SD_INT_MASK
, 0x0);
291 ret
= snd_sof_dsp_read_poll_timeout(sdev
, HDA_DSP_HDA_BAR
,
294 HDA_DSP_REG_POLL_INTERVAL_US
,
295 HDA_DSP_STREAM_RUN_TIMEOUT
);
300 snd_sof_dsp_write(sdev
, HDA_DSP_HDA_BAR
, sd_offset
+
301 SOF_HDA_ADSP_REG_CL_SD_STS
,
302 SOF_HDA_CL_DMA_SD_INT_MASK
);
304 hstream
->running
= false;
305 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
, SOF_HDA_INTCTL
,
306 1 << hstream
->index
, 0x0);
309 dev_err(sdev
->dev
, "error: unknown command: %d\n", cmd
);
317 * prepare for common hdac registers settings, for both code loader
320 int hda_dsp_stream_hw_params(struct snd_sof_dev
*sdev
,
321 struct hdac_ext_stream
*stream
,
322 struct snd_dma_buffer
*dmab
,
323 struct snd_pcm_hw_params
*params
)
325 struct hdac_bus
*bus
= sof_to_bus(sdev
);
326 struct hdac_stream
*hstream
= &stream
->hstream
;
327 int sd_offset
= SOF_STREAM_SD_OFFSET(hstream
);
328 int ret
, timeout
= HDA_DSP_STREAM_RESET_TIMEOUT
;
329 u32 dma_start
= SOF_HDA_SD_CTL_DMA_START
;
334 dev_err(sdev
->dev
, "error: no stream available\n");
338 /* decouple host and link DMA */
339 mask
= 0x1 << hstream
->index
;
340 snd_sof_dsp_update_bits(sdev
, HDA_DSP_PP_BAR
, SOF_HDA_REG_PP_PPCTL
,
344 dev_err(sdev
->dev
, "error: no dma buffer allocated!\n");
348 /* clear stream status */
349 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
, sd_offset
,
350 SOF_HDA_CL_DMA_SD_INT_MASK
|
351 SOF_HDA_SD_CTL_DMA_START
, 0);
353 ret
= snd_sof_dsp_read_poll_timeout(sdev
, HDA_DSP_HDA_BAR
,
356 HDA_DSP_REG_POLL_INTERVAL_US
,
357 HDA_DSP_STREAM_RUN_TIMEOUT
);
362 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
,
363 sd_offset
+ SOF_HDA_ADSP_REG_CL_SD_STS
,
364 SOF_HDA_CL_DMA_SD_INT_MASK
,
365 SOF_HDA_CL_DMA_SD_INT_MASK
);
368 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
, sd_offset
, 0x1,
372 val
= snd_sof_dsp_read(sdev
, HDA_DSP_HDA_BAR
,
378 dev_err(sdev
->dev
, "error: stream reset failed\n");
382 timeout
= HDA_DSP_STREAM_RESET_TIMEOUT
;
383 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
, sd_offset
, 0x1,
386 /* wait for hardware to report that stream is out of reset */
389 val
= snd_sof_dsp_read(sdev
, HDA_DSP_HDA_BAR
,
391 if ((val
& 0x1) == 0)
395 dev_err(sdev
->dev
, "error: timeout waiting for stream reset\n");
400 *hstream
->posbuf
= 0;
402 /* reset BDL address */
403 snd_sof_dsp_write(sdev
, HDA_DSP_HDA_BAR
,
404 sd_offset
+ SOF_HDA_ADSP_REG_CL_SD_BDLPL
,
406 snd_sof_dsp_write(sdev
, HDA_DSP_HDA_BAR
,
407 sd_offset
+ SOF_HDA_ADSP_REG_CL_SD_BDLPU
,
410 /* clear stream status */
411 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
, sd_offset
,
412 SOF_HDA_CL_DMA_SD_INT_MASK
|
413 SOF_HDA_SD_CTL_DMA_START
, 0);
415 ret
= snd_sof_dsp_read_poll_timeout(sdev
, HDA_DSP_HDA_BAR
,
418 HDA_DSP_REG_POLL_INTERVAL_US
,
419 HDA_DSP_STREAM_RUN_TIMEOUT
);
424 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
,
425 sd_offset
+ SOF_HDA_ADSP_REG_CL_SD_STS
,
426 SOF_HDA_CL_DMA_SD_INT_MASK
,
427 SOF_HDA_CL_DMA_SD_INT_MASK
);
431 ret
= hda_dsp_stream_setup_bdl(sdev
, dmab
, hstream
);
433 dev_err(sdev
->dev
, "error: set up of BDL failed\n");
437 /* program stream tag to set up stream descriptor for DMA */
438 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
, sd_offset
,
439 SOF_HDA_CL_SD_CTL_STREAM_TAG_MASK
,
440 hstream
->stream_tag
<<
441 SOF_HDA_CL_SD_CTL_STREAM_TAG_SHIFT
);
443 /* program cyclic buffer length */
444 snd_sof_dsp_write(sdev
, HDA_DSP_HDA_BAR
,
445 sd_offset
+ SOF_HDA_ADSP_REG_CL_SD_CBL
,
449 * Recommended hardware programming sequence for HDAudio DMA format
451 * 1. Put DMA into coupled mode by clearing PPCTL.PROCEN bit
452 * for corresponding stream index before the time of writing
453 * format to SDxFMT register.
455 * 3. Set PPCTL.PROCEN bit for corresponding stream index to
456 * enable decoupled mode
459 /* couple host and link DMA, disable DSP features */
460 snd_sof_dsp_update_bits(sdev
, HDA_DSP_PP_BAR
, SOF_HDA_REG_PP_PPCTL
,
463 /* program stream format */
464 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
,
466 SOF_HDA_ADSP_REG_CL_SD_FORMAT
,
467 0xffff, hstream
->format_val
);
469 /* decouple host and link DMA, enable DSP features */
470 snd_sof_dsp_update_bits(sdev
, HDA_DSP_PP_BAR
, SOF_HDA_REG_PP_PPCTL
,
473 /* program last valid index */
474 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
,
475 sd_offset
+ SOF_HDA_ADSP_REG_CL_SD_LVI
,
476 0xffff, (hstream
->frags
- 1));
478 /* program BDL address */
479 snd_sof_dsp_write(sdev
, HDA_DSP_HDA_BAR
,
480 sd_offset
+ SOF_HDA_ADSP_REG_CL_SD_BDLPL
,
481 (u32
)hstream
->bdl
.addr
);
482 snd_sof_dsp_write(sdev
, HDA_DSP_HDA_BAR
,
483 sd_offset
+ SOF_HDA_ADSP_REG_CL_SD_BDLPU
,
484 upper_32_bits(hstream
->bdl
.addr
));
486 /* enable position buffer */
487 if (!(snd_sof_dsp_read(sdev
, HDA_DSP_HDA_BAR
, SOF_HDA_ADSP_DPLBASE
)
488 & SOF_HDA_ADSP_DPLBASE_ENABLE
)) {
489 snd_sof_dsp_write(sdev
, HDA_DSP_HDA_BAR
, SOF_HDA_ADSP_DPUBASE
,
490 upper_32_bits(bus
->posbuf
.addr
));
491 snd_sof_dsp_write(sdev
, HDA_DSP_HDA_BAR
, SOF_HDA_ADSP_DPLBASE
,
492 (u32
)bus
->posbuf
.addr
|
493 SOF_HDA_ADSP_DPLBASE_ENABLE
);
496 /* set interrupt enable bits */
497 snd_sof_dsp_update_bits(sdev
, HDA_DSP_HDA_BAR
, sd_offset
,
498 SOF_HDA_CL_DMA_SD_INT_MASK
,
499 SOF_HDA_CL_DMA_SD_INT_MASK
);
502 if (hstream
->direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
504 snd_sof_dsp_read(sdev
, HDA_DSP_HDA_BAR
,
506 SOF_HDA_ADSP_REG_CL_SD_FIFOSIZE
);
507 hstream
->fifo_size
&= 0xffff;
508 hstream
->fifo_size
+= 1;
510 hstream
->fifo_size
= 0;
516 int hda_dsp_stream_hw_free(struct snd_sof_dev
*sdev
,
517 struct snd_pcm_substream
*substream
)
519 struct hdac_stream
*stream
= substream
->runtime
->private_data
;
520 struct hdac_ext_stream
*link_dev
= container_of(stream
,
521 struct hdac_ext_stream
,
523 struct hdac_bus
*bus
= sof_to_bus(sdev
);
524 u32 mask
= 0x1 << stream
->index
;
526 spin_lock_irq(&bus
->reg_lock
);
527 /* couple host and link DMA if link DMA channel is idle */
528 if (!link_dev
->link_locked
)
529 snd_sof_dsp_update_bits(sdev
, HDA_DSP_PP_BAR
,
530 SOF_HDA_REG_PP_PPCTL
, mask
, 0);
531 spin_unlock_irq(&bus
->reg_lock
);
536 irqreturn_t
hda_dsp_stream_interrupt(int irq
, void *context
)
538 struct hdac_bus
*bus
= context
;
539 int ret
= IRQ_WAKE_THREAD
;
542 spin_lock(&bus
->reg_lock
);
544 status
= snd_hdac_chip_readl(bus
, INTSTS
);
545 dev_vdbg(bus
->dev
, "stream irq, INTSTS status: 0x%x\n", status
);
547 /* Register inaccessible, ignore it.*/
548 if (status
== 0xffffffff)
551 spin_unlock(&bus
->reg_lock
);
556 static bool hda_dsp_stream_check(struct hdac_bus
*bus
, u32 status
)
558 struct sof_intel_hda_dev
*sof_hda
= bus_to_sof_hda(bus
);
559 struct hdac_stream
*s
;
563 list_for_each_entry(s
, &bus
->stream_list
, list
) {
564 if (status
& BIT(s
->index
) && s
->opened
) {
565 sd_status
= snd_hdac_stream_readb(s
, SD_STS
);
567 dev_vdbg(bus
->dev
, "stream %d status 0x%x\n",
568 s
->index
, sd_status
);
570 snd_hdac_stream_writeb(s
, SD_STS
, sd_status
);
575 (sd_status
& SOF_HDA_CL_DMA_SD_INT_COMPLETE
) == 0)
578 /* Inform ALSA only in case not do that with IPC */
579 if (sof_hda
->no_ipc_position
)
580 snd_sof_pcm_period_elapsed(s
->substream
);
587 irqreturn_t
hda_dsp_stream_threaded_handler(int irq
, void *context
)
589 struct hdac_bus
*bus
= context
;
590 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
598 * Loop 10 times to handle missed interrupts caused by
599 * unsolicited responses from the codec
601 for (i
= 0, active
= true; i
< 10 && active
; i
++) {
602 spin_lock_irq(&bus
->reg_lock
);
604 status
= snd_hdac_chip_readl(bus
, INTSTS
);
607 active
= hda_dsp_stream_check(bus
, status
);
609 /* check and clear RIRB interrupt */
610 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
611 if (status
& AZX_INT_CTRL_EN
) {
612 rirb_status
= snd_hdac_chip_readb(bus
, RIRBSTS
);
613 if (rirb_status
& RIRB_INT_MASK
) {
615 if (rirb_status
& RIRB_INT_RESPONSE
)
616 snd_hdac_bus_update_rirb(bus
);
617 snd_hdac_chip_writeb(bus
, RIRBSTS
,
622 spin_unlock_irq(&bus
->reg_lock
);
628 int hda_dsp_stream_init(struct snd_sof_dev
*sdev
)
630 struct hdac_bus
*bus
= sof_to_bus(sdev
);
631 struct hdac_ext_stream
*stream
;
632 struct hdac_stream
*hstream
;
633 struct pci_dev
*pci
= to_pci_dev(sdev
->dev
);
634 struct sof_intel_hda_dev
*sof_hda
= bus_to_sof_hda(bus
);
636 int i
, num_playback
, num_capture
, num_total
, ret
;
639 gcap
= snd_sof_dsp_read(sdev
, HDA_DSP_HDA_BAR
, SOF_HDA_GCAP
);
640 dev_dbg(sdev
->dev
, "hda global caps = 0x%x\n", gcap
);
642 /* get stream count from GCAP */
643 num_capture
= (gcap
>> 8) & 0x0f;
644 num_playback
= (gcap
>> 12) & 0x0f;
645 num_total
= num_playback
+ num_capture
;
647 dev_dbg(sdev
->dev
, "detected %d playback and %d capture streams\n",
648 num_playback
, num_capture
);
650 if (num_playback
>= SOF_HDA_PLAYBACK_STREAMS
) {
651 dev_err(sdev
->dev
, "error: too many playback streams %d\n",
656 if (num_capture
>= SOF_HDA_CAPTURE_STREAMS
) {
657 dev_err(sdev
->dev
, "error: too many capture streams %d\n",
663 * mem alloc for the position buffer
664 * TODO: check position buffer update
666 ret
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, &pci
->dev
,
667 SOF_HDA_DPIB_ENTRY_SIZE
* num_total
,
670 dev_err(sdev
->dev
, "error: posbuffer dma alloc failed\n");
674 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
675 /* mem alloc for the CORB/RIRB ringbuffers */
676 ret
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, &pci
->dev
,
677 PAGE_SIZE
, &bus
->rb
);
679 dev_err(sdev
->dev
, "error: RB alloc failed\n");
684 /* create capture streams */
685 for (i
= 0; i
< num_capture
; i
++) {
686 struct sof_intel_hda_stream
*hda_stream
;
688 hda_stream
= devm_kzalloc(sdev
->dev
, sizeof(*hda_stream
),
693 hda_stream
->sdev
= sdev
;
695 stream
= &hda_stream
->hda_stream
;
697 stream
->pphc_addr
= sdev
->bar
[HDA_DSP_PP_BAR
] +
698 SOF_HDA_PPHC_BASE
+ SOF_HDA_PPHC_INTERVAL
* i
;
700 stream
->pplc_addr
= sdev
->bar
[HDA_DSP_PP_BAR
] +
701 SOF_HDA_PPLC_BASE
+ SOF_HDA_PPLC_MULTI
* num_total
+
702 SOF_HDA_PPLC_INTERVAL
* i
;
704 /* do we support SPIB */
705 if (sdev
->bar
[HDA_DSP_SPIB_BAR
]) {
706 stream
->spib_addr
= sdev
->bar
[HDA_DSP_SPIB_BAR
] +
707 SOF_HDA_SPIB_BASE
+ SOF_HDA_SPIB_INTERVAL
* i
+
710 stream
->fifo_addr
= sdev
->bar
[HDA_DSP_SPIB_BAR
] +
711 SOF_HDA_SPIB_BASE
+ SOF_HDA_SPIB_INTERVAL
* i
+
712 SOF_HDA_SPIB_MAXFIFO
;
715 hstream
= &stream
->hstream
;
717 hstream
->sd_int_sta_mask
= 1 << i
;
719 sd_offset
= SOF_STREAM_SD_OFFSET(hstream
);
720 hstream
->sd_addr
= sdev
->bar
[HDA_DSP_HDA_BAR
] + sd_offset
;
721 hstream
->stream_tag
= i
+ 1;
722 hstream
->opened
= false;
723 hstream
->running
= false;
724 hstream
->direction
= SNDRV_PCM_STREAM_CAPTURE
;
726 /* memory alloc for stream BDL */
727 ret
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, &pci
->dev
,
728 HDA_DSP_BDL_SIZE
, &hstream
->bdl
);
730 dev_err(sdev
->dev
, "error: stream bdl dma alloc failed\n");
733 hstream
->posbuf
= (__le32
*)(bus
->posbuf
.area
+
734 (hstream
->index
) * 8);
736 list_add_tail(&hstream
->list
, &bus
->stream_list
);
739 /* create playback streams */
740 for (i
= num_capture
; i
< num_total
; i
++) {
741 struct sof_intel_hda_stream
*hda_stream
;
743 hda_stream
= devm_kzalloc(sdev
->dev
, sizeof(*hda_stream
),
748 hda_stream
->sdev
= sdev
;
750 stream
= &hda_stream
->hda_stream
;
752 /* we always have DSP support */
753 stream
->pphc_addr
= sdev
->bar
[HDA_DSP_PP_BAR
] +
754 SOF_HDA_PPHC_BASE
+ SOF_HDA_PPHC_INTERVAL
* i
;
756 stream
->pplc_addr
= sdev
->bar
[HDA_DSP_PP_BAR
] +
757 SOF_HDA_PPLC_BASE
+ SOF_HDA_PPLC_MULTI
* num_total
+
758 SOF_HDA_PPLC_INTERVAL
* i
;
760 /* do we support SPIB */
761 if (sdev
->bar
[HDA_DSP_SPIB_BAR
]) {
762 stream
->spib_addr
= sdev
->bar
[HDA_DSP_SPIB_BAR
] +
763 SOF_HDA_SPIB_BASE
+ SOF_HDA_SPIB_INTERVAL
* i
+
766 stream
->fifo_addr
= sdev
->bar
[HDA_DSP_SPIB_BAR
] +
767 SOF_HDA_SPIB_BASE
+ SOF_HDA_SPIB_INTERVAL
* i
+
768 SOF_HDA_SPIB_MAXFIFO
;
771 hstream
= &stream
->hstream
;
773 hstream
->sd_int_sta_mask
= 1 << i
;
775 sd_offset
= SOF_STREAM_SD_OFFSET(hstream
);
776 hstream
->sd_addr
= sdev
->bar
[HDA_DSP_HDA_BAR
] + sd_offset
;
777 hstream
->stream_tag
= i
- num_capture
+ 1;
778 hstream
->opened
= false;
779 hstream
->running
= false;
780 hstream
->direction
= SNDRV_PCM_STREAM_PLAYBACK
;
782 /* mem alloc for stream BDL */
783 ret
= snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, &pci
->dev
,
784 HDA_DSP_BDL_SIZE
, &hstream
->bdl
);
786 dev_err(sdev
->dev
, "error: stream bdl dma alloc failed\n");
790 hstream
->posbuf
= (__le32
*)(bus
->posbuf
.area
+
791 (hstream
->index
) * 8);
793 list_add_tail(&hstream
->list
, &bus
->stream_list
);
796 /* store total stream count (playback + capture) from GCAP */
797 sof_hda
->stream_max
= num_total
;
802 void hda_dsp_stream_free(struct snd_sof_dev
*sdev
)
804 struct hdac_bus
*bus
= sof_to_bus(sdev
);
805 struct hdac_stream
*s
, *_s
;
806 struct hdac_ext_stream
*stream
;
807 struct sof_intel_hda_stream
*hda_stream
;
809 /* free position buffer */
810 if (bus
->posbuf
.area
)
811 snd_dma_free_pages(&bus
->posbuf
);
813 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
814 /* free position buffer */
816 snd_dma_free_pages(&bus
->rb
);
819 list_for_each_entry_safe(s
, _s
, &bus
->stream_list
, list
) {
822 /* free bdl buffer */
824 snd_dma_free_pages(&s
->bdl
);
826 stream
= stream_to_hdac_ext_stream(s
);
827 hda_stream
= container_of(stream
, struct sof_intel_hda_stream
,
829 devm_kfree(sdev
->dev
, hda_stream
);