2 * skl-pcm.c -ASoC HDA Platform driver file implementing PCM functionality
4 * Copyright (C) 2014-2015 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 #include <linux/pci.h>
23 #include <linux/pm_runtime.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
27 #include "skl-topology.h"
28 #include "skl-sst-dsp.h"
29 #include "skl-sst-ipc.h"
35 static struct snd_pcm_hardware azx_pcm_hw
= {
36 .info
= (SNDRV_PCM_INFO_MMAP
|
37 SNDRV_PCM_INFO_INTERLEAVED
|
38 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
39 SNDRV_PCM_INFO_MMAP_VALID
|
40 SNDRV_PCM_INFO_PAUSE
|
41 SNDRV_PCM_INFO_RESUME
|
42 SNDRV_PCM_INFO_SYNC_START
|
43 SNDRV_PCM_INFO_HAS_WALL_CLOCK
| /* legacy */
44 SNDRV_PCM_INFO_HAS_LINK_ATIME
|
45 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP
),
46 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
47 SNDRV_PCM_FMTBIT_S32_LE
|
48 SNDRV_PCM_FMTBIT_S24_LE
,
49 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
|
55 .buffer_bytes_max
= AZX_MAX_BUF_SIZE
,
56 .period_bytes_min
= 128,
57 .period_bytes_max
= AZX_MAX_BUF_SIZE
/ 2,
59 .periods_max
= AZX_MAX_FRAG
,
64 struct hdac_ext_stream
*get_hdac_ext_stream(struct snd_pcm_substream
*substream
)
66 return substream
->runtime
->private_data
;
69 static struct hdac_ext_bus
*get_bus_ctx(struct snd_pcm_substream
*substream
)
71 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
72 struct hdac_stream
*hstream
= hdac_stream(stream
);
73 struct hdac_bus
*bus
= hstream
->bus
;
75 return hbus_to_ebus(bus
);
78 static int skl_substream_alloc_pages(struct hdac_ext_bus
*ebus
,
79 struct snd_pcm_substream
*substream
,
82 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
84 hdac_stream(stream
)->bufsize
= 0;
85 hdac_stream(stream
)->period_bytes
= 0;
86 hdac_stream(stream
)->format_val
= 0;
88 return snd_pcm_lib_malloc_pages(substream
, size
);
91 static int skl_substream_free_pages(struct hdac_bus
*bus
,
92 struct snd_pcm_substream
*substream
)
94 return snd_pcm_lib_free_pages(substream
);
97 static void skl_set_pcm_constrains(struct hdac_ext_bus
*ebus
,
98 struct snd_pcm_runtime
*runtime
)
100 snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
);
102 /* avoid wrap-around with wall-clock */
103 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_TIME
,
107 static enum hdac_ext_stream_type
skl_get_host_stream_type(struct hdac_ext_bus
*ebus
)
109 if ((ebus_to_hbus(ebus
))->ppcap
)
110 return HDAC_EXT_STREAM_TYPE_HOST
;
112 return HDAC_EXT_STREAM_TYPE_COUPLED
;
116 * check if the stream opened is marked as ignore_suspend by machine, if so
117 * then enable suspend_active refcount
119 * The count supend_active does not need lock as it is used in open/close
120 * and suspend context
122 static void skl_set_suspend_active(struct snd_pcm_substream
*substream
,
123 struct snd_soc_dai
*dai
, bool enable
)
125 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
126 struct snd_soc_dapm_widget
*w
;
127 struct skl
*skl
= ebus_to_skl(ebus
);
129 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
130 w
= dai
->playback_widget
;
132 w
= dai
->capture_widget
;
134 if (w
->ignore_suspend
&& enable
)
135 skl
->supend_active
++;
136 else if (w
->ignore_suspend
&& !enable
)
137 skl
->supend_active
--;
140 static int skl_pcm_open(struct snd_pcm_substream
*substream
,
141 struct snd_soc_dai
*dai
)
143 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
144 struct hdac_ext_stream
*stream
;
145 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
146 struct skl_dma_params
*dma_params
;
147 struct skl
*skl
= get_skl_ctx(dai
->dev
);
148 struct skl_module_cfg
*mconfig
;
150 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
152 stream
= snd_hdac_ext_stream_assign(ebus
, substream
,
153 skl_get_host_stream_type(ebus
));
157 skl_set_pcm_constrains(ebus
, runtime
);
160 * disable WALLCLOCK timestamps for capture streams
161 * until we figure out how to handle digital inputs
163 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
) {
164 runtime
->hw
.info
&= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK
; /* legacy */
165 runtime
->hw
.info
&= ~SNDRV_PCM_INFO_HAS_LINK_ATIME
;
168 runtime
->private_data
= stream
;
170 dma_params
= kzalloc(sizeof(*dma_params
), GFP_KERNEL
);
174 dma_params
->stream_tag
= hdac_stream(stream
)->stream_tag
;
175 snd_soc_dai_set_dma_data(dai
, substream
, dma_params
);
177 dev_dbg(dai
->dev
, "stream tag set in dma params=%d\n",
178 dma_params
->stream_tag
);
179 skl_set_suspend_active(substream
, dai
, true);
180 snd_pcm_set_sync(substream
);
182 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
183 skl_tplg_d0i3_get(skl
, mconfig
->d0i3_caps
);
188 static int skl_get_format(struct snd_pcm_substream
*substream
,
189 struct snd_soc_dai
*dai
)
191 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
192 struct skl_dma_params
*dma_params
;
193 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
196 if ((ebus_to_hbus(ebus
))->ppcap
) {
197 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
199 format_val
= snd_hdac_calc_stream_format(runtime
->rate
,
204 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
206 dma_params
= snd_soc_dai_get_dma_data(codec_dai
, substream
);
208 format_val
= dma_params
->format
;
214 static int skl_be_prepare(struct snd_pcm_substream
*substream
,
215 struct snd_soc_dai
*dai
)
217 struct skl
*skl
= get_skl_ctx(dai
->dev
);
218 struct skl_sst
*ctx
= skl
->skl_sst
;
219 struct skl_module_cfg
*mconfig
;
221 if (dai
->playback_widget
->power
|| dai
->capture_widget
->power
)
224 mconfig
= skl_tplg_be_get_cpr_module(dai
, substream
->stream
);
228 return skl_dsp_set_dma_control(ctx
, mconfig
);
231 static int skl_pcm_prepare(struct snd_pcm_substream
*substream
,
232 struct snd_soc_dai
*dai
)
234 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
235 struct skl
*skl
= get_skl_ctx(dai
->dev
);
236 unsigned int format_val
;
238 struct skl_module_cfg
*mconfig
;
240 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
242 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
244 format_val
= skl_get_format(substream
, dai
);
245 dev_dbg(dai
->dev
, "stream_tag=%d formatvalue=%d\n",
246 hdac_stream(stream
)->stream_tag
, format_val
);
247 snd_hdac_stream_reset(hdac_stream(stream
));
249 /* In case of XRUN recovery, reset the FW pipe to clean state */
250 if (mconfig
&& (substream
->runtime
->status
->state
==
251 SNDRV_PCM_STATE_XRUN
))
252 skl_reset_pipe(skl
->skl_sst
, mconfig
->pipe
);
254 err
= snd_hdac_stream_set_params(hdac_stream(stream
), format_val
);
258 err
= snd_hdac_stream_setup(hdac_stream(stream
));
262 hdac_stream(stream
)->prepared
= 1;
267 static int skl_pcm_hw_params(struct snd_pcm_substream
*substream
,
268 struct snd_pcm_hw_params
*params
,
269 struct snd_soc_dai
*dai
)
271 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
272 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
273 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
274 struct skl_pipe_params p_params
= {0};
275 struct skl_module_cfg
*m_cfg
;
278 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
279 ret
= skl_substream_alloc_pages(ebus
, substream
,
280 params_buffer_bytes(params
));
284 dev_dbg(dai
->dev
, "format_val, rate=%d, ch=%d, format=%d\n",
285 runtime
->rate
, runtime
->channels
, runtime
->format
);
287 dma_id
= hdac_stream(stream
)->stream_tag
- 1;
288 dev_dbg(dai
->dev
, "dma_id=%d\n", dma_id
);
290 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
291 p_params
.ch
= params_channels(params
);
292 p_params
.s_freq
= params_rate(params
);
293 p_params
.host_dma_id
= dma_id
;
294 p_params
.stream
= substream
->stream
;
296 m_cfg
= skl_tplg_fe_get_cpr_module(dai
, p_params
.stream
);
298 skl_tplg_update_pipe_params(dai
->dev
, m_cfg
, &p_params
);
303 static void skl_pcm_close(struct snd_pcm_substream
*substream
,
304 struct snd_soc_dai
*dai
)
306 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
307 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
308 struct skl_dma_params
*dma_params
= NULL
;
309 struct skl
*skl
= ebus_to_skl(ebus
);
310 struct skl_module_cfg
*mconfig
;
312 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
314 snd_hdac_ext_stream_release(stream
, skl_get_host_stream_type(ebus
));
316 dma_params
= snd_soc_dai_get_dma_data(dai
, substream
);
318 * now we should set this to NULL as we are freeing by the
321 snd_soc_dai_set_dma_data(dai
, substream
, NULL
);
322 skl_set_suspend_active(substream
, dai
, false);
325 * check if close is for "Reference Pin" and set back the
326 * CGCTL.MISCBDCGE if disabled by driver
328 if (!strncmp(dai
->name
, "Reference Pin", 13) &&
329 skl
->skl_sst
->miscbdcg_disabled
) {
330 skl
->skl_sst
->enable_miscbdcge(dai
->dev
, true);
331 skl
->skl_sst
->miscbdcg_disabled
= false;
334 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
335 skl_tplg_d0i3_put(skl
, mconfig
->d0i3_caps
);
340 static int skl_pcm_hw_free(struct snd_pcm_substream
*substream
,
341 struct snd_soc_dai
*dai
)
343 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
344 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
346 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
348 snd_hdac_stream_cleanup(hdac_stream(stream
));
349 hdac_stream(stream
)->prepared
= 0;
351 return skl_substream_free_pages(ebus_to_hbus(ebus
), substream
);
354 static int skl_be_hw_params(struct snd_pcm_substream
*substream
,
355 struct snd_pcm_hw_params
*params
,
356 struct snd_soc_dai
*dai
)
358 struct skl_pipe_params p_params
= {0};
360 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
361 p_params
.ch
= params_channels(params
);
362 p_params
.s_freq
= params_rate(params
);
363 p_params
.stream
= substream
->stream
;
365 return skl_tplg_be_update_params(dai
, &p_params
);
368 static int skl_decoupled_trigger(struct snd_pcm_substream
*substream
,
371 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
372 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
373 struct hdac_ext_stream
*stream
;
375 unsigned long cookie
;
376 struct hdac_stream
*hstr
;
378 stream
= get_hdac_ext_stream(substream
);
379 hstr
= hdac_stream(stream
);
385 case SNDRV_PCM_TRIGGER_START
:
386 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
387 case SNDRV_PCM_TRIGGER_RESUME
:
391 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
392 case SNDRV_PCM_TRIGGER_SUSPEND
:
393 case SNDRV_PCM_TRIGGER_STOP
:
401 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
404 snd_hdac_stream_start(hdac_stream(stream
), true);
405 snd_hdac_stream_timecounter_init(hstr
, 0);
407 snd_hdac_stream_stop(hdac_stream(stream
));
410 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
415 static int skl_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
,
416 struct snd_soc_dai
*dai
)
418 struct skl
*skl
= get_skl_ctx(dai
->dev
);
419 struct skl_sst
*ctx
= skl
->skl_sst
;
420 struct skl_module_cfg
*mconfig
;
421 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
422 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
423 struct snd_soc_dapm_widget
*w
;
426 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
430 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
431 w
= dai
->playback_widget
;
433 w
= dai
->capture_widget
;
436 case SNDRV_PCM_TRIGGER_RESUME
:
437 if (!w
->ignore_suspend
) {
438 skl_pcm_prepare(substream
, dai
);
440 * enable DMA Resume enable bit for the stream, set the
441 * dpib & lpib position to resume before starting the
444 snd_hdac_ext_stream_drsm_enable(ebus
, true,
445 hdac_stream(stream
)->index
);
446 snd_hdac_ext_stream_set_dpibr(ebus
, stream
,
448 snd_hdac_ext_stream_set_lpib(stream
, stream
->lpib
);
451 case SNDRV_PCM_TRIGGER_START
:
452 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
454 * Start HOST DMA and Start FE Pipe.This is to make sure that
455 * there are no underrun/overrun in the case when the FE
456 * pipeline is started but there is a delay in starting the
457 * DMA channel on the host.
459 snd_hdac_ext_stream_decouple(ebus
, stream
, true);
460 ret
= skl_decoupled_trigger(substream
, cmd
);
463 return skl_run_pipe(ctx
, mconfig
->pipe
);
466 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
467 case SNDRV_PCM_TRIGGER_SUSPEND
:
468 case SNDRV_PCM_TRIGGER_STOP
:
470 * Stop FE Pipe first and stop DMA. This is to make sure that
471 * there are no underrun/overrun in the case if there is a delay
472 * between the two operations.
474 ret
= skl_stop_pipe(ctx
, mconfig
->pipe
);
478 ret
= skl_decoupled_trigger(substream
, cmd
);
479 if ((cmd
== SNDRV_PCM_TRIGGER_SUSPEND
) && !w
->ignore_suspend
) {
480 /* save the dpib and lpib positions */
481 stream
->dpib
= readl(ebus
->bus
.remap_addr
+
482 AZX_REG_VS_SDXDPIB_XBASE
+
483 (AZX_REG_VS_SDXDPIB_XINTERVAL
*
484 hdac_stream(stream
)->index
));
486 stream
->lpib
= snd_hdac_stream_get_pos_lpib(
487 hdac_stream(stream
));
488 snd_hdac_ext_stream_decouple(ebus
, stream
, false);
499 static int skl_link_hw_params(struct snd_pcm_substream
*substream
,
500 struct snd_pcm_hw_params
*params
,
501 struct snd_soc_dai
*dai
)
503 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
504 struct hdac_ext_stream
*link_dev
;
505 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
506 struct hdac_ext_dma_params
*dma_params
;
507 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
508 struct skl_pipe_params p_params
= {0};
510 link_dev
= snd_hdac_ext_stream_assign(ebus
, substream
,
511 HDAC_EXT_STREAM_TYPE_LINK
);
515 snd_soc_dai_set_dma_data(dai
, substream
, (void *)link_dev
);
517 /* set the stream tag in the codec dai dma params */
518 dma_params
= snd_soc_dai_get_dma_data(codec_dai
, substream
);
520 dma_params
->stream_tag
= hdac_stream(link_dev
)->stream_tag
;
522 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
523 p_params
.ch
= params_channels(params
);
524 p_params
.s_freq
= params_rate(params
);
525 p_params
.stream
= substream
->stream
;
526 p_params
.link_dma_id
= hdac_stream(link_dev
)->stream_tag
- 1;
528 return skl_tplg_be_update_params(dai
, &p_params
);
531 static int skl_link_pcm_prepare(struct snd_pcm_substream
*substream
,
532 struct snd_soc_dai
*dai
)
534 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
535 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
536 struct hdac_ext_stream
*link_dev
=
537 snd_soc_dai_get_dma_data(dai
, substream
);
538 unsigned int format_val
= 0;
539 struct skl_dma_params
*dma_params
;
540 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
541 struct hdac_ext_link
*link
;
542 struct skl
*skl
= get_skl_ctx(dai
->dev
);
543 struct skl_module_cfg
*mconfig
= NULL
;
545 dma_params
= (struct skl_dma_params
*)
546 snd_soc_dai_get_dma_data(codec_dai
, substream
);
548 format_val
= dma_params
->format
;
549 dev_dbg(dai
->dev
, "stream_tag=%d formatvalue=%d codec_dai_name=%s\n",
550 hdac_stream(link_dev
)->stream_tag
, format_val
, codec_dai
->name
);
552 link
= snd_hdac_ext_bus_get_link(ebus
, rtd
->codec
->component
.name
);
556 snd_hdac_ext_link_stream_reset(link_dev
);
558 /* In case of XRUN recovery, reset the FW pipe to clean state */
559 mconfig
= skl_tplg_be_get_cpr_module(dai
, substream
->stream
);
560 if (mconfig
&& (substream
->runtime
->status
->state
==
561 SNDRV_PCM_STATE_XRUN
))
562 skl_reset_pipe(skl
->skl_sst
, mconfig
->pipe
);
564 snd_hdac_ext_link_stream_setup(link_dev
, format_val
);
566 snd_hdac_ext_link_set_stream_id(link
, hdac_stream(link_dev
)->stream_tag
);
567 link_dev
->link_prepared
= 1;
572 static int skl_link_pcm_trigger(struct snd_pcm_substream
*substream
,
573 int cmd
, struct snd_soc_dai
*dai
)
575 struct hdac_ext_stream
*link_dev
=
576 snd_soc_dai_get_dma_data(dai
, substream
);
577 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
578 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
580 dev_dbg(dai
->dev
, "In %s cmd=%d\n", __func__
, cmd
);
582 case SNDRV_PCM_TRIGGER_RESUME
:
583 skl_link_pcm_prepare(substream
, dai
);
584 case SNDRV_PCM_TRIGGER_START
:
585 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
586 snd_hdac_ext_stream_decouple(ebus
, stream
, true);
587 snd_hdac_ext_link_stream_start(link_dev
);
590 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
591 case SNDRV_PCM_TRIGGER_SUSPEND
:
592 case SNDRV_PCM_TRIGGER_STOP
:
593 snd_hdac_ext_link_stream_clear(link_dev
);
594 if (cmd
== SNDRV_PCM_TRIGGER_SUSPEND
)
595 snd_hdac_ext_stream_decouple(ebus
, stream
, false);
604 static int skl_link_hw_free(struct snd_pcm_substream
*substream
,
605 struct snd_soc_dai
*dai
)
607 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
608 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
609 struct hdac_ext_stream
*link_dev
=
610 snd_soc_dai_get_dma_data(dai
, substream
);
611 struct hdac_ext_link
*link
;
613 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
615 link_dev
->link_prepared
= 0;
617 link
= snd_hdac_ext_bus_get_link(ebus
, rtd
->codec
->component
.name
);
621 snd_hdac_ext_link_clear_stream_id(link
, hdac_stream(link_dev
)->stream_tag
);
622 snd_hdac_ext_stream_release(link_dev
, HDAC_EXT_STREAM_TYPE_LINK
);
626 static struct snd_soc_dai_ops skl_pcm_dai_ops
= {
627 .startup
= skl_pcm_open
,
628 .shutdown
= skl_pcm_close
,
629 .prepare
= skl_pcm_prepare
,
630 .hw_params
= skl_pcm_hw_params
,
631 .hw_free
= skl_pcm_hw_free
,
632 .trigger
= skl_pcm_trigger
,
635 static struct snd_soc_dai_ops skl_dmic_dai_ops
= {
636 .hw_params
= skl_be_hw_params
,
639 static struct snd_soc_dai_ops skl_be_ssp_dai_ops
= {
640 .hw_params
= skl_be_hw_params
,
641 .prepare
= skl_be_prepare
,
644 static struct snd_soc_dai_ops skl_link_dai_ops
= {
645 .prepare
= skl_link_pcm_prepare
,
646 .hw_params
= skl_link_hw_params
,
647 .hw_free
= skl_link_hw_free
,
648 .trigger
= skl_link_pcm_trigger
,
651 static struct snd_soc_dai_driver skl_platform_dai
[] = {
653 .name
= "System Pin",
654 .ops
= &skl_pcm_dai_ops
,
656 .stream_name
= "System Playback",
657 .channels_min
= HDA_MONO
,
658 .channels_max
= HDA_STEREO
,
659 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
| SNDRV_PCM_RATE_8000
,
660 .formats
= SNDRV_PCM_FMTBIT_S16_LE
|
661 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S32_LE
,
664 .stream_name
= "System Capture",
665 .channels_min
= HDA_MONO
,
666 .channels_max
= HDA_STEREO
,
667 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
668 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
672 .name
= "Reference Pin",
673 .ops
= &skl_pcm_dai_ops
,
675 .stream_name
= "Reference Capture",
676 .channels_min
= HDA_MONO
,
677 .channels_max
= HDA_QUAD
,
678 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
679 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
683 .name
= "Deepbuffer Pin",
684 .ops
= &skl_pcm_dai_ops
,
686 .stream_name
= "Deepbuffer Playback",
687 .channels_min
= HDA_STEREO
,
688 .channels_max
= HDA_STEREO
,
689 .rates
= SNDRV_PCM_RATE_48000
,
690 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
694 .name
= "LowLatency Pin",
695 .ops
= &skl_pcm_dai_ops
,
697 .stream_name
= "Low Latency Playback",
698 .channels_min
= HDA_STEREO
,
699 .channels_max
= HDA_STEREO
,
700 .rates
= SNDRV_PCM_RATE_48000
,
701 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
706 .ops
= &skl_pcm_dai_ops
,
708 .stream_name
= "DMIC Capture",
709 .channels_min
= HDA_MONO
,
710 .channels_max
= HDA_QUAD
,
711 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
712 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
717 .ops
= &skl_pcm_dai_ops
,
719 .stream_name
= "HDMI1 Playback",
720 .channels_min
= HDA_STEREO
,
722 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
723 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
724 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
725 SNDRV_PCM_RATE_192000
,
726 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
727 SNDRV_PCM_FMTBIT_S32_LE
,
732 .ops
= &skl_pcm_dai_ops
,
734 .stream_name
= "HDMI2 Playback",
735 .channels_min
= HDA_STEREO
,
737 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
738 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
739 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
740 SNDRV_PCM_RATE_192000
,
741 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
742 SNDRV_PCM_FMTBIT_S32_LE
,
747 .ops
= &skl_pcm_dai_ops
,
749 .stream_name
= "HDMI3 Playback",
750 .channels_min
= HDA_STEREO
,
752 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
753 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
754 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
755 SNDRV_PCM_RATE_192000
,
756 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
757 SNDRV_PCM_FMTBIT_S32_LE
,
764 .ops
= &skl_be_ssp_dai_ops
,
766 .stream_name
= "ssp0 Tx",
767 .channels_min
= HDA_STEREO
,
768 .channels_max
= HDA_STEREO
,
769 .rates
= SNDRV_PCM_RATE_48000
,
770 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
773 .stream_name
= "ssp0 Rx",
774 .channels_min
= HDA_STEREO
,
775 .channels_max
= HDA_STEREO
,
776 .rates
= SNDRV_PCM_RATE_48000
,
777 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
782 .ops
= &skl_be_ssp_dai_ops
,
784 .stream_name
= "ssp1 Tx",
785 .channels_min
= HDA_STEREO
,
786 .channels_max
= HDA_STEREO
,
787 .rates
= SNDRV_PCM_RATE_48000
,
788 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
791 .stream_name
= "ssp1 Rx",
792 .channels_min
= HDA_STEREO
,
793 .channels_max
= HDA_STEREO
,
794 .rates
= SNDRV_PCM_RATE_48000
,
795 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
800 .ops
= &skl_be_ssp_dai_ops
,
802 .stream_name
= "ssp2 Tx",
803 .channels_min
= HDA_STEREO
,
804 .channels_max
= HDA_STEREO
,
805 .rates
= SNDRV_PCM_RATE_48000
,
806 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
809 .stream_name
= "ssp2 Rx",
810 .channels_min
= HDA_STEREO
,
811 .channels_max
= HDA_STEREO
,
812 .rates
= SNDRV_PCM_RATE_48000
,
813 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
818 .ops
= &skl_be_ssp_dai_ops
,
820 .stream_name
= "ssp3 Tx",
821 .channels_min
= HDA_STEREO
,
822 .channels_max
= HDA_STEREO
,
823 .rates
= SNDRV_PCM_RATE_48000
,
824 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
827 .stream_name
= "ssp3 Rx",
828 .channels_min
= HDA_STEREO
,
829 .channels_max
= HDA_STEREO
,
830 .rates
= SNDRV_PCM_RATE_48000
,
831 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
836 .ops
= &skl_be_ssp_dai_ops
,
838 .stream_name
= "ssp4 Tx",
839 .channels_min
= HDA_STEREO
,
840 .channels_max
= HDA_STEREO
,
841 .rates
= SNDRV_PCM_RATE_48000
,
842 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
845 .stream_name
= "ssp4 Rx",
846 .channels_min
= HDA_STEREO
,
847 .channels_max
= HDA_STEREO
,
848 .rates
= SNDRV_PCM_RATE_48000
,
849 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
854 .ops
= &skl_be_ssp_dai_ops
,
856 .stream_name
= "ssp5 Tx",
857 .channels_min
= HDA_STEREO
,
858 .channels_max
= HDA_STEREO
,
859 .rates
= SNDRV_PCM_RATE_48000
,
860 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
863 .stream_name
= "ssp5 Rx",
864 .channels_min
= HDA_STEREO
,
865 .channels_max
= HDA_STEREO
,
866 .rates
= SNDRV_PCM_RATE_48000
,
867 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
871 .name
= "iDisp1 Pin",
872 .ops
= &skl_link_dai_ops
,
874 .stream_name
= "iDisp1 Tx",
875 .channels_min
= HDA_STEREO
,
877 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|SNDRV_PCM_RATE_48000
,
878 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
879 SNDRV_PCM_FMTBIT_S24_LE
,
883 .name
= "iDisp2 Pin",
884 .ops
= &skl_link_dai_ops
,
886 .stream_name
= "iDisp2 Tx",
887 .channels_min
= HDA_STEREO
,
889 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|
890 SNDRV_PCM_RATE_48000
,
891 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
892 SNDRV_PCM_FMTBIT_S24_LE
,
896 .name
= "iDisp3 Pin",
897 .ops
= &skl_link_dai_ops
,
899 .stream_name
= "iDisp3 Tx",
900 .channels_min
= HDA_STEREO
,
902 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|
903 SNDRV_PCM_RATE_48000
,
904 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
905 SNDRV_PCM_FMTBIT_S24_LE
,
909 .name
= "DMIC01 Pin",
910 .ops
= &skl_dmic_dai_ops
,
912 .stream_name
= "DMIC01 Rx",
913 .channels_min
= HDA_MONO
,
914 .channels_max
= HDA_QUAD
,
915 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
916 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
920 .name
= "HD-Codec Pin",
921 .ops
= &skl_link_dai_ops
,
923 .stream_name
= "HD-Codec Tx",
924 .channels_min
= HDA_STEREO
,
925 .channels_max
= HDA_STEREO
,
926 .rates
= SNDRV_PCM_RATE_48000
,
927 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
930 .stream_name
= "HD-Codec Rx",
931 .channels_min
= HDA_STEREO
,
932 .channels_max
= HDA_STEREO
,
933 .rates
= SNDRV_PCM_RATE_48000
,
934 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
939 static int skl_platform_open(struct snd_pcm_substream
*substream
)
941 struct snd_pcm_runtime
*runtime
;
942 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
943 struct snd_soc_dai_link
*dai_link
= rtd
->dai_link
;
945 dev_dbg(rtd
->cpu_dai
->dev
, "In %s:%s\n", __func__
,
946 dai_link
->cpu_dai_name
);
948 runtime
= substream
->runtime
;
949 snd_soc_set_runtime_hwparams(substream
, &azx_pcm_hw
);
954 static int skl_coupled_trigger(struct snd_pcm_substream
*substream
,
957 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
958 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
959 struct hdac_ext_stream
*stream
;
960 struct snd_pcm_substream
*s
;
963 unsigned long cookie
;
964 struct hdac_stream
*hstr
;
966 stream
= get_hdac_ext_stream(substream
);
967 hstr
= hdac_stream(stream
);
969 dev_dbg(bus
->dev
, "In %s cmd=%d\n", __func__
, cmd
);
975 case SNDRV_PCM_TRIGGER_START
:
976 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
977 case SNDRV_PCM_TRIGGER_RESUME
:
981 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
982 case SNDRV_PCM_TRIGGER_SUSPEND
:
983 case SNDRV_PCM_TRIGGER_STOP
:
991 snd_pcm_group_for_each_entry(s
, substream
) {
992 if (s
->pcm
->card
!= substream
->pcm
->card
)
994 stream
= get_hdac_ext_stream(s
);
995 sbits
|= 1 << hdac_stream(stream
)->index
;
996 snd_pcm_trigger_done(s
, substream
);
999 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
1001 /* first, set SYNC bits of corresponding streams */
1002 snd_hdac_stream_sync_trigger(hstr
, true, sbits
, AZX_REG_SSYNC
);
1004 snd_pcm_group_for_each_entry(s
, substream
) {
1005 if (s
->pcm
->card
!= substream
->pcm
->card
)
1007 stream
= get_hdac_ext_stream(s
);
1009 snd_hdac_stream_start(hdac_stream(stream
), true);
1011 snd_hdac_stream_stop(hdac_stream(stream
));
1013 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
1015 snd_hdac_stream_sync(hstr
, start
, sbits
);
1017 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
1019 /* reset SYNC bits */
1020 snd_hdac_stream_sync_trigger(hstr
, false, sbits
, AZX_REG_SSYNC
);
1022 snd_hdac_stream_timecounter_init(hstr
, sbits
);
1023 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
1028 static int skl_platform_pcm_trigger(struct snd_pcm_substream
*substream
,
1031 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
1033 if (!(ebus_to_hbus(ebus
))->ppcap
)
1034 return skl_coupled_trigger(substream
, cmd
);
1039 static snd_pcm_uframes_t skl_platform_pcm_pointer
1040 (struct snd_pcm_substream
*substream
)
1042 struct hdac_ext_stream
*hstream
= get_hdac_ext_stream(substream
);
1043 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
1047 * Use DPIB for Playback stream as the periodic DMA Position-in-
1048 * Buffer Writes may be scheduled at the same time or later than
1049 * the MSI and does not guarantee to reflect the Position of the
1050 * last buffer that was transferred. Whereas DPIB register in
1051 * HAD space reflects the actual data that is transferred.
1052 * Use the position buffer for capture, as DPIB write gets
1053 * completed earlier than the actual data written to the DDR.
1055 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1056 pos
= readl(ebus
->bus
.remap_addr
+ AZX_REG_VS_SDXDPIB_XBASE
+
1057 (AZX_REG_VS_SDXDPIB_XINTERVAL
*
1058 hdac_stream(hstream
)->index
));
1060 pos
= snd_hdac_stream_get_pos_posbuf(hdac_stream(hstream
));
1062 if (pos
>= hdac_stream(hstream
)->bufsize
)
1065 return bytes_to_frames(substream
->runtime
, pos
);
1068 static u64
skl_adjust_codec_delay(struct snd_pcm_substream
*substream
,
1071 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
1072 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1073 u64 codec_frames
, codec_nsecs
;
1075 if (!codec_dai
->driver
->ops
->delay
)
1078 codec_frames
= codec_dai
->driver
->ops
->delay(substream
, codec_dai
);
1079 codec_nsecs
= div_u64(codec_frames
* 1000000000LL,
1080 substream
->runtime
->rate
);
1082 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
1083 return nsec
+ codec_nsecs
;
1085 return (nsec
> codec_nsecs
) ? nsec
- codec_nsecs
: 0;
1088 static int skl_get_time_info(struct snd_pcm_substream
*substream
,
1089 struct timespec
*system_ts
, struct timespec
*audio_ts
,
1090 struct snd_pcm_audio_tstamp_config
*audio_tstamp_config
,
1091 struct snd_pcm_audio_tstamp_report
*audio_tstamp_report
)
1093 struct hdac_ext_stream
*sstream
= get_hdac_ext_stream(substream
);
1094 struct hdac_stream
*hstr
= hdac_stream(sstream
);
1097 if ((substream
->runtime
->hw
.info
& SNDRV_PCM_INFO_HAS_LINK_ATIME
) &&
1098 (audio_tstamp_config
->type_requested
== SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK
)) {
1100 snd_pcm_gettime(substream
->runtime
, system_ts
);
1102 nsec
= timecounter_read(&hstr
->tc
);
1103 nsec
= div_u64(nsec
, 3); /* can be optimized */
1104 if (audio_tstamp_config
->report_delay
)
1105 nsec
= skl_adjust_codec_delay(substream
, nsec
);
1107 *audio_ts
= ns_to_timespec(nsec
);
1109 audio_tstamp_report
->actual_type
= SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK
;
1110 audio_tstamp_report
->accuracy_report
= 1; /* rest of struct is valid */
1111 audio_tstamp_report
->accuracy
= 42; /* 24MHzWallClk == 42ns resolution */
1114 audio_tstamp_report
->actual_type
= SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT
;
1120 static const struct snd_pcm_ops skl_platform_ops
= {
1121 .open
= skl_platform_open
,
1122 .ioctl
= snd_pcm_lib_ioctl
,
1123 .trigger
= skl_platform_pcm_trigger
,
1124 .pointer
= skl_platform_pcm_pointer
,
1125 .get_time_info
= skl_get_time_info
,
1126 .mmap
= snd_pcm_lib_default_mmap
,
1127 .page
= snd_pcm_sgbuf_ops_page
,
1130 static void skl_pcm_free(struct snd_pcm
*pcm
)
1132 snd_pcm_lib_preallocate_free_for_all(pcm
);
1135 #define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
1137 static int skl_pcm_new(struct snd_soc_pcm_runtime
*rtd
)
1139 struct snd_soc_dai
*dai
= rtd
->cpu_dai
;
1140 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
1141 struct snd_pcm
*pcm
= rtd
->pcm
;
1144 struct skl
*skl
= ebus_to_skl(ebus
);
1146 if (dai
->driver
->playback
.channels_min
||
1147 dai
->driver
->capture
.channels_min
) {
1148 /* buffer pre-allocation */
1149 size
= CONFIG_SND_HDA_PREALLOC_SIZE
* 1024;
1150 if (size
> MAX_PREALLOC_SIZE
)
1151 size
= MAX_PREALLOC_SIZE
;
1152 retval
= snd_pcm_lib_preallocate_pages_for_all(pcm
,
1153 SNDRV_DMA_TYPE_DEV_SG
,
1154 snd_dma_pci_data(skl
->pci
),
1155 size
, MAX_PREALLOC_SIZE
);
1157 dev_err(dai
->dev
, "dma buffer allocationf fail\n");
1165 static int skl_populate_modules(struct skl
*skl
)
1167 struct skl_pipeline
*p
;
1168 struct skl_pipe_module
*m
;
1169 struct snd_soc_dapm_widget
*w
;
1170 struct skl_module_cfg
*mconfig
;
1173 list_for_each_entry(p
, &skl
->ppl_list
, node
) {
1174 list_for_each_entry(m
, &p
->pipe
->w_list
, node
) {
1179 ret
= snd_skl_get_module_info(skl
->skl_sst
, mconfig
);
1181 dev_err(skl
->skl_sst
->dev
,
1182 "query module info failed:%d\n", ret
);
1191 static int skl_platform_soc_probe(struct snd_soc_platform
*platform
)
1193 struct hdac_ext_bus
*ebus
= dev_get_drvdata(platform
->dev
);
1194 struct skl
*skl
= ebus_to_skl(ebus
);
1195 const struct skl_dsp_ops
*ops
;
1198 pm_runtime_get_sync(platform
->dev
);
1199 if ((ebus_to_hbus(ebus
))->ppcap
) {
1200 ret
= skl_tplg_init(platform
, ebus
);
1202 dev_err(platform
->dev
, "Failed to init topology!\n");
1205 skl
->platform
= platform
;
1207 /* load the firmwares, since all is set */
1208 ops
= skl_get_dsp_ops(skl
->pci
->device
);
1212 if (skl
->skl_sst
->is_first_boot
== false) {
1213 dev_err(platform
->dev
, "DSP reports first boot done!!!\n");
1217 ret
= ops
->init_fw(platform
->dev
, skl
->skl_sst
);
1219 dev_err(platform
->dev
, "Failed to boot first fw: %d\n", ret
);
1222 skl_populate_modules(skl
);
1223 skl
->skl_sst
->update_d0i3c
= skl_update_d0i3c
;
1225 pm_runtime_mark_last_busy(platform
->dev
);
1226 pm_runtime_put_autosuspend(platform
->dev
);
1230 static struct snd_soc_platform_driver skl_platform_drv
= {
1231 .probe
= skl_platform_soc_probe
,
1232 .ops
= &skl_platform_ops
,
1233 .pcm_new
= skl_pcm_new
,
1234 .pcm_free
= skl_pcm_free
,
1237 static const struct snd_soc_component_driver skl_component
= {
1241 int skl_platform_register(struct device
*dev
)
1244 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
1245 struct skl
*skl
= ebus_to_skl(ebus
);
1247 INIT_LIST_HEAD(&skl
->ppl_list
);
1249 ret
= snd_soc_register_platform(dev
, &skl_platform_drv
);
1251 dev_err(dev
, "soc platform registration failed %d\n", ret
);
1254 ret
= snd_soc_register_component(dev
, &skl_component
,
1256 ARRAY_SIZE(skl_platform_dai
));
1258 dev_err(dev
, "soc component registration failed %d\n", ret
);
1259 snd_soc_unregister_platform(dev
);
1266 int skl_platform_unregister(struct device
*dev
)
1268 snd_soc_unregister_component(dev
);
1269 snd_soc_unregister_platform(dev
);