forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/intel/skylake/skl-topology.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * skl-topology.c - Implements Platform component ALSA controls/widget
34 * handlers.
....@@ -5,22 +6,15 @@
56 * Copyright (C) 2014-2015 Intel Corp
67 * Author: Jeeja KP <jeeja.kp@intel.com>
78 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as version 2, as
11
- * published by the Free Software Foundation.
12
- *
13
- * This program is distributed in the hope that it will be useful, but
14
- * WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- * General Public License for more details.
179 */
1810
1911 #include <linux/slab.h>
2012 #include <linux/types.h>
2113 #include <linux/firmware.h>
2214 #include <linux/uuid.h>
15
+#include <sound/intel-nhlt.h>
2316 #include <sound/soc.h>
17
+#include <sound/soc-acpi.h>
2418 #include <sound/soc-topology.h>
2519 #include <uapi/sound/snd_sst_tokens.h>
2620 #include <uapi/sound/skl-tplg-interface.h>
....@@ -53,9 +47,9 @@
5347 #define CHECK_HW_PARAMS(ch, freq, bps, prm_ch, prm_freq, prm_bps) \
5448 ((ch == prm_ch) && (bps == prm_bps) && (freq == prm_freq))
5549
56
-void skl_tplg_d0i3_get(struct skl *skl, enum d0i3_capability caps)
50
+void skl_tplg_d0i3_get(struct skl_dev *skl, enum d0i3_capability caps)
5751 {
58
- struct skl_d0i3_data *d0i3 = &skl->skl_sst->d0i3;
52
+ struct skl_d0i3_data *d0i3 = &skl->d0i3;
5953
6054 switch (caps) {
6155 case SKL_D0I3_NONE:
....@@ -72,9 +66,9 @@
7266 }
7367 }
7468
75
-void skl_tplg_d0i3_put(struct skl *skl, enum d0i3_capability caps)
69
+void skl_tplg_d0i3_put(struct skl_dev *skl, enum d0i3_capability caps)
7670 {
77
- struct skl_d0i3_data *d0i3 = &skl->skl_sst->d0i3;
71
+ struct skl_d0i3_data *d0i3 = &skl->d0i3;
7872
7973 switch (caps) {
8074 case SKL_D0I3_NONE:
....@@ -117,118 +111,23 @@
117111 }
118112 }
119113
120
-/*
121
- * Each pipelines needs memory to be allocated. Check if we have free memory
122
- * from available pool.
123
- */
124
-static bool skl_is_pipe_mem_avail(struct skl *skl,
125
- struct skl_module_cfg *mconfig)
114
+static void skl_dump_mconfig(struct skl_dev *skl, struct skl_module_cfg *mcfg)
126115 {
127
- struct skl_sst *ctx = skl->skl_sst;
116
+ struct skl_module_iface *iface = &mcfg->module->formats[mcfg->fmt_idx];
128117
129
- if (skl->resource.mem + mconfig->pipe->memory_pages >
130
- skl->resource.max_mem) {
131
- dev_err(ctx->dev,
132
- "%s: module_id %d instance %d\n", __func__,
133
- mconfig->id.module_id,
134
- mconfig->id.instance_id);
135
- dev_err(ctx->dev,
136
- "exceeds ppl memory available %d mem %d\n",
137
- skl->resource.max_mem, skl->resource.mem);
138
- return false;
139
- } else {
140
- return true;
141
- }
142
-}
143
-
144
-/*
145
- * Add the mem to the mem pool. This is freed when pipe is deleted.
146
- * Note: DSP does actual memory management we only keep track for complete
147
- * pool
148
- */
149
-static void skl_tplg_alloc_pipe_mem(struct skl *skl,
150
- struct skl_module_cfg *mconfig)
151
-{
152
- skl->resource.mem += mconfig->pipe->memory_pages;
153
-}
154
-
155
-/*
156
- * Pipeline needs needs DSP CPU resources for computation, this is
157
- * quantified in MCPS (Million Clocks Per Second) required for module/pipe
158
- *
159
- * Each pipelines needs mcps to be allocated. Check if we have mcps for this
160
- * pipe.
161
- */
162
-
163
-static bool skl_is_pipe_mcps_avail(struct skl *skl,
164
- struct skl_module_cfg *mconfig)
165
-{
166
- struct skl_sst *ctx = skl->skl_sst;
167
- u8 res_idx = mconfig->res_idx;
168
- struct skl_module_res *res = &mconfig->module->resources[res_idx];
169
-
170
- if (skl->resource.mcps + res->cps > skl->resource.max_mcps) {
171
- dev_err(ctx->dev,
172
- "%s: module_id %d instance %d\n", __func__,
173
- mconfig->id.module_id, mconfig->id.instance_id);
174
- dev_err(ctx->dev,
175
- "exceeds ppl mcps available %d > mem %d\n",
176
- skl->resource.max_mcps, skl->resource.mcps);
177
- return false;
178
- } else {
179
- return true;
180
- }
181
-}
182
-
183
-static void skl_tplg_alloc_pipe_mcps(struct skl *skl,
184
- struct skl_module_cfg *mconfig)
185
-{
186
- u8 res_idx = mconfig->res_idx;
187
- struct skl_module_res *res = &mconfig->module->resources[res_idx];
188
-
189
- skl->resource.mcps += res->cps;
190
-}
191
-
192
-/*
193
- * Free the mcps when tearing down
194
- */
195
-static void
196
-skl_tplg_free_pipe_mcps(struct skl *skl, struct skl_module_cfg *mconfig)
197
-{
198
- u8 res_idx = mconfig->res_idx;
199
- struct skl_module_res *res = &mconfig->module->resources[res_idx];
200
-
201
- skl->resource.mcps -= res->cps;
202
-}
203
-
204
-/*
205
- * Free the memory when tearing down
206
- */
207
-static void
208
-skl_tplg_free_pipe_mem(struct skl *skl, struct skl_module_cfg *mconfig)
209
-{
210
- skl->resource.mem -= mconfig->pipe->memory_pages;
211
-}
212
-
213
-
214
-static void skl_dump_mconfig(struct skl_sst *ctx,
215
- struct skl_module_cfg *mcfg)
216
-{
217
- struct skl_module_iface *iface = &mcfg->module->formats[0];
218
-
219
- dev_dbg(ctx->dev, "Dumping config\n");
220
- dev_dbg(ctx->dev, "Input Format:\n");
221
- dev_dbg(ctx->dev, "channels = %d\n", iface->inputs[0].fmt.channels);
222
- dev_dbg(ctx->dev, "s_freq = %d\n", iface->inputs[0].fmt.s_freq);
223
- dev_dbg(ctx->dev, "ch_cfg = %d\n", iface->inputs[0].fmt.ch_cfg);
224
- dev_dbg(ctx->dev, "valid bit depth = %d\n",
118
+ dev_dbg(skl->dev, "Dumping config\n");
119
+ dev_dbg(skl->dev, "Input Format:\n");
120
+ dev_dbg(skl->dev, "channels = %d\n", iface->inputs[0].fmt.channels);
121
+ dev_dbg(skl->dev, "s_freq = %d\n", iface->inputs[0].fmt.s_freq);
122
+ dev_dbg(skl->dev, "ch_cfg = %d\n", iface->inputs[0].fmt.ch_cfg);
123
+ dev_dbg(skl->dev, "valid bit depth = %d\n",
225124 iface->inputs[0].fmt.valid_bit_depth);
226
- dev_dbg(ctx->dev, "Output Format:\n");
227
- dev_dbg(ctx->dev, "channels = %d\n", iface->outputs[0].fmt.channels);
228
- dev_dbg(ctx->dev, "s_freq = %d\n", iface->outputs[0].fmt.s_freq);
229
- dev_dbg(ctx->dev, "valid bit depth = %d\n",
125
+ dev_dbg(skl->dev, "Output Format:\n");
126
+ dev_dbg(skl->dev, "channels = %d\n", iface->outputs[0].fmt.channels);
127
+ dev_dbg(skl->dev, "s_freq = %d\n", iface->outputs[0].fmt.s_freq);
128
+ dev_dbg(skl->dev, "valid bit depth = %d\n",
230129 iface->outputs[0].fmt.valid_bit_depth);
231
- dev_dbg(ctx->dev, "ch_cfg = %d\n", iface->outputs[0].fmt.ch_cfg);
130
+ dev_dbg(skl->dev, "ch_cfg = %d\n", iface->outputs[0].fmt.ch_cfg);
232131 }
233132
234133 static void skl_tplg_update_chmap(struct skl_module_fmt *fmt, int chs)
....@@ -296,8 +195,8 @@
296195 struct skl_module_fmt *in_fmt, *out_fmt;
297196
298197 /* Fixups will be applied to pin 0 only */
299
- in_fmt = &m_cfg->module->formats[0].inputs[0].fmt;
300
- out_fmt = &m_cfg->module->formats[0].outputs[0].fmt;
198
+ in_fmt = &m_cfg->module->formats[m_cfg->fmt_idx].inputs[0].fmt;
199
+ out_fmt = &m_cfg->module->formats[m_cfg->fmt_idx].outputs[0].fmt;
301200
302201 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK) {
303202 if (is_fe) {
....@@ -330,7 +229,7 @@
330229 * params, so once we have calculate params, we need buffer calculation as
331230 * well.
332231 */
333
-static void skl_tplg_update_buffer_size(struct skl_sst *ctx,
232
+static void skl_tplg_update_buffer_size(struct skl_dev *skl,
334233 struct skl_module_cfg *mcfg)
335234 {
336235 int multiplier = 1;
....@@ -340,9 +239,9 @@
340239 /* Since fixups is applied to pin 0 only, ibs, obs needs
341240 * change for pin 0 only
342241 */
343
- res = &mcfg->module->resources[0];
344
- in_fmt = &mcfg->module->formats[0].inputs[0].fmt;
345
- out_fmt = &mcfg->module->formats[0].outputs[0].fmt;
242
+ res = &mcfg->module->resources[mcfg->res_idx];
243
+ in_fmt = &mcfg->module->formats[mcfg->fmt_idx].inputs[0].fmt;
244
+ out_fmt = &mcfg->module->formats[mcfg->fmt_idx].outputs[0].fmt;
346245
347246 if (mcfg->m_type == SKL_MODULE_TYPE_SRCINT)
348247 multiplier = 5;
....@@ -382,13 +281,12 @@
382281 }
383282
384283 static int skl_tplg_update_be_blob(struct snd_soc_dapm_widget *w,
385
- struct skl_sst *ctx)
284
+ struct skl_dev *skl)
386285 {
387286 struct skl_module_cfg *m_cfg = w->priv;
388287 int link_type, dir;
389288 u32 ch, s_freq, s_fmt;
390289 struct nhlt_specific_cfg *cfg;
391
- struct skl *skl = get_skl_ctx(ctx->dev);
392290 u8 dev_type = skl_tplg_be_dev_type(m_cfg->dev_type);
393291 int fmt_idx = m_cfg->fmt_idx;
394292 struct skl_module_iface *m_iface = &m_cfg->module->formats[fmt_idx];
....@@ -397,7 +295,7 @@
397295 if (m_cfg->formats_config.caps_size > 0)
398296 return 0;
399297
400
- dev_dbg(ctx->dev, "Applying default cfg blob\n");
298
+ dev_dbg(skl->dev, "Applying default cfg blob\n");
401299 switch (m_cfg->dev_type) {
402300 case SKL_DEVICE_DMIC:
403301 link_type = NHLT_LINK_DMIC;
....@@ -433,9 +331,9 @@
433331 m_cfg->formats_config.caps_size = cfg->size;
434332 m_cfg->formats_config.caps = (u32 *) &cfg->caps;
435333 } else {
436
- dev_err(ctx->dev, "Blob NULL for id %x type %d dirn %d\n",
334
+ dev_err(skl->dev, "Blob NULL for id %x type %d dirn %d\n",
437335 m_cfg->vbus_id, link_type, dir);
438
- dev_err(ctx->dev, "PCM: ch %d, freq %d, fmt %d\n",
336
+ dev_err(skl->dev, "PCM: ch %d, freq %d, fmt %d\n",
439337 ch, s_freq, s_fmt);
440338 return -EIO;
441339 }
....@@ -444,7 +342,7 @@
444342 }
445343
446344 static void skl_tplg_update_module_params(struct snd_soc_dapm_widget *w,
447
- struct skl_sst *ctx)
345
+ struct skl_dev *skl)
448346 {
449347 struct skl_module_cfg *m_cfg = w->priv;
450348 struct skl_pipe_params *params = m_cfg->pipe->p_params;
....@@ -454,10 +352,10 @@
454352 if (!m_cfg->params_fixup)
455353 return;
456354
457
- dev_dbg(ctx->dev, "Mconfig for widget=%s BEFORE updation\n",
355
+ dev_dbg(skl->dev, "Mconfig for widget=%s BEFORE updation\n",
458356 w->name);
459357
460
- skl_dump_mconfig(ctx, m_cfg);
358
+ skl_dump_mconfig(skl, m_cfg);
461359
462360 if (p_conn_type == SKL_PIPE_CONN_TYPE_FE)
463361 is_fe = true;
....@@ -465,12 +363,12 @@
465363 is_fe = false;
466364
467365 skl_tplg_update_params_fixup(m_cfg, params, is_fe);
468
- skl_tplg_update_buffer_size(ctx, m_cfg);
366
+ skl_tplg_update_buffer_size(skl, m_cfg);
469367
470
- dev_dbg(ctx->dev, "Mconfig for widget=%s AFTER updation\n",
368
+ dev_dbg(skl->dev, "Mconfig for widget=%s AFTER updation\n",
471369 w->name);
472370
473
- skl_dump_mconfig(ctx, m_cfg);
371
+ skl_dump_mconfig(skl, m_cfg);
474372 }
475373
476374 /*
....@@ -479,7 +377,7 @@
479377 * set module params will be done after module is initialised.
480378 */
481379 static int skl_tplg_set_module_params(struct snd_soc_dapm_widget *w,
482
- struct skl_sst *ctx)
380
+ struct skl_dev *skl)
483381 {
484382 int i, ret;
485383 struct skl_module_cfg *mconfig = w->priv;
....@@ -491,7 +389,7 @@
491389 if (mconfig->formats_config.caps_size > 0 &&
492390 mconfig->formats_config.set_params == SKL_PARAM_SET) {
493391 sp_cfg = &mconfig->formats_config;
494
- ret = skl_set_module_params(ctx, sp_cfg->caps,
392
+ ret = skl_set_module_params(skl, sp_cfg->caps,
495393 sp_cfg->caps_size,
496394 sp_cfg->param_id, mconfig);
497395 if (ret < 0)
....@@ -505,7 +403,7 @@
505403 bc = (struct skl_algo_data *)sb->dobj.private;
506404
507405 if (bc->set_params == SKL_PARAM_SET) {
508
- ret = skl_set_module_params(ctx,
406
+ ret = skl_set_module_params(skl,
509407 (u32 *)bc->params, bc->size,
510408 bc->param_id, mconfig);
511409 if (ret < 0)
....@@ -550,15 +448,15 @@
550448 return 0;
551449 }
552450
553
-static int skl_tplg_module_prepare(struct skl_sst *ctx, struct skl_pipe *pipe,
451
+static int skl_tplg_module_prepare(struct skl_dev *skl, struct skl_pipe *pipe,
554452 struct snd_soc_dapm_widget *w, struct skl_module_cfg *mcfg)
555453 {
556454 switch (mcfg->dev_type) {
557455 case SKL_DEVICE_HDAHOST:
558
- return skl_pcm_host_dma_prepare(ctx->dev, pipe->p_params);
456
+ return skl_pcm_host_dma_prepare(skl->dev, pipe->p_params);
559457
560458 case SKL_DEVICE_HDALINK:
561
- return skl_pcm_link_dma_prepare(ctx->dev, pipe->p_params);
459
+ return skl_pcm_link_dma_prepare(skl->dev, pipe->p_params);
562460 }
563461
564462 return 0;
....@@ -570,25 +468,24 @@
570468 * skl_init_module() routine, so invoke that for all modules in a pipeline
571469 */
572470 static int
573
-skl_tplg_init_pipe_modules(struct skl *skl, struct skl_pipe *pipe)
471
+skl_tplg_init_pipe_modules(struct skl_dev *skl, struct skl_pipe *pipe)
574472 {
575473 struct skl_pipe_module *w_module;
576474 struct snd_soc_dapm_widget *w;
577475 struct skl_module_cfg *mconfig;
578
- struct skl_sst *ctx = skl->skl_sst;
579476 u8 cfg_idx;
580477 int ret = 0;
581478
582479 list_for_each_entry(w_module, &pipe->w_list, node) {
583
- uuid_le *uuid_mod;
480
+ guid_t *uuid_mod;
584481 w = w_module->w;
585482 mconfig = w->priv;
586483
587484 /* check if module ids are populated */
588485 if (mconfig->id.module_id < 0) {
589
- dev_err(skl->skl_sst->dev,
486
+ dev_err(skl->dev,
590487 "module %pUL id not populated\n",
591
- (uuid_le *)mconfig->guid);
488
+ (guid_t *)mconfig->guid);
592489 return -EIO;
593490 }
594491
....@@ -596,12 +493,8 @@
596493 mconfig->fmt_idx = mconfig->mod_cfg[cfg_idx].fmt_idx;
597494 mconfig->res_idx = mconfig->mod_cfg[cfg_idx].res_idx;
598495
599
- /* check resource available */
600
- if (!skl_is_pipe_mcps_avail(skl, mconfig))
601
- return -ENOMEM;
602
-
603
- if (mconfig->module->loadable && ctx->dsp->fw_ops.load_mod) {
604
- ret = ctx->dsp->fw_ops.load_mod(ctx->dsp,
496
+ if (mconfig->module->loadable && skl->dsp->fw_ops.load_mod) {
497
+ ret = skl->dsp->fw_ops.load_mod(skl->dsp,
605498 mconfig->id.module_id, mconfig->guid);
606499 if (ret < 0)
607500 return ret;
....@@ -610,80 +503,112 @@
610503 }
611504
612505 /* prepare the DMA if the module is gateway cpr */
613
- ret = skl_tplg_module_prepare(ctx, pipe, w, mconfig);
506
+ ret = skl_tplg_module_prepare(skl, pipe, w, mconfig);
614507 if (ret < 0)
615508 return ret;
616509
617510 /* update blob if blob is null for be with default value */
618
- skl_tplg_update_be_blob(w, ctx);
511
+ skl_tplg_update_be_blob(w, skl);
619512
620513 /*
621514 * apply fix/conversion to module params based on
622515 * FE/BE params
623516 */
624
- skl_tplg_update_module_params(w, ctx);
625
- uuid_mod = (uuid_le *)mconfig->guid;
626
- mconfig->id.pvt_id = skl_get_pvt_id(ctx, uuid_mod,
517
+ skl_tplg_update_module_params(w, skl);
518
+ uuid_mod = (guid_t *)mconfig->guid;
519
+ mconfig->id.pvt_id = skl_get_pvt_id(skl, uuid_mod,
627520 mconfig->id.instance_id);
628521 if (mconfig->id.pvt_id < 0)
629522 return ret;
630523 skl_tplg_set_module_init_data(w);
631524
632
- ret = skl_dsp_get_core(ctx->dsp, mconfig->core_id);
525
+ ret = skl_dsp_get_core(skl->dsp, mconfig->core_id);
633526 if (ret < 0) {
634
- dev_err(ctx->dev, "Failed to wake up core %d ret=%d\n",
527
+ dev_err(skl->dev, "Failed to wake up core %d ret=%d\n",
635528 mconfig->core_id, ret);
636529 return ret;
637530 }
638531
639
- ret = skl_init_module(ctx, mconfig);
532
+ ret = skl_init_module(skl, mconfig);
640533 if (ret < 0) {
641
- skl_put_pvt_id(ctx, uuid_mod, &mconfig->id.pvt_id);
534
+ skl_put_pvt_id(skl, uuid_mod, &mconfig->id.pvt_id);
642535 goto err;
643536 }
644
- skl_tplg_alloc_pipe_mcps(skl, mconfig);
645
- ret = skl_tplg_set_module_params(w, ctx);
537
+
538
+ ret = skl_tplg_set_module_params(w, skl);
646539 if (ret < 0)
647540 goto err;
648541 }
649542
650543 return 0;
651544 err:
652
- skl_dsp_put_core(ctx->dsp, mconfig->core_id);
545
+ skl_dsp_put_core(skl->dsp, mconfig->core_id);
653546 return ret;
654547 }
655548
656
-static int skl_tplg_unload_pipe_modules(struct skl_sst *ctx,
549
+static int skl_tplg_unload_pipe_modules(struct skl_dev *skl,
657550 struct skl_pipe *pipe)
658551 {
659552 int ret = 0;
660
- struct skl_pipe_module *w_module = NULL;
661
- struct skl_module_cfg *mconfig = NULL;
553
+ struct skl_pipe_module *w_module;
554
+ struct skl_module_cfg *mconfig;
662555
663556 list_for_each_entry(w_module, &pipe->w_list, node) {
664
- uuid_le *uuid_mod;
557
+ guid_t *uuid_mod;
665558 mconfig = w_module->w->priv;
666
- uuid_mod = (uuid_le *)mconfig->guid;
559
+ uuid_mod = (guid_t *)mconfig->guid;
667560
668
- if (mconfig->module->loadable && ctx->dsp->fw_ops.unload_mod &&
561
+ if (mconfig->module->loadable && skl->dsp->fw_ops.unload_mod &&
669562 mconfig->m_state > SKL_MODULE_UNINIT) {
670
- ret = ctx->dsp->fw_ops.unload_mod(ctx->dsp,
563
+ ret = skl->dsp->fw_ops.unload_mod(skl->dsp,
671564 mconfig->id.module_id);
672565 if (ret < 0)
673566 return -EIO;
674567 }
675
- skl_put_pvt_id(ctx, uuid_mod, &mconfig->id.pvt_id);
568
+ skl_put_pvt_id(skl, uuid_mod, &mconfig->id.pvt_id);
676569
677
- ret = skl_dsp_put_core(ctx->dsp, mconfig->core_id);
570
+ ret = skl_dsp_put_core(skl->dsp, mconfig->core_id);
678571 if (ret < 0) {
679572 /* don't return; continue with other modules */
680
- dev_err(ctx->dev, "Failed to sleep core %d ret=%d\n",
573
+ dev_err(skl->dev, "Failed to sleep core %d ret=%d\n",
681574 mconfig->core_id, ret);
682575 }
683576 }
684577
685578 /* no modules to unload in this path, so return */
686579 return ret;
580
+}
581
+
582
+static bool skl_tplg_is_multi_fmt(struct skl_dev *skl, struct skl_pipe *pipe)
583
+{
584
+ struct skl_pipe_fmt *cur_fmt;
585
+ struct skl_pipe_fmt *next_fmt;
586
+ int i;
587
+
588
+ if (pipe->nr_cfgs <= 1)
589
+ return false;
590
+
591
+ if (pipe->conn_type != SKL_PIPE_CONN_TYPE_FE)
592
+ return true;
593
+
594
+ for (i = 0; i < pipe->nr_cfgs - 1; i++) {
595
+ if (pipe->direction == SNDRV_PCM_STREAM_PLAYBACK) {
596
+ cur_fmt = &pipe->configs[i].out_fmt;
597
+ next_fmt = &pipe->configs[i + 1].out_fmt;
598
+ } else {
599
+ cur_fmt = &pipe->configs[i].in_fmt;
600
+ next_fmt = &pipe->configs[i + 1].in_fmt;
601
+ }
602
+
603
+ if (!CHECK_HW_PARAMS(cur_fmt->channels, cur_fmt->freq,
604
+ cur_fmt->bps,
605
+ next_fmt->channels,
606
+ next_fmt->freq,
607
+ next_fmt->bps))
608
+ return true;
609
+ }
610
+
611
+ return false;
687612 }
688613
689614 /*
....@@ -694,9 +619,8 @@
694619 * 0th configuratation by default for such pipes.
695620 */
696621 static int
697
-skl_tplg_get_pipe_config(struct skl *skl, struct skl_module_cfg *mconfig)
622
+skl_tplg_get_pipe_config(struct skl_dev *skl, struct skl_module_cfg *mconfig)
698623 {
699
- struct skl_sst *ctx = skl->skl_sst;
700624 struct skl_pipe *pipe = mconfig->pipe;
701625 struct skl_pipe_params *params = pipe->p_params;
702626 struct skl_path_config *pconfig = &pipe->configs[0];
....@@ -709,8 +633,16 @@
709633 return 0;
710634 }
711635
636
+ if (skl_tplg_is_multi_fmt(skl, pipe)) {
637
+ pipe->cur_config_idx = pipe->pipe_config_idx;
638
+ pipe->memory_pages = pconfig->mem_pages;
639
+ dev_dbg(skl->dev, "found pipe config idx:%d\n",
640
+ pipe->cur_config_idx);
641
+ return 0;
642
+ }
643
+
712644 if (pipe->conn_type == SKL_PIPE_CONN_TYPE_NONE) {
713
- dev_dbg(ctx->dev, "No conn_type detected, take 0th config\n");
645
+ dev_dbg(skl->dev, "No conn_type detected, take 0th config\n");
714646 pipe->cur_config_idx = 0;
715647 pipe->memory_pages = pconfig->mem_pages;
716648
....@@ -734,13 +666,13 @@
734666 fmt->channels, fmt->freq, fmt->bps)) {
735667 pipe->cur_config_idx = i;
736668 pipe->memory_pages = pconfig->mem_pages;
737
- dev_dbg(ctx->dev, "Using pipe config: %d\n", i);
669
+ dev_dbg(skl->dev, "Using pipe config: %d\n", i);
738670
739671 return 0;
740672 }
741673 }
742674
743
- dev_err(ctx->dev, "Invalid pipe config: %d %d %d for pipe: %d\n",
675
+ dev_err(skl->dev, "Invalid pipe config: %d %d %d for pipe: %d\n",
744676 params->ch, params->s_freq, params->s_fmt, pipe->ppl_id);
745677 return -EINVAL;
746678 }
....@@ -748,43 +680,31 @@
748680 /*
749681 * Mixer module represents a pipeline. So in the Pre-PMU event of mixer we
750682 * need create the pipeline. So we do following:
751
- * - check the resources
752683 * - Create the pipeline
753684 * - Initialize the modules in pipeline
754685 * - finally bind all modules together
755686 */
756687 static int skl_tplg_mixer_dapm_pre_pmu_event(struct snd_soc_dapm_widget *w,
757
- struct skl *skl)
688
+ struct skl_dev *skl)
758689 {
759690 int ret;
760691 struct skl_module_cfg *mconfig = w->priv;
761692 struct skl_pipe_module *w_module;
762693 struct skl_pipe *s_pipe = mconfig->pipe;
763694 struct skl_module_cfg *src_module = NULL, *dst_module, *module;
764
- struct skl_sst *ctx = skl->skl_sst;
765695 struct skl_module_deferred_bind *modules;
766696
767697 ret = skl_tplg_get_pipe_config(skl, mconfig);
768698 if (ret < 0)
769699 return ret;
770700
771
- /* check resource available */
772
- if (!skl_is_pipe_mcps_avail(skl, mconfig))
773
- return -EBUSY;
774
-
775
- if (!skl_is_pipe_mem_avail(skl, mconfig))
776
- return -ENOMEM;
777
-
778701 /*
779702 * Create a list of modules for pipe.
780703 * This list contains modules from source to sink
781704 */
782
- ret = skl_create_pipeline(ctx, mconfig->pipe);
705
+ ret = skl_create_pipeline(skl, mconfig->pipe);
783706 if (ret < 0)
784707 return ret;
785
-
786
- skl_tplg_alloc_pipe_mem(skl, mconfig);
787
- skl_tplg_alloc_pipe_mcps(skl, mconfig);
788708
789709 /* Init all pipe modules from source to sink */
790710 ret = skl_tplg_init_pipe_modules(skl, s_pipe);
....@@ -800,7 +720,7 @@
800720 continue;
801721 }
802722
803
- ret = skl_bind_modules(ctx, src_module, dst_module);
723
+ ret = skl_bind_modules(skl, src_module, dst_module);
804724 if (ret < 0)
805725 return ret;
806726
....@@ -818,7 +738,7 @@
818738 list_for_each_entry(modules, &skl->bind_list, node) {
819739 module = w_module->w->priv;
820740 if (modules->dst == module)
821
- skl_bind_modules(ctx, modules->src,
741
+ skl_bind_modules(skl, modules->src,
822742 modules->dst);
823743 }
824744 }
....@@ -826,7 +746,7 @@
826746 return 0;
827747 }
828748
829
-static int skl_fill_sink_instance_id(struct skl_sst *ctx, u32 *params,
749
+static int skl_fill_sink_instance_id(struct skl_dev *skl, u32 *params,
830750 int size, struct skl_module_cfg *mcfg)
831751 {
832752 int i, pvt_id;
....@@ -837,7 +757,7 @@
837757 struct skl_mod_inst_map *inst = kpb_params->u.map;
838758
839759 for (i = 0; i < kpb_params->num_modules; i++) {
840
- pvt_id = skl_get_pvt_instance_id_map(ctx, inst->mod_id,
760
+ pvt_id = skl_get_pvt_instance_id_map(skl, inst->mod_id,
841761 inst->inst_id);
842762 if (pvt_id < 0)
843763 return -EINVAL;
....@@ -857,7 +777,7 @@
857777 * send params after binding
858778 */
859779 static int skl_tplg_set_module_bind_params(struct snd_soc_dapm_widget *w,
860
- struct skl_module_cfg *mcfg, struct skl_sst *ctx)
780
+ struct skl_module_cfg *mcfg, struct skl_dev *skl)
861781 {
862782 int i, ret;
863783 struct skl_module_cfg *mconfig = w->priv;
....@@ -884,7 +804,7 @@
884804 if (mconfig->formats_config.caps_size > 0 &&
885805 mconfig->formats_config.set_params == SKL_PARAM_BIND) {
886806 sp_cfg = &mconfig->formats_config;
887
- ret = skl_set_module_params(ctx, sp_cfg->caps,
807
+ ret = skl_set_module_params(skl, sp_cfg->caps,
888808 sp_cfg->caps_size,
889809 sp_cfg->param_id, mconfig);
890810 if (ret < 0)
....@@ -898,15 +818,14 @@
898818 bc = (struct skl_algo_data *)sb->dobj.private;
899819
900820 if (bc->set_params == SKL_PARAM_BIND) {
901
- params = kzalloc(bc->max, GFP_KERNEL);
821
+ params = kmemdup(bc->params, bc->max, GFP_KERNEL);
902822 if (!params)
903823 return -ENOMEM;
904824
905
- memcpy(params, bc->params, bc->max);
906
- skl_fill_sink_instance_id(ctx, params, bc->max,
825
+ skl_fill_sink_instance_id(skl, params, bc->max,
907826 mconfig);
908827
909
- ret = skl_set_module_params(ctx, params,
828
+ ret = skl_set_module_params(skl, params,
910829 bc->max, bc->param_id, mconfig);
911830 kfree(params);
912831
....@@ -919,19 +838,19 @@
919838 return 0;
920839 }
921840
922
-static int skl_get_module_id(struct skl_sst *ctx, uuid_le *uuid)
841
+static int skl_get_module_id(struct skl_dev *skl, guid_t *uuid)
923842 {
924843 struct uuid_module *module;
925844
926
- list_for_each_entry(module, &ctx->uuid_list, list) {
927
- if (uuid_le_cmp(*uuid, module->uuid) == 0)
845
+ list_for_each_entry(module, &skl->uuid_list, list) {
846
+ if (guid_equal(uuid, &module->uuid))
928847 return module->id;
929848 }
930849
931850 return -EINVAL;
932851 }
933852
934
-static int skl_tplg_find_moduleid_from_uuid(struct skl *skl,
853
+static int skl_tplg_find_moduleid_from_uuid(struct skl_dev *skl,
935854 const struct snd_kcontrol_new *k)
936855 {
937856 struct soc_bytes_ext *sb = (void *) k->private_value;
....@@ -942,9 +861,7 @@
942861
943862 if (bc->set_params == SKL_PARAM_BIND && bc->max) {
944863 uuid_params = (struct skl_kpb_params *)bc->params;
945
- size = uuid_params->num_modules *
946
- sizeof(struct skl_mod_inst_map) +
947
- sizeof(uuid_params->num_modules);
864
+ size = struct_size(params, u.map, uuid_params->num_modules);
948865
949866 params = devm_kzalloc(bus->dev, size, GFP_KERNEL);
950867 if (!params)
....@@ -953,7 +870,7 @@
953870 params->num_modules = uuid_params->num_modules;
954871
955872 for (i = 0; i < uuid_params->num_modules; i++) {
956
- module_id = skl_get_module_id(skl->skl_sst,
873
+ module_id = skl_get_module_id(skl,
957874 &uuid_params->u.map_uuid[i].mod_uuid);
958875 if (module_id < 0) {
959876 devm_kfree(bus->dev, params);
....@@ -977,7 +894,7 @@
977894 * Retrieve the module id from UUID mentioned in the
978895 * post bind params
979896 */
980
-void skl_tplg_add_moduleid_in_bind_params(struct skl *skl,
897
+void skl_tplg_add_moduleid_in_bind_params(struct skl_dev *skl,
981898 struct snd_soc_dapm_widget *w)
982899 {
983900 struct skl_module_cfg *mconfig = w->priv;
....@@ -996,12 +913,12 @@
996913 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) &&
997914 (skl_tplg_find_moduleid_from_uuid(skl,
998915 &w->kcontrol_news[i]) < 0))
999
- dev_err(skl->skl_sst->dev,
916
+ dev_err(skl->dev,
1000917 "%s: invalid kpb post bind params\n",
1001918 __func__);
1002919 }
1003920
1004
-static int skl_tplg_module_add_deferred_bind(struct skl *skl,
921
+static int skl_tplg_module_add_deferred_bind(struct skl_dev *skl,
1005922 struct skl_module_cfg *src, struct skl_module_cfg *dst)
1006923 {
1007924 struct skl_module_deferred_bind *m_list, *modules;
....@@ -1039,26 +956,27 @@
1039956 }
1040957
1041958 static int skl_tplg_bind_sinks(struct snd_soc_dapm_widget *w,
1042
- struct skl *skl,
959
+ struct skl_dev *skl,
1043960 struct snd_soc_dapm_widget *src_w,
1044961 struct skl_module_cfg *src_mconfig)
1045962 {
1046963 struct snd_soc_dapm_path *p;
1047964 struct snd_soc_dapm_widget *sink = NULL, *next_sink = NULL;
1048965 struct skl_module_cfg *sink_mconfig;
1049
- struct skl_sst *ctx = skl->skl_sst;
1050966 int ret;
1051967
1052968 snd_soc_dapm_widget_for_each_sink_path(w, p) {
1053969 if (!p->connect)
1054970 continue;
1055971
1056
- dev_dbg(ctx->dev, "%s: src widget=%s\n", __func__, w->name);
1057
- dev_dbg(ctx->dev, "%s: sink widget=%s\n", __func__, p->sink->name);
972
+ dev_dbg(skl->dev,
973
+ "%s: src widget=%s\n", __func__, w->name);
974
+ dev_dbg(skl->dev,
975
+ "%s: sink widget=%s\n", __func__, p->sink->name);
1058976
1059977 next_sink = p->sink;
1060978
1061
- if (!is_skl_dsp_widget_type(p->sink, ctx->dev))
979
+ if (!is_skl_dsp_widget_type(p->sink, skl->dev))
1062980 return skl_tplg_bind_sinks(p->sink, skl, src_w, src_mconfig);
1063981
1064982 /*
....@@ -1067,7 +985,7 @@
1067985 * they are ones used for SKL so check that first
1068986 */
1069987 if ((p->sink->priv != NULL) &&
1070
- is_skl_dsp_widget_type(p->sink, ctx->dev)) {
988
+ is_skl_dsp_widget_type(p->sink, skl->dev)) {
1071989
1072990 sink = p->sink;
1073991 sink_mconfig = sink->priv;
....@@ -1099,19 +1017,21 @@
10991017 continue;
11001018
11011019 /* Bind source to sink, mixin is always source */
1102
- ret = skl_bind_modules(ctx, src_mconfig, sink_mconfig);
1020
+ ret = skl_bind_modules(skl, src_mconfig, sink_mconfig);
11031021 if (ret)
11041022 return ret;
11051023
11061024 /* set module params after bind */
1107
- skl_tplg_set_module_bind_params(src_w, src_mconfig, ctx);
1108
- skl_tplg_set_module_bind_params(sink, sink_mconfig, ctx);
1025
+ skl_tplg_set_module_bind_params(src_w,
1026
+ src_mconfig, skl);
1027
+ skl_tplg_set_module_bind_params(sink,
1028
+ sink_mconfig, skl);
11091029
11101030 /* Start sinks pipe first */
11111031 if (sink_mconfig->pipe->state != SKL_PIPE_STARTED) {
11121032 if (sink_mconfig->pipe->conn_type !=
11131033 SKL_PIPE_CONN_TYPE_FE)
1114
- ret = skl_run_pipe(ctx,
1034
+ ret = skl_run_pipe(skl,
11151035 sink_mconfig->pipe);
11161036 if (ret)
11171037 return ret;
....@@ -1136,10 +1056,9 @@
11361056 * - Then run current pipe
11371057 */
11381058 static int skl_tplg_pga_dapm_pre_pmu_event(struct snd_soc_dapm_widget *w,
1139
- struct skl *skl)
1059
+ struct skl_dev *skl)
11401060 {
11411061 struct skl_module_cfg *src_mconfig;
1142
- struct skl_sst *ctx = skl->skl_sst;
11431062 int ret = 0;
11441063
11451064 src_mconfig = w->priv;
....@@ -1155,25 +1074,24 @@
11551074
11561075 /* Start source pipe last after starting all sinks */
11571076 if (src_mconfig->pipe->conn_type != SKL_PIPE_CONN_TYPE_FE)
1158
- return skl_run_pipe(ctx, src_mconfig->pipe);
1077
+ return skl_run_pipe(skl, src_mconfig->pipe);
11591078
11601079 return 0;
11611080 }
11621081
11631082 static struct snd_soc_dapm_widget *skl_get_src_dsp_widget(
1164
- struct snd_soc_dapm_widget *w, struct skl *skl)
1083
+ struct snd_soc_dapm_widget *w, struct skl_dev *skl)
11651084 {
11661085 struct snd_soc_dapm_path *p;
11671086 struct snd_soc_dapm_widget *src_w = NULL;
1168
- struct skl_sst *ctx = skl->skl_sst;
11691087
11701088 snd_soc_dapm_widget_for_each_source_path(w, p) {
11711089 src_w = p->source;
11721090 if (!p->connect)
11731091 continue;
11741092
1175
- dev_dbg(ctx->dev, "sink widget=%s\n", w->name);
1176
- dev_dbg(ctx->dev, "src widget=%s\n", p->source->name);
1093
+ dev_dbg(skl->dev, "sink widget=%s\n", w->name);
1094
+ dev_dbg(skl->dev, "src widget=%s\n", p->source->name);
11771095
11781096 /*
11791097 * here we will check widgets in sink pipelines, so that can
....@@ -1181,7 +1099,7 @@
11811099 * ones used for SKL so check that first
11821100 */
11831101 if ((p->source->priv != NULL) &&
1184
- is_skl_dsp_widget_type(p->source, ctx->dev)) {
1102
+ is_skl_dsp_widget_type(p->source, skl->dev)) {
11851103 return p->source;
11861104 }
11871105 }
....@@ -1202,12 +1120,11 @@
12021120 * - start this pipeline
12031121 */
12041122 static int skl_tplg_mixer_dapm_post_pmu_event(struct snd_soc_dapm_widget *w,
1205
- struct skl *skl)
1123
+ struct skl_dev *skl)
12061124 {
12071125 int ret = 0;
12081126 struct snd_soc_dapm_widget *source, *sink;
12091127 struct skl_module_cfg *src_mconfig, *sink_mconfig;
1210
- struct skl_sst *ctx = skl->skl_sst;
12111128 int src_pipe_started = 0;
12121129
12131130 sink = w;
....@@ -1233,16 +1150,16 @@
12331150 }
12341151
12351152 if (src_pipe_started) {
1236
- ret = skl_bind_modules(ctx, src_mconfig, sink_mconfig);
1153
+ ret = skl_bind_modules(skl, src_mconfig, sink_mconfig);
12371154 if (ret)
12381155 return ret;
12391156
12401157 /* set module params after bind */
1241
- skl_tplg_set_module_bind_params(source, src_mconfig, ctx);
1242
- skl_tplg_set_module_bind_params(sink, sink_mconfig, ctx);
1158
+ skl_tplg_set_module_bind_params(source, src_mconfig, skl);
1159
+ skl_tplg_set_module_bind_params(sink, sink_mconfig, skl);
12431160
12441161 if (sink_mconfig->pipe->conn_type != SKL_PIPE_CONN_TYPE_FE)
1245
- ret = skl_run_pipe(ctx, sink_mconfig->pipe);
1162
+ ret = skl_run_pipe(skl, sink_mconfig->pipe);
12461163 }
12471164
12481165 return ret;
....@@ -1255,16 +1172,15 @@
12551172 * - unbind with source pipelines if still connected
12561173 */
12571174 static int skl_tplg_mixer_dapm_pre_pmd_event(struct snd_soc_dapm_widget *w,
1258
- struct skl *skl)
1175
+ struct skl_dev *skl)
12591176 {
12601177 struct skl_module_cfg *src_mconfig, *sink_mconfig;
12611178 int ret = 0, i;
1262
- struct skl_sst *ctx = skl->skl_sst;
12631179
12641180 sink_mconfig = w->priv;
12651181
12661182 /* Stop the pipe */
1267
- ret = skl_stop_pipe(ctx, sink_mconfig->pipe);
1183
+ ret = skl_stop_pipe(skl, sink_mconfig->pipe);
12681184 if (ret)
12691185 return ret;
12701186
....@@ -1274,7 +1190,7 @@
12741190 if (!src_mconfig)
12751191 continue;
12761192
1277
- ret = skl_unbind_modules(ctx,
1193
+ ret = skl_unbind_modules(skl,
12781194 src_mconfig, sink_mconfig);
12791195 }
12801196 }
....@@ -1284,27 +1200,21 @@
12841200
12851201 /*
12861202 * in the Post-PMD event of mixer we need to do following:
1287
- * - Free the mcps used
1288
- * - Free the mem used
12891203 * - Unbind the modules within the pipeline
12901204 * - Delete the pipeline (modules are not required to be explicitly
12911205 * deleted, pipeline delete is enough here
12921206 */
12931207 static int skl_tplg_mixer_dapm_post_pmd_event(struct snd_soc_dapm_widget *w,
1294
- struct skl *skl)
1208
+ struct skl_dev *skl)
12951209 {
12961210 struct skl_module_cfg *mconfig = w->priv;
12971211 struct skl_pipe_module *w_module;
12981212 struct skl_module_cfg *src_module = NULL, *dst_module;
1299
- struct skl_sst *ctx = skl->skl_sst;
13001213 struct skl_pipe *s_pipe = mconfig->pipe;
13011214 struct skl_module_deferred_bind *modules, *tmp;
13021215
13031216 if (s_pipe->state == SKL_PIPE_INVALID)
13041217 return -EINVAL;
1305
-
1306
- skl_tplg_free_pipe_mcps(skl, mconfig);
1307
- skl_tplg_free_pipe_mem(skl, mconfig);
13081218
13091219 list_for_each_entry(w_module, &s_pipe->w_list, node) {
13101220 if (list_empty(&skl->bind_list))
....@@ -1318,7 +1228,7 @@
13181228 * modules from deferred bind list.
13191229 */
13201230 if (modules->dst == src_module) {
1321
- skl_unbind_modules(ctx, modules->src,
1231
+ skl_unbind_modules(skl, modules->src,
13221232 modules->dst);
13231233 }
13241234
....@@ -1338,44 +1248,40 @@
13381248 list_for_each_entry(w_module, &s_pipe->w_list, node) {
13391249 dst_module = w_module->w->priv;
13401250
1341
- if (mconfig->m_state >= SKL_MODULE_INIT_DONE)
1342
- skl_tplg_free_pipe_mcps(skl, dst_module);
13431251 if (src_module == NULL) {
13441252 src_module = dst_module;
13451253 continue;
13461254 }
13471255
1348
- skl_unbind_modules(ctx, src_module, dst_module);
1256
+ skl_unbind_modules(skl, src_module, dst_module);
13491257 src_module = dst_module;
13501258 }
13511259
1352
- skl_delete_pipe(ctx, mconfig->pipe);
1260
+ skl_delete_pipe(skl, mconfig->pipe);
13531261
13541262 list_for_each_entry(w_module, &s_pipe->w_list, node) {
13551263 src_module = w_module->w->priv;
13561264 src_module->m_state = SKL_MODULE_UNINIT;
13571265 }
13581266
1359
- return skl_tplg_unload_pipe_modules(ctx, s_pipe);
1267
+ return skl_tplg_unload_pipe_modules(skl, s_pipe);
13601268 }
13611269
13621270 /*
13631271 * in the Post-PMD event of PGA we need to do following:
1364
- * - Free the mcps used
13651272 * - Stop the pipeline
13661273 * - In source pipe is connected, unbind with source pipelines
13671274 */
13681275 static int skl_tplg_pga_dapm_post_pmd_event(struct snd_soc_dapm_widget *w,
1369
- struct skl *skl)
1276
+ struct skl_dev *skl)
13701277 {
13711278 struct skl_module_cfg *src_mconfig, *sink_mconfig;
13721279 int ret = 0, i;
1373
- struct skl_sst *ctx = skl->skl_sst;
13741280
13751281 src_mconfig = w->priv;
13761282
13771283 /* Stop the pipe since this is a mixin module */
1378
- ret = skl_stop_pipe(ctx, src_mconfig->pipe);
1284
+ ret = skl_stop_pipe(skl, src_mconfig->pipe);
13791285 if (ret)
13801286 return ret;
13811287
....@@ -1388,7 +1294,7 @@
13881294 * This is a connecter and if path is found that means
13891295 * unbind between source and sink has not happened yet
13901296 */
1391
- ret = skl_unbind_modules(ctx, src_mconfig,
1297
+ ret = skl_unbind_modules(skl, src_mconfig,
13921298 sink_mconfig);
13931299 }
13941300 }
....@@ -1406,7 +1312,7 @@
14061312 struct snd_kcontrol *k, int event)
14071313 {
14081314 struct snd_soc_dapm_context *dapm = w->dapm;
1409
- struct skl *skl = get_skl_ctx(dapm->dev);
1315
+ struct skl_dev *skl = get_skl_ctx(dapm->dev);
14101316
14111317 switch (event) {
14121318 case SND_SOC_DAPM_PRE_PMU:
....@@ -1436,7 +1342,7 @@
14361342
14371343 {
14381344 struct snd_soc_dapm_context *dapm = w->dapm;
1439
- struct skl *skl = get_skl_ctx(dapm->dev);
1345
+ struct skl_dev *skl = get_skl_ctx(dapm->dev);
14401346
14411347 switch (event) {
14421348 case SND_SOC_DAPM_PRE_PMU:
....@@ -1449,6 +1355,68 @@
14491355 return 0;
14501356 }
14511357
1358
+static int skl_tplg_multi_config_set_get(struct snd_kcontrol *kcontrol,
1359
+ struct snd_ctl_elem_value *ucontrol,
1360
+ bool is_set)
1361
+{
1362
+ struct snd_soc_component *component =
1363
+ snd_soc_kcontrol_component(kcontrol);
1364
+ struct hdac_bus *bus = snd_soc_component_get_drvdata(component);
1365
+ struct skl_dev *skl = bus_to_skl(bus);
1366
+ struct skl_pipeline *ppl;
1367
+ struct skl_pipe *pipe = NULL;
1368
+ struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value;
1369
+ u32 *pipe_id;
1370
+
1371
+ if (!ec)
1372
+ return -EINVAL;
1373
+
1374
+ if (is_set && ucontrol->value.enumerated.item[0] > ec->items)
1375
+ return -EINVAL;
1376
+
1377
+ pipe_id = ec->dobj.private;
1378
+
1379
+ list_for_each_entry(ppl, &skl->ppl_list, node) {
1380
+ if (ppl->pipe->ppl_id == *pipe_id) {
1381
+ pipe = ppl->pipe;
1382
+ break;
1383
+ }
1384
+ }
1385
+ if (!pipe)
1386
+ return -EIO;
1387
+
1388
+ if (is_set)
1389
+ pipe->pipe_config_idx = ucontrol->value.enumerated.item[0];
1390
+ else
1391
+ ucontrol->value.enumerated.item[0] = pipe->pipe_config_idx;
1392
+
1393
+ return 0;
1394
+}
1395
+
1396
+static int skl_tplg_multi_config_get(struct snd_kcontrol *kcontrol,
1397
+ struct snd_ctl_elem_value *ucontrol)
1398
+{
1399
+ return skl_tplg_multi_config_set_get(kcontrol, ucontrol, false);
1400
+}
1401
+
1402
+static int skl_tplg_multi_config_set(struct snd_kcontrol *kcontrol,
1403
+ struct snd_ctl_elem_value *ucontrol)
1404
+{
1405
+ return skl_tplg_multi_config_set_get(kcontrol, ucontrol, true);
1406
+}
1407
+
1408
+static int skl_tplg_multi_config_get_dmic(struct snd_kcontrol *kcontrol,
1409
+ struct snd_ctl_elem_value *ucontrol)
1410
+{
1411
+ return skl_tplg_multi_config_set_get(kcontrol, ucontrol, false);
1412
+}
1413
+
1414
+static int skl_tplg_multi_config_set_dmic(struct snd_kcontrol *kcontrol,
1415
+ struct snd_ctl_elem_value *ucontrol)
1416
+{
1417
+ return skl_tplg_multi_config_set_get(kcontrol, ucontrol, true);
1418
+}
1419
+
14521420 static int skl_tplg_tlv_control_get(struct snd_kcontrol *kcontrol,
14531421 unsigned int __user *data, unsigned int size)
14541422 {
....@@ -1457,10 +1425,10 @@
14571425 struct skl_algo_data *bc = (struct skl_algo_data *)sb->dobj.private;
14581426 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
14591427 struct skl_module_cfg *mconfig = w->priv;
1460
- struct skl *skl = get_skl_ctx(w->dapm->dev);
1428
+ struct skl_dev *skl = get_skl_ctx(w->dapm->dev);
14611429
14621430 if (w->power)
1463
- skl_get_module_params(skl->skl_sst, (u32 *)bc->params,
1431
+ skl_get_module_params(skl, (u32 *)bc->params,
14641432 bc->size, bc->param_id, mconfig);
14651433
14661434 /* decrement size for TLV header */
....@@ -1492,28 +1460,18 @@
14921460 struct soc_bytes_ext *sb =
14931461 (struct soc_bytes_ext *)kcontrol->private_value;
14941462 struct skl_algo_data *ac = (struct skl_algo_data *)sb->dobj.private;
1495
- struct skl *skl = get_skl_ctx(w->dapm->dev);
1463
+ struct skl_dev *skl = get_skl_ctx(w->dapm->dev);
14961464
14971465 if (ac->params) {
14981466 if (size > ac->max)
14991467 return -EINVAL;
1500
-
15011468 ac->size = size;
1502
- /*
1503
- * if the param_is is of type Vendor, firmware expects actual
1504
- * parameter id and size from the control.
1505
- */
1506
- if (ac->param_id == SKL_PARAM_VENDOR_ID) {
1507
- if (copy_from_user(ac->params, data, size))
1508
- return -EFAULT;
1509
- } else {
1510
- if (copy_from_user(ac->params,
1511
- data + 2, size))
1512
- return -EFAULT;
1513
- }
1469
+
1470
+ if (copy_from_user(ac->params, data, size))
1471
+ return -EFAULT;
15141472
15151473 if (w->power)
1516
- return skl_set_module_params(skl->skl_sst,
1474
+ return skl_set_module_params(skl,
15171475 (u32 *)ac->params, ac->size,
15181476 ac->param_id, mconfig);
15191477 }
....@@ -1673,11 +1631,12 @@
16731631 struct skl_module_cfg *mconfig,
16741632 struct skl_pipe_params *params)
16751633 {
1676
- struct skl_module_res *res = &mconfig->module->resources[0];
1677
- struct skl *skl = get_skl_ctx(dev);
1634
+ struct skl_module_res *res;
1635
+ struct skl_dev *skl = get_skl_ctx(dev);
16781636 struct skl_module_fmt *format = NULL;
16791637 u8 cfg_idx = mconfig->pipe->cur_config_idx;
16801638
1639
+ res = &mconfig->module->resources[mconfig->res_idx];
16811640 skl_tplg_fill_dma_id(mconfig, params);
16821641 mconfig->fmt_idx = mconfig->mod_cfg[cfg_idx].fmt_idx;
16831642 mconfig->res_idx = mconfig->mod_cfg[cfg_idx].res_idx;
....@@ -1686,9 +1645,9 @@
16861645 return 0;
16871646
16881647 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK)
1689
- format = &mconfig->module->formats[0].inputs[0].fmt;
1648
+ format = &mconfig->module->formats[mconfig->fmt_idx].inputs[0].fmt;
16901649 else
1691
- format = &mconfig->module->formats[0].outputs[0].fmt;
1650
+ format = &mconfig->module->formats[mconfig->fmt_idx].outputs[0].fmt;
16921651
16931652 /* set the hw_params */
16941653 format->s_freq = params->s_freq;
....@@ -1871,7 +1830,7 @@
18711830 struct skl_pipe_params *params)
18721831 {
18731832 struct nhlt_specific_cfg *cfg;
1874
- struct skl *skl = get_skl_ctx(dai->dev);
1833
+ struct skl_dev *skl = get_skl_ctx(dai->dev);
18751834 int link_type = skl_tplg_be_link_type(mconfig->dev_type);
18761835 u8 dev_type = skl_tplg_be_dev_type(mconfig->dev_type);
18771836
....@@ -1929,7 +1888,7 @@
19291888 static int skl_tplg_be_set_sink_pipe_params(struct snd_soc_dai *dai,
19301889 struct snd_soc_dapm_widget *w, struct skl_pipe_params *params)
19311890 {
1932
- struct snd_soc_dapm_path *p = NULL;
1891
+ struct snd_soc_dapm_path *p;
19331892 int ret = -EIO;
19341893
19351894 snd_soc_dapm_widget_for_each_sink_path(w, p) {
....@@ -1992,6 +1951,16 @@
19921951 .get = skl_tplg_mic_control_get,
19931952 .put = skl_tplg_mic_control_set,
19941953 },
1954
+ {
1955
+ .id = SKL_CONTROL_TYPE_MULTI_IO_SELECT,
1956
+ .get = skl_tplg_multi_config_get,
1957
+ .put = skl_tplg_multi_config_set,
1958
+ },
1959
+ {
1960
+ .id = SKL_CONTROL_TYPE_MULTI_IO_SELECT_DMIC,
1961
+ .get = skl_tplg_multi_config_get_dmic,
1962
+ .put = skl_tplg_multi_config_set_dmic,
1963
+ }
19951964 };
19961965
19971966 static int skl_tplg_fill_pipe_cfg(struct device *dev,
....@@ -2085,7 +2054,7 @@
20852054 * Return an existing pipe if the pipe already exists.
20862055 */
20872056 static int skl_tplg_add_pipe(struct device *dev,
2088
- struct skl_module_cfg *mconfig, struct skl *skl,
2057
+ struct skl_module_cfg *mconfig, struct skl_dev *skl,
20892058 struct snd_soc_tplg_vendor_value_elem *tkn_elem)
20902059 {
20912060 struct skl_pipeline *ppl;
....@@ -2124,11 +2093,11 @@
21242093 return 0;
21252094 }
21262095
2127
-static int skl_tplg_get_uuid(struct device *dev, u8 *guid,
2096
+static int skl_tplg_get_uuid(struct device *dev, guid_t *guid,
21282097 struct snd_soc_tplg_vendor_uuid_elem *uuid_tkn)
21292098 {
21302099 if (uuid_tkn->token == SKL_TKN_UUID) {
2131
- memcpy(guid, &uuid_tkn->uuid, 16);
2100
+ import_guid(guid, uuid_tkn->uuid);
21322101 return 0;
21332102 }
21342103
....@@ -2154,7 +2123,7 @@
21542123 break;
21552124
21562125 case SKL_TKN_UUID:
2157
- ret = skl_tplg_get_uuid(dev, m_pin[pin_index].id.mod_uuid.b,
2126
+ ret = skl_tplg_get_uuid(dev, &m_pin[pin_index].id.mod_uuid,
21582127 (struct snd_soc_tplg_vendor_uuid_elem *)tkn_elem);
21592128 if (ret < 0)
21602129 return ret;
....@@ -2345,10 +2314,6 @@
23452314 return -EINVAL;
23462315
23472316 switch (tkn_elem->token) {
2348
- case SKL_TKN_MM_U32_CPS:
2349
- res->cps = tkn_elem->value;
2350
- break;
2351
-
23522317 case SKL_TKN_MM_U32_DMA_SIZE:
23532318 res->dma_buffer_size = tkn_elem->value;
23542319 break;
....@@ -2369,16 +2334,17 @@
23692334 res->ibs = tkn_elem->value;
23702335 break;
23712336
2372
- case SKL_TKN_U32_MAX_MCPS:
2373
- res->cps = tkn_elem->value;
2374
- break;
2375
-
23762337 case SKL_TKN_MM_U32_RES_PIN_ID:
23772338 case SKL_TKN_MM_U32_PIN_BUF:
23782339 ret = skl_tplg_manifest_pin_res_tkn(dev, tkn_elem, res,
23792340 pin_idx, dir);
23802341 if (ret < 0)
23812342 return ret;
2343
+ break;
2344
+
2345
+ case SKL_TKN_MM_U32_CPS:
2346
+ case SKL_TKN_U32_MAX_MCPS:
2347
+ /* ignore unused tokens */
23822348 break;
23832349
23842350 default:
....@@ -2396,7 +2362,7 @@
23962362 */
23972363 static int skl_tplg_get_token(struct device *dev,
23982364 struct snd_soc_tplg_vendor_value_elem *tkn_elem,
2399
- struct skl *skl, struct skl_module_cfg *mconfig)
2365
+ struct skl_dev *skl, struct skl_module_cfg *mconfig)
24002366 {
24012367 int tkn_count = 0;
24022368 int ret;
....@@ -2646,7 +2612,7 @@
26462612 * module private data
26472613 */
26482614 static int skl_tplg_get_tokens(struct device *dev,
2649
- char *pvt_data, struct skl *skl,
2615
+ char *pvt_data, struct skl_dev *skl,
26502616 struct skl_module_cfg *mconfig, int block_size)
26512617 {
26522618 struct snd_soc_tplg_vendor_array *array;
....@@ -2670,7 +2636,7 @@
26702636
26712637 case SND_SOC_TPLG_TUPLE_TYPE_UUID:
26722638 if (is_module_guid) {
2673
- ret = skl_tplg_get_uuid(dev, mconfig->guid,
2639
+ ret = skl_tplg_get_uuid(dev, (guid_t *)mconfig->guid,
26742640 array->uuid);
26752641 is_module_guid = false;
26762642 } else {
....@@ -2742,8 +2708,8 @@
27422708 * Otherwise we create a new instance and add into driver list
27432709 */
27442710 static int skl_tplg_add_pipe_v4(struct device *dev,
2745
- struct skl_module_cfg *mconfig, struct skl *skl,
2746
- struct skl_dfw_v4_pipe *dfw_pipe)
2711
+ struct skl_module_cfg *mconfig, struct skl_dev *skl,
2712
+ struct skl_dfw_v4_pipe *dfw_pipe)
27472713 {
27482714 struct skl_pipeline *ppl;
27492715 struct skl_pipe *pipe;
....@@ -2819,7 +2785,7 @@
28192785 }
28202786
28212787 static int skl_tplg_get_pvt_data_v4(struct snd_soc_tplg_dapm_widget *tplg_w,
2822
- struct skl *skl, struct device *dev,
2788
+ struct skl_dev *skl, struct device *dev,
28232789 struct skl_module_cfg *mconfig)
28242790 {
28252791 struct skl_dfw_v4_module *dfw =
....@@ -2833,7 +2799,7 @@
28332799 return ret;
28342800 mconfig->id.module_id = -1;
28352801 mconfig->id.instance_id = dfw->instance_id;
2836
- mconfig->module->resources[0].cps = dfw->max_mcps;
2802
+ mconfig->module->resources[0].cpc = dfw->max_mcps / 1000;
28372803 mconfig->module->resources[0].ibs = dfw->ibs;
28382804 mconfig->module->resources[0].obs = dfw->obs;
28392805 mconfig->core_id = dfw->core_id;
....@@ -2901,11 +2867,11 @@
29012867 * for the type and size of the suceeding data block.
29022868 */
29032869 static int skl_tplg_get_pvt_data(struct snd_soc_tplg_dapm_widget *tplg_w,
2904
- struct skl *skl, struct device *dev,
2870
+ struct skl_dev *skl, struct device *dev,
29052871 struct skl_module_cfg *mconfig)
29062872 {
29072873 struct snd_soc_tplg_vendor_array *array;
2908
- int num_blocks, block_size = 0, block_type, off = 0;
2874
+ int num_blocks, block_size, block_type, off = 0;
29092875 char *data;
29102876 int ret;
29112877
....@@ -2996,9 +2962,8 @@
29962962 }
29972963 }
29982964
2999
-void skl_cleanup_resources(struct skl *skl)
2965
+void skl_cleanup_resources(struct skl_dev *skl)
30002966 {
3001
- struct skl_sst *ctx = skl->skl_sst;
30022967 struct snd_soc_component *soc_component = skl->component;
30032968 struct snd_soc_dapm_widget *w;
30042969 struct snd_soc_card *card;
....@@ -3010,15 +2975,12 @@
30102975 if (!card || !card->instantiated)
30112976 return;
30122977
3013
- skl->resource.mem = 0;
3014
- skl->resource.mcps = 0;
3015
-
30162978 list_for_each_entry(w, &card->widgets, list) {
3017
- if (is_skl_dsp_widget_type(w, ctx->dev) && w->priv != NULL)
2979
+ if (is_skl_dsp_widget_type(w, skl->dev) && w->priv != NULL)
30182980 skl_clear_pin_config(soc_component, w);
30192981 }
30202982
3021
- skl_clear_module_cnt(ctx->dsp);
2983
+ skl_clear_module_cnt(skl->dsp);
30222984 }
30232985
30242986 /*
....@@ -3034,7 +2996,7 @@
30342996 {
30352997 int ret;
30362998 struct hdac_bus *bus = snd_soc_component_get_drvdata(cmpnt);
3037
- struct skl *skl = bus_to_skl(bus);
2999
+ struct skl_dev *skl = bus_to_skl(bus);
30383000 struct skl_module_cfg *mconfig;
30393001
30403002 if (!tplg_w->priv.size)
....@@ -3104,7 +3066,7 @@
31043066 ac->size = dfw_ac->max;
31053067
31063068 if (ac->max) {
3107
- ac->params = (char *) devm_kzalloc(dev, ac->max, GFP_KERNEL);
3069
+ ac->params = devm_kzalloc(dev, ac->max, GFP_KERNEL);
31083070 if (!ac->params)
31093071 return -ENOMEM;
31103072
....@@ -3159,12 +3121,21 @@
31593121 case SND_SOC_TPLG_CTL_ENUM:
31603122 tplg_ec = container_of(hdr,
31613123 struct snd_soc_tplg_enum_control, hdr);
3162
- if (kctl->access & SNDRV_CTL_ELEM_ACCESS_READWRITE) {
3124
+ if (kctl->access & SNDRV_CTL_ELEM_ACCESS_READ) {
31633125 se = (struct soc_enum *)kctl->private_value;
31643126 if (tplg_ec->priv.size)
3165
- return skl_init_enum_data(bus->dev, se,
3166
- tplg_ec);
3127
+ skl_init_enum_data(bus->dev, se, tplg_ec);
31673128 }
3129
+
3130
+ /*
3131
+ * now that the control initializations are done, remove
3132
+ * write permission for the DMIC configuration enums to
3133
+ * avoid conflicts between NHLT settings and user interaction
3134
+ */
3135
+
3136
+ if (hdr->ops.get == SKL_CONTROL_TYPE_MULTI_IO_SELECT_DMIC)
3137
+ kctl->access = SNDRV_CTL_ELEM_ACCESS_READ;
3138
+
31683139 break;
31693140
31703141 default:
....@@ -3178,21 +3149,21 @@
31783149
31793150 static int skl_tplg_fill_str_mfest_tkn(struct device *dev,
31803151 struct snd_soc_tplg_vendor_string_elem *str_elem,
3181
- struct skl *skl)
3152
+ struct skl_dev *skl)
31823153 {
31833154 int tkn_count = 0;
31843155 static int ref_count;
31853156
31863157 switch (str_elem->token) {
31873158 case SKL_TKN_STR_LIB_NAME:
3188
- if (ref_count > skl->skl_sst->lib_count - 1) {
3159
+ if (ref_count > skl->lib_count - 1) {
31893160 ref_count = 0;
31903161 return -EINVAL;
31913162 }
31923163
3193
- strncpy(skl->skl_sst->lib_info[ref_count].name,
3164
+ strncpy(skl->lib_info[ref_count].name,
31943165 str_elem->string,
3195
- ARRAY_SIZE(skl->skl_sst->lib_info[ref_count].name));
3166
+ ARRAY_SIZE(skl->lib_info[ref_count].name));
31963167 ref_count++;
31973168 break;
31983169
....@@ -3207,7 +3178,7 @@
32073178
32083179 static int skl_tplg_get_str_tkn(struct device *dev,
32093180 struct snd_soc_tplg_vendor_array *array,
3210
- struct skl *skl)
3181
+ struct skl_dev *skl)
32113182 {
32123183 int tkn_count = 0, ret;
32133184 struct snd_soc_tplg_vendor_string_elem *str_elem;
....@@ -3314,9 +3285,9 @@
33143285
33153286 static int skl_tplg_get_int_tkn(struct device *dev,
33163287 struct snd_soc_tplg_vendor_value_elem *tkn_elem,
3317
- struct skl *skl)
3288
+ struct skl_dev *skl)
33183289 {
3319
- int tkn_count = 0, ret, size;
3290
+ int tkn_count = 0, ret;
33203291 static int mod_idx, res_val_idx, intf_val_idx, dir, pin_idx;
33213292 struct skl_module_res *res = NULL;
33223293 struct skl_module_iface *fmt = NULL;
....@@ -3324,6 +3295,7 @@
33243295 static struct skl_astate_param *astate_table;
33253296 static int astate_cfg_idx, count;
33263297 int i;
3298
+ size_t size;
33273299
33283300 if (skl->modules) {
33293301 mod = skl->modules[mod_idx];
....@@ -3333,7 +3305,7 @@
33333305
33343306 switch (tkn_elem->token) {
33353307 case SKL_TKN_U32_LIB_COUNT:
3336
- skl->skl_sst->lib_count = tkn_elem->value;
3308
+ skl->lib_count = tkn_elem->value;
33373309 break;
33383310
33393311 case SKL_TKN_U8_NUM_MOD:
....@@ -3367,8 +3339,8 @@
33673339 return -EINVAL;
33683340 }
33693341
3370
- size = tkn_elem->value * sizeof(struct skl_astate_param) +
3371
- sizeof(count);
3342
+ size = struct_size(skl->cfg.astate_cfg, astate_table,
3343
+ tkn_elem->value);
33723344 skl->cfg.astate_cfg = devm_kzalloc(dev, size, GFP_KERNEL);
33733345 if (!skl->cfg.astate_cfg)
33743346 return -ENOMEM;
....@@ -3479,35 +3451,17 @@
34793451 return tkn_count;
34803452 }
34813453
3482
-static int skl_tplg_get_manifest_uuid(struct device *dev,
3483
- struct skl *skl,
3484
- struct snd_soc_tplg_vendor_uuid_elem *uuid_tkn)
3485
-{
3486
- static int ref_count;
3487
- struct skl_module *mod;
3488
-
3489
- if (uuid_tkn->token == SKL_TKN_UUID) {
3490
- mod = skl->modules[ref_count];
3491
- memcpy(&mod->uuid, &uuid_tkn->uuid, sizeof(uuid_tkn->uuid));
3492
- ref_count++;
3493
- } else {
3494
- dev_err(dev, "Not an UUID token tkn %d\n", uuid_tkn->token);
3495
- return -EINVAL;
3496
- }
3497
-
3498
- return 0;
3499
-}
3500
-
35013454 /*
35023455 * Fill the manifest structure by parsing the tokens based on the
35033456 * type.
35043457 */
35053458 static int skl_tplg_get_manifest_tkn(struct device *dev,
3506
- char *pvt_data, struct skl *skl,
3459
+ char *pvt_data, struct skl_dev *skl,
35073460 int block_size)
35083461 {
35093462 int tkn_count = 0, ret;
35103463 int off = 0, tuple_size = 0;
3464
+ u8 uuid_index = 0;
35113465 struct snd_soc_tplg_vendor_array *array;
35123466 struct snd_soc_tplg_vendor_value_elem *tkn_elem;
35133467
....@@ -3530,9 +3484,17 @@
35303484 continue;
35313485
35323486 case SND_SOC_TPLG_TUPLE_TYPE_UUID:
3533
- ret = skl_tplg_get_manifest_uuid(dev, skl, array->uuid);
3534
- if (ret < 0)
3535
- return ret;
3487
+ if (array->uuid->token != SKL_TKN_UUID) {
3488
+ dev_err(dev, "Not an UUID token: %d\n",
3489
+ array->uuid->token);
3490
+ return -EINVAL;
3491
+ }
3492
+ if (uuid_index >= skl->nr_modules) {
3493
+ dev_err(dev, "Too many UUID tokens\n");
3494
+ return -EINVAL;
3495
+ }
3496
+ import_guid(&skl->modules[uuid_index++]->uuid,
3497
+ array->uuid->uuid);
35363498
35373499 tuple_size += sizeof(*array->uuid);
35383500 continue;
....@@ -3564,7 +3526,7 @@
35643526 * preceded by descriptors for type and size of data block.
35653527 */
35663528 static int skl_tplg_get_manifest_data(struct snd_soc_tplg_manifest *manifest,
3567
- struct device *dev, struct skl *skl)
3529
+ struct device *dev, struct skl_dev *skl)
35683530 {
35693531 struct snd_soc_tplg_vendor_array *array;
35703532 int num_blocks, block_size = 0, block_type, off = 0;
....@@ -3626,7 +3588,7 @@
36263588 struct snd_soc_tplg_manifest *manifest)
36273589 {
36283590 struct hdac_bus *bus = snd_soc_component_get_drvdata(cmpnt);
3629
- struct skl *skl = bus_to_skl(bus);
3591
+ struct skl_dev *skl = bus_to_skl(bus);
36303592
36313593 /* proceed only if we have private data defined */
36323594 if (manifest->priv.size == 0)
....@@ -3634,13 +3596,45 @@
36343596
36353597 skl_tplg_get_manifest_data(manifest, bus->dev, skl);
36363598
3637
- if (skl->skl_sst->lib_count > SKL_MAX_LIB) {
3599
+ if (skl->lib_count > SKL_MAX_LIB) {
36383600 dev_err(bus->dev, "Exceeding max Library count. Got:%d\n",
3639
- skl->skl_sst->lib_count);
3601
+ skl->lib_count);
36403602 return -EINVAL;
36413603 }
36423604
36433605 return 0;
3606
+}
3607
+
3608
+static void skl_tplg_complete(struct snd_soc_component *component)
3609
+{
3610
+ struct snd_soc_dobj *dobj;
3611
+ struct snd_soc_acpi_mach *mach =
3612
+ dev_get_platdata(component->card->dev);
3613
+ int i;
3614
+
3615
+ list_for_each_entry(dobj, &component->dobj_list, list) {
3616
+ struct snd_kcontrol *kcontrol = dobj->control.kcontrol;
3617
+ struct soc_enum *se;
3618
+ char **texts;
3619
+ char chan_text[4];
3620
+
3621
+ if (dobj->type != SND_SOC_DOBJ_ENUM || !kcontrol ||
3622
+ kcontrol->put != skl_tplg_multi_config_set_dmic)
3623
+ continue;
3624
+
3625
+ se = (struct soc_enum *)kcontrol->private_value;
3626
+ texts = dobj->control.dtexts;
3627
+ sprintf(chan_text, "c%d", mach->mach_params.dmic_num);
3628
+
3629
+ for (i = 0; i < se->items; i++) {
3630
+ struct snd_ctl_elem_value val = {};
3631
+
3632
+ if (strstr(texts[i], chan_text)) {
3633
+ val.value.enumerated.item[0] = i;
3634
+ kcontrol->put(kcontrol, &val);
3635
+ }
3636
+ }
3637
+ }
36443638 }
36453639
36463640 static struct snd_soc_tplg_ops skl_tplg_ops = {
....@@ -3652,6 +3646,7 @@
36523646 .io_ops_count = ARRAY_SIZE(skl_tplg_kcontrol_ops),
36533647 .manifest = skl_manifest_load,
36543648 .dai_load = skl_dai_load,
3649
+ .complete = skl_tplg_complete,
36553650 };
36563651
36573652 /*
....@@ -3685,7 +3680,7 @@
36853680 return 0;
36863681 }
36873682
3688
-static void skl_tplg_set_pipe_type(struct skl *skl, struct skl_pipe *pipe)
3683
+static void skl_tplg_set_pipe_type(struct skl_dev *skl, struct skl_pipe *pipe)
36893684 {
36903685 struct skl_pipe_module *w_module;
36913686 struct snd_soc_dapm_widget *w;
....@@ -3708,10 +3703,6 @@
37083703 pipe->passthru = false;
37093704 }
37103705
3711
-/* This will be read from topology manifest, currently defined here */
3712
-#define SKL_MAX_MCPS 30000000
3713
-#define SKL_FW_MAX_MEM 1000000
3714
-
37153706 /*
37163707 * SKL topology init routine
37173708 */
....@@ -3719,13 +3710,25 @@
37193710 {
37203711 int ret;
37213712 const struct firmware *fw;
3722
- struct skl *skl = bus_to_skl(bus);
3713
+ struct skl_dev *skl = bus_to_skl(bus);
37233714 struct skl_pipeline *ppl;
37243715
37253716 ret = request_firmware(&fw, skl->tplg_name, bus->dev);
37263717 if (ret < 0) {
3727
- dev_info(bus->dev, "tplg fw %s load failed with %d, falling back to dfw_sst.bin",
3728
- skl->tplg_name, ret);
3718
+ char alt_tplg_name[64];
3719
+
3720
+ snprintf(alt_tplg_name, sizeof(alt_tplg_name), "%s-tplg.bin",
3721
+ skl->mach->drv_name);
3722
+ dev_info(bus->dev, "tplg fw %s load failed with %d, trying alternative tplg name %s",
3723
+ skl->tplg_name, ret, alt_tplg_name);
3724
+
3725
+ ret = request_firmware(&fw, alt_tplg_name, bus->dev);
3726
+ if (!ret)
3727
+ goto component_load;
3728
+
3729
+ dev_info(bus->dev, "tplg %s failed with %d, falling back to dfw_sst.bin",
3730
+ alt_tplg_name, ret);
3731
+
37293732 ret = request_firmware(&fw, "dfw_sst.bin", bus->dev);
37303733 if (ret < 0) {
37313734 dev_err(bus->dev, "Fallback tplg fw %s load failed with %d\n",
....@@ -3734,28 +3737,41 @@
37343737 }
37353738 }
37363739
3740
+component_load:
3741
+
37373742 /*
37383743 * The complete tplg for SKL is loaded as index 0, we don't use
37393744 * any other index
37403745 */
3741
- ret = snd_soc_tplg_component_load(component,
3742
- &skl_tplg_ops, fw, 0);
3746
+ ret = snd_soc_tplg_component_load(component, &skl_tplg_ops, fw, 0);
37433747 if (ret < 0) {
37443748 dev_err(bus->dev, "tplg component load failed%d\n", ret);
3745
- release_firmware(fw);
3746
- return -EINVAL;
3749
+ goto err;
37473750 }
37483751
3749
- skl->resource.max_mcps = SKL_MAX_MCPS;
3750
- skl->resource.max_mem = SKL_FW_MAX_MEM;
3751
-
3752
- skl->tplg = fw;
37533752 ret = skl_tplg_create_pipe_widget_list(component);
3754
- if (ret < 0)
3755
- return ret;
3753
+ if (ret < 0) {
3754
+ dev_err(bus->dev, "tplg create pipe widget list failed%d\n",
3755
+ ret);
3756
+ goto err;
3757
+ }
37563758
37573759 list_for_each_entry(ppl, &skl->ppl_list, node)
37583760 skl_tplg_set_pipe_type(skl, ppl->pipe);
37593761
3760
- return 0;
3762
+err:
3763
+ release_firmware(fw);
3764
+ return ret;
3765
+}
3766
+
3767
+void skl_tplg_exit(struct snd_soc_component *component, struct hdac_bus *bus)
3768
+{
3769
+ struct skl_dev *skl = bus_to_skl(bus);
3770
+ struct skl_pipeline *ppl, *tmp;
3771
+
3772
+ list_for_each_entry_safe(ppl, tmp, &skl->ppl_list, node)
3773
+ list_del(&ppl->node);
3774
+
3775
+ /* clean up topology */
3776
+ snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL);
37613777 }