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 | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 75 | static int skl_dsp_setup_spib(struct device *dev, unsigned int size, |
| 76 | int stream_tag, int enable) |
| 77 | { |
| 78 | struct hdac_ext_bus *ebus = dev_get_drvdata(dev); |
| 79 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
| 80 | struct hdac_stream *stream = snd_hdac_get_stream(bus, |
| 81 | SNDRV_PCM_STREAM_PLAYBACK, stream_tag); |
| 82 | struct hdac_ext_stream *estream; |
| 83 | |
| 84 | if (!stream) |
| 85 | return -EINVAL; |
| 86 | |
| 87 | estream = stream_to_hdac_ext_stream(stream); |
| 88 | /* enable/disable SPIB for this hdac stream */ |
| 89 | snd_hdac_ext_stream_spbcap_enable(ebus, enable, stream->index); |
| 90 | |
| 91 | /* set the spib value */ |
| 92 | snd_hdac_ext_stream_set_spib(ebus, estream, size); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static int skl_dsp_prepare(struct device *dev, unsigned int format, |
| 98 | unsigned int size, struct snd_dma_buffer *dmab) |
| 99 | { |
| 100 | struct hdac_ext_bus *ebus = dev_get_drvdata(dev); |
| 101 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
| 102 | struct hdac_ext_stream *estream; |
| 103 | struct hdac_stream *stream; |
| 104 | struct snd_pcm_substream substream; |
| 105 | int ret; |
| 106 | |
| 107 | if (!bus) |
| 108 | return -ENODEV; |
| 109 | |
| 110 | memset(&substream, 0, sizeof(substream)); |
| 111 | substream.stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 112 | |
| 113 | estream = snd_hdac_ext_stream_assign(ebus, &substream, |
| 114 | HDAC_EXT_STREAM_TYPE_HOST); |
| 115 | if (!estream) |
| 116 | return -ENODEV; |
| 117 | |
| 118 | stream = hdac_stream(estream); |
| 119 | |
| 120 | /* assign decouple host dma channel */ |
| 121 | ret = snd_hdac_dsp_prepare(stream, format, size, dmab); |
| 122 | if (ret < 0) |
| 123 | return ret; |
| 124 | |
| 125 | skl_dsp_setup_spib(dev, size, stream->stream_tag, true); |
| 126 | |
| 127 | return stream->stream_tag; |
| 128 | } |
| 129 | |
| 130 | static int skl_dsp_trigger(struct device *dev, bool start, int stream_tag) |
| 131 | { |
| 132 | struct hdac_ext_bus *ebus = dev_get_drvdata(dev); |
| 133 | struct hdac_stream *stream; |
| 134 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
| 135 | |
| 136 | if (!bus) |
| 137 | return -ENODEV; |
| 138 | |
| 139 | stream = snd_hdac_get_stream(bus, |
| 140 | SNDRV_PCM_STREAM_PLAYBACK, stream_tag); |
| 141 | if (!stream) |
| 142 | return -EINVAL; |
| 143 | |
| 144 | snd_hdac_dsp_trigger(stream, start); |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int skl_dsp_cleanup(struct device *dev, |
| 150 | struct snd_dma_buffer *dmab, int stream_tag) |
| 151 | { |
| 152 | struct hdac_ext_bus *ebus = dev_get_drvdata(dev); |
| 153 | struct hdac_stream *stream; |
| 154 | struct hdac_ext_stream *estream; |
| 155 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
| 156 | |
| 157 | if (!bus) |
| 158 | return -ENODEV; |
| 159 | |
| 160 | stream = snd_hdac_get_stream(bus, |
| 161 | SNDRV_PCM_STREAM_PLAYBACK, stream_tag); |
| 162 | if (!stream) |
| 163 | return -EINVAL; |
| 164 | |
| 165 | estream = stream_to_hdac_ext_stream(stream); |
| 166 | skl_dsp_setup_spib(dev, 0, stream_tag, false); |
| 167 | snd_hdac_ext_stream_release(estream, HDAC_EXT_STREAM_TYPE_HOST); |
| 168 | |
| 169 | snd_hdac_dsp_cleanup(stream, dmab); |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 174 | static struct skl_dsp_loader_ops skl_get_loader_ops(void) |
| 175 | { |
| 176 | struct skl_dsp_loader_ops loader_ops; |
| 177 | |
| 178 | memset(&loader_ops, 0, sizeof(struct skl_dsp_loader_ops)); |
| 179 | |
| 180 | loader_ops.alloc_dma_buf = skl_alloc_dma_buf; |
| 181 | loader_ops.free_dma_buf = skl_free_dma_buf; |
| 182 | |
| 183 | return loader_ops; |
| 184 | }; |
| 185 | |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 186 | static struct skl_dsp_loader_ops bxt_get_loader_ops(void) |
| 187 | { |
| 188 | struct skl_dsp_loader_ops loader_ops; |
| 189 | |
| 190 | memset(&loader_ops, 0, sizeof(loader_ops)); |
| 191 | |
| 192 | loader_ops.alloc_dma_buf = skl_alloc_dma_buf; |
| 193 | loader_ops.free_dma_buf = skl_free_dma_buf; |
| 194 | loader_ops.prepare = skl_dsp_prepare; |
| 195 | loader_ops.trigger = skl_dsp_trigger; |
| 196 | loader_ops.cleanup = skl_dsp_cleanup; |
| 197 | |
| 198 | return loader_ops; |
| 199 | }; |
| 200 | |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 201 | static const struct skl_dsp_ops dsp_ops[] = { |
| 202 | { |
| 203 | .id = 0x9d70, |
| 204 | .loader_ops = skl_get_loader_ops, |
| 205 | .init = skl_sst_dsp_init, |
Vinod Koul | 78cdbbd | 2016-07-26 18:06:42 +0530 | [diff] [blame^] | 206 | .init_fw = skl_sst_init_fw, |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 207 | .cleanup = skl_sst_dsp_cleanup |
| 208 | }, |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 209 | { |
Vinod Koul | 451dfb5f | 2016-07-11 22:02:08 +0530 | [diff] [blame] | 210 | .id = 0x9d71, |
| 211 | .loader_ops = skl_get_loader_ops, |
| 212 | .init = skl_sst_dsp_init, |
Vinod Koul | 78cdbbd | 2016-07-26 18:06:42 +0530 | [diff] [blame^] | 213 | .init_fw = skl_sst_init_fw, |
Vinod Koul | 451dfb5f | 2016-07-11 22:02:08 +0530 | [diff] [blame] | 214 | .cleanup = skl_sst_dsp_cleanup |
| 215 | }, |
| 216 | { |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 217 | .id = 0x5a98, |
| 218 | .loader_ops = bxt_get_loader_ops, |
| 219 | .init = bxt_sst_dsp_init, |
Vinod Koul | 78cdbbd | 2016-07-26 18:06:42 +0530 | [diff] [blame^] | 220 | .init_fw = bxt_sst_init_fw, |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 221 | .cleanup = bxt_sst_dsp_cleanup |
| 222 | }, |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 223 | }; |
| 224 | |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 225 | const struct skl_dsp_ops *skl_get_dsp_ops(int pci_id) |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 226 | { |
| 227 | int i; |
| 228 | |
| 229 | for (i = 0; i < ARRAY_SIZE(dsp_ops); i++) { |
| 230 | if (dsp_ops[i].id == pci_id) |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 231 | return &dsp_ops[i]; |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 232 | } |
| 233 | |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 234 | return NULL; |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 235 | } |
| 236 | |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 237 | int skl_init_dsp(struct skl *skl) |
| 238 | { |
| 239 | void __iomem *mmio_base; |
| 240 | struct hdac_ext_bus *ebus = &skl->ebus; |
| 241 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 242 | struct skl_dsp_loader_ops loader_ops; |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 243 | int irq = bus->irq; |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 244 | const struct skl_dsp_ops *ops; |
| 245 | int ret; |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 246 | |
| 247 | /* enable ppcap interrupt */ |
| 248 | snd_hdac_ext_bus_ppcap_enable(&skl->ebus, true); |
| 249 | snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, true); |
| 250 | |
| 251 | /* read the BAR of the ADSP MMIO */ |
| 252 | mmio_base = pci_ioremap_bar(skl->pci, 4); |
| 253 | if (mmio_base == NULL) { |
| 254 | dev_err(bus->dev, "ioremap error\n"); |
| 255 | return -ENXIO; |
| 256 | } |
| 257 | |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 258 | ops = skl_get_dsp_ops(skl->pci->device); |
| 259 | if (!ops) |
| 260 | return -EIO; |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 261 | |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 262 | loader_ops = ops->loader_ops(); |
| 263 | ret = ops->init(bus->dev, mmio_base, irq, |
| 264 | skl->fw_name, loader_ops, |
| 265 | &skl->skl_sst); |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 266 | |
Jeeja KP | 2ac454f | 2015-10-22 23:22:40 +0530 | [diff] [blame] | 267 | if (ret < 0) |
| 268 | return ret; |
| 269 | |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 270 | dev_dbg(bus->dev, "dsp registration status=%d\n", ret); |
| 271 | |
| 272 | return ret; |
| 273 | } |
| 274 | |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 275 | int skl_free_dsp(struct skl *skl) |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 276 | { |
| 277 | struct hdac_ext_bus *ebus = &skl->ebus; |
| 278 | struct hdac_bus *bus = ebus_to_hbus(ebus); |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 279 | struct skl_sst *ctx = skl->skl_sst; |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 280 | const struct skl_dsp_ops *ops; |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 281 | |
| 282 | /* disable ppcap interrupt */ |
| 283 | snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, false); |
| 284 | |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 285 | ops = skl_get_dsp_ops(skl->pci->device); |
| 286 | if (!ops) |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 287 | return -EIO; |
| 288 | |
Vinod Koul | 73a6758 | 2016-07-26 18:06:41 +0530 | [diff] [blame] | 289 | ops->cleanup(bus->dev, ctx); |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 290 | |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 291 | if (ctx->dsp->addr.lpe) |
| 292 | iounmap(ctx->dsp->addr.lpe); |
Jeeja KP | bc23ca3 | 2016-03-11 10:12:53 +0530 | [diff] [blame] | 293 | |
| 294 | return 0; |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | int skl_suspend_dsp(struct skl *skl) |
| 298 | { |
| 299 | struct skl_sst *ctx = skl->skl_sst; |
| 300 | int ret; |
| 301 | |
| 302 | /* if ppcap is not supported return 0 */ |
| 303 | if (!skl->ebus.ppcap) |
| 304 | return 0; |
| 305 | |
| 306 | ret = skl_dsp_sleep(ctx->dsp); |
| 307 | if (ret < 0) |
| 308 | return ret; |
| 309 | |
| 310 | /* disable ppcap interrupt */ |
| 311 | snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, false); |
| 312 | snd_hdac_ext_bus_ppcap_enable(&skl->ebus, false); |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | int skl_resume_dsp(struct skl *skl) |
| 318 | { |
| 319 | struct skl_sst *ctx = skl->skl_sst; |
Jeeja KP | 4e10996 | 2015-10-22 23:22:39 +0530 | [diff] [blame] | 320 | int ret; |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 321 | |
| 322 | /* if ppcap is not supported return 0 */ |
| 323 | if (!skl->ebus.ppcap) |
| 324 | return 0; |
| 325 | |
| 326 | /* enable ppcap interrupt */ |
| 327 | snd_hdac_ext_bus_ppcap_enable(&skl->ebus, true); |
| 328 | snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, true); |
| 329 | |
Vinod Koul | 78cdbbd | 2016-07-26 18:06:42 +0530 | [diff] [blame^] | 330 | /* check if DSP 1st boot is done */ |
| 331 | if (skl->skl_sst->is_first_boot == true) |
| 332 | return 0; |
| 333 | |
Jeeja KP | 4e10996 | 2015-10-22 23:22:39 +0530 | [diff] [blame] | 334 | ret = skl_dsp_wake(ctx->dsp); |
| 335 | if (ret < 0) |
| 336 | return ret; |
| 337 | |
| 338 | skl_dsp_enable_notification(skl->skl_sst, false); |
| 339 | return ret; |
Jeeja KP | d255b09 | 2015-07-21 23:53:56 +0530 | [diff] [blame] | 340 | } |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 341 | |
| 342 | enum skl_bitdepth skl_get_bit_depth(int params) |
| 343 | { |
| 344 | switch (params) { |
| 345 | case 8: |
| 346 | return SKL_DEPTH_8BIT; |
| 347 | |
| 348 | case 16: |
| 349 | return SKL_DEPTH_16BIT; |
| 350 | |
| 351 | case 24: |
| 352 | return SKL_DEPTH_24BIT; |
| 353 | |
| 354 | case 32: |
| 355 | return SKL_DEPTH_32BIT; |
| 356 | |
| 357 | default: |
| 358 | return SKL_DEPTH_INVALID; |
| 359 | |
| 360 | } |
| 361 | } |
| 362 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 363 | /* |
| 364 | * Each module in DSP expects a base module configuration, which consists of |
| 365 | * PCM format information, which we calculate in driver and resource values |
| 366 | * which are read from widget information passed through topology binary |
| 367 | * This is send when we create a module with INIT_INSTANCE IPC msg |
| 368 | */ |
| 369 | static void skl_set_base_module_format(struct skl_sst *ctx, |
| 370 | struct skl_module_cfg *mconfig, |
| 371 | struct skl_base_cfg *base_cfg) |
| 372 | { |
Hardik T Shah | 4cd9899 | 2015-10-27 09:22:55 +0900 | [diff] [blame] | 373 | struct skl_module_fmt *format = &mconfig->in_fmt[0]; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 374 | |
| 375 | base_cfg->audio_fmt.number_of_channels = (u8)format->channels; |
| 376 | |
| 377 | base_cfg->audio_fmt.s_freq = format->s_freq; |
| 378 | base_cfg->audio_fmt.bit_depth = format->bit_depth; |
| 379 | base_cfg->audio_fmt.valid_bit_depth = format->valid_bit_depth; |
| 380 | base_cfg->audio_fmt.ch_cfg = format->ch_cfg; |
| 381 | |
| 382 | dev_dbg(ctx->dev, "bit_depth=%x valid_bd=%x ch_config=%x\n", |
| 383 | format->bit_depth, format->valid_bit_depth, |
| 384 | format->ch_cfg); |
| 385 | |
Jeeja KP | 3e81f1a | 2015-10-27 09:22:59 +0900 | [diff] [blame] | 386 | base_cfg->audio_fmt.channel_map = format->ch_map; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 387 | |
Jeeja KP | 3e81f1a | 2015-10-27 09:22:59 +0900 | [diff] [blame] | 388 | base_cfg->audio_fmt.interleaving = format->interleaving_style; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 389 | |
| 390 | base_cfg->cps = mconfig->mcps; |
| 391 | base_cfg->ibs = mconfig->ibs; |
| 392 | base_cfg->obs = mconfig->obs; |
Jeeja KP | b18c458 | 2015-12-03 23:29:51 +0530 | [diff] [blame] | 393 | base_cfg->is_pages = mconfig->mem_pages; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Copies copier capabilities into copier module and updates copier module |
| 398 | * config size. |
| 399 | */ |
| 400 | static void skl_copy_copier_caps(struct skl_module_cfg *mconfig, |
| 401 | struct skl_cpr_cfg *cpr_mconfig) |
| 402 | { |
| 403 | if (mconfig->formats_config.caps_size == 0) |
| 404 | return; |
| 405 | |
| 406 | memcpy(cpr_mconfig->gtw_cfg.config_data, |
| 407 | mconfig->formats_config.caps, |
| 408 | mconfig->formats_config.caps_size); |
| 409 | |
| 410 | cpr_mconfig->gtw_cfg.config_length = |
| 411 | (mconfig->formats_config.caps_size) / 4; |
| 412 | } |
| 413 | |
Jeeja KP | bfa764a | 2015-10-22 23:22:41 +0530 | [diff] [blame] | 414 | #define SKL_NON_GATEWAY_CPR_NODE_ID 0xFFFFFFFF |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 415 | /* |
| 416 | * Calculate the gatewat settings required for copier module, type of |
| 417 | * gateway and index of gateway to use |
| 418 | */ |
Dharageswari.R | 4fdf810 | 2016-02-05 12:19:05 +0530 | [diff] [blame] | 419 | static u32 skl_get_node_id(struct skl_sst *ctx, |
| 420 | struct skl_module_cfg *mconfig) |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 421 | { |
| 422 | union skl_connector_node_id node_id = {0}; |
Jeeja KP | d7b1881 | 2015-10-22 23:22:38 +0530 | [diff] [blame] | 423 | union skl_ssp_dma_node ssp_node = {0}; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 424 | struct skl_pipe_params *params = mconfig->pipe->p_params; |
| 425 | |
| 426 | switch (mconfig->dev_type) { |
| 427 | case SKL_DEVICE_BT: |
| 428 | node_id.node.dma_type = |
| 429 | (SKL_CONN_SOURCE == mconfig->hw_conn_type) ? |
| 430 | SKL_DMA_I2S_LINK_OUTPUT_CLASS : |
| 431 | SKL_DMA_I2S_LINK_INPUT_CLASS; |
| 432 | node_id.node.vindex = params->host_dma_id + |
| 433 | (mconfig->vbus_id << 3); |
| 434 | break; |
| 435 | |
| 436 | case SKL_DEVICE_I2S: |
| 437 | node_id.node.dma_type = |
| 438 | (SKL_CONN_SOURCE == mconfig->hw_conn_type) ? |
| 439 | SKL_DMA_I2S_LINK_OUTPUT_CLASS : |
| 440 | SKL_DMA_I2S_LINK_INPUT_CLASS; |
Jeeja KP | d7b1881 | 2015-10-22 23:22:38 +0530 | [diff] [blame] | 441 | ssp_node.dma_node.time_slot_index = mconfig->time_slot; |
| 442 | ssp_node.dma_node.i2s_instance = mconfig->vbus_id; |
| 443 | node_id.node.vindex = ssp_node.val; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 444 | break; |
| 445 | |
| 446 | case SKL_DEVICE_DMIC: |
| 447 | node_id.node.dma_type = SKL_DMA_DMIC_LINK_INPUT_CLASS; |
| 448 | node_id.node.vindex = mconfig->vbus_id + |
| 449 | (mconfig->time_slot); |
| 450 | break; |
| 451 | |
| 452 | case SKL_DEVICE_HDALINK: |
| 453 | node_id.node.dma_type = |
| 454 | (SKL_CONN_SOURCE == mconfig->hw_conn_type) ? |
| 455 | SKL_DMA_HDA_LINK_OUTPUT_CLASS : |
| 456 | SKL_DMA_HDA_LINK_INPUT_CLASS; |
| 457 | node_id.node.vindex = params->link_dma_id; |
| 458 | break; |
| 459 | |
Jeeja KP | bfa764a | 2015-10-22 23:22:41 +0530 | [diff] [blame] | 460 | case SKL_DEVICE_HDAHOST: |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 461 | node_id.node.dma_type = |
| 462 | (SKL_CONN_SOURCE == mconfig->hw_conn_type) ? |
| 463 | SKL_DMA_HDA_HOST_OUTPUT_CLASS : |
| 464 | SKL_DMA_HDA_HOST_INPUT_CLASS; |
| 465 | node_id.node.vindex = params->host_dma_id; |
| 466 | break; |
Jeeja KP | bfa764a | 2015-10-22 23:22:41 +0530 | [diff] [blame] | 467 | |
| 468 | default: |
Dharageswari.R | 4fdf810 | 2016-02-05 12:19:05 +0530 | [diff] [blame] | 469 | node_id.val = 0xFFFFFFFF; |
| 470 | break; |
| 471 | } |
| 472 | |
| 473 | return node_id.val; |
| 474 | } |
| 475 | |
| 476 | static void skl_setup_cpr_gateway_cfg(struct skl_sst *ctx, |
| 477 | struct skl_module_cfg *mconfig, |
| 478 | struct skl_cpr_cfg *cpr_mconfig) |
| 479 | { |
| 480 | cpr_mconfig->gtw_cfg.node_id = skl_get_node_id(ctx, mconfig); |
| 481 | |
| 482 | 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] | 483 | cpr_mconfig->cpr_feature_mask = 0; |
| 484 | return; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 485 | } |
| 486 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 487 | if (SKL_CONN_SOURCE == mconfig->hw_conn_type) |
| 488 | cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * mconfig->obs; |
| 489 | else |
| 490 | cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * mconfig->ibs; |
| 491 | |
| 492 | cpr_mconfig->cpr_feature_mask = 0; |
| 493 | cpr_mconfig->gtw_cfg.config_length = 0; |
| 494 | |
| 495 | skl_copy_copier_caps(mconfig, cpr_mconfig); |
| 496 | } |
| 497 | |
Dharageswari.R | c115fa5 | 2016-02-05 12:19:07 +0530 | [diff] [blame] | 498 | #define DMA_CONTROL_ID 5 |
| 499 | |
| 500 | int skl_dsp_set_dma_control(struct skl_sst *ctx, struct skl_module_cfg *mconfig) |
| 501 | { |
| 502 | struct skl_dma_control *dma_ctrl; |
| 503 | struct skl_i2s_config_blob config_blob; |
| 504 | struct skl_ipc_large_config_msg msg = {0}; |
| 505 | int err = 0; |
| 506 | |
| 507 | |
| 508 | /* |
| 509 | * if blob size is same as capablity size, then no dma control |
| 510 | * present so return |
| 511 | */ |
| 512 | if (mconfig->formats_config.caps_size == sizeof(config_blob)) |
| 513 | return 0; |
| 514 | |
| 515 | msg.large_param_id = DMA_CONTROL_ID; |
| 516 | msg.param_data_size = sizeof(struct skl_dma_control) + |
| 517 | mconfig->formats_config.caps_size; |
| 518 | |
| 519 | dma_ctrl = kzalloc(msg.param_data_size, GFP_KERNEL); |
| 520 | if (dma_ctrl == NULL) |
| 521 | return -ENOMEM; |
| 522 | |
| 523 | dma_ctrl->node_id = skl_get_node_id(ctx, mconfig); |
| 524 | |
| 525 | /* size in dwords */ |
| 526 | dma_ctrl->config_length = sizeof(config_blob) / 4; |
| 527 | |
| 528 | memcpy(dma_ctrl->config_data, mconfig->formats_config.caps, |
| 529 | mconfig->formats_config.caps_size); |
| 530 | |
| 531 | err = skl_ipc_set_large_config(&ctx->ipc, &msg, (u32 *)dma_ctrl); |
| 532 | |
| 533 | kfree(dma_ctrl); |
| 534 | |
| 535 | return err; |
| 536 | } |
| 537 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 538 | static void skl_setup_out_format(struct skl_sst *ctx, |
| 539 | struct skl_module_cfg *mconfig, |
| 540 | struct skl_audio_data_format *out_fmt) |
| 541 | { |
Hardik T Shah | 4cd9899 | 2015-10-27 09:22:55 +0900 | [diff] [blame] | 542 | struct skl_module_fmt *format = &mconfig->out_fmt[0]; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 543 | |
| 544 | out_fmt->number_of_channels = (u8)format->channels; |
| 545 | out_fmt->s_freq = format->s_freq; |
| 546 | out_fmt->bit_depth = format->bit_depth; |
| 547 | out_fmt->valid_bit_depth = format->valid_bit_depth; |
| 548 | out_fmt->ch_cfg = format->ch_cfg; |
| 549 | |
Jeeja KP | 3e81f1a | 2015-10-27 09:22:59 +0900 | [diff] [blame] | 550 | out_fmt->channel_map = format->ch_map; |
| 551 | out_fmt->interleaving = format->interleaving_style; |
| 552 | out_fmt->sample_type = format->sample_type; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 553 | |
| 554 | dev_dbg(ctx->dev, "copier out format chan=%d fre=%d bitdepth=%d\n", |
| 555 | out_fmt->number_of_channels, format->s_freq, format->bit_depth); |
| 556 | } |
| 557 | |
| 558 | /* |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 559 | * DSP needs SRC module for frequency conversion, SRC takes base module |
| 560 | * configuration and the target frequency as extra parameter passed as src |
| 561 | * config |
| 562 | */ |
| 563 | static void skl_set_src_format(struct skl_sst *ctx, |
| 564 | struct skl_module_cfg *mconfig, |
| 565 | struct skl_src_module_cfg *src_mconfig) |
| 566 | { |
Hardik T Shah | 4cd9899 | 2015-10-27 09:22:55 +0900 | [diff] [blame] | 567 | struct skl_module_fmt *fmt = &mconfig->out_fmt[0]; |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 568 | |
| 569 | skl_set_base_module_format(ctx, mconfig, |
| 570 | (struct skl_base_cfg *)src_mconfig); |
| 571 | |
| 572 | src_mconfig->src_cfg = fmt->s_freq; |
| 573 | } |
| 574 | |
| 575 | /* |
| 576 | * DSP needs updown module to do channel conversion. updown module take base |
| 577 | * module configuration and channel configuration |
| 578 | * It also take coefficients and now we have defaults applied here |
| 579 | */ |
| 580 | static void skl_set_updown_mixer_format(struct skl_sst *ctx, |
| 581 | struct skl_module_cfg *mconfig, |
| 582 | struct skl_up_down_mixer_cfg *mixer_mconfig) |
| 583 | { |
Hardik T Shah | 4cd9899 | 2015-10-27 09:22:55 +0900 | [diff] [blame] | 584 | struct skl_module_fmt *fmt = &mconfig->out_fmt[0]; |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 585 | int i = 0; |
| 586 | |
| 587 | skl_set_base_module_format(ctx, mconfig, |
| 588 | (struct skl_base_cfg *)mixer_mconfig); |
| 589 | mixer_mconfig->out_ch_cfg = fmt->ch_cfg; |
| 590 | |
| 591 | /* Select F/W default coefficient */ |
| 592 | mixer_mconfig->coeff_sel = 0x0; |
| 593 | |
| 594 | /* User coeff, don't care since we are selecting F/W defaults */ |
| 595 | for (i = 0; i < UP_DOWN_MIXER_MAX_COEFF; i++) |
| 596 | mixer_mconfig->coeff[i] = 0xDEADBEEF; |
| 597 | } |
| 598 | |
| 599 | /* |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 600 | * 'copier' is DSP internal module which copies data from Host DMA (HDA host |
| 601 | * dma) or link (hda link, SSP, PDM) |
| 602 | * Here we calculate the copier module parameters, like PCM format, output |
| 603 | * format, gateway settings |
| 604 | * copier_module_config is sent as input buffer with INIT_INSTANCE IPC msg |
| 605 | */ |
| 606 | static void skl_set_copier_format(struct skl_sst *ctx, |
| 607 | struct skl_module_cfg *mconfig, |
| 608 | struct skl_cpr_cfg *cpr_mconfig) |
| 609 | { |
| 610 | struct skl_audio_data_format *out_fmt = &cpr_mconfig->out_fmt; |
| 611 | struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)cpr_mconfig; |
| 612 | |
| 613 | skl_set_base_module_format(ctx, mconfig, base_cfg); |
| 614 | |
| 615 | skl_setup_out_format(ctx, mconfig, out_fmt); |
| 616 | skl_setup_cpr_gateway_cfg(ctx, mconfig, cpr_mconfig); |
| 617 | } |
| 618 | |
Jeeja KP | 399b210 | 2015-11-28 15:01:48 +0530 | [diff] [blame] | 619 | /* |
| 620 | * Algo module are DSP pre processing modules. Algo module take base module |
| 621 | * configuration and params |
| 622 | */ |
| 623 | |
| 624 | static void skl_set_algo_format(struct skl_sst *ctx, |
| 625 | struct skl_module_cfg *mconfig, |
| 626 | struct skl_algo_cfg *algo_mcfg) |
| 627 | { |
| 628 | struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)algo_mcfg; |
| 629 | |
| 630 | skl_set_base_module_format(ctx, mconfig, base_cfg); |
| 631 | |
| 632 | if (mconfig->formats_config.caps_size == 0) |
| 633 | return; |
| 634 | |
| 635 | memcpy(algo_mcfg->params, |
| 636 | mconfig->formats_config.caps, |
| 637 | mconfig->formats_config.caps_size); |
| 638 | |
| 639 | } |
| 640 | |
Dharageswari R | fd18110 | 2015-12-03 23:29:52 +0530 | [diff] [blame] | 641 | /* |
| 642 | * Mic select module allows selecting one or many input channels, thus |
| 643 | * acting as a demux. |
| 644 | * |
| 645 | * Mic select module take base module configuration and out-format |
| 646 | * configuration |
| 647 | */ |
| 648 | static void skl_set_base_outfmt_format(struct skl_sst *ctx, |
| 649 | struct skl_module_cfg *mconfig, |
| 650 | struct skl_base_outfmt_cfg *base_outfmt_mcfg) |
| 651 | { |
| 652 | struct skl_audio_data_format *out_fmt = &base_outfmt_mcfg->out_fmt; |
| 653 | struct skl_base_cfg *base_cfg = |
| 654 | (struct skl_base_cfg *)base_outfmt_mcfg; |
| 655 | |
| 656 | skl_set_base_module_format(ctx, mconfig, base_cfg); |
| 657 | skl_setup_out_format(ctx, mconfig, out_fmt); |
| 658 | } |
| 659 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 660 | static u16 skl_get_module_param_size(struct skl_sst *ctx, |
| 661 | struct skl_module_cfg *mconfig) |
| 662 | { |
| 663 | u16 param_size; |
| 664 | |
| 665 | switch (mconfig->m_type) { |
| 666 | case SKL_MODULE_TYPE_COPIER: |
| 667 | param_size = sizeof(struct skl_cpr_cfg); |
| 668 | param_size += mconfig->formats_config.caps_size; |
| 669 | return param_size; |
| 670 | |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 671 | case SKL_MODULE_TYPE_SRCINT: |
| 672 | return sizeof(struct skl_src_module_cfg); |
| 673 | |
| 674 | case SKL_MODULE_TYPE_UPDWMIX: |
| 675 | return sizeof(struct skl_up_down_mixer_cfg); |
| 676 | |
Jeeja KP | 399b210 | 2015-11-28 15:01:48 +0530 | [diff] [blame] | 677 | case SKL_MODULE_TYPE_ALGO: |
| 678 | param_size = sizeof(struct skl_base_cfg); |
| 679 | param_size += mconfig->formats_config.caps_size; |
| 680 | return param_size; |
| 681 | |
Dharageswari R | fd18110 | 2015-12-03 23:29:52 +0530 | [diff] [blame] | 682 | case SKL_MODULE_TYPE_BASE_OUTFMT: |
| 683 | return sizeof(struct skl_base_outfmt_cfg); |
| 684 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 685 | default: |
| 686 | /* |
| 687 | * return only base cfg when no specific module type is |
| 688 | * specified |
| 689 | */ |
| 690 | return sizeof(struct skl_base_cfg); |
| 691 | } |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | /* |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 697 | * DSP firmware supports various modules like copier, SRC, updown etc. |
| 698 | * These modules required various parameters to be calculated and sent for |
| 699 | * the module initialization to DSP. By default a generic module needs only |
| 700 | * base module format configuration |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 701 | */ |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 702 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 703 | static int skl_set_module_format(struct skl_sst *ctx, |
| 704 | struct skl_module_cfg *module_config, |
| 705 | u16 *module_config_size, |
| 706 | void **param_data) |
| 707 | { |
| 708 | u16 param_size; |
| 709 | |
| 710 | param_size = skl_get_module_param_size(ctx, module_config); |
| 711 | |
| 712 | *param_data = kzalloc(param_size, GFP_KERNEL); |
| 713 | if (NULL == *param_data) |
| 714 | return -ENOMEM; |
| 715 | |
| 716 | *module_config_size = param_size; |
| 717 | |
| 718 | switch (module_config->m_type) { |
| 719 | case SKL_MODULE_TYPE_COPIER: |
| 720 | skl_set_copier_format(ctx, module_config, *param_data); |
| 721 | break; |
| 722 | |
Hardik T Shah | a0ffe48 | 2015-08-01 19:40:42 +0530 | [diff] [blame] | 723 | case SKL_MODULE_TYPE_SRCINT: |
| 724 | skl_set_src_format(ctx, module_config, *param_data); |
| 725 | break; |
| 726 | |
| 727 | case SKL_MODULE_TYPE_UPDWMIX: |
| 728 | skl_set_updown_mixer_format(ctx, module_config, *param_data); |
| 729 | break; |
| 730 | |
Jeeja KP | 399b210 | 2015-11-28 15:01:48 +0530 | [diff] [blame] | 731 | case SKL_MODULE_TYPE_ALGO: |
| 732 | skl_set_algo_format(ctx, module_config, *param_data); |
| 733 | break; |
| 734 | |
Dharageswari R | fd18110 | 2015-12-03 23:29:52 +0530 | [diff] [blame] | 735 | case SKL_MODULE_TYPE_BASE_OUTFMT: |
| 736 | skl_set_base_outfmt_format(ctx, module_config, *param_data); |
| 737 | break; |
| 738 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 739 | default: |
| 740 | skl_set_base_module_format(ctx, module_config, *param_data); |
| 741 | break; |
| 742 | |
| 743 | } |
| 744 | |
| 745 | dev_dbg(ctx->dev, "Module type=%d config size: %d bytes\n", |
| 746 | module_config->id.module_id, param_size); |
Vedang Patel | 91c1832 | 2016-06-24 17:37:11 -0700 | [diff] [blame] | 747 | print_hex_dump_debug("Module params:", DUMP_PREFIX_OFFSET, 8, 4, |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 748 | *param_data, param_size, false); |
| 749 | return 0; |
| 750 | } |
| 751 | |
| 752 | static int skl_get_queue_index(struct skl_module_pin *mpin, |
| 753 | struct skl_module_inst_id id, int max) |
| 754 | { |
| 755 | int i; |
| 756 | |
| 757 | for (i = 0; i < max; i++) { |
| 758 | if (mpin[i].id.module_id == id.module_id && |
| 759 | mpin[i].id.instance_id == id.instance_id) |
| 760 | return i; |
| 761 | } |
| 762 | |
| 763 | return -EINVAL; |
| 764 | } |
| 765 | |
| 766 | /* |
| 767 | * Allocates queue for each module. |
| 768 | * if dynamic, the pin_index is allocated 0 to max_pin. |
| 769 | * In static, the pin_index is fixed based on module_id and instance id |
| 770 | */ |
| 771 | static int skl_alloc_queue(struct skl_module_pin *mpin, |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 772 | struct skl_module_cfg *tgt_cfg, int max) |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 773 | { |
| 774 | int i; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 775 | struct skl_module_inst_id id = tgt_cfg->id; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 776 | /* |
| 777 | * if pin in dynamic, find first free pin |
| 778 | * otherwise find match module and instance id pin as topology will |
| 779 | * ensure a unique pin is assigned to this so no need to |
| 780 | * allocate/free |
| 781 | */ |
| 782 | for (i = 0; i < max; i++) { |
| 783 | if (mpin[i].is_dynamic) { |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 784 | if (!mpin[i].in_use && |
| 785 | mpin[i].pin_state == SKL_PIN_UNBIND) { |
| 786 | |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 787 | mpin[i].in_use = true; |
| 788 | mpin[i].id.module_id = id.module_id; |
| 789 | mpin[i].id.instance_id = id.instance_id; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 790 | mpin[i].tgt_mcfg = tgt_cfg; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 791 | return i; |
| 792 | } |
| 793 | } else { |
| 794 | if (mpin[i].id.module_id == id.module_id && |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 795 | mpin[i].id.instance_id == id.instance_id && |
| 796 | mpin[i].pin_state == SKL_PIN_UNBIND) { |
| 797 | |
| 798 | mpin[i].tgt_mcfg = tgt_cfg; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 799 | return i; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 800 | } |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | return -EINVAL; |
| 805 | } |
| 806 | |
| 807 | static void skl_free_queue(struct skl_module_pin *mpin, int q_index) |
| 808 | { |
| 809 | if (mpin[q_index].is_dynamic) { |
| 810 | mpin[q_index].in_use = false; |
| 811 | mpin[q_index].id.module_id = 0; |
| 812 | mpin[q_index].id.instance_id = 0; |
| 813 | } |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 814 | mpin[q_index].pin_state = SKL_PIN_UNBIND; |
| 815 | mpin[q_index].tgt_mcfg = NULL; |
| 816 | } |
| 817 | |
| 818 | /* Module state will be set to unint, if all the out pin state is UNBIND */ |
| 819 | |
| 820 | static void skl_clear_module_state(struct skl_module_pin *mpin, int max, |
| 821 | struct skl_module_cfg *mcfg) |
| 822 | { |
| 823 | int i; |
| 824 | bool found = false; |
| 825 | |
| 826 | for (i = 0; i < max; i++) { |
| 827 | if (mpin[i].pin_state == SKL_PIN_UNBIND) |
| 828 | continue; |
| 829 | found = true; |
| 830 | break; |
| 831 | } |
| 832 | |
| 833 | if (!found) |
| 834 | mcfg->m_state = SKL_MODULE_UNINIT; |
| 835 | return; |
Jeeja KP | 23db472 | 2015-08-01 19:40:41 +0530 | [diff] [blame] | 836 | } |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 837 | |
| 838 | /* |
| 839 | * A module needs to be instanataited in DSP. A mdoule is present in a |
| 840 | * collection of module referred as a PIPE. |
| 841 | * We first calculate the module format, based on module type and then |
| 842 | * invoke the DSP by sending IPC INIT_INSTANCE using ipc helper |
| 843 | */ |
| 844 | int skl_init_module(struct skl_sst *ctx, |
Jeeja KP | 9939a9c | 2015-11-28 15:01:47 +0530 | [diff] [blame] | 845 | struct skl_module_cfg *mconfig) |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 846 | { |
| 847 | u16 module_config_size = 0; |
| 848 | void *param_data = NULL; |
| 849 | int ret; |
| 850 | struct skl_ipc_init_instance_msg msg; |
| 851 | |
| 852 | dev_dbg(ctx->dev, "%s: module_id = %d instance=%d\n", __func__, |
| 853 | mconfig->id.module_id, mconfig->id.instance_id); |
| 854 | |
| 855 | if (mconfig->pipe->state != SKL_PIPE_CREATED) { |
| 856 | dev_err(ctx->dev, "Pipe not created state= %d pipe_id= %d\n", |
| 857 | mconfig->pipe->state, mconfig->pipe->ppl_id); |
| 858 | return -EIO; |
| 859 | } |
| 860 | |
| 861 | ret = skl_set_module_format(ctx, mconfig, |
| 862 | &module_config_size, ¶m_data); |
| 863 | if (ret < 0) { |
| 864 | dev_err(ctx->dev, "Failed to set module format ret=%d\n", ret); |
| 865 | return ret; |
| 866 | } |
| 867 | |
| 868 | msg.module_id = mconfig->id.module_id; |
| 869 | msg.instance_id = mconfig->id.instance_id; |
| 870 | msg.ppl_instance_id = mconfig->pipe->ppl_id; |
| 871 | msg.param_data_size = module_config_size; |
| 872 | msg.core_id = mconfig->core_id; |
| 873 | |
| 874 | ret = skl_ipc_init_instance(&ctx->ipc, &msg, param_data); |
| 875 | if (ret < 0) { |
| 876 | dev_err(ctx->dev, "Failed to init instance ret=%d\n", ret); |
| 877 | kfree(param_data); |
| 878 | return ret; |
| 879 | } |
| 880 | mconfig->m_state = SKL_MODULE_INIT_DONE; |
Mousumi Jana | 76222d6d | 2016-04-28 18:45:26 +0530 | [diff] [blame] | 881 | kfree(param_data); |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 882 | return ret; |
| 883 | } |
| 884 | |
| 885 | static void skl_dump_bind_info(struct skl_sst *ctx, struct skl_module_cfg |
| 886 | *src_module, struct skl_module_cfg *dst_module) |
| 887 | { |
| 888 | dev_dbg(ctx->dev, "%s: src module_id = %d src_instance=%d\n", |
| 889 | __func__, src_module->id.module_id, src_module->id.instance_id); |
| 890 | dev_dbg(ctx->dev, "%s: dst_module=%d dst_instacne=%d\n", __func__, |
| 891 | dst_module->id.module_id, dst_module->id.instance_id); |
| 892 | |
| 893 | dev_dbg(ctx->dev, "src_module state = %d dst module state = %d\n", |
| 894 | src_module->m_state, dst_module->m_state); |
| 895 | } |
| 896 | |
| 897 | /* |
| 898 | * On module freeup, we need to unbind the module with modules |
| 899 | * it is already bind. |
| 900 | * Find the pin allocated and unbind then using bind_unbind IPC |
| 901 | */ |
| 902 | int skl_unbind_modules(struct skl_sst *ctx, |
| 903 | struct skl_module_cfg *src_mcfg, |
| 904 | struct skl_module_cfg *dst_mcfg) |
| 905 | { |
| 906 | int ret; |
| 907 | struct skl_ipc_bind_unbind_msg msg; |
| 908 | struct skl_module_inst_id src_id = src_mcfg->id; |
| 909 | struct skl_module_inst_id dst_id = dst_mcfg->id; |
| 910 | int in_max = dst_mcfg->max_in_queue; |
| 911 | int out_max = src_mcfg->max_out_queue; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 912 | int src_index, dst_index, src_pin_state, dst_pin_state; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 913 | |
| 914 | skl_dump_bind_info(ctx, src_mcfg, dst_mcfg); |
| 915 | |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 916 | /* get src queue index */ |
| 917 | src_index = skl_get_queue_index(src_mcfg->m_out_pin, dst_id, out_max); |
| 918 | if (src_index < 0) |
Jeeja KP | 9cf3049 | 2016-02-03 17:59:48 +0530 | [diff] [blame] | 919 | return 0; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 920 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 921 | msg.src_queue = src_index; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 922 | |
| 923 | /* get dst queue index */ |
| 924 | dst_index = skl_get_queue_index(dst_mcfg->m_in_pin, src_id, in_max); |
| 925 | if (dst_index < 0) |
Jeeja KP | 9cf3049 | 2016-02-03 17:59:48 +0530 | [diff] [blame] | 926 | return 0; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 927 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 928 | msg.dst_queue = dst_index; |
| 929 | |
| 930 | src_pin_state = src_mcfg->m_out_pin[src_index].pin_state; |
| 931 | dst_pin_state = dst_mcfg->m_in_pin[dst_index].pin_state; |
| 932 | |
| 933 | if (src_pin_state != SKL_PIN_BIND_DONE || |
| 934 | dst_pin_state != SKL_PIN_BIND_DONE) |
| 935 | return 0; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 936 | |
| 937 | msg.module_id = src_mcfg->id.module_id; |
| 938 | msg.instance_id = src_mcfg->id.instance_id; |
| 939 | msg.dst_module_id = dst_mcfg->id.module_id; |
| 940 | msg.dst_instance_id = dst_mcfg->id.instance_id; |
| 941 | msg.bind = false; |
| 942 | |
| 943 | ret = skl_ipc_bind_unbind(&ctx->ipc, &msg); |
| 944 | if (!ret) { |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 945 | /* free queue only if unbind is success */ |
| 946 | skl_free_queue(src_mcfg->m_out_pin, src_index); |
| 947 | skl_free_queue(dst_mcfg->m_in_pin, dst_index); |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 948 | |
| 949 | /* |
| 950 | * check only if src module bind state, bind is |
| 951 | * always from src -> sink |
| 952 | */ |
| 953 | 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] | 954 | } |
| 955 | |
| 956 | return ret; |
| 957 | } |
| 958 | |
| 959 | /* |
| 960 | * Once a module is instantiated it need to be 'bind' with other modules in |
| 961 | * the pipeline. For binding we need to find the module pins which are bind |
| 962 | * together |
| 963 | * This function finds the pins and then sends bund_unbind IPC message to |
| 964 | * DSP using IPC helper |
| 965 | */ |
| 966 | int skl_bind_modules(struct skl_sst *ctx, |
| 967 | struct skl_module_cfg *src_mcfg, |
| 968 | struct skl_module_cfg *dst_mcfg) |
| 969 | { |
| 970 | int ret; |
| 971 | struct skl_ipc_bind_unbind_msg msg; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 972 | int in_max = dst_mcfg->max_in_queue; |
| 973 | int out_max = src_mcfg->max_out_queue; |
| 974 | int src_index, dst_index; |
| 975 | |
| 976 | skl_dump_bind_info(ctx, src_mcfg, dst_mcfg); |
| 977 | |
Jeeja KP | 0c684c4 | 2016-02-03 17:59:49 +0530 | [diff] [blame] | 978 | if (src_mcfg->m_state < SKL_MODULE_INIT_DONE || |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 979 | dst_mcfg->m_state < SKL_MODULE_INIT_DONE) |
| 980 | return 0; |
| 981 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 982 | 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] | 983 | if (src_index < 0) |
| 984 | return -EINVAL; |
| 985 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 986 | msg.src_queue = src_index; |
| 987 | 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] | 988 | if (dst_index < 0) { |
| 989 | skl_free_queue(src_mcfg->m_out_pin, src_index); |
| 990 | return -EINVAL; |
| 991 | } |
| 992 | |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 993 | msg.dst_queue = dst_index; |
Jeeja KP | beb73b2 | 2015-08-01 19:40:43 +0530 | [diff] [blame] | 994 | |
| 995 | dev_dbg(ctx->dev, "src queue = %d dst queue =%d\n", |
| 996 | msg.src_queue, msg.dst_queue); |
| 997 | |
| 998 | msg.module_id = src_mcfg->id.module_id; |
| 999 | msg.instance_id = src_mcfg->id.instance_id; |
| 1000 | msg.dst_module_id = dst_mcfg->id.module_id; |
| 1001 | msg.dst_instance_id = dst_mcfg->id.instance_id; |
| 1002 | msg.bind = true; |
| 1003 | |
| 1004 | ret = skl_ipc_bind_unbind(&ctx->ipc, &msg); |
| 1005 | |
| 1006 | if (!ret) { |
| 1007 | src_mcfg->m_state = SKL_MODULE_BIND_DONE; |
Jeeja KP | 4f74570 | 2015-10-27 09:22:49 +0900 | [diff] [blame] | 1008 | src_mcfg->m_out_pin[src_index].pin_state = SKL_PIN_BIND_DONE; |
| 1009 | 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] | 1010 | } else { |
| 1011 | /* error case , if IPC fails, clear the queue index */ |
| 1012 | skl_free_queue(src_mcfg->m_out_pin, src_index); |
| 1013 | skl_free_queue(dst_mcfg->m_in_pin, dst_index); |
| 1014 | } |
| 1015 | |
| 1016 | return ret; |
| 1017 | } |
Jeeja KP | c9b1e83 | 2015-08-01 19:40:44 +0530 | [diff] [blame] | 1018 | |
| 1019 | static int skl_set_pipe_state(struct skl_sst *ctx, struct skl_pipe *pipe, |
| 1020 | enum skl_ipc_pipeline_state state) |
| 1021 | { |
| 1022 | dev_dbg(ctx->dev, "%s: pipe_satate = %d\n", __func__, state); |
| 1023 | |
| 1024 | return skl_ipc_set_pipeline_state(&ctx->ipc, pipe->ppl_id, state); |
| 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | * A pipeline is a collection of modules. Before a module in instantiated a |
| 1029 | * pipeline needs to be created for it. |
| 1030 | * This function creates pipeline, by sending create pipeline IPC messages |
| 1031 | * to FW |
| 1032 | */ |
| 1033 | int skl_create_pipeline(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 1034 | { |
| 1035 | int ret; |
| 1036 | |
| 1037 | dev_dbg(ctx->dev, "%s: pipe_id = %d\n", __func__, pipe->ppl_id); |
| 1038 | |
| 1039 | ret = skl_ipc_create_pipeline(&ctx->ipc, pipe->memory_pages, |
| 1040 | pipe->pipe_priority, pipe->ppl_id); |
| 1041 | if (ret < 0) { |
| 1042 | dev_err(ctx->dev, "Failed to create pipeline\n"); |
| 1043 | return ret; |
| 1044 | } |
| 1045 | |
| 1046 | pipe->state = SKL_PIPE_CREATED; |
| 1047 | |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
| 1051 | /* |
| 1052 | * A pipeline needs to be deleted on cleanup. If a pipeline is running, then |
| 1053 | * pause the pipeline first and then delete it |
| 1054 | * The pipe delete is done by sending delete pipeline IPC. DSP will stop the |
| 1055 | * DMA engines and releases resources |
| 1056 | */ |
| 1057 | int skl_delete_pipe(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 1058 | { |
| 1059 | int ret; |
| 1060 | |
| 1061 | dev_dbg(ctx->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id); |
| 1062 | |
Dharageswari R | 1ae7ca0 | 2016-06-03 18:29:36 +0530 | [diff] [blame] | 1063 | /* If pipe is started, do stop the pipe in FW. */ |
Jeeja KP | c9b1e83 | 2015-08-01 19:40:44 +0530 | [diff] [blame] | 1064 | if (pipe->state > SKL_PIPE_STARTED) { |
| 1065 | ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED); |
| 1066 | if (ret < 0) { |
| 1067 | dev_err(ctx->dev, "Failed to stop pipeline\n"); |
| 1068 | return ret; |
| 1069 | } |
| 1070 | |
| 1071 | pipe->state = SKL_PIPE_PAUSED; |
Jeeja KP | c9b1e83 | 2015-08-01 19:40:44 +0530 | [diff] [blame] | 1072 | } |
| 1073 | |
Dharageswari R | 1ae7ca0 | 2016-06-03 18:29:36 +0530 | [diff] [blame] | 1074 | /* If pipe was not created in FW, do not try to delete it */ |
| 1075 | if (pipe->state < SKL_PIPE_CREATED) |
| 1076 | return 0; |
| 1077 | |
| 1078 | ret = skl_ipc_delete_pipeline(&ctx->ipc, pipe->ppl_id); |
| 1079 | if (ret < 0) { |
| 1080 | dev_err(ctx->dev, "Failed to delete pipeline\n"); |
| 1081 | return ret; |
| 1082 | } |
| 1083 | |
| 1084 | pipe->state = SKL_PIPE_INVALID; |
| 1085 | |
Jeeja KP | c9b1e83 | 2015-08-01 19:40:44 +0530 | [diff] [blame] | 1086 | return ret; |
| 1087 | } |
| 1088 | |
| 1089 | /* |
| 1090 | * A pipeline is also a scheduling entity in DSP which can be run, stopped |
| 1091 | * For processing data the pipe need to be run by sending IPC set pipe state |
| 1092 | * to DSP |
| 1093 | */ |
| 1094 | int skl_run_pipe(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 1095 | { |
| 1096 | int ret; |
| 1097 | |
| 1098 | dev_dbg(ctx->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id); |
| 1099 | |
| 1100 | /* If pipe was not created in FW, do not try to pause or delete */ |
| 1101 | if (pipe->state < SKL_PIPE_CREATED) |
| 1102 | return 0; |
| 1103 | |
| 1104 | /* Pipe has to be paused before it is started */ |
| 1105 | ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED); |
| 1106 | if (ret < 0) { |
| 1107 | dev_err(ctx->dev, "Failed to pause pipe\n"); |
| 1108 | return ret; |
| 1109 | } |
| 1110 | |
| 1111 | pipe->state = SKL_PIPE_PAUSED; |
| 1112 | |
| 1113 | ret = skl_set_pipe_state(ctx, pipe, PPL_RUNNING); |
| 1114 | if (ret < 0) { |
| 1115 | dev_err(ctx->dev, "Failed to start pipe\n"); |
| 1116 | return ret; |
| 1117 | } |
| 1118 | |
| 1119 | pipe->state = SKL_PIPE_STARTED; |
| 1120 | |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | /* |
| 1125 | * Stop the pipeline by sending set pipe state IPC |
| 1126 | * DSP doesnt implement stop so we always send pause message |
| 1127 | */ |
| 1128 | int skl_stop_pipe(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 1129 | { |
| 1130 | int ret; |
| 1131 | |
| 1132 | dev_dbg(ctx->dev, "In %s pipe=%d\n", __func__, pipe->ppl_id); |
| 1133 | |
| 1134 | /* If pipe was not created in FW, do not try to pause or delete */ |
| 1135 | if (pipe->state < SKL_PIPE_PAUSED) |
| 1136 | return 0; |
| 1137 | |
| 1138 | ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED); |
| 1139 | if (ret < 0) { |
| 1140 | dev_dbg(ctx->dev, "Failed to stop pipe\n"); |
| 1141 | return ret; |
| 1142 | } |
| 1143 | |
Jeeja KP | 353f72a | 2016-06-03 18:29:35 +0530 | [diff] [blame] | 1144 | pipe->state = SKL_PIPE_PAUSED; |
Jeeja KP | c9b1e83 | 2015-08-01 19:40:44 +0530 | [diff] [blame] | 1145 | |
| 1146 | return 0; |
| 1147 | } |
Jeeja KP | 9939a9c | 2015-11-28 15:01:47 +0530 | [diff] [blame] | 1148 | |
Jeeja KP | 2004432 | 2016-06-03 18:29:34 +0530 | [diff] [blame] | 1149 | /* |
| 1150 | * Reset the pipeline by sending set pipe state IPC this will reset the DMA |
| 1151 | * from the DSP side |
| 1152 | */ |
| 1153 | int skl_reset_pipe(struct skl_sst *ctx, struct skl_pipe *pipe) |
| 1154 | { |
| 1155 | int ret; |
| 1156 | |
| 1157 | /* If pipe was not created in FW, do not try to pause or delete */ |
| 1158 | if (pipe->state < SKL_PIPE_PAUSED) |
| 1159 | return 0; |
| 1160 | |
| 1161 | ret = skl_set_pipe_state(ctx, pipe, PPL_RESET); |
| 1162 | if (ret < 0) { |
| 1163 | dev_dbg(ctx->dev, "Failed to reset pipe ret=%d\n", ret); |
| 1164 | return ret; |
| 1165 | } |
| 1166 | |
| 1167 | pipe->state = SKL_PIPE_RESET; |
| 1168 | |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
Jeeja KP | 9939a9c | 2015-11-28 15:01:47 +0530 | [diff] [blame] | 1172 | /* Algo parameter set helper function */ |
| 1173 | int skl_set_module_params(struct skl_sst *ctx, u32 *params, int size, |
| 1174 | u32 param_id, struct skl_module_cfg *mcfg) |
| 1175 | { |
| 1176 | struct skl_ipc_large_config_msg msg; |
| 1177 | |
| 1178 | msg.module_id = mcfg->id.module_id; |
| 1179 | msg.instance_id = mcfg->id.instance_id; |
| 1180 | msg.param_data_size = size; |
| 1181 | msg.large_param_id = param_id; |
| 1182 | |
| 1183 | return skl_ipc_set_large_config(&ctx->ipc, &msg, params); |
| 1184 | } |
Omair M Abdullah | 7d9f291 | 2015-12-03 23:29:56 +0530 | [diff] [blame] | 1185 | |
| 1186 | int skl_get_module_params(struct skl_sst *ctx, u32 *params, int size, |
| 1187 | u32 param_id, struct skl_module_cfg *mcfg) |
| 1188 | { |
| 1189 | struct skl_ipc_large_config_msg msg; |
| 1190 | |
| 1191 | msg.module_id = mcfg->id.module_id; |
| 1192 | msg.instance_id = mcfg->id.instance_id; |
| 1193 | msg.param_data_size = size; |
| 1194 | msg.large_param_id = param_id; |
| 1195 | |
| 1196 | return skl_ipc_get_large_config(&ctx->ipc, &msg, params); |
| 1197 | } |