1 // SPDX-License-Identifier: GPL-2.0-only
3 * skl-pcm.c -ASoC HDA Platform driver file implementing PCM functionality
5 * Copyright (C) 2014-2015 Intel Corp
6 * Author: Jeeja KP <jeeja.kp@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 #include <linux/pci.h>
14 #include <linux/pm_runtime.h>
15 #include <linux/delay.h>
16 #include <sound/pcm_params.h>
17 #include <sound/soc.h>
19 #include "skl-topology.h"
20 #include "skl-sst-dsp.h"
21 #include "skl-sst-ipc.h"
28 static const struct snd_pcm_hardware azx_pcm_hw
= {
29 .info
= (SNDRV_PCM_INFO_MMAP
|
30 SNDRV_PCM_INFO_INTERLEAVED
|
31 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
32 SNDRV_PCM_INFO_MMAP_VALID
|
33 SNDRV_PCM_INFO_PAUSE
|
34 SNDRV_PCM_INFO_RESUME
|
35 SNDRV_PCM_INFO_SYNC_START
|
36 SNDRV_PCM_INFO_HAS_WALL_CLOCK
| /* legacy */
37 SNDRV_PCM_INFO_HAS_LINK_ATIME
|
38 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP
),
39 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
40 SNDRV_PCM_FMTBIT_S32_LE
|
41 SNDRV_PCM_FMTBIT_S24_LE
,
42 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
|
48 .buffer_bytes_max
= AZX_MAX_BUF_SIZE
,
49 .period_bytes_min
= 128,
50 .period_bytes_max
= AZX_MAX_BUF_SIZE
/ 2,
52 .periods_max
= AZX_MAX_FRAG
,
57 struct hdac_ext_stream
*get_hdac_ext_stream(struct snd_pcm_substream
*substream
)
59 return substream
->runtime
->private_data
;
62 static struct hdac_bus
*get_bus_ctx(struct snd_pcm_substream
*substream
)
64 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
65 struct hdac_stream
*hstream
= hdac_stream(stream
);
66 struct hdac_bus
*bus
= hstream
->bus
;
70 static int skl_substream_alloc_pages(struct hdac_bus
*bus
,
71 struct snd_pcm_substream
*substream
,
74 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
76 hdac_stream(stream
)->bufsize
= 0;
77 hdac_stream(stream
)->period_bytes
= 0;
78 hdac_stream(stream
)->format_val
= 0;
83 static void skl_set_pcm_constrains(struct hdac_bus
*bus
,
84 struct snd_pcm_runtime
*runtime
)
86 snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
);
88 /* avoid wrap-around with wall-clock */
89 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_TIME
,
93 static enum hdac_ext_stream_type
skl_get_host_stream_type(struct hdac_bus
*bus
)
96 return HDAC_EXT_STREAM_TYPE_HOST
;
98 return HDAC_EXT_STREAM_TYPE_COUPLED
;
102 * check if the stream opened is marked as ignore_suspend by machine, if so
103 * then enable suspend_active refcount
105 * The count supend_active does not need lock as it is used in open/close
106 * and suspend context
108 static void skl_set_suspend_active(struct snd_pcm_substream
*substream
,
109 struct snd_soc_dai
*dai
, bool enable
)
111 struct hdac_bus
*bus
= dev_get_drvdata(dai
->dev
);
112 struct snd_soc_dapm_widget
*w
;
113 struct skl_dev
*skl
= bus_to_skl(bus
);
115 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
116 w
= dai
->playback_widget
;
118 w
= dai
->capture_widget
;
120 if (w
->ignore_suspend
&& enable
)
121 skl
->supend_active
++;
122 else if (w
->ignore_suspend
&& !enable
)
123 skl
->supend_active
--;
126 int skl_pcm_host_dma_prepare(struct device
*dev
, struct skl_pipe_params
*params
)
128 struct hdac_bus
*bus
= dev_get_drvdata(dev
);
129 struct skl_dev
*skl
= bus_to_skl(bus
);
130 unsigned int format_val
;
131 struct hdac_stream
*hstream
;
132 struct hdac_ext_stream
*stream
;
135 hstream
= snd_hdac_get_stream(bus
, params
->stream
,
136 params
->host_dma_id
+ 1);
140 stream
= stream_to_hdac_ext_stream(hstream
);
141 snd_hdac_ext_stream_decouple(bus
, stream
, true);
143 format_val
= snd_hdac_calc_stream_format(params
->s_freq
,
144 params
->ch
, params
->format
, params
->host_bps
, 0);
146 dev_dbg(dev
, "format_val=%d, rate=%d, ch=%d, format=%d\n",
147 format_val
, params
->s_freq
, params
->ch
, params
->format
);
149 snd_hdac_stream_reset(hdac_stream(stream
));
150 err
= snd_hdac_stream_set_params(hdac_stream(stream
), format_val
);
155 * The recommended SDxFMT programming sequence for BXT
156 * platforms is to couple the stream before writing the format
158 if (IS_BXT(skl
->pci
)) {
159 snd_hdac_ext_stream_decouple(bus
, stream
, false);
160 err
= snd_hdac_stream_setup(hdac_stream(stream
));
161 snd_hdac_ext_stream_decouple(bus
, stream
, true);
163 err
= snd_hdac_stream_setup(hdac_stream(stream
));
169 hdac_stream(stream
)->prepared
= 1;
174 int skl_pcm_link_dma_prepare(struct device
*dev
, struct skl_pipe_params
*params
)
176 struct hdac_bus
*bus
= dev_get_drvdata(dev
);
177 unsigned int format_val
;
178 struct hdac_stream
*hstream
;
179 struct hdac_ext_stream
*stream
;
180 struct hdac_ext_link
*link
;
181 unsigned char stream_tag
;
183 hstream
= snd_hdac_get_stream(bus
, params
->stream
,
184 params
->link_dma_id
+ 1);
188 stream
= stream_to_hdac_ext_stream(hstream
);
189 snd_hdac_ext_stream_decouple(bus
, stream
, true);
190 format_val
= snd_hdac_calc_stream_format(params
->s_freq
, params
->ch
,
191 params
->format
, params
->link_bps
, 0);
193 dev_dbg(dev
, "format_val=%d, rate=%d, ch=%d, format=%d\n",
194 format_val
, params
->s_freq
, params
->ch
, params
->format
);
196 snd_hdac_ext_link_stream_reset(stream
);
198 snd_hdac_ext_link_stream_setup(stream
, format_val
);
200 stream_tag
= hstream
->stream_tag
;
201 if (stream
->hstream
.direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
202 list_for_each_entry(link
, &bus
->hlink_list
, list
) {
203 if (link
->index
== params
->link_index
)
204 snd_hdac_ext_link_set_stream_id(link
,
209 stream
->link_prepared
= 1;
214 static int skl_pcm_open(struct snd_pcm_substream
*substream
,
215 struct snd_soc_dai
*dai
)
217 struct hdac_bus
*bus
= dev_get_drvdata(dai
->dev
);
218 struct hdac_ext_stream
*stream
;
219 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
220 struct skl_dma_params
*dma_params
;
221 struct skl_dev
*skl
= get_skl_ctx(dai
->dev
);
222 struct skl_module_cfg
*mconfig
;
224 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
226 stream
= snd_hdac_ext_stream_assign(bus
, substream
,
227 skl_get_host_stream_type(bus
));
231 skl_set_pcm_constrains(bus
, runtime
);
234 * disable WALLCLOCK timestamps for capture streams
235 * until we figure out how to handle digital inputs
237 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
) {
238 runtime
->hw
.info
&= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK
; /* legacy */
239 runtime
->hw
.info
&= ~SNDRV_PCM_INFO_HAS_LINK_ATIME
;
242 runtime
->private_data
= stream
;
244 dma_params
= kzalloc(sizeof(*dma_params
), GFP_KERNEL
);
248 dma_params
->stream_tag
= hdac_stream(stream
)->stream_tag
;
249 snd_soc_dai_set_dma_data(dai
, substream
, dma_params
);
251 dev_dbg(dai
->dev
, "stream tag set in dma params=%d\n",
252 dma_params
->stream_tag
);
253 skl_set_suspend_active(substream
, dai
, true);
254 snd_pcm_set_sync(substream
);
256 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
260 skl_tplg_d0i3_get(skl
, mconfig
->d0i3_caps
);
265 static int skl_pcm_prepare(struct snd_pcm_substream
*substream
,
266 struct snd_soc_dai
*dai
)
268 struct skl_dev
*skl
= get_skl_ctx(dai
->dev
);
269 struct skl_module_cfg
*mconfig
;
272 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
274 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
277 * In case of XRUN recovery or in the case when the application
278 * calls prepare another time, reset the FW pipe to clean state
281 (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_XRUN
||
282 mconfig
->pipe
->state
== SKL_PIPE_CREATED
||
283 mconfig
->pipe
->state
== SKL_PIPE_PAUSED
)) {
285 ret
= skl_reset_pipe(skl
, mconfig
->pipe
);
290 ret
= skl_pcm_host_dma_prepare(dai
->dev
,
291 mconfig
->pipe
->p_params
);
299 static int skl_pcm_hw_params(struct snd_pcm_substream
*substream
,
300 struct snd_pcm_hw_params
*params
,
301 struct snd_soc_dai
*dai
)
303 struct hdac_bus
*bus
= dev_get_drvdata(dai
->dev
);
304 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
305 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
306 struct skl_pipe_params p_params
= {0};
307 struct skl_module_cfg
*m_cfg
;
310 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
311 ret
= skl_substream_alloc_pages(bus
, substream
,
312 params_buffer_bytes(params
));
316 dev_dbg(dai
->dev
, "format_val, rate=%d, ch=%d, format=%d\n",
317 runtime
->rate
, runtime
->channels
, runtime
->format
);
319 dma_id
= hdac_stream(stream
)->stream_tag
- 1;
320 dev_dbg(dai
->dev
, "dma_id=%d\n", dma_id
);
322 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
323 p_params
.ch
= params_channels(params
);
324 p_params
.s_freq
= params_rate(params
);
325 p_params
.host_dma_id
= dma_id
;
326 p_params
.stream
= substream
->stream
;
327 p_params
.format
= params_format(params
);
328 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
329 p_params
.host_bps
= dai
->driver
->playback
.sig_bits
;
331 p_params
.host_bps
= dai
->driver
->capture
.sig_bits
;
334 m_cfg
= skl_tplg_fe_get_cpr_module(dai
, p_params
.stream
);
336 skl_tplg_update_pipe_params(dai
->dev
, m_cfg
, &p_params
);
341 static void skl_pcm_close(struct snd_pcm_substream
*substream
,
342 struct snd_soc_dai
*dai
)
344 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
345 struct hdac_bus
*bus
= dev_get_drvdata(dai
->dev
);
346 struct skl_dma_params
*dma_params
= NULL
;
347 struct skl_dev
*skl
= bus_to_skl(bus
);
348 struct skl_module_cfg
*mconfig
;
350 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
352 snd_hdac_ext_stream_release(stream
, skl_get_host_stream_type(bus
));
354 dma_params
= snd_soc_dai_get_dma_data(dai
, substream
);
356 * now we should set this to NULL as we are freeing by the
359 snd_soc_dai_set_dma_data(dai
, substream
, NULL
);
360 skl_set_suspend_active(substream
, dai
, false);
363 * check if close is for "Reference Pin" and set back the
364 * CGCTL.MISCBDCGE if disabled by driver
366 if (!strncmp(dai
->name
, "Reference Pin", 13) &&
367 skl
->miscbdcg_disabled
) {
368 skl
->enable_miscbdcge(dai
->dev
, true);
369 skl
->miscbdcg_disabled
= false;
372 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
374 skl_tplg_d0i3_put(skl
, mconfig
->d0i3_caps
);
379 static int skl_pcm_hw_free(struct snd_pcm_substream
*substream
,
380 struct snd_soc_dai
*dai
)
382 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
383 struct skl_dev
*skl
= get_skl_ctx(dai
->dev
);
384 struct skl_module_cfg
*mconfig
;
387 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
389 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
392 ret
= skl_reset_pipe(skl
, mconfig
->pipe
);
394 dev_err(dai
->dev
, "%s:Reset failed ret =%d",
398 snd_hdac_stream_cleanup(hdac_stream(stream
));
399 hdac_stream(stream
)->prepared
= 0;
404 static int skl_be_hw_params(struct snd_pcm_substream
*substream
,
405 struct snd_pcm_hw_params
*params
,
406 struct snd_soc_dai
*dai
)
408 struct skl_pipe_params p_params
= {0};
410 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
411 p_params
.ch
= params_channels(params
);
412 p_params
.s_freq
= params_rate(params
);
413 p_params
.stream
= substream
->stream
;
415 return skl_tplg_be_update_params(dai
, &p_params
);
418 static int skl_decoupled_trigger(struct snd_pcm_substream
*substream
,
421 struct hdac_bus
*bus
= get_bus_ctx(substream
);
422 struct hdac_ext_stream
*stream
;
424 unsigned long cookie
;
425 struct hdac_stream
*hstr
;
427 stream
= get_hdac_ext_stream(substream
);
428 hstr
= hdac_stream(stream
);
434 case SNDRV_PCM_TRIGGER_START
:
435 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
436 case SNDRV_PCM_TRIGGER_RESUME
:
440 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
441 case SNDRV_PCM_TRIGGER_SUSPEND
:
442 case SNDRV_PCM_TRIGGER_STOP
:
450 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
453 snd_hdac_stream_start(hdac_stream(stream
), true);
454 snd_hdac_stream_timecounter_init(hstr
, 0);
456 snd_hdac_stream_stop(hdac_stream(stream
));
459 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
464 static int skl_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
,
465 struct snd_soc_dai
*dai
)
467 struct skl_dev
*skl
= get_skl_ctx(dai
->dev
);
468 struct skl_module_cfg
*mconfig
;
469 struct hdac_bus
*bus
= get_bus_ctx(substream
);
470 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
471 struct snd_soc_dapm_widget
*w
;
474 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
478 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
479 w
= dai
->playback_widget
;
481 w
= dai
->capture_widget
;
484 case SNDRV_PCM_TRIGGER_RESUME
:
485 if (!w
->ignore_suspend
) {
487 * enable DMA Resume enable bit for the stream, set the
488 * dpib & lpib position to resume before starting the
491 snd_hdac_ext_stream_drsm_enable(bus
, true,
492 hdac_stream(stream
)->index
);
493 snd_hdac_ext_stream_set_dpibr(bus
, stream
,
495 snd_hdac_ext_stream_set_lpib(stream
, stream
->lpib
);
499 case SNDRV_PCM_TRIGGER_START
:
500 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
502 * Start HOST DMA and Start FE Pipe.This is to make sure that
503 * there are no underrun/overrun in the case when the FE
504 * pipeline is started but there is a delay in starting the
505 * DMA channel on the host.
507 ret
= skl_decoupled_trigger(substream
, cmd
);
510 return skl_run_pipe(skl
, mconfig
->pipe
);
513 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
514 case SNDRV_PCM_TRIGGER_SUSPEND
:
515 case SNDRV_PCM_TRIGGER_STOP
:
517 * Stop FE Pipe first and stop DMA. This is to make sure that
518 * there are no underrun/overrun in the case if there is a delay
519 * between the two operations.
521 ret
= skl_stop_pipe(skl
, mconfig
->pipe
);
525 ret
= skl_decoupled_trigger(substream
, cmd
);
526 if ((cmd
== SNDRV_PCM_TRIGGER_SUSPEND
) && !w
->ignore_suspend
) {
527 /* save the dpib and lpib positions */
528 stream
->dpib
= readl(bus
->remap_addr
+
529 AZX_REG_VS_SDXDPIB_XBASE
+
530 (AZX_REG_VS_SDXDPIB_XINTERVAL
*
531 hdac_stream(stream
)->index
));
533 stream
->lpib
= snd_hdac_stream_get_pos_lpib(
534 hdac_stream(stream
));
535 snd_hdac_ext_stream_decouple(bus
, stream
, false);
547 static int skl_link_hw_params(struct snd_pcm_substream
*substream
,
548 struct snd_pcm_hw_params
*params
,
549 struct snd_soc_dai
*dai
)
551 struct hdac_bus
*bus
= dev_get_drvdata(dai
->dev
);
552 struct hdac_ext_stream
*link_dev
;
553 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
554 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
555 struct skl_pipe_params p_params
= {0};
556 struct hdac_ext_link
*link
;
559 link_dev
= snd_hdac_ext_stream_assign(bus
, substream
,
560 HDAC_EXT_STREAM_TYPE_LINK
);
564 snd_soc_dai_set_dma_data(dai
, substream
, (void *)link_dev
);
566 link
= snd_hdac_ext_bus_get_link(bus
, codec_dai
->component
->name
);
570 stream_tag
= hdac_stream(link_dev
)->stream_tag
;
572 /* set the stream tag in the codec dai dma params */
573 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
574 snd_soc_dai_set_tdm_slot(codec_dai
, stream_tag
, 0, 0, 0);
576 snd_soc_dai_set_tdm_slot(codec_dai
, 0, stream_tag
, 0, 0);
578 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
579 p_params
.ch
= params_channels(params
);
580 p_params
.s_freq
= params_rate(params
);
581 p_params
.stream
= substream
->stream
;
582 p_params
.link_dma_id
= stream_tag
- 1;
583 p_params
.link_index
= link
->index
;
584 p_params
.format
= params_format(params
);
586 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
587 p_params
.link_bps
= codec_dai
->driver
->playback
.sig_bits
;
589 p_params
.link_bps
= codec_dai
->driver
->capture
.sig_bits
;
591 return skl_tplg_be_update_params(dai
, &p_params
);
594 static int skl_link_pcm_prepare(struct snd_pcm_substream
*substream
,
595 struct snd_soc_dai
*dai
)
597 struct skl_dev
*skl
= get_skl_ctx(dai
->dev
);
598 struct skl_module_cfg
*mconfig
= NULL
;
600 /* In case of XRUN recovery, reset the FW pipe to clean state */
601 mconfig
= skl_tplg_be_get_cpr_module(dai
, substream
->stream
);
602 if (mconfig
&& !mconfig
->pipe
->passthru
&&
603 (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_XRUN
))
604 skl_reset_pipe(skl
, mconfig
->pipe
);
609 static int skl_link_pcm_trigger(struct snd_pcm_substream
*substream
,
610 int cmd
, struct snd_soc_dai
*dai
)
612 struct hdac_ext_stream
*link_dev
=
613 snd_soc_dai_get_dma_data(dai
, substream
);
614 struct hdac_bus
*bus
= get_bus_ctx(substream
);
615 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
617 dev_dbg(dai
->dev
, "In %s cmd=%d\n", __func__
, cmd
);
619 case SNDRV_PCM_TRIGGER_RESUME
:
620 case SNDRV_PCM_TRIGGER_START
:
621 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
622 snd_hdac_ext_link_stream_start(link_dev
);
625 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
626 case SNDRV_PCM_TRIGGER_SUSPEND
:
627 case SNDRV_PCM_TRIGGER_STOP
:
628 snd_hdac_ext_link_stream_clear(link_dev
);
629 if (cmd
== SNDRV_PCM_TRIGGER_SUSPEND
)
630 snd_hdac_ext_stream_decouple(bus
, stream
, false);
639 static int skl_link_hw_free(struct snd_pcm_substream
*substream
,
640 struct snd_soc_dai
*dai
)
642 struct hdac_bus
*bus
= dev_get_drvdata(dai
->dev
);
643 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
644 struct hdac_ext_stream
*link_dev
=
645 snd_soc_dai_get_dma_data(dai
, substream
);
646 struct hdac_ext_link
*link
;
647 unsigned char stream_tag
;
649 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
651 link_dev
->link_prepared
= 0;
653 link
= snd_hdac_ext_bus_get_link(bus
, rtd
->codec_dai
->component
->name
);
657 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
658 stream_tag
= hdac_stream(link_dev
)->stream_tag
;
659 snd_hdac_ext_link_clear_stream_id(link
, stream_tag
);
662 snd_hdac_ext_stream_release(link_dev
, HDAC_EXT_STREAM_TYPE_LINK
);
666 static const struct snd_soc_dai_ops skl_pcm_dai_ops
= {
667 .startup
= skl_pcm_open
,
668 .shutdown
= skl_pcm_close
,
669 .prepare
= skl_pcm_prepare
,
670 .hw_params
= skl_pcm_hw_params
,
671 .hw_free
= skl_pcm_hw_free
,
672 .trigger
= skl_pcm_trigger
,
675 static const struct snd_soc_dai_ops skl_dmic_dai_ops
= {
676 .hw_params
= skl_be_hw_params
,
679 static const struct snd_soc_dai_ops skl_be_ssp_dai_ops
= {
680 .hw_params
= skl_be_hw_params
,
683 static const struct snd_soc_dai_ops skl_link_dai_ops
= {
684 .prepare
= skl_link_pcm_prepare
,
685 .hw_params
= skl_link_hw_params
,
686 .hw_free
= skl_link_hw_free
,
687 .trigger
= skl_link_pcm_trigger
,
690 static struct snd_soc_dai_driver skl_fe_dai
[] = {
692 .name
= "System Pin",
693 .ops
= &skl_pcm_dai_ops
,
695 .stream_name
= "System Playback",
696 .channels_min
= HDA_MONO
,
697 .channels_max
= HDA_STEREO
,
698 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
| SNDRV_PCM_RATE_8000
,
699 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
700 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S32_LE
,
704 .stream_name
= "System Capture",
705 .channels_min
= HDA_MONO
,
706 .channels_max
= HDA_STEREO
,
707 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
708 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
713 .name
= "System Pin2",
714 .ops
= &skl_pcm_dai_ops
,
716 .stream_name
= "Headset Playback",
717 .channels_min
= HDA_MONO
,
718 .channels_max
= HDA_STEREO
,
719 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
|
721 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
722 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S32_LE
,
726 .name
= "Echoref Pin",
727 .ops
= &skl_pcm_dai_ops
,
729 .stream_name
= "Echoreference Capture",
730 .channels_min
= HDA_STEREO
,
731 .channels_max
= HDA_STEREO
,
732 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
|
734 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
735 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S32_LE
,
739 .name
= "Reference Pin",
740 .ops
= &skl_pcm_dai_ops
,
742 .stream_name
= "Reference Capture",
743 .channels_min
= HDA_MONO
,
744 .channels_max
= HDA_QUAD
,
745 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
746 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
751 .name
= "Deepbuffer Pin",
752 .ops
= &skl_pcm_dai_ops
,
754 .stream_name
= "Deepbuffer Playback",
755 .channels_min
= HDA_STEREO
,
756 .channels_max
= HDA_STEREO
,
757 .rates
= SNDRV_PCM_RATE_48000
,
758 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
763 .name
= "LowLatency Pin",
764 .ops
= &skl_pcm_dai_ops
,
766 .stream_name
= "Low Latency Playback",
767 .channels_min
= HDA_STEREO
,
768 .channels_max
= HDA_STEREO
,
769 .rates
= SNDRV_PCM_RATE_48000
,
770 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
776 .ops
= &skl_pcm_dai_ops
,
778 .stream_name
= "DMIC Capture",
779 .channels_min
= HDA_MONO
,
780 .channels_max
= HDA_QUAD
,
781 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
782 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
788 .ops
= &skl_pcm_dai_ops
,
790 .stream_name
= "HDMI1 Playback",
791 .channels_min
= HDA_STEREO
,
793 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
794 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
795 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
796 SNDRV_PCM_RATE_192000
,
797 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
798 SNDRV_PCM_FMTBIT_S32_LE
,
804 .ops
= &skl_pcm_dai_ops
,
806 .stream_name
= "HDMI2 Playback",
807 .channels_min
= HDA_STEREO
,
809 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
810 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
811 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
812 SNDRV_PCM_RATE_192000
,
813 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
814 SNDRV_PCM_FMTBIT_S32_LE
,
820 .ops
= &skl_pcm_dai_ops
,
822 .stream_name
= "HDMI3 Playback",
823 .channels_min
= HDA_STEREO
,
825 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
826 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
827 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
828 SNDRV_PCM_RATE_192000
,
829 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
830 SNDRV_PCM_FMTBIT_S32_LE
,
837 static struct snd_soc_dai_driver skl_platform_dai
[] = {
840 .ops
= &skl_be_ssp_dai_ops
,
842 .stream_name
= "ssp0 Tx",
843 .channels_min
= HDA_STEREO
,
844 .channels_max
= HDA_STEREO
,
845 .rates
= SNDRV_PCM_RATE_48000
,
846 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
849 .stream_name
= "ssp0 Rx",
850 .channels_min
= HDA_STEREO
,
851 .channels_max
= HDA_STEREO
,
852 .rates
= SNDRV_PCM_RATE_48000
,
853 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
858 .ops
= &skl_be_ssp_dai_ops
,
860 .stream_name
= "ssp1 Tx",
861 .channels_min
= HDA_STEREO
,
862 .channels_max
= HDA_STEREO
,
863 .rates
= SNDRV_PCM_RATE_48000
,
864 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
867 .stream_name
= "ssp1 Rx",
868 .channels_min
= HDA_STEREO
,
869 .channels_max
= HDA_STEREO
,
870 .rates
= SNDRV_PCM_RATE_48000
,
871 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
876 .ops
= &skl_be_ssp_dai_ops
,
878 .stream_name
= "ssp2 Tx",
879 .channels_min
= HDA_STEREO
,
880 .channels_max
= HDA_STEREO
,
881 .rates
= SNDRV_PCM_RATE_48000
,
882 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
885 .stream_name
= "ssp2 Rx",
886 .channels_min
= HDA_STEREO
,
887 .channels_max
= HDA_STEREO
,
888 .rates
= SNDRV_PCM_RATE_48000
,
889 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
894 .ops
= &skl_be_ssp_dai_ops
,
896 .stream_name
= "ssp3 Tx",
897 .channels_min
= HDA_STEREO
,
898 .channels_max
= HDA_STEREO
,
899 .rates
= SNDRV_PCM_RATE_48000
,
900 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
903 .stream_name
= "ssp3 Rx",
904 .channels_min
= HDA_STEREO
,
905 .channels_max
= HDA_STEREO
,
906 .rates
= SNDRV_PCM_RATE_48000
,
907 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
912 .ops
= &skl_be_ssp_dai_ops
,
914 .stream_name
= "ssp4 Tx",
915 .channels_min
= HDA_STEREO
,
916 .channels_max
= HDA_STEREO
,
917 .rates
= SNDRV_PCM_RATE_48000
,
918 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
921 .stream_name
= "ssp4 Rx",
922 .channels_min
= HDA_STEREO
,
923 .channels_max
= HDA_STEREO
,
924 .rates
= SNDRV_PCM_RATE_48000
,
925 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
930 .ops
= &skl_be_ssp_dai_ops
,
932 .stream_name
= "ssp5 Tx",
933 .channels_min
= HDA_STEREO
,
934 .channels_max
= HDA_STEREO
,
935 .rates
= SNDRV_PCM_RATE_48000
,
936 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
939 .stream_name
= "ssp5 Rx",
940 .channels_min
= HDA_STEREO
,
941 .channels_max
= HDA_STEREO
,
942 .rates
= SNDRV_PCM_RATE_48000
,
943 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
947 .name
= "iDisp1 Pin",
948 .ops
= &skl_link_dai_ops
,
950 .stream_name
= "iDisp1 Tx",
951 .channels_min
= HDA_STEREO
,
953 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|SNDRV_PCM_RATE_48000
,
954 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
955 SNDRV_PCM_FMTBIT_S24_LE
,
959 .name
= "iDisp2 Pin",
960 .ops
= &skl_link_dai_ops
,
962 .stream_name
= "iDisp2 Tx",
963 .channels_min
= HDA_STEREO
,
965 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|
966 SNDRV_PCM_RATE_48000
,
967 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
968 SNDRV_PCM_FMTBIT_S24_LE
,
972 .name
= "iDisp3 Pin",
973 .ops
= &skl_link_dai_ops
,
975 .stream_name
= "iDisp3 Tx",
976 .channels_min
= HDA_STEREO
,
978 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|
979 SNDRV_PCM_RATE_48000
,
980 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
981 SNDRV_PCM_FMTBIT_S24_LE
,
985 .name
= "DMIC01 Pin",
986 .ops
= &skl_dmic_dai_ops
,
988 .stream_name
= "DMIC01 Rx",
989 .channels_min
= HDA_MONO
,
990 .channels_max
= HDA_QUAD
,
991 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
992 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
996 .name
= "DMIC16k Pin",
997 .ops
= &skl_dmic_dai_ops
,
999 .stream_name
= "DMIC16k Rx",
1000 .channels_min
= HDA_MONO
,
1001 .channels_max
= HDA_QUAD
,
1002 .rates
= SNDRV_PCM_RATE_16000
,
1003 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
1007 .name
= "Analog CPU DAI",
1008 .ops
= &skl_link_dai_ops
,
1010 .stream_name
= "Analog CPU Playback",
1011 .channels_min
= HDA_MONO
,
1012 .channels_max
= HDA_MAX
,
1013 .rates
= SNDRV_PCM_RATE_8000_192000
,
1014 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
1015 SNDRV_PCM_FMTBIT_S32_LE
,
1018 .stream_name
= "Analog CPU Capture",
1019 .channels_min
= HDA_MONO
,
1020 .channels_max
= HDA_MAX
,
1021 .rates
= SNDRV_PCM_RATE_8000_192000
,
1022 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
1023 SNDRV_PCM_FMTBIT_S32_LE
,
1027 .name
= "Alt Analog CPU DAI",
1028 .ops
= &skl_link_dai_ops
,
1030 .stream_name
= "Alt Analog CPU Playback",
1031 .channels_min
= HDA_MONO
,
1032 .channels_max
= HDA_MAX
,
1033 .rates
= SNDRV_PCM_RATE_8000_192000
,
1034 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
1035 SNDRV_PCM_FMTBIT_S32_LE
,
1038 .stream_name
= "Alt Analog CPU Capture",
1039 .channels_min
= HDA_MONO
,
1040 .channels_max
= HDA_MAX
,
1041 .rates
= SNDRV_PCM_RATE_8000_192000
,
1042 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
1043 SNDRV_PCM_FMTBIT_S32_LE
,
1047 .name
= "Digital CPU DAI",
1048 .ops
= &skl_link_dai_ops
,
1050 .stream_name
= "Digital CPU Playback",
1051 .channels_min
= HDA_MONO
,
1052 .channels_max
= HDA_MAX
,
1053 .rates
= SNDRV_PCM_RATE_8000_192000
,
1054 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
1055 SNDRV_PCM_FMTBIT_S32_LE
,
1058 .stream_name
= "Digital CPU Capture",
1059 .channels_min
= HDA_MONO
,
1060 .channels_max
= HDA_MAX
,
1061 .rates
= SNDRV_PCM_RATE_8000_192000
,
1062 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
1063 SNDRV_PCM_FMTBIT_S32_LE
,
1068 int skl_dai_load(struct snd_soc_component
*cmp
, int index
,
1069 struct snd_soc_dai_driver
*dai_drv
,
1070 struct snd_soc_tplg_pcm
*pcm
, struct snd_soc_dai
*dai
)
1072 dai_drv
->ops
= &skl_pcm_dai_ops
;
1077 static int skl_platform_soc_open(struct snd_soc_component
*component
,
1078 struct snd_pcm_substream
*substream
)
1080 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
1081 struct snd_soc_dai_link
*dai_link
= rtd
->dai_link
;
1083 dev_dbg(rtd
->cpu_dai
->dev
, "In %s:%s\n", __func__
,
1084 dai_link
->cpus
->dai_name
);
1086 snd_soc_set_runtime_hwparams(substream
, &azx_pcm_hw
);
1091 static int skl_coupled_trigger(struct snd_pcm_substream
*substream
,
1094 struct hdac_bus
*bus
= get_bus_ctx(substream
);
1095 struct hdac_ext_stream
*stream
;
1096 struct snd_pcm_substream
*s
;
1099 unsigned long cookie
;
1100 struct hdac_stream
*hstr
;
1102 stream
= get_hdac_ext_stream(substream
);
1103 hstr
= hdac_stream(stream
);
1105 dev_dbg(bus
->dev
, "In %s cmd=%d\n", __func__
, cmd
);
1107 if (!hstr
->prepared
)
1111 case SNDRV_PCM_TRIGGER_START
:
1112 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1113 case SNDRV_PCM_TRIGGER_RESUME
:
1117 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1118 case SNDRV_PCM_TRIGGER_SUSPEND
:
1119 case SNDRV_PCM_TRIGGER_STOP
:
1127 snd_pcm_group_for_each_entry(s
, substream
) {
1128 if (s
->pcm
->card
!= substream
->pcm
->card
)
1130 stream
= get_hdac_ext_stream(s
);
1131 sbits
|= 1 << hdac_stream(stream
)->index
;
1132 snd_pcm_trigger_done(s
, substream
);
1135 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
1137 /* first, set SYNC bits of corresponding streams */
1138 snd_hdac_stream_sync_trigger(hstr
, true, sbits
, AZX_REG_SSYNC
);
1140 snd_pcm_group_for_each_entry(s
, substream
) {
1141 if (s
->pcm
->card
!= substream
->pcm
->card
)
1143 stream
= get_hdac_ext_stream(s
);
1145 snd_hdac_stream_start(hdac_stream(stream
), true);
1147 snd_hdac_stream_stop(hdac_stream(stream
));
1149 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
1151 snd_hdac_stream_sync(hstr
, start
, sbits
);
1153 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
1155 /* reset SYNC bits */
1156 snd_hdac_stream_sync_trigger(hstr
, false, sbits
, AZX_REG_SSYNC
);
1158 snd_hdac_stream_timecounter_init(hstr
, sbits
);
1159 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
1164 static int skl_platform_soc_trigger(struct snd_soc_component
*component
,
1165 struct snd_pcm_substream
*substream
,
1168 struct hdac_bus
*bus
= get_bus_ctx(substream
);
1171 return skl_coupled_trigger(substream
, cmd
);
1176 static snd_pcm_uframes_t
skl_platform_soc_pointer(
1177 struct snd_soc_component
*component
,
1178 struct snd_pcm_substream
*substream
)
1180 struct hdac_ext_stream
*hstream
= get_hdac_ext_stream(substream
);
1181 struct hdac_bus
*bus
= get_bus_ctx(substream
);
1185 * Use DPIB for Playback stream as the periodic DMA Position-in-
1186 * Buffer Writes may be scheduled at the same time or later than
1187 * the MSI and does not guarantee to reflect the Position of the
1188 * last buffer that was transferred. Whereas DPIB register in
1189 * HAD space reflects the actual data that is transferred.
1190 * Use the position buffer for capture, as DPIB write gets
1191 * completed earlier than the actual data written to the DDR.
1193 * For capture stream following workaround is required to fix the
1194 * incorrect position reporting.
1196 * 1. Wait for 20us before reading the DMA position in buffer once
1197 * the interrupt is generated for stream completion as update happens
1198 * on the HDA frame boundary i.e. 20.833uSec.
1199 * 2. Read DPIB register to flush the DMA position value. This dummy
1200 * read is required to flush DMA position value.
1201 * 3. Read the DMA Position-in-Buffer. This value now will be equal to
1202 * or greater than period boundary.
1205 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1206 pos
= readl(bus
->remap_addr
+ AZX_REG_VS_SDXDPIB_XBASE
+
1207 (AZX_REG_VS_SDXDPIB_XINTERVAL
*
1208 hdac_stream(hstream
)->index
));
1211 readl(bus
->remap_addr
+
1212 AZX_REG_VS_SDXDPIB_XBASE
+
1213 (AZX_REG_VS_SDXDPIB_XINTERVAL
*
1214 hdac_stream(hstream
)->index
));
1215 pos
= snd_hdac_stream_get_pos_posbuf(hdac_stream(hstream
));
1218 if (pos
>= hdac_stream(hstream
)->bufsize
)
1221 return bytes_to_frames(substream
->runtime
, pos
);
1224 static int skl_platform_soc_mmap(struct snd_soc_component
*component
,
1225 struct snd_pcm_substream
*substream
,
1226 struct vm_area_struct
*area
)
1228 return snd_pcm_lib_default_mmap(substream
, area
);
1231 static u64
skl_adjust_codec_delay(struct snd_pcm_substream
*substream
,
1234 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
1235 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1236 u64 codec_frames
, codec_nsecs
;
1238 if (!codec_dai
->driver
->ops
->delay
)
1241 codec_frames
= codec_dai
->driver
->ops
->delay(substream
, codec_dai
);
1242 codec_nsecs
= div_u64(codec_frames
* 1000000000LL,
1243 substream
->runtime
->rate
);
1245 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
1246 return nsec
+ codec_nsecs
;
1248 return (nsec
> codec_nsecs
) ? nsec
- codec_nsecs
: 0;
1251 static int skl_platform_soc_get_time_info(
1252 struct snd_soc_component
*component
,
1253 struct snd_pcm_substream
*substream
,
1254 struct timespec64
*system_ts
, struct timespec64
*audio_ts
,
1255 struct snd_pcm_audio_tstamp_config
*audio_tstamp_config
,
1256 struct snd_pcm_audio_tstamp_report
*audio_tstamp_report
)
1258 struct hdac_ext_stream
*sstream
= get_hdac_ext_stream(substream
);
1259 struct hdac_stream
*hstr
= hdac_stream(sstream
);
1262 if ((substream
->runtime
->hw
.info
& SNDRV_PCM_INFO_HAS_LINK_ATIME
) &&
1263 (audio_tstamp_config
->type_requested
== SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK
)) {
1265 snd_pcm_gettime(substream
->runtime
, system_ts
);
1267 nsec
= timecounter_read(&hstr
->tc
);
1268 nsec
= div_u64(nsec
, 3); /* can be optimized */
1269 if (audio_tstamp_config
->report_delay
)
1270 nsec
= skl_adjust_codec_delay(substream
, nsec
);
1272 *audio_ts
= ns_to_timespec64(nsec
);
1274 audio_tstamp_report
->actual_type
= SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK
;
1275 audio_tstamp_report
->accuracy_report
= 1; /* rest of struct is valid */
1276 audio_tstamp_report
->accuracy
= 42; /* 24MHzWallClk == 42ns resolution */
1279 audio_tstamp_report
->actual_type
= SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT
;
1285 #define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
1287 static int skl_platform_soc_new(struct snd_soc_component
*component
,
1288 struct snd_soc_pcm_runtime
*rtd
)
1290 struct snd_soc_dai
*dai
= rtd
->cpu_dai
;
1291 struct hdac_bus
*bus
= dev_get_drvdata(dai
->dev
);
1292 struct snd_pcm
*pcm
= rtd
->pcm
;
1294 struct skl_dev
*skl
= bus_to_skl(bus
);
1296 if (dai
->driver
->playback
.channels_min
||
1297 dai
->driver
->capture
.channels_min
) {
1298 /* buffer pre-allocation */
1299 size
= CONFIG_SND_HDA_PREALLOC_SIZE
* 1024;
1300 if (size
> MAX_PREALLOC_SIZE
)
1301 size
= MAX_PREALLOC_SIZE
;
1302 snd_pcm_set_managed_buffer_all(pcm
,
1303 SNDRV_DMA_TYPE_DEV_SG
,
1305 size
, MAX_PREALLOC_SIZE
);
1311 static int skl_get_module_info(struct skl_dev
*skl
,
1312 struct skl_module_cfg
*mconfig
)
1314 struct skl_module_inst_id
*pin_id
;
1315 guid_t
*uuid_mod
, *uuid_tplg
;
1316 struct skl_module
*skl_module
;
1317 struct uuid_module
*module
;
1320 uuid_mod
= (guid_t
*)mconfig
->guid
;
1322 if (list_empty(&skl
->uuid_list
)) {
1323 dev_err(skl
->dev
, "Module list is empty\n");
1327 list_for_each_entry(module
, &skl
->uuid_list
, list
) {
1328 if (guid_equal(uuid_mod
, &module
->uuid
)) {
1329 mconfig
->id
.module_id
= module
->id
;
1330 if (mconfig
->module
)
1331 mconfig
->module
->loadable
= module
->is_loadable
;
1340 uuid_mod
= &module
->uuid
;
1342 for (i
= 0; i
< skl
->nr_modules
; i
++) {
1343 skl_module
= skl
->modules
[i
];
1344 uuid_tplg
= &skl_module
->uuid
;
1345 if (guid_equal(uuid_mod
, uuid_tplg
)) {
1346 mconfig
->module
= skl_module
;
1351 if (skl
->nr_modules
&& ret
)
1354 list_for_each_entry(module
, &skl
->uuid_list
, list
) {
1355 for (i
= 0; i
< MAX_IN_QUEUE
; i
++) {
1356 pin_id
= &mconfig
->m_in_pin
[i
].id
;
1357 if (guid_equal(&pin_id
->mod_uuid
, &module
->uuid
))
1358 pin_id
->module_id
= module
->id
;
1361 for (i
= 0; i
< MAX_OUT_QUEUE
; i
++) {
1362 pin_id
= &mconfig
->m_out_pin
[i
].id
;
1363 if (guid_equal(&pin_id
->mod_uuid
, &module
->uuid
))
1364 pin_id
->module_id
= module
->id
;
1371 static int skl_populate_modules(struct skl_dev
*skl
)
1373 struct skl_pipeline
*p
;
1374 struct skl_pipe_module
*m
;
1375 struct snd_soc_dapm_widget
*w
;
1376 struct skl_module_cfg
*mconfig
;
1379 list_for_each_entry(p
, &skl
->ppl_list
, node
) {
1380 list_for_each_entry(m
, &p
->pipe
->w_list
, node
) {
1384 ret
= skl_get_module_info(skl
, mconfig
);
1387 "query module info failed\n");
1391 skl_tplg_add_moduleid_in_bind_params(skl
, w
);
1398 static int skl_platform_soc_probe(struct snd_soc_component
*component
)
1400 struct hdac_bus
*bus
= dev_get_drvdata(component
->dev
);
1401 struct skl_dev
*skl
= bus_to_skl(bus
);
1402 const struct skl_dsp_ops
*ops
;
1405 pm_runtime_get_sync(component
->dev
);
1407 skl
->component
= component
;
1410 skl
->debugfs
= skl_debugfs_init(skl
);
1412 ret
= skl_tplg_init(component
, bus
);
1414 dev_err(component
->dev
, "Failed to init topology!\n");
1418 /* load the firmwares, since all is set */
1419 ops
= skl_get_dsp_ops(skl
->pci
->device
);
1424 * Disable dynamic clock and power gating during firmware
1425 * and library download
1427 skl
->enable_miscbdcge(component
->dev
, false);
1428 skl
->clock_power_gating(component
->dev
, false);
1430 ret
= ops
->init_fw(component
->dev
, skl
);
1431 skl
->enable_miscbdcge(component
->dev
, true);
1432 skl
->clock_power_gating(component
->dev
, true);
1434 dev_err(component
->dev
, "Failed to boot first fw: %d\n", ret
);
1437 skl_populate_modules(skl
);
1438 skl
->update_d0i3c
= skl_update_d0i3c
;
1440 if (skl
->cfg
.astate_cfg
!= NULL
) {
1441 skl_dsp_set_astate_cfg(skl
,
1442 skl
->cfg
.astate_cfg
->count
,
1443 skl
->cfg
.astate_cfg
);
1446 pm_runtime_mark_last_busy(component
->dev
);
1447 pm_runtime_put_autosuspend(component
->dev
);
1452 static void skl_platform_soc_remove(struct snd_soc_component
*component
)
1454 struct hdac_bus
*bus
= dev_get_drvdata(component
->dev
);
1455 struct skl_dev
*skl
= bus_to_skl(bus
);
1457 skl_tplg_exit(component
, bus
);
1459 skl_debugfs_exit(skl
);
1462 static const struct snd_soc_component_driver skl_component
= {
1464 .probe
= skl_platform_soc_probe
,
1465 .remove
= skl_platform_soc_remove
,
1466 .open
= skl_platform_soc_open
,
1467 .trigger
= skl_platform_soc_trigger
,
1468 .pointer
= skl_platform_soc_pointer
,
1469 .get_time_info
= skl_platform_soc_get_time_info
,
1470 .mmap
= skl_platform_soc_mmap
,
1471 .pcm_construct
= skl_platform_soc_new
,
1472 .module_get_upon_open
= 1, /* increment refcount when a pcm is opened */
1475 int skl_platform_register(struct device
*dev
)
1478 struct snd_soc_dai_driver
*dais
;
1479 int num_dais
= ARRAY_SIZE(skl_platform_dai
);
1480 struct hdac_bus
*bus
= dev_get_drvdata(dev
);
1481 struct skl_dev
*skl
= bus_to_skl(bus
);
1483 skl
->dais
= kmemdup(skl_platform_dai
, sizeof(skl_platform_dai
),
1490 if (!skl
->use_tplg_pcm
) {
1491 dais
= krealloc(skl
->dais
, sizeof(skl_fe_dai
) +
1492 sizeof(skl_platform_dai
), GFP_KERNEL
);
1499 memcpy(&skl
->dais
[ARRAY_SIZE(skl_platform_dai
)], skl_fe_dai
,
1500 sizeof(skl_fe_dai
));
1501 num_dais
+= ARRAY_SIZE(skl_fe_dai
);
1504 ret
= devm_snd_soc_register_component(dev
, &skl_component
,
1505 skl
->dais
, num_dais
);
1507 dev_err(dev
, "soc component registration failed %d\n", ret
);
1512 int skl_platform_unregister(struct device
*dev
)
1514 struct hdac_bus
*bus
= dev_get_drvdata(dev
);
1515 struct skl_dev
*skl
= bus_to_skl(bus
);
1516 struct skl_module_deferred_bind
*modules
, *tmp
;
1518 if (!list_empty(&skl
->bind_list
)) {
1519 list_for_each_entry_safe(modules
, tmp
, &skl
->bind_list
, node
) {
1520 list_del(&modules
->node
);