2 * skl-message.c - HDA DSP interface for FW registration, Pipe and Module
5 * Copyright (C) 2015 Intel Corp
6 * Author:Rafal Redzimski <rafal.f.redzimski@intel.com>
7 * Jeeja KP <jeeja.kp@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as version 2, as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
20 #include <linux/slab.h>
21 #include <linux/pci.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include "skl-sst-dsp.h"
25 #include "skl-sst-ipc.h"
27 #include "../common/sst-dsp.h"
28 #include "../common/sst-dsp-priv.h"
29 #include "skl-topology.h"
30 #include "skl-tplg-interface.h"
32 static int skl_alloc_dma_buf(struct device
*dev
,
33 struct snd_dma_buffer
*dmab
, size_t size
)
35 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
36 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
41 return bus
->io_ops
->dma_alloc_pages(bus
, SNDRV_DMA_TYPE_DEV
, size
, dmab
);
44 static int skl_free_dma_buf(struct device
*dev
, struct snd_dma_buffer
*dmab
)
46 struct hdac_ext_bus
*ebus
= dev_get_drvdata(dev
);
47 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
52 bus
->io_ops
->dma_free_pages(bus
, dmab
);
57 int skl_init_dsp(struct skl
*skl
)
59 void __iomem
*mmio_base
;
60 struct hdac_ext_bus
*ebus
= &skl
->ebus
;
61 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
63 struct skl_dsp_loader_ops loader_ops
;
66 loader_ops
.alloc_dma_buf
= skl_alloc_dma_buf
;
67 loader_ops
.free_dma_buf
= skl_free_dma_buf
;
69 /* enable ppcap interrupt */
70 snd_hdac_ext_bus_ppcap_enable(&skl
->ebus
, true);
71 snd_hdac_ext_bus_ppcap_int_enable(&skl
->ebus
, true);
73 /* read the BAR of the ADSP MMIO */
74 mmio_base
= pci_ioremap_bar(skl
->pci
, 4);
75 if (mmio_base
== NULL
) {
76 dev_err(bus
->dev
, "ioremap error\n");
80 ret
= skl_sst_dsp_init(bus
->dev
, mmio_base
, irq
,
81 loader_ops
, &skl
->skl_sst
);
83 dev_dbg(bus
->dev
, "dsp registration status=%d\n", ret
);
88 void skl_free_dsp(struct skl
*skl
)
90 struct hdac_ext_bus
*ebus
= &skl
->ebus
;
91 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
92 struct skl_sst
*ctx
= skl
->skl_sst
;
94 /* disable ppcap interrupt */
95 snd_hdac_ext_bus_ppcap_int_enable(&skl
->ebus
, false);
97 skl_sst_dsp_cleanup(bus
->dev
, ctx
);
98 if (ctx
->dsp
->addr
.lpe
)
99 iounmap(ctx
->dsp
->addr
.lpe
);
102 int skl_suspend_dsp(struct skl
*skl
)
104 struct skl_sst
*ctx
= skl
->skl_sst
;
107 /* if ppcap is not supported return 0 */
108 if (!skl
->ebus
.ppcap
)
111 ret
= skl_dsp_sleep(ctx
->dsp
);
115 /* disable ppcap interrupt */
116 snd_hdac_ext_bus_ppcap_int_enable(&skl
->ebus
, false);
117 snd_hdac_ext_bus_ppcap_enable(&skl
->ebus
, false);
122 int skl_resume_dsp(struct skl
*skl
)
124 struct skl_sst
*ctx
= skl
->skl_sst
;
126 /* if ppcap is not supported return 0 */
127 if (!skl
->ebus
.ppcap
)
130 /* enable ppcap interrupt */
131 snd_hdac_ext_bus_ppcap_enable(&skl
->ebus
, true);
132 snd_hdac_ext_bus_ppcap_int_enable(&skl
->ebus
, true);
134 return skl_dsp_wake(ctx
->dsp
);
137 enum skl_bitdepth
skl_get_bit_depth(int params
)
141 return SKL_DEPTH_8BIT
;
144 return SKL_DEPTH_16BIT
;
147 return SKL_DEPTH_24BIT
;
150 return SKL_DEPTH_32BIT
;
153 return SKL_DEPTH_INVALID
;
158 static u32
skl_create_channel_map(enum skl_ch_cfg ch_cfg
)
163 case SKL_CH_CFG_MONO
:
164 config
= (0xFFFFFFF0 | SKL_CHANNEL_LEFT
);
167 case SKL_CH_CFG_STEREO
:
168 config
= (0xFFFFFF00 | SKL_CHANNEL_LEFT
169 | (SKL_CHANNEL_RIGHT
<< 4));
173 config
= (0xFFFFF000 | SKL_CHANNEL_LEFT
174 | (SKL_CHANNEL_RIGHT
<< 4)
175 | (SKL_CHANNEL_LFE
<< 8));
179 config
= (0xFFFFF000 | SKL_CHANNEL_LEFT
180 | (SKL_CHANNEL_CENTER
<< 4)
181 | (SKL_CHANNEL_RIGHT
<< 8));
185 config
= (0xFFFF0000 | SKL_CHANNEL_LEFT
186 | (SKL_CHANNEL_CENTER
<< 4)
187 | (SKL_CHANNEL_RIGHT
<< 8)
188 | (SKL_CHANNEL_LFE
<< 12));
191 case SKL_CH_CFG_QUATRO
:
192 config
= (0xFFFF0000 | SKL_CHANNEL_LEFT
193 | (SKL_CHANNEL_RIGHT
<< 4)
194 | (SKL_CHANNEL_LEFT_SURROUND
<< 8)
195 | (SKL_CHANNEL_RIGHT_SURROUND
<< 12));
199 config
= (0xFFFF0000 | SKL_CHANNEL_LEFT
200 | (SKL_CHANNEL_CENTER
<< 4)
201 | (SKL_CHANNEL_RIGHT
<< 8)
202 | (SKL_CHANNEL_CENTER_SURROUND
<< 12));
206 config
= (0xFFF00000 | SKL_CHANNEL_LEFT
207 | (SKL_CHANNEL_CENTER
<< 4)
208 | (SKL_CHANNEL_RIGHT
<< 8)
209 | (SKL_CHANNEL_LEFT_SURROUND
<< 12)
210 | (SKL_CHANNEL_RIGHT_SURROUND
<< 16));
214 config
= (0xFF000000 | SKL_CHANNEL_CENTER
215 | (SKL_CHANNEL_LEFT
<< 4)
216 | (SKL_CHANNEL_RIGHT
<< 8)
217 | (SKL_CHANNEL_LEFT_SURROUND
<< 12)
218 | (SKL_CHANNEL_RIGHT_SURROUND
<< 16)
219 | (SKL_CHANNEL_LFE
<< 20));
222 case SKL_CH_CFG_DUAL_MONO
:
223 config
= (0xFFFFFF00 | SKL_CHANNEL_LEFT
224 | (SKL_CHANNEL_LEFT
<< 4));
227 case SKL_CH_CFG_I2S_DUAL_STEREO_0
:
228 config
= (0xFFFFFF00 | SKL_CHANNEL_LEFT
229 | (SKL_CHANNEL_RIGHT
<< 4));
232 case SKL_CH_CFG_I2S_DUAL_STEREO_1
:
233 config
= (0xFFFF00FF | (SKL_CHANNEL_LEFT
<< 8)
234 | (SKL_CHANNEL_RIGHT
<< 12));
247 * Each module in DSP expects a base module configuration, which consists of
248 * PCM format information, which we calculate in driver and resource values
249 * which are read from widget information passed through topology binary
250 * This is send when we create a module with INIT_INSTANCE IPC msg
252 static void skl_set_base_module_format(struct skl_sst
*ctx
,
253 struct skl_module_cfg
*mconfig
,
254 struct skl_base_cfg
*base_cfg
)
256 struct skl_module_fmt
*format
= &mconfig
->in_fmt
;
258 base_cfg
->audio_fmt
.number_of_channels
= (u8
)format
->channels
;
260 base_cfg
->audio_fmt
.s_freq
= format
->s_freq
;
261 base_cfg
->audio_fmt
.bit_depth
= format
->bit_depth
;
262 base_cfg
->audio_fmt
.valid_bit_depth
= format
->valid_bit_depth
;
263 base_cfg
->audio_fmt
.ch_cfg
= format
->ch_cfg
;
265 dev_dbg(ctx
->dev
, "bit_depth=%x valid_bd=%x ch_config=%x\n",
266 format
->bit_depth
, format
->valid_bit_depth
,
269 base_cfg
->audio_fmt
.channel_map
= skl_create_channel_map(
270 base_cfg
->audio_fmt
.ch_cfg
);
272 base_cfg
->audio_fmt
.interleaving
= SKL_INTERLEAVING_PER_CHANNEL
;
274 base_cfg
->cps
= mconfig
->mcps
;
275 base_cfg
->ibs
= mconfig
->ibs
;
276 base_cfg
->obs
= mconfig
->obs
;
280 * Copies copier capabilities into copier module and updates copier module
283 static void skl_copy_copier_caps(struct skl_module_cfg
*mconfig
,
284 struct skl_cpr_cfg
*cpr_mconfig
)
286 if (mconfig
->formats_config
.caps_size
== 0)
289 memcpy(cpr_mconfig
->gtw_cfg
.config_data
,
290 mconfig
->formats_config
.caps
,
291 mconfig
->formats_config
.caps_size
);
293 cpr_mconfig
->gtw_cfg
.config_length
=
294 (mconfig
->formats_config
.caps_size
) / 4;
298 * Calculate the gatewat settings required for copier module, type of
299 * gateway and index of gateway to use
301 static void skl_setup_cpr_gateway_cfg(struct skl_sst
*ctx
,
302 struct skl_module_cfg
*mconfig
,
303 struct skl_cpr_cfg
*cpr_mconfig
)
305 union skl_connector_node_id node_id
= {0};
306 struct skl_pipe_params
*params
= mconfig
->pipe
->p_params
;
308 switch (mconfig
->dev_type
) {
310 node_id
.node
.dma_type
=
311 (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
) ?
312 SKL_DMA_I2S_LINK_OUTPUT_CLASS
:
313 SKL_DMA_I2S_LINK_INPUT_CLASS
;
314 node_id
.node
.vindex
= params
->host_dma_id
+
315 (mconfig
->vbus_id
<< 3);
319 node_id
.node
.dma_type
=
320 (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
) ?
321 SKL_DMA_I2S_LINK_OUTPUT_CLASS
:
322 SKL_DMA_I2S_LINK_INPUT_CLASS
;
323 node_id
.node
.vindex
= params
->host_dma_id
+
324 (mconfig
->time_slot
<< 1) +
325 (mconfig
->vbus_id
<< 3);
328 case SKL_DEVICE_DMIC
:
329 node_id
.node
.dma_type
= SKL_DMA_DMIC_LINK_INPUT_CLASS
;
330 node_id
.node
.vindex
= mconfig
->vbus_id
+
331 (mconfig
->time_slot
);
334 case SKL_DEVICE_HDALINK
:
335 node_id
.node
.dma_type
=
336 (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
) ?
337 SKL_DMA_HDA_LINK_OUTPUT_CLASS
:
338 SKL_DMA_HDA_LINK_INPUT_CLASS
;
339 node_id
.node
.vindex
= params
->link_dma_id
;
343 node_id
.node
.dma_type
=
344 (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
) ?
345 SKL_DMA_HDA_HOST_OUTPUT_CLASS
:
346 SKL_DMA_HDA_HOST_INPUT_CLASS
;
347 node_id
.node
.vindex
= params
->host_dma_id
;
351 cpr_mconfig
->gtw_cfg
.node_id
= node_id
.val
;
353 if (SKL_CONN_SOURCE
== mconfig
->hw_conn_type
)
354 cpr_mconfig
->gtw_cfg
.dma_buffer_size
= 2 * mconfig
->obs
;
356 cpr_mconfig
->gtw_cfg
.dma_buffer_size
= 2 * mconfig
->ibs
;
358 cpr_mconfig
->cpr_feature_mask
= 0;
359 cpr_mconfig
->gtw_cfg
.config_length
= 0;
361 skl_copy_copier_caps(mconfig
, cpr_mconfig
);
364 static void skl_setup_out_format(struct skl_sst
*ctx
,
365 struct skl_module_cfg
*mconfig
,
366 struct skl_audio_data_format
*out_fmt
)
368 struct skl_module_fmt
*format
= &mconfig
->out_fmt
;
370 out_fmt
->number_of_channels
= (u8
)format
->channels
;
371 out_fmt
->s_freq
= format
->s_freq
;
372 out_fmt
->bit_depth
= format
->bit_depth
;
373 out_fmt
->valid_bit_depth
= format
->valid_bit_depth
;
374 out_fmt
->ch_cfg
= format
->ch_cfg
;
376 out_fmt
->channel_map
= skl_create_channel_map(out_fmt
->ch_cfg
);
377 out_fmt
->interleaving
= SKL_INTERLEAVING_PER_CHANNEL
;
379 dev_dbg(ctx
->dev
, "copier out format chan=%d fre=%d bitdepth=%d\n",
380 out_fmt
->number_of_channels
, format
->s_freq
, format
->bit_depth
);
384 * 'copier' is DSP internal module which copies data from Host DMA (HDA host
385 * dma) or link (hda link, SSP, PDM)
386 * Here we calculate the copier module parameters, like PCM format, output
387 * format, gateway settings
388 * copier_module_config is sent as input buffer with INIT_INSTANCE IPC msg
390 static void skl_set_copier_format(struct skl_sst
*ctx
,
391 struct skl_module_cfg
*mconfig
,
392 struct skl_cpr_cfg
*cpr_mconfig
)
394 struct skl_audio_data_format
*out_fmt
= &cpr_mconfig
->out_fmt
;
395 struct skl_base_cfg
*base_cfg
= (struct skl_base_cfg
*)cpr_mconfig
;
397 skl_set_base_module_format(ctx
, mconfig
, base_cfg
);
399 skl_setup_out_format(ctx
, mconfig
, out_fmt
);
400 skl_setup_cpr_gateway_cfg(ctx
, mconfig
, cpr_mconfig
);
403 static u16
skl_get_module_param_size(struct skl_sst
*ctx
,
404 struct skl_module_cfg
*mconfig
)
408 switch (mconfig
->m_type
) {
409 case SKL_MODULE_TYPE_COPIER
:
410 param_size
= sizeof(struct skl_cpr_cfg
);
411 param_size
+= mconfig
->formats_config
.caps_size
;
416 * return only base cfg when no specific module type is
419 return sizeof(struct skl_base_cfg
);
426 * DSP firmware supports various modules like copier etc. These modules
427 * required various parameters to be calculated and sent for the module
428 * initialization to DSP. By default a generic module needs only base module
429 * format configuration
431 static int skl_set_module_format(struct skl_sst
*ctx
,
432 struct skl_module_cfg
*module_config
,
433 u16
*module_config_size
,
438 param_size
= skl_get_module_param_size(ctx
, module_config
);
440 *param_data
= kzalloc(param_size
, GFP_KERNEL
);
441 if (NULL
== *param_data
)
444 *module_config_size
= param_size
;
446 switch (module_config
->m_type
) {
447 case SKL_MODULE_TYPE_COPIER
:
448 skl_set_copier_format(ctx
, module_config
, *param_data
);
452 skl_set_base_module_format(ctx
, module_config
, *param_data
);
457 dev_dbg(ctx
->dev
, "Module type=%d config size: %d bytes\n",
458 module_config
->id
.module_id
, param_size
);
459 print_hex_dump(KERN_DEBUG
, "Module params:", DUMP_PREFIX_OFFSET
, 8, 4,
460 *param_data
, param_size
, false);
464 static int skl_get_queue_index(struct skl_module_pin
*mpin
,
465 struct skl_module_inst_id id
, int max
)
469 for (i
= 0; i
< max
; i
++) {
470 if (mpin
[i
].id
.module_id
== id
.module_id
&&
471 mpin
[i
].id
.instance_id
== id
.instance_id
)
479 * Allocates queue for each module.
480 * if dynamic, the pin_index is allocated 0 to max_pin.
481 * In static, the pin_index is fixed based on module_id and instance id
483 static int skl_alloc_queue(struct skl_module_pin
*mpin
,
484 struct skl_module_inst_id id
, int max
)
489 * if pin in dynamic, find first free pin
490 * otherwise find match module and instance id pin as topology will
491 * ensure a unique pin is assigned to this so no need to
494 for (i
= 0; i
< max
; i
++) {
495 if (mpin
[i
].is_dynamic
) {
496 if (!mpin
[i
].in_use
) {
497 mpin
[i
].in_use
= true;
498 mpin
[i
].id
.module_id
= id
.module_id
;
499 mpin
[i
].id
.instance_id
= id
.instance_id
;
503 if (mpin
[i
].id
.module_id
== id
.module_id
&&
504 mpin
[i
].id
.instance_id
== id
.instance_id
)
512 static void skl_free_queue(struct skl_module_pin
*mpin
, int q_index
)
514 if (mpin
[q_index
].is_dynamic
) {
515 mpin
[q_index
].in_use
= false;
516 mpin
[q_index
].id
.module_id
= 0;
517 mpin
[q_index
].id
.instance_id
= 0;