Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 1 | /* |
| 2 | * skl-message.c - HDA DSP interface for FW registration, Pipe and Module |
| 3 | * configurations |
| 4 | * |
| 5 | * Copyright (C) 2015 Intel Corp |
| 6 | * Author:Rafal Redzimski <rafal.f.redzimski@intel.com> |
| 7 | * Jeeja KP <jeeja.kp@intel.com> |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | */ |
| 19 | |
| 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" |
| 26 | #include "skl.h" |
| 27 | #include "../common/sst-dsp.h" |
| 28 | #include "../common/sst-dsp-priv.h" |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 29 | #include "skl-topology.h" |
| 30 | #include "skl-tplg-interface.h" |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 31 | |
| 32 | static int skl_alloc_dma_buf(struct device *dev, |
| 33 | struct snd_dma_buffer *dmab, size_t size) |
| 34 | { |
| 35 | struct hdac_ext_bus *ebus = dev_get_drvdata(dev); |
| 36 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
| 37 | |
| 38 | if (!bus) |
| 39 | return -ENODEV; |
| 40 | |
| 41 | return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, size, dmab); |
| 42 | } |
| 43 | |
| 44 | static int skl_free_dma_buf(struct device *dev, struct snd_dma_buffer *dmab) |
| 45 | { |
| 46 | struct hdac_ext_bus *ebus = dev_get_drvdata(dev); |
| 47 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
| 48 | |
| 49 | if (!bus) |
| 50 | return -ENODEV; |
| 51 | |
| 52 | bus->io_ops->dma_free_pages(bus, dmab); |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Jeeja KP | 4e10996 | 2015-10-22 23:22:39 +0530 | [diff] [blame] | 57 | #define NOTIFICATION_PARAM_ID 3 |
| 58 | #define NOTIFICATION_MASK 0xf |
| 59 | |
| 60 | /* disable notfication for underruns/overruns from firmware module */ |
| 61 | static void skl_dsp_enable_notification(struct skl_sst *ctx, bool enable) |
| 62 | { |
| 63 | struct notification_mask mask; |
| 64 | struct skl_ipc_large_config_msg msg = {0}; |
| 65 | |
| 66 | mask.notify = NOTIFICATION_MASK; |
| 67 | mask.enable = enable; |
| 68 | |
| 69 | msg.large_param_id = NOTIFICATION_PARAM_ID; |
| 70 | msg.param_data_size = sizeof(mask); |
| 71 | |
| 72 | skl_ipc_set_large_config(&ctx->ipc, &msg, (u32 *)&mask); |
| 73 | } |
| 74 | |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 75 | int skl_init_dsp(struct skl *skl) |
| 76 | { |
| 77 | void __iomem *mmio_base; |
| 78 | struct hdac_ext_bus *ebus = &skl->ebus; |
| 79 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
| 80 | int irq = bus->irq; |
| 81 | struct skl_dsp_loader_ops loader_ops; |
| 82 | int ret; |
| 83 | |
| 84 | loader_ops.alloc_dma_buf = skl_alloc_dma_buf; |
| 85 | loader_ops.free_dma_buf = skl_free_dma_buf; |
| 86 | |
| 87 | /* enable ppcap interrupt */ |
| 88 | snd_hdac_ext_bus_ppcap_enable(&skl->ebus, true); |
| 89 | snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, true); |
| 90 | |
| 91 | /* read the BAR of the ADSP MMIO */ |
| 92 | mmio_base = pci_ioremap_bar(skl->pci, 4); |
| 93 | if (mmio_base == NULL) { |
| 94 | dev_err(bus->dev, "ioremap error\n"); |
| 95 | return -ENXIO; |
| 96 | } |
| 97 | |
| 98 | ret = skl_sst_dsp_init(bus->dev, mmio_base, irq, |
Vinod Koul | aecf6fd | 2015-11-05 21:34:15 +0530 | [diff] [blame] | 99 | skl->fw_name, loader_ops, &skl->skl_sst); |
Jeeja KP | 2ac454f | 2015-10-22 23:22:40 +0530 | [diff] [blame] | 100 | if (ret < 0) |
| 101 | return ret; |
| 102 | |
Jeeja KP | 4e10996 | 2015-10-22 23:22:39 +0530 | [diff] [blame] | 103 | skl_dsp_enable_notification(skl->skl_sst, false); |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 104 | dev_dbg(bus->dev, "dsp registration status=%d\n", ret); |
| 105 | |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | void skl_free_dsp(struct skl *skl) |
| 110 | { |
| 111 | struct hdac_ext_bus *ebus = &skl->ebus; |
| 112 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
| 113 | struct skl_sst *ctx = skl->skl_sst; |
| 114 | |
| 115 | /* disable ppcap interrupt */ |
| 116 | snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, false); |
| 117 | |
| 118 | skl_sst_dsp_cleanup(bus->dev, ctx); |
| 119 | if (ctx->dsp->addr.lpe) |
| 120 | iounmap(ctx->dsp->addr.lpe); |
| 121 | } |
| 122 | |
| 123 | int skl_suspend_dsp(struct skl *skl) |
| 124 | { |
| 125 | struct skl_sst *ctx = skl->skl_sst; |
| 126 | int ret; |
| 127 | |
| 128 | /* if ppcap is not supported return 0 */ |
| 129 | if (!skl->ebus.ppcap) |
| 130 | return 0; |
| 131 | |
| 132 | ret = skl_dsp_sleep(ctx->dsp); |
| 133 | if (ret < 0) |
| 134 | return ret; |
| 135 | |
| 136 | /* disable ppcap interrupt */ |
| 137 | snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, false); |
| 138 | snd_hdac_ext_bus_ppcap_enable(&skl->ebus, false); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | int skl_resume_dsp(struct skl *skl) |
| 144 | { |
| 145 | struct skl_sst *ctx = skl->skl_sst; |
Jeeja KP | 4e10996 | 2015-10-22 23:22:39 +0530 | [diff] [blame] | 146 | int ret; |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 147 | |
| 148 | /* if ppcap is not supported return 0 */ |
| 149 | if (!skl->ebus.ppcap) |
| 150 | return 0; |
| 151 | |
| 152 | /* enable ppcap interrupt */ |
| 153 | snd_hdac_ext_bus_ppcap_enable(&skl->ebus, true); |
| 154 | snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, true); |
| 155 | |
Jeeja KP | 4e10996 | 2015-10-22 23:22:39 +0530 | [diff] [blame] | 156 | ret = skl_dsp_wake(ctx->dsp); |
| 157 | if (ret < 0) |
| 158 | return ret; |
| 159 | |
| 160 | skl_dsp_enable_notification(skl->skl_sst, false); |
| 161 | return ret; |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 162 | } |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 163 | |
| 164 | enum skl_bitdepth skl_get_bit_depth(int params) |
| 165 | { |
| 166 | switch (params) { |
| 167 | case 8: |
| 168 | return SKL_DEPTH_8BIT; |
| 169 | |
| 170 | case 16: |
| 171 | return SKL_DEPTH_16BIT; |
| 172 | |
| 173 | case 24: |
| 174 | return SKL_DEPTH_24BIT; |
| 175 | |
| 176 | case 32: |
| 177 | return SKL_DEPTH_32BIT; |
| 178 | |
| 179 | default: |
| 180 | return SKL_DEPTH_INVALID; |
| 181 | |
| 182 | } |
| 183 | } |
| 184 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 185 | /* |
| 186 | * Each module in DSP expects a base module configuration, which consists of |
| 187 | * PCM format information, which we calculate in driver and resource values |
| 188 | * which are read from widget information passed through topology binary |
| 189 | * This is send when we create a module with INIT_INSTANCE IPC msg |
| 190 | */ |
| 191 | static void skl_set_base_module_format(struct skl_sst *ctx, |
| 192 | struct skl_module_cfg *mconfig, |
| 193 | struct skl_base_cfg *base_cfg) |
| 194 | { |
Hardik T Shah | 4cd9899 | 2015-10-27 09:22:55 +0900 | [diff] [blame] | 195 | struct skl_module_fmt *format = &mconfig->in_fmt[0]; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 196 | |
| 197 | base_cfg->audio_fmt.number_of_channels = (u8)format->channels; |
| 198 | |
| 199 | base_cfg->audio_fmt.s_freq = format->s_freq; |
| 200 | base_cfg->audio_fmt.bit_depth = format->bit_depth; |
| 201 | base_cfg->audio_fmt.valid_bit_depth = format->valid_bit_depth; |
| 202 | base_cfg->audio_fmt.ch_cfg = format->ch_cfg; |
| 203 | |
| 204 | dev_dbg(ctx->dev, "bit_depth=%x valid_bd=%x ch_config=%x\n", |
| 205 | format->bit_depth, format->valid_bit_depth, |
| 206 | format->ch_cfg); |
| 207 | |
Jeeja KP | 3e81f1a | 2015-10-27 09:22:59 +0900 | [diff] [blame] | 208 | base_cfg->audio_fmt.channel_map = format->ch_map; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 209 | |
Jeeja KP | 3e81f1a | 2015-10-27 09:22:59 +0900 | [diff] [blame] | 210 | base_cfg->audio_fmt.interleaving = format->interleaving_style; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 211 | |
| 212 | base_cfg->cps = mconfig->mcps; |
| 213 | base_cfg->ibs = mconfig->ibs; |
| 214 | base_cfg->obs = mconfig->obs; |
Jeeja KP | b18c458 | 2015-12-03 23:29:51 +0530 | [diff] [blame] | 215 | base_cfg->is_pages = mconfig->mem_pages; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* |
| 219 | * Copies copier capabilities into copier module and updates copier module |
| 220 | * config size. |
| 221 | */ |
| 222 | static void skl_copy_copier_caps(struct skl_module_cfg *mconfig, |
| 223 | struct skl_cpr_cfg *cpr_mconfig) |
| 224 | { |
| 225 | if (mconfig->formats_config.caps_size == 0) |
| 226 | return; |
| 227 | |
| 228 | memcpy(cpr_mconfig->gtw_cfg.config_data, |
| 229 | mconfig->formats_config.caps, |
| 230 | mconfig->formats_config.caps_size); |
| 231 | |
| 232 | cpr_mconfig->gtw_cfg.config_length = |
| 233 | (mconfig->formats_config.caps_size) / 4; |
| 234 | } |
| 235 | |
Jeeja KP | bfa764a | 2015-10-22 23:22:41 +0530 | [diff] [blame] | 236 | #define SKL_NON_GATEWAY_CPR_NODE_ID 0xFFFFFFFF |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 237 | /* |
| 238 | * Calculate the gatewat settings required for copier module, type of |
| 239 | * gateway and index of gateway to use |
| 240 | */ |
Dharageswari.R | 4fdf810 | 2016-02-05 12:19:05 +0530 | [diff] [blame^] | 241 | static u32 skl_get_node_id(struct skl_sst *ctx, |
| 242 | struct skl_module_cfg *mconfig) |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 243 | { |
| 244 | union skl_connector_node_id node_id = {0}; |
Jeeja KP | d7b1881 | 2015-10-22 23:22:38 +0530 | [diff] [blame] | 245 | union skl_ssp_dma_node ssp_node = {0}; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 246 | struct skl_pipe_params *params = mconfig->pipe->p_params; |
| 247 | |
| 248 | switch (mconfig->dev_type) { |
| 249 | case SKL_DEVICE_BT: |
| 250 | node_id.node.dma_type = |
| 251 | (SKL_CONN_SOURCE == mconfig->hw_conn_type) ? |
| 252 | SKL_DMA_I2S_LINK_OUTPUT_CLASS : |
| 253 | SKL_DMA_I2S_LINK_INPUT_CLASS; |
| 254 | node_id.node.vindex = params->host_dma_id + |
| 255 | (mconfig->vbus_id << 3); |
| 256 | break; |
| 257 | |
| 258 | case SKL_DEVICE_I2S: |
| 259 | node_id.node.dma_type = |
| 260 | (SKL_CONN_SOURCE == mconfig->hw_conn_type) ? |
| 261 | SKL_DMA_I2S_LINK_OUTPUT_CLASS : |
| 262 | SKL_DMA_I2S_LINK_INPUT_CLASS; |
Jeeja KP | d7b1881 | 2015-10-22 23:22:38 +0530 | [diff] [blame] | 263 | ssp_node.dma_node.time_slot_index = mconfig->time_slot; |
| 264 | ssp_node.dma_node.i2s_instance = mconfig->vbus_id; |
| 265 | node_id.node.vindex = ssp_node.val; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 266 | break; |
| 267 | |
| 268 | case SKL_DEVICE_DMIC: |
| 269 | node_id.node.dma_type = SKL_DMA_DMIC_LINK_INPUT_CLASS; |
| 270 | node_id.node.vindex = mconfig->vbus_id + |
| 271 | (mconfig->time_slot); |
| 272 | break; |
| 273 | |
| 274 | case SKL_DEVICE_HDALINK: |
| 275 | node_id.node.dma_type = |
| 276 | (SKL_CONN_SOURCE == mconfig->hw_conn_type) ? |
| 277 | SKL_DMA_HDA_LINK_OUTPUT_CLASS : |
| 278 | SKL_DMA_HDA_LINK_INPUT_CLASS; |
| 279 | node_id.node.vindex = params->link_dma_id; |
| 280 | break; |
| 281 | |
Jeeja KP | bfa764a | 2015-10-22 23:22:41 +0530 | [diff] [blame] | 282 | case SKL_DEVICE_HDAHOST: |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 283 | node_id.node.dma_type = |
| 284 | (SKL_CONN_SOURCE == mconfig->hw_conn_type) ? |
| 285 | SKL_DMA_HDA_HOST_OUTPUT_CLASS : |
| 286 | SKL_DMA_HDA_HOST_INPUT_CLASS; |
| 287 | node_id.node.vindex = params->host_dma_id; |
| 288 | break; |
Jeeja KP | bfa764a | 2015-10-22 23:22:41 +0530 | [diff] [blame] | 289 | |
| 290 | default: |
Dharageswari.R | 4fdf810 | 2016-02-05 12:19:05 +0530 | [diff] [blame^] | 291 | node_id.val = 0xFFFFFFFF; |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | return node_id.val; |
| 296 | } |
| 297 | |
| 298 | static void skl_setup_cpr_gateway_cfg(struct skl_sst *ctx, |
| 299 | struct skl_module_cfg *mconfig, |
| 300 | struct skl_cpr_cfg *cpr_mconfig) |
| 301 | { |
| 302 | cpr_mconfig->gtw_cfg.node_id = skl_get_node_id(ctx, mconfig); |
| 303 | |
| 304 | if (cpr_mconfig->gtw_cfg.node_id == SKL_NON_GATEWAY_CPR_NODE_ID) { |
Jeeja KP | bfa764a | 2015-10-22 23:22:41 +0530 | [diff] [blame] | 305 | cpr_mconfig->cpr_feature_mask = 0; |
| 306 | return; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 307 | } |
| 308 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 309 | if (SKL_CONN_SOURCE == mconfig->hw_conn_type) |
| 310 | cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * mconfig->obs; |
| 311 | else |
| 312 | cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * mconfig->ibs; |
| 313 | |
| 314 | cpr_mconfig->cpr_feature_mask = 0; |
| 315 | cpr_mconfig->gtw_cfg.config_length = 0; |
| 316 | |
| 317 | skl_copy_copier_caps(mconfig, cpr_mconfig); |
| 318 | } |
| 319 | |
| 320 | static void skl_setup_out_format(struct skl_sst *ctx, |
| 321 | struct skl_module_cfg *mconfig, |
| 322 | struct skl_audio_data_format *out_fmt) |
| 323 | { |
Hardik T Shah | 4cd9899 | 2015-10-27 09:22:55 +0900 | [diff] [blame] | 324 | struct skl_module_fmt *format = &mconfig->out_fmt[0]; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 325 | |
| 326 | out_fmt->number_of_channels = (u8)format->channels; |
| 327 | out_fmt->s_freq = format->s_freq; |
| 328 | out_fmt->bit_depth = format->bit_depth; |
| 329 | out_fmt->valid_bit_depth = format->valid_bit_depth; |
| 330 | out_fmt->ch_cfg = format->ch_cfg; |
| 331 | |
Jeeja KP | 3e81f1a | 2015-10-27 09:22:59 +0900 | [diff] [blame] | 332 | out_fmt->channel_map = format->ch_map; |
| 333 | out_fmt->interleaving = format->interleaving_style; |
| 334 | out_fmt->sample_type = format->sample_type; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 335 | |
| 336 | dev_dbg(ctx->dev, "copier out format chan=%d fre=%d bitdepth=%d\n", |
| 337 | out_fmt->number_of_channels, format->s_freq, format->bit_depth); |
| 338 | } |
| 339 | |
| 340 | /* |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 341 | * DSP needs SRC module for frequency conversion, SRC takes base module |
| 342 | * configuration and the target frequency as extra parameter passed as src |
| 343 | * config |
| 344 | */ |
| 345 | static void skl_set_src_format(struct skl_sst *ctx, |
| 346 | struct skl_module_cfg *mconfig, |
| 347 | struct skl_src_module_cfg *src_mconfig) |
| 348 | { |
Hardik T Shah | 4cd9899 | 2015-10-27 09:22:55 +0900 | [diff] [blame] | 349 | struct skl_module_fmt *fmt = &mconfig->out_fmt[0]; |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 350 | |
| 351 | skl_set_base_module_format(ctx, mconfig, |
| 352 | (struct skl_base_cfg *)src_mconfig); |
| 353 | |
| 354 | src_mconfig->src_cfg = fmt->s_freq; |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * DSP needs updown module to do channel conversion. updown module take base |
| 359 | * module configuration and channel configuration |
| 360 | * It also take coefficients and now we have defaults applied here |
| 361 | */ |
| 362 | static void skl_set_updown_mixer_format(struct skl_sst *ctx, |
| 363 | struct skl_module_cfg *mconfig, |
| 364 | struct skl_up_down_mixer_cfg *mixer_mconfig) |
| 365 | { |
Hardik T Shah | 4cd9899 | 2015-10-27 09:22:55 +0900 | [diff] [blame] | 366 | struct skl_module_fmt *fmt = &mconfig->out_fmt[0]; |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 367 | int i = 0; |
| 368 | |
| 369 | skl_set_base_module_format(ctx, mconfig, |
| 370 | (struct skl_base_cfg *)mixer_mconfig); |
| 371 | mixer_mconfig->out_ch_cfg = fmt->ch_cfg; |
| 372 | |
| 373 | /* Select F/W default coefficient */ |
| 374 | mixer_mconfig->coeff_sel = 0x0; |
| 375 | |
| 376 | /* User coeff, don't care since we are selecting F/W defaults */ |
| 377 | for (i = 0; i < UP_DOWN_MIXER_MAX_COEFF; i++) |
| 378 | mixer_mconfig->coeff[i] = 0xDEADBEEF; |
| 379 | } |
| 380 | |
| 381 | /* |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 382 | * 'copier' is DSP internal module which copies data from Host DMA (HDA host |
| 383 | * dma) or link (hda link, SSP, PDM) |
| 384 | * Here we calculate the copier module parameters, like PCM format, output |
| 385 | * format, gateway settings |
| 386 | * copier_module_config is sent as input buffer with INIT_INSTANCE IPC msg |
| 387 | */ |
| 388 | static void skl_set_copier_format(struct skl_sst *ctx, |
| 389 | struct skl_module_cfg *mconfig, |
| 390 | struct skl_cpr_cfg *cpr_mconfig) |
| 391 | { |
| 392 | struct skl_audio_data_format *out_fmt = &cpr_mconfig->out_fmt; |
| 393 | struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)cpr_mconfig; |
| 394 | |
| 395 | skl_set_base_module_format(ctx, mconfig, base_cfg); |
| 396 | |
| 397 | skl_setup_out_format(ctx, mconfig, out_fmt); |
| 398 | skl_setup_cpr_gateway_cfg(ctx, mconfig, cpr_mconfig); |
| 399 | } |
| 400 | |
Jeeja KP | 399b210 | 2015-11-28 15:01:48 +0530 | [diff] [blame] | 401 | /* |
| 402 | * Algo module are DSP pre processing modules. Algo module take base module |
| 403 | * configuration and params |
| 404 | */ |
| 405 | |
| 406 | static void skl_set_algo_format(struct skl_sst *ctx, |
| 407 | struct skl_module_cfg *mconfig, |
| 408 | struct skl_algo_cfg *algo_mcfg) |
| 409 | { |
| 410 | struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)algo_mcfg; |
| 411 | |
| 412 | skl_set_base_module_format(ctx, mconfig, base_cfg); |
| 413 | |
| 414 | if (mconfig->formats_config.caps_size == 0) |
| 415 | return; |
| 416 | |
| 417 | memcpy(algo_mcfg->params, |
| 418 | mconfig->formats_config.caps, |
| 419 | mconfig->formats_config.caps_size); |
| 420 | |
| 421 | } |
| 422 | |
Dharageswari R | fd18110 | 2015-12-03 23:29:52 +0530 | [diff] [blame] | 423 | /* |
| 424 | * Mic select module allows selecting one or many input channels, thus |
| 425 | * acting as a demux. |
| 426 | * |
| 427 | * Mic select module take base module configuration and out-format |
| 428 | * configuration |
| 429 | */ |
| 430 | static void skl_set_base_outfmt_format(struct skl_sst *ctx, |
| 431 | struct skl_module_cfg *mconfig, |
| 432 | struct skl_base_outfmt_cfg *base_outfmt_mcfg) |
| 433 | { |
| 434 | struct skl_audio_data_format *out_fmt = &base_outfmt_mcfg->out_fmt; |
| 435 | struct skl_base_cfg *base_cfg = |
| 436 | (struct skl_base_cfg *)base_outfmt_mcfg; |
| 437 | |
| 438 | skl_set_base_module_format(ctx, mconfig, base_cfg); |
| 439 | skl_setup_out_format(ctx, mconfig, out_fmt); |
| 440 | } |
| 441 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 442 | static u16 skl_get_module_param_size(struct skl_sst *ctx, |
| 443 | struct skl_module_cfg *mconfig) |
| 444 | { |
| 445 | u16 param_size; |
| 446 | |
| 447 | switch (mconfig->m_type) { |
| 448 | case SKL_MODULE_TYPE_COPIER: |
| 449 | param_size = sizeof(struct skl_cpr_cfg); |
| 450 | param_size += mconfig->formats_config.caps_size; |
| 451 | return param_size; |
| 452 | |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 453 | case SKL_MODULE_TYPE_SRCINT: |
| 454 | return sizeof(struct skl_src_module_cfg); |
| 455 | |
| 456 | case SKL_MODULE_TYPE_UPDWMIX: |
| 457 | return sizeof(struct skl_up_down_mixer_cfg); |
| 458 | |
Jeeja KP | 399b210 | 2015-11-28 15:01:48 +0530 | [diff] [blame] | 459 | case SKL_MODULE_TYPE_ALGO: |
| 460 | param_size = sizeof(struct skl_base_cfg); |
| 461 | param_size += mconfig->formats_config.caps_size; |
| 462 | return param_size; |
| 463 | |
Dharageswari R | fd18110 | 2015-12-03 23:29:52 +0530 | [diff] [blame] | 464 | case SKL_MODULE_TYPE_BASE_OUTFMT: |
| 465 | return sizeof(struct skl_base_outfmt_cfg); |
| 466 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 467 | default: |
| 468 | /* |
| 469 | * return only base cfg when no specific module type is |
| 470 | * specified |
| 471 | */ |
| 472 | return sizeof(struct skl_base_cfg); |
| 473 | } |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | /* |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 479 | * DSP firmware supports various modules like copier, SRC, updown etc. |
| 480 | * These modules required various parameters to be calculated and sent for |
| 481 | * the module initialization to DSP. By default a generic module needs only |
| 482 | * base module format configuration |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 483 | */ |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 484 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 485 | static int skl_set_module_format(struct skl_sst *ctx, |
| 486 | struct skl_module_cfg *module_config, |
| 487 | u16 *module_config_size, |
| 488 | void **param_data) |
| 489 | { |
| 490 | u16 param_size; |
| 491 | |
| 492 | param_size = skl_get_module_param_size(ctx, module_config); |
| 493 | |
| 494 | *param_data = kzalloc(param_size, GFP_KERNEL); |
| 495 | if (NULL == *param_data) |
| 496 | return -ENOMEM; |
| 497 | |
| 498 | *module_config_size = param_size; |
| 499 | |
| 500 | switch (module_config->m_type) { |
| 501 | case SKL_MODULE_TYPE_COPIER: |
| 502 | skl_set_copier_format(ctx, module_config, *param_data); |
| 503 | break; |
| 504 | |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 505 | case SKL_MODULE_TYPE_SRCINT: |
| 506 | skl_set_src_format(ctx, module_config, *param_data); |
| 507 | break; |
| 508 | |
| 509 | case SKL_MODULE_TYPE_UPDWMIX: |
| 510 | skl_set_updown_mixer_format(ctx, module_config, *param_data); |
| 511 | break; |
| 512 | |
Jeeja KP | 399b210 | 2015-11-28 15:01:48 +0530 | [diff] [blame] | 513 | case SKL_MODULE_TYPE_ALGO: |
| 514 | skl_set_algo_format(ctx, module_config, *param_data); |
| 515 | break; |
| 516 | |
Dharageswari R | fd18110 | 2015-12-03 23:29:52 +0530 | [diff] [blame] | 517 | case SKL_MODULE_TYPE_BASE_OUTFMT: |
| 518 | skl_set_base_outfmt_format(ctx, module_config, *param_data); |
| 519 | break; |
| 520 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 521 | default: |
| 522 | skl_set_base_module_format(ctx, module_config, *param_data); |
| 523 | break; |
| 524 | |
| 525 | } |
| 526 | |
| 527 | dev_dbg(ctx->dev, "Module type=%d config size: %d bytes\n", |
| 528 | module_config->id.module_id, param_size); |
| 529 | print_hex_dump(KERN_DEBUG, "Module params:", DUMP_PREFIX_OFFSET, 8, 4, |
| 530 | *param_data, param_size, false); |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static int skl_get_queue_index(struct skl_module_pin *mpin, |
| 535 | struct skl_module_inst_id id, int max) |
| 536 | { |
| 537 | int i; |
| 538 | |
| 539 | for (i = 0; i < max; i++) { |
| 540 | if (mpin[i].id.module_id == id.module_id && |
| 541 | mpin[i].id.instance_id == id.instance_id) |
| 542 | return i; |
| 543 | } |
| 544 | |
| 545 | return -EINVAL; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * Allocates queue for each module. |
| 550 | * if dynamic, the pin_index is allocated 0 to max_pin. |
| 551 | * In static, the pin_index is fixed based on module_id and instance id |
| 552 | */ |
| 553 | static int skl_alloc_queue(struct skl_module_pin *mpin, |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 554 | struct skl_module_cfg *tgt_cfg, int max) |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 555 | { |
| 556 | int i; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 557 | struct skl_module_inst_id id = tgt_cfg->id; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 558 | /* |
| 559 | * if pin in dynamic, find first free pin |
| 560 | * otherwise find match module and instance id pin as topology will |
| 561 | * ensure a unique pin is assigned to this so no need to |
| 562 | * allocate/free |
| 563 | */ |
| 564 | for (i = 0; i < max; i++) { |
| 565 | if (mpin[i].is_dynamic) { |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 566 | if (!mpin[i].in_use && |
| 567 | mpin[i].pin_state == SKL_PIN_UNBIND) { |
| 568 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 569 | mpin[i].in_use = true; |
| 570 | mpin[i].id.module_id = id.module_id; |
| 571 | mpin[i].id.instance_id = id.instance_id; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 572 | mpin[i].tgt_mcfg = tgt_cfg; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 573 | return i; |
| 574 | } |
| 575 | } else { |
| 576 | if (mpin[i].id.module_id == id.module_id && |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 577 | mpin[i].id.instance_id == id.instance_id && |
| 578 | mpin[i].pin_state == SKL_PIN_UNBIND) { |
| 579 | |
| 580 | mpin[i].tgt_mcfg = tgt_cfg; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 581 | return i; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 582 | } |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | |
| 586 | return -EINVAL; |
| 587 | } |
| 588 | |
| 589 | static void skl_free_queue(struct skl_module_pin *mpin, int q_index) |
| 590 | { |
| 591 | if (mpin[q_index].is_dynamic) { |
| 592 | mpin[q_index].in_use = false; |
| 593 | mpin[q_index].id.module_id = 0; |
| 594 | mpin[q_index].id.instance_id = 0; |
| 595 | } |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 596 | mpin[q_index].pin_state = SKL_PIN_UNBIND; |
| 597 | mpin[q_index].tgt_mcfg = NULL; |
| 598 | } |
| 599 | |
| 600 | /* Module state will be set to unint, if all the out pin state is UNBIND */ |
| 601 | |
| 602 | static void skl_clear_module_state(struct skl_module_pin *mpin, int max, |
| 603 | struct skl_module_cfg *mcfg) |
| 604 | { |
| 605 | int i; |
| 606 | bool found = false; |
| 607 | |
| 608 | for (i = 0; i < max; i++) { |
| 609 | if (mpin[i].pin_state == SKL_PIN_UNBIND) |
| 610 | continue; |
| 611 | found = true; |
| 612 | break; |
| 613 | } |
| 614 | |
| 615 | if (!found) |
| 616 | mcfg->m_state = SKL_MODULE_UNINIT; |
| 617 | return; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 618 | } |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 619 | |
| 620 | /* |
| 621 | * A module needs to be instanataited in DSP. A mdoule is present in a |
| 622 | * collection of module referred as a PIPE. |
| 623 | * We first calculate the module format, based on module type and then |
| 624 | * invoke the DSP by sending IPC INIT_INSTANCE using ipc helper |
| 625 | */ |
| 626 | int skl_init_module(struct skl_sst *ctx, |
Jeeja KP | 9939a9c | 2015-11-28 15:01:47 +0530 | [diff] [blame] | 627 | struct skl_module_cfg *mconfig) |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 628 | { |
| 629 | u16 module_config_size = 0; |
| 630 | void *param_data = NULL; |
| 631 | int ret; |
| 632 | struct skl_ipc_init_instance_msg msg; |
| 633 | |
| 634 | dev_dbg(ctx->dev, "%s: module_id = %d instance=%d\n", __func__, |
| 635 | mconfig->id.module_id, mconfig->id.instance_id); |
| 636 | |
| 637 | if (mconfig->pipe->state != SKL_PIPE_CREATED) { |
| 638 | dev_err(ctx->dev, "Pipe not created state= %d pipe_id= %d\n", |
| 639 | mconfig->pipe->state, mconfig->pipe->ppl_id); |
| 640 | return -EIO; |
| 641 | } |
| 642 | |
| 643 | ret = skl_set_module_format(ctx, mconfig, |
| 644 | &module_config_size, ¶m_data); |
| 645 | if (ret < 0) { |
| 646 | dev_err(ctx->dev, "Failed to set module format ret=%d\n", ret); |
| 647 | return ret; |
| 648 | } |
| 649 | |
| 650 | msg.module_id = mconfig->id.module_id; |
| 651 | msg.instance_id = mconfig->id.instance_id; |
| 652 | msg.ppl_instance_id = mconfig->pipe->ppl_id; |
| 653 | msg.param_data_size = module_config_size; |
| 654 | msg.core_id = mconfig->core_id; |
| 655 | |
| 656 | ret = skl_ipc_init_instance(&ctx->ipc, &msg, param_data); |
| 657 | if (ret < 0) { |
| 658 | dev_err(ctx->dev, "Failed to init instance ret=%d\n", ret); |
| 659 | kfree(param_data); |
| 660 | return ret; |
| 661 | } |
| 662 | mconfig->m_state = SKL_MODULE_INIT_DONE; |
| 663 | |
| 664 | return ret; |
| 665 | } |
| 666 | |
| 667 | static void skl_dump_bind_info(struct skl_sst *ctx, struct skl_module_cfg |
| 668 | *src_module, struct skl_module_cfg *dst_module) |
| 669 | { |
| 670 | dev_dbg(ctx->dev, "%s: src module_id = %d src_instance=%d\n", |
| 671 | __func__, src_module->id.module_id, src_module->id.instance_id); |
| 672 | dev_dbg(ctx->dev, "%s: dst_module=%d dst_instacne=%d\n", __func__, |
| 673 | dst_module->id.module_id, dst_module->id.instance_id); |
| 674 | |
| 675 | dev_dbg(ctx->dev, "src_module state = %d dst module state = %d\n", |
| 676 | src_module->m_state, dst_module->m_state); |
| 677 | } |
| 678 | |
| 679 | /* |
| 680 | * On module freeup, we need to unbind the module with modules |
| 681 | * it is already bind. |
| 682 | * Find the pin allocated and unbind then using bind_unbind IPC |
| 683 | */ |
| 684 | int skl_unbind_modules(struct skl_sst *ctx, |
| 685 | struct skl_module_cfg *src_mcfg, |
| 686 | struct skl_module_cfg *dst_mcfg) |
| 687 | { |
| 688 | int ret; |
| 689 | struct skl_ipc_bind_unbind_msg msg; |
| 690 | struct skl_module_inst_id src_id = src_mcfg->id; |
| 691 | struct skl_module_inst_id dst_id = dst_mcfg->id; |
| 692 | int in_max = dst_mcfg->max_in_queue; |
| 693 | int out_max = src_mcfg->max_out_queue; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 694 | int src_index, dst_index, src_pin_state, dst_pin_state; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 695 | |
| 696 | skl_dump_bind_info(ctx, src_mcfg, dst_mcfg); |
| 697 | |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 698 | /* get src queue index */ |
| 699 | src_index = skl_get_queue_index(src_mcfg->m_out_pin, dst_id, out_max); |
| 700 | if (src_index < 0) |
Jeeja KP | 9cf3049 | 2016-02-03 17:59:48 +0530 | [diff] [blame] | 701 | return 0; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 702 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 703 | msg.src_queue = src_index; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 704 | |
| 705 | /* get dst queue index */ |
| 706 | dst_index = skl_get_queue_index(dst_mcfg->m_in_pin, src_id, in_max); |
| 707 | if (dst_index < 0) |
Jeeja KP | 9cf3049 | 2016-02-03 17:59:48 +0530 | [diff] [blame] | 708 | return 0; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 709 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 710 | msg.dst_queue = dst_index; |
| 711 | |
| 712 | src_pin_state = src_mcfg->m_out_pin[src_index].pin_state; |
| 713 | dst_pin_state = dst_mcfg->m_in_pin[dst_index].pin_state; |
| 714 | |
| 715 | if (src_pin_state != SKL_PIN_BIND_DONE || |
| 716 | dst_pin_state != SKL_PIN_BIND_DONE) |
| 717 | return 0; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 718 | |
| 719 | msg.module_id = src_mcfg->id.module_id; |
| 720 | msg.instance_id = src_mcfg->id.instance_id; |
| 721 | msg.dst_module_id = dst_mcfg->id.module_id; |
| 722 | msg.dst_instance_id = dst_mcfg->id.instance_id; |
| 723 | msg.bind = false; |
| 724 | |
| 725 | ret = skl_ipc_bind_unbind(&ctx->ipc, &msg); |
| 726 | if (!ret) { |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 727 | /* free queue only if unbind is success */ |
| 728 | skl_free_queue(src_mcfg->m_out_pin, src_index); |
| 729 | skl_free_queue(dst_mcfg->m_in_pin, dst_index); |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 730 | |
| 731 | /* |
| 732 | * check only if src module bind state, bind is |
| 733 | * always from src -> sink |
| 734 | */ |
| 735 | skl_clear_module_state(src_mcfg->m_out_pin, out_max, src_mcfg); |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | return ret; |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | * Once a module is instantiated it need to be 'bind' with other modules in |
| 743 | * the pipeline. For binding we need to find the module pins which are bind |
| 744 | * together |
| 745 | * This function finds the pins and then sends bund_unbind IPC message to |
| 746 | * DSP using IPC helper |
| 747 | */ |
| 748 | int skl_bind_modules(struct skl_sst *ctx, |
| 749 | struct skl_module_cfg *src_mcfg, |
| 750 | struct skl_module_cfg *dst_mcfg) |
| 751 | { |
| 752 | int ret; |
| 753 | struct skl_ipc_bind_unbind_msg msg; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 754 | int in_max = dst_mcfg->max_in_queue; |
| 755 | int out_max = src_mcfg->max_out_queue; |
| 756 | int src_index, dst_index; |
| 757 | |
| 758 | skl_dump_bind_info(ctx, src_mcfg, dst_mcfg); |
| 759 | |
Jeeja KP | 0c684c4 | 2016-02-03 17:59:49 +0530 | [diff] [blame] | 760 | if (src_mcfg->m_state < SKL_MODULE_INIT_DONE || |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 761 | dst_mcfg->m_state < SKL_MODULE_INIT_DONE) |
| 762 | return 0; |
| 763 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 764 | src_index = skl_alloc_queue(src_mcfg->m_out_pin, dst_mcfg, out_max); |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 765 | if (src_index < 0) |
| 766 | return -EINVAL; |
| 767 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 768 | msg.src_queue = src_index; |
| 769 | dst_index = skl_alloc_queue(dst_mcfg->m_in_pin, src_mcfg, in_max); |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 770 | if (dst_index < 0) { |
| 771 | skl_free_queue(src_mcfg->m_out_pin, src_index); |
| 772 | return -EINVAL; |
| 773 | } |
| 774 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 775 | msg.dst_queue = dst_index; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 776 | |
| 777 | dev_dbg(ctx->dev, "src queue = %d dst queue =%d\n", |
| 778 | msg.src_queue, msg.dst_queue); |
| 779 | |
| 780 | msg.module_id = src_mcfg->id.module_id; |
| 781 | msg.instance_id = src_mcfg->id.instance_id; |
| 782 | msg.dst_module_id = dst_mcfg->id.module_id; |
| 783 | msg.dst_instance_id = dst_mcfg->id.instance_id; |
| 784 | msg.bind = true; |
| 785 | |
| 786 | ret = skl_ipc_bind_unbind(&ctx->ipc, &msg); |
| 787 | |
| 788 | if (!ret) { |
| 789 | src_mcfg->m_state = SKL_MODULE_BIND_DONE; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 790 | src_mcfg->m_out_pin[src_index].pin_state = SKL_PIN_BIND_DONE; |
| 791 | dst_mcfg->m_in_pin[dst_index].pin_state = SKL_PIN_BIND_DONE; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 792 | } else { |
| 793 | /* error case , if IPC fails, clear the queue index */ |
| 794 | skl_free_queue(src_mcfg->m_out_pin, src_index); |
| 795 | skl_free_queue(dst_mcfg->m_in_pin, dst_index); |
| 796 | } |
| 797 | |
| 798 | return ret; |
| 799 | } |
Jeeja KP | c9b1e83 | 2015-08-01 19:40:44 +0530 | [diff] [blame] | 800 | |
| 801 | static int skl_set_pipe_state(struct skl_sst *ctx, struct skl_pipe *pipe, |
| 802 | enum skl_ipc_pipeline_state state) |
| 803 | { |
| 804 | dev_dbg(ctx->dev, "%s: pipe_satate = %d\n", __func__, state); |
| 805 | |
| 806 | return skl_ipc_set_pipeline_state(&ctx->ipc, pipe->ppl_id, state); |
| 807 | } |
| 808 | |
| 809 | /* |
| 810 | * A pipeline is a collection of modules. Before a module in instantiated a |
| 811 | * pipeline needs to be created for it. |
| 812 | * This function creates pipeline, by sending create pipeline IPC messages |
| 813 | * to FW |
| 814 | */ |
| 815 | int skl_create_pipeline(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 816 | { |
| 817 | int ret; |
| 818 | |
| 819 | dev_dbg(ctx->dev, "%s: pipe_id = %d\n", __func__, pipe->ppl_id); |
| 820 | |
| 821 | ret = skl_ipc_create_pipeline(&ctx->ipc, pipe->memory_pages, |
| 822 | pipe->pipe_priority, pipe->ppl_id); |
| 823 | if (ret < 0) { |
| 824 | dev_err(ctx->dev, "Failed to create pipeline\n"); |
| 825 | return ret; |
| 826 | } |
| 827 | |
| 828 | pipe->state = SKL_PIPE_CREATED; |
| 829 | |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | /* |
| 834 | * A pipeline needs to be deleted on cleanup. If a pipeline is running, then |
| 835 | * pause the pipeline first and then delete it |
| 836 | * The pipe delete is done by sending delete pipeline IPC. DSP will stop the |
| 837 | * DMA engines and releases resources |
| 838 | */ |
| 839 | int skl_delete_pipe(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 840 | { |
| 841 | int ret; |
| 842 | |
| 843 | dev_dbg(ctx->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id); |
| 844 | |
| 845 | /* If pipe is not started, do not try to stop the pipe in FW. */ |
| 846 | if (pipe->state > SKL_PIPE_STARTED) { |
| 847 | ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED); |
| 848 | if (ret < 0) { |
| 849 | dev_err(ctx->dev, "Failed to stop pipeline\n"); |
| 850 | return ret; |
| 851 | } |
| 852 | |
| 853 | pipe->state = SKL_PIPE_PAUSED; |
| 854 | } else { |
| 855 | /* If pipe was not created in FW, do not try to delete it */ |
| 856 | if (pipe->state < SKL_PIPE_CREATED) |
| 857 | return 0; |
| 858 | |
| 859 | ret = skl_ipc_delete_pipeline(&ctx->ipc, pipe->ppl_id); |
| 860 | if (ret < 0) |
| 861 | dev_err(ctx->dev, "Failed to delete pipeline\n"); |
Jeeja KP | d2c7db8 | 2015-12-18 15:11:58 +0530 | [diff] [blame] | 862 | |
| 863 | pipe->state = SKL_PIPE_INVALID; |
Jeeja KP | c9b1e83 | 2015-08-01 19:40:44 +0530 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | return ret; |
| 867 | } |
| 868 | |
| 869 | /* |
| 870 | * A pipeline is also a scheduling entity in DSP which can be run, stopped |
| 871 | * For processing data the pipe need to be run by sending IPC set pipe state |
| 872 | * to DSP |
| 873 | */ |
| 874 | int skl_run_pipe(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 875 | { |
| 876 | int ret; |
| 877 | |
| 878 | dev_dbg(ctx->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id); |
| 879 | |
| 880 | /* If pipe was not created in FW, do not try to pause or delete */ |
| 881 | if (pipe->state < SKL_PIPE_CREATED) |
| 882 | return 0; |
| 883 | |
| 884 | /* Pipe has to be paused before it is started */ |
| 885 | ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED); |
| 886 | if (ret < 0) { |
| 887 | dev_err(ctx->dev, "Failed to pause pipe\n"); |
| 888 | return ret; |
| 889 | } |
| 890 | |
| 891 | pipe->state = SKL_PIPE_PAUSED; |
| 892 | |
| 893 | ret = skl_set_pipe_state(ctx, pipe, PPL_RUNNING); |
| 894 | if (ret < 0) { |
| 895 | dev_err(ctx->dev, "Failed to start pipe\n"); |
| 896 | return ret; |
| 897 | } |
| 898 | |
| 899 | pipe->state = SKL_PIPE_STARTED; |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | /* |
| 905 | * Stop the pipeline by sending set pipe state IPC |
| 906 | * DSP doesnt implement stop so we always send pause message |
| 907 | */ |
| 908 | int skl_stop_pipe(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 909 | { |
| 910 | int ret; |
| 911 | |
| 912 | dev_dbg(ctx->dev, "In %s pipe=%d\n", __func__, pipe->ppl_id); |
| 913 | |
| 914 | /* If pipe was not created in FW, do not try to pause or delete */ |
| 915 | if (pipe->state < SKL_PIPE_PAUSED) |
| 916 | return 0; |
| 917 | |
| 918 | ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED); |
| 919 | if (ret < 0) { |
| 920 | dev_dbg(ctx->dev, "Failed to stop pipe\n"); |
| 921 | return ret; |
| 922 | } |
| 923 | |
| 924 | pipe->state = SKL_PIPE_CREATED; |
| 925 | |
| 926 | return 0; |
| 927 | } |
Jeeja KP | 9939a9c | 2015-11-28 15:01:47 +0530 | [diff] [blame] | 928 | |
| 929 | /* Algo parameter set helper function */ |
| 930 | int skl_set_module_params(struct skl_sst *ctx, u32 *params, int size, |
| 931 | u32 param_id, struct skl_module_cfg *mcfg) |
| 932 | { |
| 933 | struct skl_ipc_large_config_msg msg; |
| 934 | |
| 935 | msg.module_id = mcfg->id.module_id; |
| 936 | msg.instance_id = mcfg->id.instance_id; |
| 937 | msg.param_data_size = size; |
| 938 | msg.large_param_id = param_id; |
| 939 | |
| 940 | return skl_ipc_set_large_config(&ctx->ipc, &msg, params); |
| 941 | } |
Omair M Abdullah | 7d9f291 | 2015-12-03 23:29:56 +0530 | [diff] [blame] | 942 | |
| 943 | int skl_get_module_params(struct skl_sst *ctx, u32 *params, int size, |
| 944 | u32 param_id, struct skl_module_cfg *mcfg) |
| 945 | { |
| 946 | struct skl_ipc_large_config_msg msg; |
| 947 | |
| 948 | msg.module_id = mcfg->id.module_id; |
| 949 | msg.instance_id = mcfg->id.instance_id; |
| 950 | msg.param_data_size = size; |
| 951 | msg.large_param_id = param_id; |
| 952 | |
| 953 | return skl_ipc_get_large_config(&ctx->ipc, &msg, params); |
| 954 | } |