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
|
54 .channels_max
= HDA_QUAD
,
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
)
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
;
148 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
150 stream
= snd_hdac_ext_stream_assign(ebus
, substream
,
151 skl_get_host_stream_type(ebus
));
155 skl_set_pcm_constrains(ebus
, runtime
);
158 * disable WALLCLOCK timestamps for capture streams
159 * until we figure out how to handle digital inputs
161 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
) {
162 runtime
->hw
.info
&= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK
; /* legacy */
163 runtime
->hw
.info
&= ~SNDRV_PCM_INFO_HAS_LINK_ATIME
;
166 runtime
->private_data
= stream
;
168 dma_params
= kzalloc(sizeof(*dma_params
), GFP_KERNEL
);
172 dma_params
->stream_tag
= hdac_stream(stream
)->stream_tag
;
173 snd_soc_dai_set_dma_data(dai
, substream
, dma_params
);
175 dev_dbg(dai
->dev
, "stream tag set in dma params=%d\n",
176 dma_params
->stream_tag
);
177 skl_set_suspend_active(substream
, dai
, true);
178 snd_pcm_set_sync(substream
);
183 static int skl_get_format(struct snd_pcm_substream
*substream
,
184 struct snd_soc_dai
*dai
)
186 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
187 struct skl_dma_params
*dma_params
;
188 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
192 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
194 format_val
= snd_hdac_calc_stream_format(runtime
->rate
,
199 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
201 dma_params
= snd_soc_dai_get_dma_data(codec_dai
, substream
);
203 format_val
= dma_params
->format
;
209 static int skl_be_prepare(struct snd_pcm_substream
*substream
,
210 struct snd_soc_dai
*dai
)
212 struct skl
*skl
= get_skl_ctx(dai
->dev
);
213 struct skl_sst
*ctx
= skl
->skl_sst
;
214 struct skl_module_cfg
*mconfig
;
216 if ((dai
->playback_active
> 1) || (dai
->capture_active
> 1))
219 mconfig
= skl_tplg_be_get_cpr_module(dai
, substream
->stream
);
223 return skl_dsp_set_dma_control(ctx
, mconfig
);
226 static int skl_pcm_prepare(struct snd_pcm_substream
*substream
,
227 struct snd_soc_dai
*dai
)
229 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
230 unsigned int format_val
;
233 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
235 format_val
= skl_get_format(substream
, dai
);
236 dev_dbg(dai
->dev
, "stream_tag=%d formatvalue=%d\n",
237 hdac_stream(stream
)->stream_tag
, format_val
);
238 snd_hdac_stream_reset(hdac_stream(stream
));
240 err
= snd_hdac_stream_set_params(hdac_stream(stream
), format_val
);
244 err
= snd_hdac_stream_setup(hdac_stream(stream
));
248 hdac_stream(stream
)->prepared
= 1;
253 static int skl_pcm_hw_params(struct snd_pcm_substream
*substream
,
254 struct snd_pcm_hw_params
*params
,
255 struct snd_soc_dai
*dai
)
257 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
258 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
259 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
260 struct skl_pipe_params p_params
= {0};
261 struct skl_module_cfg
*m_cfg
;
264 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
265 ret
= skl_substream_alloc_pages(ebus
, substream
,
266 params_buffer_bytes(params
));
270 dev_dbg(dai
->dev
, "format_val, rate=%d, ch=%d, format=%d\n",
271 runtime
->rate
, runtime
->channels
, runtime
->format
);
273 dma_id
= hdac_stream(stream
)->stream_tag
- 1;
274 dev_dbg(dai
->dev
, "dma_id=%d\n", dma_id
);
276 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
277 p_params
.ch
= params_channels(params
);
278 p_params
.s_freq
= params_rate(params
);
279 p_params
.host_dma_id
= dma_id
;
280 p_params
.stream
= substream
->stream
;
282 m_cfg
= skl_tplg_fe_get_cpr_module(dai
, p_params
.stream
);
284 skl_tplg_update_pipe_params(dai
->dev
, m_cfg
, &p_params
);
289 static void skl_pcm_close(struct snd_pcm_substream
*substream
,
290 struct snd_soc_dai
*dai
)
292 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
293 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
294 struct skl_dma_params
*dma_params
= NULL
;
295 struct skl
*skl
= ebus_to_skl(ebus
);
297 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
299 snd_hdac_ext_stream_release(stream
, skl_get_host_stream_type(ebus
));
301 dma_params
= snd_soc_dai_get_dma_data(dai
, substream
);
303 * now we should set this to NULL as we are freeing by the
306 snd_soc_dai_set_dma_data(dai
, substream
, NULL
);
307 skl_set_suspend_active(substream
, dai
, false);
310 * check if close is for "Reference Pin" and set back the
311 * CGCTL.MISCBDCGE if disabled by driver
313 if (!strncmp(dai
->name
, "Reference Pin", 13) &&
314 skl
->skl_sst
->miscbdcg_disabled
) {
315 skl
->skl_sst
->enable_miscbdcge(dai
->dev
, true);
316 skl
->skl_sst
->miscbdcg_disabled
= false;
322 static int skl_pcm_hw_free(struct snd_pcm_substream
*substream
,
323 struct snd_soc_dai
*dai
)
325 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
326 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
328 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
330 snd_hdac_stream_cleanup(hdac_stream(stream
));
331 hdac_stream(stream
)->prepared
= 0;
333 return skl_substream_free_pages(ebus_to_hbus(ebus
), substream
);
336 static int skl_be_hw_params(struct snd_pcm_substream
*substream
,
337 struct snd_pcm_hw_params
*params
,
338 struct snd_soc_dai
*dai
)
340 struct skl_pipe_params p_params
= {0};
342 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
343 p_params
.ch
= params_channels(params
);
344 p_params
.s_freq
= params_rate(params
);
345 p_params
.stream
= substream
->stream
;
347 return skl_tplg_be_update_params(dai
, &p_params
);
350 static int skl_decoupled_trigger(struct snd_pcm_substream
*substream
,
353 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
354 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
355 struct hdac_ext_stream
*stream
;
357 unsigned long cookie
;
358 struct hdac_stream
*hstr
;
360 stream
= get_hdac_ext_stream(substream
);
361 hstr
= hdac_stream(stream
);
367 case SNDRV_PCM_TRIGGER_START
:
368 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
369 case SNDRV_PCM_TRIGGER_RESUME
:
373 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
374 case SNDRV_PCM_TRIGGER_SUSPEND
:
375 case SNDRV_PCM_TRIGGER_STOP
:
383 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
386 snd_hdac_stream_start(hdac_stream(stream
), true);
387 snd_hdac_stream_timecounter_init(hstr
, 0);
389 snd_hdac_stream_stop(hdac_stream(stream
));
392 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
397 static int skl_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
,
398 struct snd_soc_dai
*dai
)
400 struct skl
*skl
= get_skl_ctx(dai
->dev
);
401 struct skl_sst
*ctx
= skl
->skl_sst
;
402 struct skl_module_cfg
*mconfig
;
403 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
404 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
407 mconfig
= skl_tplg_fe_get_cpr_module(dai
, substream
->stream
);
412 case SNDRV_PCM_TRIGGER_RESUME
:
413 skl_pcm_prepare(substream
, dai
);
415 * enable DMA Resume enable bit for the stream, set the dpib
416 * & lpib position to resune before starting the DMA
418 snd_hdac_ext_stream_drsm_enable(ebus
, true,
419 hdac_stream(stream
)->index
);
420 snd_hdac_ext_stream_set_dpibr(ebus
, stream
, stream
->dpib
);
421 snd_hdac_ext_stream_set_lpib(stream
, stream
->lpib
);
423 case SNDRV_PCM_TRIGGER_START
:
424 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
426 * Start HOST DMA and Start FE Pipe.This is to make sure that
427 * there are no underrun/overrun in the case when the FE
428 * pipeline is started but there is a delay in starting the
429 * DMA channel on the host.
431 snd_hdac_ext_stream_decouple(ebus
, stream
, true);
432 ret
= skl_decoupled_trigger(substream
, cmd
);
435 return skl_run_pipe(ctx
, mconfig
->pipe
);
438 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
439 case SNDRV_PCM_TRIGGER_SUSPEND
:
440 case SNDRV_PCM_TRIGGER_STOP
:
442 * Stop FE Pipe first and stop DMA. This is to make sure that
443 * there are no underrun/overrun in the case if there is a delay
444 * between the two operations.
446 ret
= skl_stop_pipe(ctx
, mconfig
->pipe
);
450 ret
= skl_decoupled_trigger(substream
, cmd
);
451 if (cmd
== SNDRV_PCM_TRIGGER_SUSPEND
) {
452 /* save the dpib and lpib positions */
453 stream
->dpib
= readl(ebus
->bus
.remap_addr
+
454 AZX_REG_VS_SDXDPIB_XBASE
+
455 (AZX_REG_VS_SDXDPIB_XINTERVAL
*
456 hdac_stream(stream
)->index
));
458 stream
->lpib
= snd_hdac_stream_get_pos_lpib(
459 hdac_stream(stream
));
460 snd_hdac_ext_stream_decouple(ebus
, stream
, false);
471 static int skl_link_hw_params(struct snd_pcm_substream
*substream
,
472 struct snd_pcm_hw_params
*params
,
473 struct snd_soc_dai
*dai
)
475 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
476 struct hdac_ext_stream
*link_dev
;
477 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
478 struct hdac_ext_dma_params
*dma_params
;
479 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
480 struct skl_pipe_params p_params
= {0};
482 link_dev
= snd_hdac_ext_stream_assign(ebus
, substream
,
483 HDAC_EXT_STREAM_TYPE_LINK
);
487 snd_soc_dai_set_dma_data(dai
, substream
, (void *)link_dev
);
489 /* set the stream tag in the codec dai dma params */
490 dma_params
= snd_soc_dai_get_dma_data(codec_dai
, substream
);
492 dma_params
->stream_tag
= hdac_stream(link_dev
)->stream_tag
;
494 p_params
.s_fmt
= snd_pcm_format_width(params_format(params
));
495 p_params
.ch
= params_channels(params
);
496 p_params
.s_freq
= params_rate(params
);
497 p_params
.stream
= substream
->stream
;
498 p_params
.link_dma_id
= hdac_stream(link_dev
)->stream_tag
- 1;
500 return skl_tplg_be_update_params(dai
, &p_params
);
503 static int skl_link_pcm_prepare(struct snd_pcm_substream
*substream
,
504 struct snd_soc_dai
*dai
)
506 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
507 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
508 struct hdac_ext_stream
*link_dev
=
509 snd_soc_dai_get_dma_data(dai
, substream
);
510 unsigned int format_val
= 0;
511 struct skl_dma_params
*dma_params
;
512 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
513 struct hdac_ext_link
*link
;
515 dma_params
= (struct skl_dma_params
*)
516 snd_soc_dai_get_dma_data(codec_dai
, substream
);
518 format_val
= dma_params
->format
;
519 dev_dbg(dai
->dev
, "stream_tag=%d formatvalue=%d codec_dai_name=%s\n",
520 hdac_stream(link_dev
)->stream_tag
, format_val
, codec_dai
->name
);
522 link
= snd_hdac_ext_bus_get_link(ebus
, rtd
->codec
->component
.name
);
526 snd_hdac_ext_bus_link_power_up(link
);
527 snd_hdac_ext_link_stream_reset(link_dev
);
529 snd_hdac_ext_link_stream_setup(link_dev
, format_val
);
531 snd_hdac_ext_link_set_stream_id(link
, hdac_stream(link_dev
)->stream_tag
);
532 link_dev
->link_prepared
= 1;
537 static int skl_link_pcm_trigger(struct snd_pcm_substream
*substream
,
538 int cmd
, struct snd_soc_dai
*dai
)
540 struct hdac_ext_stream
*link_dev
=
541 snd_soc_dai_get_dma_data(dai
, substream
);
542 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
543 struct hdac_ext_stream
*stream
= get_hdac_ext_stream(substream
);
545 dev_dbg(dai
->dev
, "In %s cmd=%d\n", __func__
, cmd
);
547 case SNDRV_PCM_TRIGGER_RESUME
:
548 skl_link_pcm_prepare(substream
, dai
);
549 case SNDRV_PCM_TRIGGER_START
:
550 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
551 snd_hdac_ext_stream_decouple(ebus
, stream
, true);
552 snd_hdac_ext_link_stream_start(link_dev
);
555 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
556 case SNDRV_PCM_TRIGGER_SUSPEND
:
557 case SNDRV_PCM_TRIGGER_STOP
:
558 snd_hdac_ext_link_stream_clear(link_dev
);
559 if (cmd
== SNDRV_PCM_TRIGGER_SUSPEND
)
560 snd_hdac_ext_stream_decouple(ebus
, stream
, false);
569 static int skl_link_hw_free(struct snd_pcm_substream
*substream
,
570 struct snd_soc_dai
*dai
)
572 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
573 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
574 struct hdac_ext_stream
*link_dev
=
575 snd_soc_dai_get_dma_data(dai
, substream
);
576 struct hdac_ext_link
*link
;
578 dev_dbg(dai
->dev
, "%s: %s\n", __func__
, dai
->name
);
580 link_dev
->link_prepared
= 0;
582 link
= snd_hdac_ext_bus_get_link(ebus
, rtd
->codec
->component
.name
);
586 snd_hdac_ext_link_clear_stream_id(link
, hdac_stream(link_dev
)->stream_tag
);
587 snd_hdac_ext_stream_release(link_dev
, HDAC_EXT_STREAM_TYPE_LINK
);
591 static struct snd_soc_dai_ops skl_pcm_dai_ops
= {
592 .startup
= skl_pcm_open
,
593 .shutdown
= skl_pcm_close
,
594 .prepare
= skl_pcm_prepare
,
595 .hw_params
= skl_pcm_hw_params
,
596 .hw_free
= skl_pcm_hw_free
,
597 .trigger
= skl_pcm_trigger
,
600 static struct snd_soc_dai_ops skl_dmic_dai_ops
= {
601 .hw_params
= skl_be_hw_params
,
604 static struct snd_soc_dai_ops skl_be_ssp_dai_ops
= {
605 .hw_params
= skl_be_hw_params
,
606 .prepare
= skl_be_prepare
,
609 static struct snd_soc_dai_ops skl_link_dai_ops
= {
610 .prepare
= skl_link_pcm_prepare
,
611 .hw_params
= skl_link_hw_params
,
612 .hw_free
= skl_link_hw_free
,
613 .trigger
= skl_link_pcm_trigger
,
616 static struct snd_soc_dai_driver skl_platform_dai
[] = {
618 .name
= "System Pin",
619 .ops
= &skl_pcm_dai_ops
,
621 .stream_name
= "System Playback",
622 .channels_min
= HDA_MONO
,
623 .channels_max
= HDA_STEREO
,
624 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
| SNDRV_PCM_RATE_8000
,
625 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
628 .stream_name
= "System Capture",
629 .channels_min
= HDA_MONO
,
630 .channels_max
= HDA_STEREO
,
631 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
632 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
636 .name
= "Reference Pin",
637 .ops
= &skl_pcm_dai_ops
,
639 .stream_name
= "Reference Capture",
640 .channels_min
= HDA_MONO
,
641 .channels_max
= HDA_QUAD
,
642 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
643 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
647 .name
= "Deepbuffer Pin",
648 .ops
= &skl_pcm_dai_ops
,
650 .stream_name
= "Deepbuffer Playback",
651 .channels_min
= HDA_STEREO
,
652 .channels_max
= HDA_STEREO
,
653 .rates
= SNDRV_PCM_RATE_48000
,
654 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
658 .name
= "LowLatency Pin",
659 .ops
= &skl_pcm_dai_ops
,
661 .stream_name
= "Low Latency Playback",
662 .channels_min
= HDA_STEREO
,
663 .channels_max
= HDA_STEREO
,
664 .rates
= SNDRV_PCM_RATE_48000
,
665 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
670 .ops
= &skl_pcm_dai_ops
,
672 .stream_name
= "DMIC Capture",
673 .channels_min
= HDA_MONO
,
674 .channels_max
= HDA_QUAD
,
675 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
676 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
681 .ops
= &skl_pcm_dai_ops
,
683 .stream_name
= "HDMI1 Playback",
684 .channels_min
= HDA_STEREO
,
685 .channels_max
= HDA_STEREO
,
686 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
687 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
688 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
689 SNDRV_PCM_RATE_192000
,
690 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
691 SNDRV_PCM_FMTBIT_S32_LE
,
696 .ops
= &skl_pcm_dai_ops
,
698 .stream_name
= "HDMI2 Playback",
699 .channels_min
= HDA_STEREO
,
700 .channels_max
= HDA_STEREO
,
701 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
702 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
703 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
704 SNDRV_PCM_RATE_192000
,
705 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
706 SNDRV_PCM_FMTBIT_S32_LE
,
711 .ops
= &skl_pcm_dai_ops
,
713 .stream_name
= "HDMI3 Playback",
714 .channels_min
= HDA_STEREO
,
715 .channels_max
= HDA_STEREO
,
716 .rates
= SNDRV_PCM_RATE_32000
| SNDRV_PCM_RATE_44100
|
717 SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_88200
|
718 SNDRV_PCM_RATE_96000
| SNDRV_PCM_RATE_176400
|
719 SNDRV_PCM_RATE_192000
,
720 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
|
721 SNDRV_PCM_FMTBIT_S32_LE
,
728 .ops
= &skl_be_ssp_dai_ops
,
730 .stream_name
= "ssp0 Tx",
731 .channels_min
= HDA_STEREO
,
732 .channels_max
= HDA_STEREO
,
733 .rates
= SNDRV_PCM_RATE_48000
,
734 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
737 .stream_name
= "ssp0 Rx",
738 .channels_min
= HDA_STEREO
,
739 .channels_max
= HDA_STEREO
,
740 .rates
= SNDRV_PCM_RATE_48000
,
741 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
746 .ops
= &skl_be_ssp_dai_ops
,
748 .stream_name
= "ssp1 Tx",
749 .channels_min
= HDA_STEREO
,
750 .channels_max
= HDA_STEREO
,
751 .rates
= SNDRV_PCM_RATE_48000
,
752 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
755 .stream_name
= "ssp1 Rx",
756 .channels_min
= HDA_STEREO
,
757 .channels_max
= HDA_STEREO
,
758 .rates
= SNDRV_PCM_RATE_48000
,
759 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
763 .name
= "iDisp1 Pin",
764 .ops
= &skl_link_dai_ops
,
766 .stream_name
= "iDisp1 Tx",
767 .channels_min
= HDA_STEREO
,
768 .channels_max
= HDA_STEREO
,
769 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|SNDRV_PCM_RATE_48000
,
770 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
771 SNDRV_PCM_FMTBIT_S24_LE
,
775 .name
= "iDisp2 Pin",
776 .ops
= &skl_link_dai_ops
,
778 .stream_name
= "iDisp2 Tx",
779 .channels_min
= HDA_STEREO
,
780 .channels_max
= HDA_STEREO
,
781 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|
782 SNDRV_PCM_RATE_48000
,
783 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
784 SNDRV_PCM_FMTBIT_S24_LE
,
788 .name
= "iDisp3 Pin",
789 .ops
= &skl_link_dai_ops
,
791 .stream_name
= "iDisp3 Tx",
792 .channels_min
= HDA_STEREO
,
793 .channels_max
= HDA_STEREO
,
794 .rates
= SNDRV_PCM_RATE_8000
|SNDRV_PCM_RATE_16000
|
795 SNDRV_PCM_RATE_48000
,
796 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
|
797 SNDRV_PCM_FMTBIT_S24_LE
,
801 .name
= "DMIC01 Pin",
802 .ops
= &skl_dmic_dai_ops
,
804 .stream_name
= "DMIC01 Rx",
805 .channels_min
= HDA_MONO
,
806 .channels_max
= HDA_QUAD
,
807 .rates
= SNDRV_PCM_RATE_48000
| SNDRV_PCM_RATE_16000
,
808 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
812 .name
= "HD-Codec Pin",
813 .ops
= &skl_link_dai_ops
,
815 .stream_name
= "HD-Codec Tx",
816 .channels_min
= HDA_STEREO
,
817 .channels_max
= HDA_STEREO
,
818 .rates
= SNDRV_PCM_RATE_48000
,
819 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
822 .stream_name
= "HD-Codec Rx",
823 .channels_min
= HDA_STEREO
,
824 .channels_max
= HDA_STEREO
,
825 .rates
= SNDRV_PCM_RATE_48000
,
826 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
831 static int skl_platform_open(struct snd_pcm_substream
*substream
)
833 struct snd_pcm_runtime
*runtime
;
834 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
835 struct snd_soc_dai_link
*dai_link
= rtd
->dai_link
;
837 dev_dbg(rtd
->cpu_dai
->dev
, "In %s:%s\n", __func__
,
838 dai_link
->cpu_dai_name
);
840 runtime
= substream
->runtime
;
841 snd_soc_set_runtime_hwparams(substream
, &azx_pcm_hw
);
846 static int skl_coupled_trigger(struct snd_pcm_substream
*substream
,
849 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
850 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
851 struct hdac_ext_stream
*stream
;
852 struct snd_pcm_substream
*s
;
855 unsigned long cookie
;
856 struct hdac_stream
*hstr
;
858 stream
= get_hdac_ext_stream(substream
);
859 hstr
= hdac_stream(stream
);
861 dev_dbg(bus
->dev
, "In %s cmd=%d\n", __func__
, cmd
);
867 case SNDRV_PCM_TRIGGER_START
:
868 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
869 case SNDRV_PCM_TRIGGER_RESUME
:
873 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
874 case SNDRV_PCM_TRIGGER_SUSPEND
:
875 case SNDRV_PCM_TRIGGER_STOP
:
883 snd_pcm_group_for_each_entry(s
, substream
) {
884 if (s
->pcm
->card
!= substream
->pcm
->card
)
886 stream
= get_hdac_ext_stream(s
);
887 sbits
|= 1 << hdac_stream(stream
)->index
;
888 snd_pcm_trigger_done(s
, substream
);
891 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
893 /* first, set SYNC bits of corresponding streams */
894 snd_hdac_stream_sync_trigger(hstr
, true, sbits
, AZX_REG_SSYNC
);
896 snd_pcm_group_for_each_entry(s
, substream
) {
897 if (s
->pcm
->card
!= substream
->pcm
->card
)
899 stream
= get_hdac_ext_stream(s
);
901 snd_hdac_stream_start(hdac_stream(stream
), true);
903 snd_hdac_stream_stop(hdac_stream(stream
));
905 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
907 snd_hdac_stream_sync(hstr
, start
, sbits
);
909 spin_lock_irqsave(&bus
->reg_lock
, cookie
);
911 /* reset SYNC bits */
912 snd_hdac_stream_sync_trigger(hstr
, false, sbits
, AZX_REG_SSYNC
);
914 snd_hdac_stream_timecounter_init(hstr
, sbits
);
915 spin_unlock_irqrestore(&bus
->reg_lock
, cookie
);
920 static int skl_platform_pcm_trigger(struct snd_pcm_substream
*substream
,
923 struct hdac_ext_bus
*ebus
= get_bus_ctx(substream
);
926 return skl_coupled_trigger(substream
, cmd
);
931 /* calculate runtime delay from LPIB */
932 static int skl_get_delay_from_lpib(struct hdac_ext_bus
*ebus
,
933 struct hdac_ext_stream
*sstream
,
936 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
937 struct hdac_stream
*hstream
= hdac_stream(sstream
);
938 struct snd_pcm_substream
*substream
= hstream
->substream
;
939 int stream
= substream
->stream
;
940 unsigned int lpib_pos
= snd_hdac_stream_get_pos_lpib(hstream
);
943 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
)
944 delay
= pos
- lpib_pos
;
946 delay
= lpib_pos
- pos
;
949 if (delay
>= hstream
->delay_negative_threshold
)
952 delay
+= hstream
->bufsize
;
955 if (hstream
->bufsize
== delay
)
958 if (delay
>= hstream
->period_bytes
) {
960 "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n",
961 delay
, hstream
->period_bytes
);
965 return bytes_to_frames(substream
->runtime
, delay
);
968 static unsigned int skl_get_position(struct hdac_ext_stream
*hstream
,
971 struct hdac_stream
*hstr
= hdac_stream(hstream
);
972 struct snd_pcm_substream
*substream
= hstr
->substream
;
973 struct hdac_ext_bus
*ebus
;
977 /* use the position buffer as default */
978 pos
= snd_hdac_stream_get_pos_posbuf(hdac_stream(hstream
));
980 if (pos
>= hdac_stream(hstream
)->bufsize
)
983 if (substream
->runtime
) {
984 ebus
= get_bus_ctx(substream
);
985 delay
= skl_get_delay_from_lpib(ebus
, hstream
, pos
)
987 substream
->runtime
->delay
+= delay
;
993 static snd_pcm_uframes_t skl_platform_pcm_pointer
994 (struct snd_pcm_substream
*substream
)
996 struct hdac_ext_stream
*hstream
= get_hdac_ext_stream(substream
);
998 return bytes_to_frames(substream
->runtime
,
999 skl_get_position(hstream
, 0));
1002 static u64
skl_adjust_codec_delay(struct snd_pcm_substream
*substream
,
1005 struct snd_soc_pcm_runtime
*rtd
= snd_pcm_substream_chip(substream
);
1006 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1007 u64 codec_frames
, codec_nsecs
;
1009 if (!codec_dai
->driver
->ops
->delay
)
1012 codec_frames
= codec_dai
->driver
->ops
->delay(substream
, codec_dai
);
1013 codec_nsecs
= div_u64(codec_frames
* 1000000000LL,
1014 substream
->runtime
->rate
);
1016 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
1017 return nsec
+ codec_nsecs
;
1019 return (nsec
> codec_nsecs
) ? nsec
- codec_nsecs
: 0;
1022 static int skl_get_time_info(struct snd_pcm_substream
*substream
,
1023 struct timespec
*system_ts
, struct timespec
*audio_ts
,
1024 struct snd_pcm_audio_tstamp_config
*audio_tstamp_config
,
1025 struct snd_pcm_audio_tstamp_report
*audio_tstamp_report
)
1027 struct hdac_ext_stream
*sstream
= get_hdac_ext_stream(substream
);
1028 struct hdac_stream
*hstr
= hdac_stream(sstream
);
1031 if ((substream
->runtime
->hw
.info
& SNDRV_PCM_INFO_HAS_LINK_ATIME
) &&
1032 (audio_tstamp_config
->type_requested
== SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK
)) {
1034 snd_pcm_gettime(substream
->runtime
, system_ts
);
1036 nsec
= timecounter_read(&hstr
->tc
);
1037 nsec
= div_u64(nsec
, 3); /* can be optimized */
1038 if (audio_tstamp_config
->report_delay
)
1039 nsec
= skl_adjust_codec_delay(substream
, nsec
);
1041 *audio_ts
= ns_to_timespec(nsec
);
1043 audio_tstamp_report
->actual_type
= SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK
;
1044 audio_tstamp_report
->accuracy_report
= 1; /* rest of struct is valid */
1045 audio_tstamp_report
->accuracy
= 42; /* 24MHzWallClk == 42ns resolution */
1048 audio_tstamp_report
->actual_type
= SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT
;
1054 static struct snd_pcm_ops skl_platform_ops
= {
1055 .open
= skl_platform_open
,
1056 .ioctl
= snd_pcm_lib_ioctl
,
1057 .trigger
= skl_platform_pcm_trigger
,
1058 .pointer
= skl_platform_pcm_pointer
,
1059 .get_time_info
= skl_get_time_info
,
1060 .mmap
= snd_pcm_lib_default_mmap
,
1061 .page
= snd_pcm_sgbuf_ops_page
,
1064 static void skl_pcm_free(struct snd_pcm
*pcm
)
1066 snd_pcm_lib_preallocate_free_for_all(pcm
);
1069 #define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
1071 static int skl_pcm_new(struct snd_soc_pcm_runtime
*rtd
)
1073 struct snd_soc_dai
*dai
= rtd
->cpu_dai
;
1074 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dai
->dev
);
1075 struct snd_pcm
*pcm
= rtd
->pcm
;
1078 struct skl
*skl
= ebus_to_skl(ebus
);
1080 if (dai
->driver
->playback
.channels_min
||
1081 dai
->driver
->capture
.channels_min
) {
1082 /* buffer pre-allocation */
1083 size
= CONFIG_SND_HDA_PREALLOC_SIZE
* 1024;
1084 if (size
> MAX_PREALLOC_SIZE
)
1085 size
= MAX_PREALLOC_SIZE
;
1086 retval
= snd_pcm_lib_preallocate_pages_for_all(pcm
,
1087 SNDRV_DMA_TYPE_DEV_SG
,
1088 snd_dma_pci_data(skl
->pci
),
1089 size
, MAX_PREALLOC_SIZE
);
1091 dev_err(dai
->dev
, "dma buffer allocationf fail\n");
1099 static int skl_platform_soc_probe(struct snd_soc_platform
*platform
)
1101 struct hdac_ext_bus
*ebus
= dev_get_drvdata(platform
->dev
);
1104 return skl_tplg_init(platform
, ebus
);
1108 static struct snd_soc_platform_driver skl_platform_drv
= {
1109 .probe
= skl_platform_soc_probe
,
1110 .ops
= &skl_platform_ops
,
1111 .pcm_new
= skl_pcm_new
,
1112 .pcm_free
= skl_pcm_free
,
1115 static const struct snd_soc_component_driver skl_component
= {
1119 int skl_platform_register(struct device
*dev
)
1122 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
1123 struct skl
*skl
= ebus_to_skl(ebus
);
1125 INIT_LIST_HEAD(&skl
->ppl_list
);
1127 ret
= snd_soc_register_platform(dev
, &skl_platform_drv
);
1129 dev_err(dev
, "soc platform registration failed %d\n", ret
);
1132 ret
= snd_soc_register_component(dev
, &skl_component
,
1134 ARRAY_SIZE(skl_platform_dai
));
1136 dev_err(dev
, "soc component registration failed %d\n", ret
);
1137 snd_soc_unregister_platform(dev
);
1144 int skl_platform_unregister(struct device
*dev
)
1146 snd_soc_unregister_component(dev
);
1147 snd_soc_unregister_platform(dev
);