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