1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/slab.h>
20#include <linux/types.h>
21#include <linux/firmware.h>
22#include <sound/soc.h>
23#include <sound/soc-topology.h>
24#include "skl-sst-dsp.h"
25#include "skl-sst-ipc.h"
26#include "skl-topology.h"
27#include "skl.h"
28#include "skl-tplg-interface.h"
29
30#define SKL_CH_FIXUP_MASK (1 << 0)
31#define SKL_RATE_FIXUP_MASK (1 << 1)
32#define SKL_FMT_FIXUP_MASK (1 << 2)
33
34
35
36
37
38static int is_skl_dsp_widget_type(struct snd_soc_dapm_widget *w)
39{
40 switch (w->id) {
41 case snd_soc_dapm_dai_link:
42 case snd_soc_dapm_dai_in:
43 case snd_soc_dapm_aif_in:
44 case snd_soc_dapm_aif_out:
45 case snd_soc_dapm_dai_out:
46 case snd_soc_dapm_switch:
47 return false;
48 default:
49 return true;
50 }
51}
52
53
54
55
56
57
58
59
60static bool skl_tplg_alloc_pipe_mem(struct skl *skl,
61 struct skl_module_cfg *mconfig)
62{
63 struct skl_sst *ctx = skl->skl_sst;
64
65 if (skl->resource.mem + mconfig->pipe->memory_pages >
66 skl->resource.max_mem) {
67 dev_err(ctx->dev,
68 "%s: module_id %d instance %d\n", __func__,
69 mconfig->id.module_id,
70 mconfig->id.instance_id);
71 dev_err(ctx->dev,
72 "exceeds ppl memory available %d mem %d\n",
73 skl->resource.max_mem, skl->resource.mem);
74 return false;
75 }
76
77 skl->resource.mem += mconfig->pipe->memory_pages;
78 return true;
79}
80
81
82
83
84
85
86
87
88
89static bool skl_tplg_alloc_pipe_mcps(struct skl *skl,
90 struct skl_module_cfg *mconfig)
91{
92 struct skl_sst *ctx = skl->skl_sst;
93
94 if (skl->resource.mcps + mconfig->mcps > skl->resource.max_mcps) {
95 dev_err(ctx->dev,
96 "%s: module_id %d instance %d\n", __func__,
97 mconfig->id.module_id, mconfig->id.instance_id);
98 dev_err(ctx->dev,
99 "exceeds ppl memory available %d > mem %d\n",
100 skl->resource.max_mcps, skl->resource.mcps);
101 return false;
102 }
103
104 skl->resource.mcps += mconfig->mcps;
105 return true;
106}
107
108
109
110
111static void
112skl_tplg_free_pipe_mcps(struct skl *skl, struct skl_module_cfg *mconfig)
113{
114 skl->resource.mcps -= mconfig->mcps;
115}
116
117
118
119
120static void
121skl_tplg_free_pipe_mem(struct skl *skl, struct skl_module_cfg *mconfig)
122{
123 skl->resource.mem -= mconfig->pipe->memory_pages;
124}
125
126
127static void skl_dump_mconfig(struct skl_sst *ctx,
128 struct skl_module_cfg *mcfg)
129{
130 dev_dbg(ctx->dev, "Dumping config\n");
131 dev_dbg(ctx->dev, "Input Format:\n");
132 dev_dbg(ctx->dev, "channels = %d\n", mcfg->in_fmt.channels);
133 dev_dbg(ctx->dev, "s_freq = %d\n", mcfg->in_fmt.s_freq);
134 dev_dbg(ctx->dev, "ch_cfg = %d\n", mcfg->in_fmt.ch_cfg);
135 dev_dbg(ctx->dev, "valid bit depth = %d\n",
136 mcfg->in_fmt.valid_bit_depth);
137 dev_dbg(ctx->dev, "Output Format:\n");
138 dev_dbg(ctx->dev, "channels = %d\n", mcfg->out_fmt.channels);
139 dev_dbg(ctx->dev, "s_freq = %d\n", mcfg->out_fmt.s_freq);
140 dev_dbg(ctx->dev, "valid bit depth = %d\n",
141 mcfg->out_fmt.valid_bit_depth);
142 dev_dbg(ctx->dev, "ch_cfg = %d\n", mcfg->out_fmt.ch_cfg);
143}
144
145static void skl_tplg_update_params(struct skl_module_fmt *fmt,
146 struct skl_pipe_params *params, int fixup)
147{
148 if (fixup & SKL_RATE_FIXUP_MASK)
149 fmt->s_freq = params->s_freq;
150 if (fixup & SKL_CH_FIXUP_MASK)
151 fmt->channels = params->ch;
152 if (fixup & SKL_FMT_FIXUP_MASK)
153 fmt->valid_bit_depth = params->s_fmt;
154}
155
156
157
158
159
160
161
162
163
164
165
166
167
168static void skl_tplg_update_params_fixup(struct skl_module_cfg *m_cfg,
169 struct skl_pipe_params *params, bool is_fe)
170{
171 int in_fixup, out_fixup;
172 struct skl_module_fmt *in_fmt, *out_fmt;
173
174 in_fmt = &m_cfg->in_fmt;
175 out_fmt = &m_cfg->out_fmt;
176
177 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK) {
178 if (is_fe) {
179 in_fixup = m_cfg->params_fixup;
180 out_fixup = (~m_cfg->converter) &
181 m_cfg->params_fixup;
182 } else {
183 out_fixup = m_cfg->params_fixup;
184 in_fixup = (~m_cfg->converter) &
185 m_cfg->params_fixup;
186 }
187 } else {
188 if (is_fe) {
189 out_fixup = m_cfg->params_fixup;
190 in_fixup = (~m_cfg->converter) &
191 m_cfg->params_fixup;
192 } else {
193 in_fixup = m_cfg->params_fixup;
194 out_fixup = (~m_cfg->converter) &
195 m_cfg->params_fixup;
196 }
197 }
198
199 skl_tplg_update_params(in_fmt, params, in_fixup);
200 skl_tplg_update_params(out_fmt, params, out_fixup);
201}
202
203
204
205
206
207
208static void skl_tplg_update_buffer_size(struct skl_sst *ctx,
209 struct skl_module_cfg *mcfg)
210{
211 int multiplier = 1;
212
213 if (mcfg->m_type == SKL_MODULE_TYPE_SRCINT)
214 multiplier = 5;
215
216 mcfg->ibs = (mcfg->in_fmt.s_freq / 1000) *
217 (mcfg->in_fmt.channels) *
218 (mcfg->in_fmt.bit_depth >> 3) *
219 multiplier;
220
221 mcfg->obs = (mcfg->out_fmt.s_freq / 1000) *
222 (mcfg->out_fmt.channels) *
223 (mcfg->out_fmt.bit_depth >> 3) *
224 multiplier;
225}
226
227static void skl_tplg_update_module_params(struct snd_soc_dapm_widget *w,
228 struct skl_sst *ctx)
229{
230 struct skl_module_cfg *m_cfg = w->priv;
231 struct skl_pipe_params *params = m_cfg->pipe->p_params;
232 int p_conn_type = m_cfg->pipe->conn_type;
233 bool is_fe;
234
235 if (!m_cfg->params_fixup)
236 return;
237
238 dev_dbg(ctx->dev, "Mconfig for widget=%s BEFORE updation\n",
239 w->name);
240
241 skl_dump_mconfig(ctx, m_cfg);
242
243 if (p_conn_type == SKL_PIPE_CONN_TYPE_FE)
244 is_fe = true;
245 else
246 is_fe = false;
247
248 skl_tplg_update_params_fixup(m_cfg, params, is_fe);
249 skl_tplg_update_buffer_size(ctx, m_cfg);
250
251 dev_dbg(ctx->dev, "Mconfig for widget=%s AFTER updation\n",
252 w->name);
253
254 skl_dump_mconfig(ctx, m_cfg);
255}
256
257
258
259
260
261
262
263static int skl_tplg_alloc_pipe_widget(struct device *dev,
264 struct snd_soc_dapm_widget *w, struct skl_pipe *pipe)
265{
266 struct skl_module_cfg *src_module = NULL;
267 struct snd_soc_dapm_path *p = NULL;
268 struct skl_pipe_module *p_module = NULL;
269
270 p_module = devm_kzalloc(dev, sizeof(*p_module), GFP_KERNEL);
271 if (!p_module)
272 return -ENOMEM;
273
274 p_module->w = w;
275 list_add_tail(&p_module->node, &pipe->w_list);
276
277 snd_soc_dapm_widget_for_each_sink_path(w, p) {
278 if ((p->sink->priv == NULL)
279 && (!is_skl_dsp_widget_type(w)))
280 continue;
281
282 if ((p->sink->priv != NULL) && p->connect
283 && is_skl_dsp_widget_type(p->sink)) {
284
285 src_module = p->sink->priv;
286 if (pipe->ppl_id == src_module->pipe->ppl_id)
287 skl_tplg_alloc_pipe_widget(dev,
288 p->sink, pipe);
289 }
290 }
291 return 0;
292}
293
294
295
296
297
298
299static int
300skl_tplg_init_pipe_modules(struct skl *skl, struct skl_pipe *pipe)
301{
302 struct skl_pipe_module *w_module;
303 struct snd_soc_dapm_widget *w;
304 struct skl_module_cfg *mconfig;
305 struct skl_sst *ctx = skl->skl_sst;
306 int ret = 0;
307
308 list_for_each_entry(w_module, &pipe->w_list, node) {
309 w = w_module->w;
310 mconfig = w->priv;
311
312
313 if (!skl_tplg_alloc_pipe_mcps(skl, mconfig))
314 return -ENOMEM;
315
316
317
318
319
320 skl_tplg_update_module_params(w, ctx);
321 ret = skl_init_module(ctx, mconfig, NULL);
322 if (ret < 0)
323 return ret;
324 }
325
326 return 0;
327}
328
329
330
331
332
333
334
335
336
337static int skl_tplg_mixer_dapm_pre_pmu_event(struct snd_soc_dapm_widget *w,
338 struct skl *skl)
339{
340 int ret;
341 struct skl_module_cfg *mconfig = w->priv;
342 struct skl_pipe_module *w_module;
343 struct skl_pipe *s_pipe = mconfig->pipe;
344 struct skl_module_cfg *src_module = NULL, *dst_module;
345 struct skl_sst *ctx = skl->skl_sst;
346
347
348 if (!skl_tplg_alloc_pipe_mcps(skl, mconfig))
349 return -EBUSY;
350
351 if (!skl_tplg_alloc_pipe_mem(skl, mconfig))
352 return -ENOMEM;
353
354
355
356
357
358 ret = skl_create_pipeline(ctx, mconfig->pipe);
359 if (ret < 0)
360 return ret;
361
362
363
364
365
366
367
368
369
370 if (list_empty(&s_pipe->w_list)) {
371 ret = skl_tplg_alloc_pipe_widget(ctx->dev, w, s_pipe);
372 if (ret < 0)
373 return ret;
374 }
375
376
377 ret = skl_tplg_init_pipe_modules(skl, s_pipe);
378 if (ret < 0)
379 return ret;
380
381
382 list_for_each_entry(w_module, &s_pipe->w_list, node) {
383 dst_module = w_module->w->priv;
384
385 if (src_module == NULL) {
386 src_module = dst_module;
387 continue;
388 }
389
390 ret = skl_bind_modules(ctx, src_module, dst_module);
391 if (ret < 0)
392 return ret;
393
394 src_module = dst_module;
395 }
396
397 return 0;
398}
399
400
401
402
403
404
405
406
407
408
409
410static int skl_tplg_pga_dapm_pre_pmu_event(struct snd_soc_dapm_widget *w,
411 struct skl *skl)
412{
413 struct snd_soc_dapm_path *p;
414 struct skl_dapm_path_list *path_list;
415 struct snd_soc_dapm_widget *source, *sink;
416 struct skl_module_cfg *src_mconfig, *sink_mconfig;
417 struct skl_sst *ctx = skl->skl_sst;
418 int ret = 0;
419
420 source = w;
421 src_mconfig = source->priv;
422
423
424
425
426
427
428 snd_soc_dapm_widget_for_each_source_path(w, p) {
429 if (!p->connect)
430 continue;
431
432 dev_dbg(ctx->dev, "%s: src widget=%s\n", __func__, w->name);
433 dev_dbg(ctx->dev, "%s: sink widget=%s\n", __func__, p->sink->name);
434
435
436
437
438
439
440 if ((p->sink->priv != NULL) &&
441 is_skl_dsp_widget_type(p->sink)) {
442
443 sink = p->sink;
444 src_mconfig = source->priv;
445 sink_mconfig = sink->priv;
446
447
448 ret = skl_bind_modules(ctx, src_mconfig, sink_mconfig);
449 if (ret)
450 return ret;
451
452
453 if (sink_mconfig->pipe->state != SKL_PIPE_STARTED) {
454 ret = skl_run_pipe(ctx, sink_mconfig->pipe);
455 if (ret)
456 return ret;
457 }
458
459 path_list = kzalloc(
460 sizeof(struct skl_dapm_path_list),
461 GFP_KERNEL);
462 if (path_list == NULL)
463 return -ENOMEM;
464
465
466 path_list->dapm_path = p;
467 list_add_tail(&path_list->node, &skl->dapm_path_list);
468 break;
469 }
470 }
471
472
473 ret = skl_run_pipe(ctx, src_mconfig->pipe);
474 if (ret)
475 return ret;
476
477 return 0;
478}
479
480
481
482
483
484
485
486
487
488
489static int skl_tplg_mixer_dapm_post_pmu_event(struct snd_soc_dapm_widget *w,
490 struct skl *skl)
491{
492 int ret = 0;
493 struct snd_soc_dapm_path *p;
494 struct snd_soc_dapm_widget *source, *sink;
495 struct skl_module_cfg *src_mconfig, *sink_mconfig;
496 struct skl_sst *ctx = skl->skl_sst;
497 int src_pipe_started = 0;
498
499 sink = w;
500 sink_mconfig = sink->priv;
501
502
503
504
505
506
507 snd_soc_dapm_widget_for_each_sink_path(w, p) {
508 if (!p->connect)
509 continue;
510
511 dev_dbg(ctx->dev, "sink widget=%s\n", w->name);
512 dev_dbg(ctx->dev, "src widget=%s\n", p->source->name);
513
514
515
516
517
518
519 if ((p->source->priv != NULL) &&
520 is_skl_dsp_widget_type(p->source)) {
521 source = p->source;
522 src_mconfig = source->priv;
523 sink_mconfig = sink->priv;
524 src_pipe_started = 1;
525
526
527
528
529
530 if (src_mconfig->pipe->state != SKL_PIPE_STARTED)
531 src_pipe_started = 0;
532 }
533 }
534
535 if (src_pipe_started) {
536 ret = skl_bind_modules(ctx, src_mconfig, sink_mconfig);
537 if (ret)
538 return ret;
539
540 ret = skl_run_pipe(ctx, sink_mconfig->pipe);
541 }
542
543 return ret;
544}
545
546
547
548
549
550
551
552static int skl_tplg_mixer_dapm_pre_pmd_event(struct snd_soc_dapm_widget *w,
553 struct skl *skl)
554{
555 struct snd_soc_dapm_widget *source, *sink;
556 struct skl_module_cfg *src_mconfig, *sink_mconfig;
557 int ret = 0, path_found = 0;
558 struct skl_dapm_path_list *path_list, *tmp_list;
559 struct skl_sst *ctx = skl->skl_sst;
560
561 sink = w;
562 sink_mconfig = sink->priv;
563
564
565 ret = skl_stop_pipe(ctx, sink_mconfig->pipe);
566 if (ret)
567 return ret;
568
569
570
571
572
573
574
575 list_for_each_entry_safe(path_list, tmp_list,
576 &skl->dapm_path_list, node) {
577 if (path_list->dapm_path->sink == sink) {
578 dev_dbg(ctx->dev, "Path found = %s\n",
579 path_list->dapm_path->name);
580 source = path_list->dapm_path->source;
581 src_mconfig = source->priv;
582 path_found = 1;
583
584 list_del(&path_list->node);
585 kfree(path_list);
586 break;
587 }
588 }
589
590
591
592
593
594
595 if (path_found) {
596 ret = skl_stop_pipe(ctx, src_mconfig->pipe);
597 if (ret < 0)
598 return ret;
599
600 ret = skl_unbind_modules(ctx, src_mconfig, sink_mconfig);
601 }
602
603 return ret;
604}
605
606
607
608
609
610
611
612
613
614static int skl_tplg_mixer_dapm_post_pmd_event(struct snd_soc_dapm_widget *w,
615 struct skl *skl)
616{
617 struct skl_module_cfg *mconfig = w->priv;
618 struct skl_pipe_module *w_module;
619 struct skl_module_cfg *src_module = NULL, *dst_module;
620 struct skl_sst *ctx = skl->skl_sst;
621 struct skl_pipe *s_pipe = mconfig->pipe;
622 int ret = 0;
623
624 skl_tplg_free_pipe_mcps(skl, mconfig);
625
626 list_for_each_entry(w_module, &s_pipe->w_list, node) {
627 dst_module = w_module->w->priv;
628
629 if (src_module == NULL) {
630 src_module = dst_module;
631 continue;
632 }
633
634 ret = skl_unbind_modules(ctx, src_module, dst_module);
635 if (ret < 0)
636 return ret;
637
638 src_module = dst_module;
639 }
640
641 ret = skl_delete_pipe(ctx, mconfig->pipe);
642 skl_tplg_free_pipe_mem(skl, mconfig);
643
644 return ret;
645}
646
647
648
649
650
651
652
653static int skl_tplg_pga_dapm_post_pmd_event(struct snd_soc_dapm_widget *w,
654 struct skl *skl)
655{
656 struct snd_soc_dapm_widget *source, *sink;
657 struct skl_module_cfg *src_mconfig, *sink_mconfig;
658 int ret = 0, path_found = 0;
659 struct skl_dapm_path_list *path_list, *tmp_path_list;
660 struct skl_sst *ctx = skl->skl_sst;
661
662 source = w;
663 src_mconfig = source->priv;
664
665 skl_tplg_free_pipe_mcps(skl, src_mconfig);
666
667 ret = skl_stop_pipe(ctx, src_mconfig->pipe);
668 if (ret)
669 return ret;
670
671 list_for_each_entry_safe(path_list, tmp_path_list, &skl->dapm_path_list, node) {
672 if (path_list->dapm_path->source == source) {
673 dev_dbg(ctx->dev, "Path found = %s\n",
674 path_list->dapm_path->name);
675 sink = path_list->dapm_path->sink;
676 sink_mconfig = sink->priv;
677 path_found = 1;
678
679 list_del(&path_list->node);
680 kfree(path_list);
681 break;
682 }
683 }
684
685
686
687
688
689 if (path_found) {
690 ret = skl_stop_pipe(ctx, src_mconfig->pipe);
691 if (ret < 0)
692 return ret;
693
694 ret = skl_unbind_modules(ctx, src_mconfig, sink_mconfig);
695 }
696
697 return ret;
698}
699
700
701
702
703
704
705
706
707static int skl_tplg_vmixer_event(struct snd_soc_dapm_widget *w,
708 struct snd_kcontrol *k, int event)
709{
710 struct snd_soc_dapm_context *dapm = w->dapm;
711 struct skl *skl = get_skl_ctx(dapm->dev);
712
713 switch (event) {
714 case SND_SOC_DAPM_PRE_PMU:
715 return skl_tplg_mixer_dapm_pre_pmu_event(w, skl);
716
717 case SND_SOC_DAPM_POST_PMD:
718 return skl_tplg_mixer_dapm_post_pmd_event(w, skl);
719 }
720
721 return 0;
722}
723
724
725
726
727
728
729
730static int skl_tplg_mixer_event(struct snd_soc_dapm_widget *w,
731 struct snd_kcontrol *k, int event)
732{
733 struct snd_soc_dapm_context *dapm = w->dapm;
734 struct skl *skl = get_skl_ctx(dapm->dev);
735
736 switch (event) {
737 case SND_SOC_DAPM_PRE_PMU:
738 return skl_tplg_mixer_dapm_pre_pmu_event(w, skl);
739
740 case SND_SOC_DAPM_POST_PMU:
741 return skl_tplg_mixer_dapm_post_pmu_event(w, skl);
742
743 case SND_SOC_DAPM_PRE_PMD:
744 return skl_tplg_mixer_dapm_pre_pmd_event(w, skl);
745
746 case SND_SOC_DAPM_POST_PMD:
747 return skl_tplg_mixer_dapm_post_pmd_event(w, skl);
748 }
749
750 return 0;
751}
752
753
754
755
756
757
758
759static int skl_tplg_pga_event(struct snd_soc_dapm_widget *w,
760 struct snd_kcontrol *k, int event)
761
762{
763 struct snd_soc_dapm_context *dapm = w->dapm;
764 struct skl *skl = get_skl_ctx(dapm->dev);
765
766 switch (event) {
767 case SND_SOC_DAPM_PRE_PMU:
768 return skl_tplg_pga_dapm_pre_pmu_event(w, skl);
769
770 case SND_SOC_DAPM_POST_PMD:
771 return skl_tplg_pga_dapm_post_pmd_event(w, skl);
772 }
773
774 return 0;
775}
776
777
778
779
780
781
782
783int skl_tplg_update_pipe_params(struct device *dev,
784 struct skl_module_cfg *mconfig,
785 struct skl_pipe_params *params)
786{
787 struct skl_pipe *pipe = mconfig->pipe;
788 struct skl_module_fmt *format = NULL;
789
790 memcpy(pipe->p_params, params, sizeof(*params));
791
792 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK)
793 format = &mconfig->in_fmt;
794 else
795 format = &mconfig->out_fmt;
796
797
798 format->s_freq = params->s_freq;
799 format->channels = params->ch;
800 format->valid_bit_depth = skl_get_bit_depth(params->s_fmt);
801
802
803
804
805
806 switch (format->valid_bit_depth) {
807 case SKL_DEPTH_16BIT:
808 format->bit_depth = format->valid_bit_depth;
809 break;
810
811 case SKL_DEPTH_24BIT:
812 format->bit_depth = SKL_DEPTH_32BIT;
813 break;
814
815 default:
816 dev_err(dev, "Invalid bit depth %x for pipe\n",
817 format->valid_bit_depth);
818 return -EINVAL;
819 }
820
821 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK) {
822 mconfig->ibs = (format->s_freq / 1000) *
823 (format->channels) *
824 (format->bit_depth >> 3);
825 } else {
826 mconfig->obs = (format->s_freq / 1000) *
827 (format->channels) *
828 (format->bit_depth >> 3);
829 }
830
831 return 0;
832}
833
834
835
836
837
838
839struct skl_module_cfg *
840skl_tplg_fe_get_cpr_module(struct snd_soc_dai *dai, int stream)
841{
842 struct snd_soc_dapm_widget *w;
843 struct snd_soc_dapm_path *p = NULL;
844
845 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
846 w = dai->playback_widget;
847 snd_soc_dapm_widget_for_each_sink_path(w, p) {
848 if (p->connect && p->sink->power &&
849 is_skl_dsp_widget_type(p->sink))
850 continue;
851
852 if (p->sink->priv) {
853 dev_dbg(dai->dev, "set params for %s\n",
854 p->sink->name);
855 return p->sink->priv;
856 }
857 }
858 } else {
859 w = dai->capture_widget;
860 snd_soc_dapm_widget_for_each_source_path(w, p) {
861 if (p->connect && p->source->power &&
862 is_skl_dsp_widget_type(p->source))
863 continue;
864
865 if (p->source->priv) {
866 dev_dbg(dai->dev, "set params for %s\n",
867 p->source->name);
868 return p->source->priv;
869 }
870 }
871 }
872
873 return NULL;
874}
875
876static u8 skl_tplg_be_link_type(int dev_type)
877{
878 int ret;
879
880 switch (dev_type) {
881 case SKL_DEVICE_BT:
882 ret = NHLT_LINK_SSP;
883 break;
884
885 case SKL_DEVICE_DMIC:
886 ret = NHLT_LINK_DMIC;
887 break;
888
889 case SKL_DEVICE_I2S:
890 ret = NHLT_LINK_SSP;
891 break;
892
893 case SKL_DEVICE_HDALINK:
894 ret = NHLT_LINK_HDA;
895 break;
896
897 default:
898 ret = NHLT_LINK_INVALID;
899 break;
900 }
901
902 return ret;
903}
904
905
906
907
908
909
910
911
912static int skl_tplg_be_fill_pipe_params(struct snd_soc_dai *dai,
913 struct skl_module_cfg *mconfig,
914 struct skl_pipe_params *params)
915{
916 struct skl_pipe *pipe = mconfig->pipe;
917 struct nhlt_specific_cfg *cfg;
918 struct skl *skl = get_skl_ctx(dai->dev);
919 int link_type = skl_tplg_be_link_type(mconfig->dev_type);
920
921 memcpy(pipe->p_params, params, sizeof(*params));
922
923
924 cfg = skl_get_ep_blob(skl, mconfig->vbus_id, link_type,
925 params->s_fmt, params->ch,
926 params->s_freq, params->stream);
927 if (cfg) {
928 mconfig->formats_config.caps_size = cfg->size;
929 mconfig->formats_config.caps = (u32 *) &cfg->caps;
930 } else {
931 dev_err(dai->dev, "Blob NULL for id %x type %d dirn %d\n",
932 mconfig->vbus_id, link_type,
933 params->stream);
934 dev_err(dai->dev, "PCM: ch %d, freq %d, fmt %d\n",
935 params->ch, params->s_freq, params->s_fmt);
936 return -EINVAL;
937 }
938
939 return 0;
940}
941
942static int skl_tplg_be_set_src_pipe_params(struct snd_soc_dai *dai,
943 struct snd_soc_dapm_widget *w,
944 struct skl_pipe_params *params)
945{
946 struct snd_soc_dapm_path *p;
947 int ret = -EIO;
948
949 snd_soc_dapm_widget_for_each_source_path(w, p) {
950 if (p->connect && is_skl_dsp_widget_type(p->source) &&
951 p->source->priv) {
952
953 if (!p->source->power) {
954 ret = skl_tplg_be_fill_pipe_params(
955 dai, p->source->priv,
956 params);
957 if (ret < 0)
958 return ret;
959 } else {
960 return -EBUSY;
961 }
962 } else {
963 ret = skl_tplg_be_set_src_pipe_params(
964 dai, p->source, params);
965 if (ret < 0)
966 return ret;
967 }
968 }
969
970 return ret;
971}
972
973static int skl_tplg_be_set_sink_pipe_params(struct snd_soc_dai *dai,
974 struct snd_soc_dapm_widget *w, struct skl_pipe_params *params)
975{
976 struct snd_soc_dapm_path *p = NULL;
977 int ret = -EIO;
978
979 snd_soc_dapm_widget_for_each_sink_path(w, p) {
980 if (p->connect && is_skl_dsp_widget_type(p->sink) &&
981 p->sink->priv) {
982
983 if (!p->sink->power) {
984 ret = skl_tplg_be_fill_pipe_params(
985 dai, p->sink->priv, params);
986 if (ret < 0)
987 return ret;
988 } else {
989 return -EBUSY;
990 }
991
992 } else {
993 ret = skl_tplg_be_set_sink_pipe_params(
994 dai, p->sink, params);
995 if (ret < 0)
996 return ret;
997 }
998 }
999
1000 return ret;
1001}
1002
1003
1004
1005
1006
1007
1008int skl_tplg_be_update_params(struct snd_soc_dai *dai,
1009 struct skl_pipe_params *params)
1010{
1011 struct snd_soc_dapm_widget *w;
1012
1013 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1014 w = dai->playback_widget;
1015
1016 return skl_tplg_be_set_src_pipe_params(dai, w, params);
1017
1018 } else {
1019 w = dai->capture_widget;
1020
1021 return skl_tplg_be_set_sink_pipe_params(dai, w, params);
1022 }
1023
1024 return 0;
1025}
1026
1027static const struct snd_soc_tplg_widget_events skl_tplg_widget_ops[] = {
1028 {SKL_MIXER_EVENT, skl_tplg_mixer_event},
1029 {SKL_VMIXER_EVENT, skl_tplg_vmixer_event},
1030 {SKL_PGA_EVENT, skl_tplg_pga_event},
1031};
1032
1033
1034
1035
1036
1037static void skl_fill_module_pin_info(struct skl_dfw_module_pin *dfw_pin,
1038 struct skl_module_pin *m_pin,
1039 bool is_dynamic, int max_pin)
1040{
1041 int i;
1042
1043 for (i = 0; i < max_pin; i++) {
1044 m_pin[i].id.module_id = dfw_pin[i].module_id;
1045 m_pin[i].id.instance_id = dfw_pin[i].instance_id;
1046 m_pin[i].in_use = false;
1047 m_pin[i].is_dynamic = is_dynamic;
1048 }
1049}
1050
1051
1052
1053
1054
1055
1056
1057static struct skl_pipe *skl_tplg_add_pipe(struct device *dev,
1058 struct skl *skl, struct skl_dfw_pipe *dfw_pipe)
1059{
1060 struct skl_pipeline *ppl;
1061 struct skl_pipe *pipe;
1062 struct skl_pipe_params *params;
1063
1064 list_for_each_entry(ppl, &skl->ppl_list, node) {
1065 if (ppl->pipe->ppl_id == dfw_pipe->pipe_id)
1066 return ppl->pipe;
1067 }
1068
1069 ppl = devm_kzalloc(dev, sizeof(*ppl), GFP_KERNEL);
1070 if (!ppl)
1071 return NULL;
1072
1073 pipe = devm_kzalloc(dev, sizeof(*pipe), GFP_KERNEL);
1074 if (!pipe)
1075 return NULL;
1076
1077 params = devm_kzalloc(dev, sizeof(*params), GFP_KERNEL);
1078 if (!params)
1079 return NULL;
1080
1081 pipe->ppl_id = dfw_pipe->pipe_id;
1082 pipe->memory_pages = dfw_pipe->memory_pages;
1083 pipe->pipe_priority = dfw_pipe->pipe_priority;
1084 pipe->conn_type = dfw_pipe->conn_type;
1085 pipe->state = SKL_PIPE_INVALID;
1086 pipe->p_params = params;
1087 INIT_LIST_HEAD(&pipe->w_list);
1088
1089 ppl->pipe = pipe;
1090 list_add(&ppl->node, &skl->ppl_list);
1091
1092 return ppl->pipe;
1093}
1094
1095
1096
1097
1098
1099
1100
1101
1102static int skl_tplg_widget_load(struct snd_soc_component *cmpnt,
1103 struct snd_soc_dapm_widget *w,
1104 struct snd_soc_tplg_dapm_widget *tplg_w)
1105{
1106 int ret;
1107 struct hdac_ext_bus *ebus = snd_soc_component_get_drvdata(cmpnt);
1108 struct skl *skl = ebus_to_skl(ebus);
1109 struct hdac_bus *bus = ebus_to_hbus(ebus);
1110 struct skl_module_cfg *mconfig;
1111 struct skl_pipe *pipe;
1112 struct skl_dfw_module *dfw_config =
1113 (struct skl_dfw_module *)tplg_w->priv.data;
1114
1115 if (!tplg_w->priv.size)
1116 goto bind_event;
1117
1118 mconfig = devm_kzalloc(bus->dev, sizeof(*mconfig), GFP_KERNEL);
1119
1120 if (!mconfig)
1121 return -ENOMEM;
1122
1123 w->priv = mconfig;
1124 mconfig->id.module_id = dfw_config->module_id;
1125 mconfig->id.instance_id = dfw_config->instance_id;
1126 mconfig->mcps = dfw_config->max_mcps;
1127 mconfig->ibs = dfw_config->ibs;
1128 mconfig->obs = dfw_config->obs;
1129 mconfig->core_id = dfw_config->core_id;
1130 mconfig->max_in_queue = dfw_config->max_in_queue;
1131 mconfig->max_out_queue = dfw_config->max_out_queue;
1132 mconfig->is_loadable = dfw_config->is_loadable;
1133 mconfig->in_fmt.channels = dfw_config->in_fmt.channels;
1134 mconfig->in_fmt.s_freq = dfw_config->in_fmt.freq;
1135 mconfig->in_fmt.bit_depth = dfw_config->in_fmt.bit_depth;
1136 mconfig->in_fmt.valid_bit_depth =
1137 dfw_config->in_fmt.valid_bit_depth;
1138 mconfig->in_fmt.ch_cfg = dfw_config->in_fmt.ch_cfg;
1139 mconfig->out_fmt.channels = dfw_config->out_fmt.channels;
1140 mconfig->out_fmt.s_freq = dfw_config->out_fmt.freq;
1141 mconfig->out_fmt.bit_depth = dfw_config->out_fmt.bit_depth;
1142 mconfig->out_fmt.valid_bit_depth =
1143 dfw_config->out_fmt.valid_bit_depth;
1144 mconfig->out_fmt.ch_cfg = dfw_config->out_fmt.ch_cfg;
1145 mconfig->params_fixup = dfw_config->params_fixup;
1146 mconfig->converter = dfw_config->converter;
1147 mconfig->m_type = dfw_config->module_type;
1148 mconfig->vbus_id = dfw_config->vbus_id;
1149
1150 pipe = skl_tplg_add_pipe(bus->dev, skl, &dfw_config->pipe);
1151 if (pipe)
1152 mconfig->pipe = pipe;
1153
1154 mconfig->dev_type = dfw_config->dev_type;
1155 mconfig->hw_conn_type = dfw_config->hw_conn_type;
1156 mconfig->time_slot = dfw_config->time_slot;
1157 mconfig->formats_config.caps_size = dfw_config->caps.caps_size;
1158
1159 mconfig->m_in_pin = devm_kzalloc(bus->dev,
1160 (mconfig->max_in_queue) *
1161 sizeof(*mconfig->m_in_pin),
1162 GFP_KERNEL);
1163 if (!mconfig->m_in_pin)
1164 return -ENOMEM;
1165
1166 mconfig->m_out_pin = devm_kzalloc(bus->dev, (mconfig->max_out_queue) *
1167 sizeof(*mconfig->m_out_pin),
1168 GFP_KERNEL);
1169 if (!mconfig->m_out_pin)
1170 return -ENOMEM;
1171
1172 skl_fill_module_pin_info(dfw_config->in_pin, mconfig->m_in_pin,
1173 dfw_config->is_dynamic_in_pin,
1174 mconfig->max_in_queue);
1175
1176 skl_fill_module_pin_info(dfw_config->out_pin, mconfig->m_out_pin,
1177 dfw_config->is_dynamic_out_pin,
1178 mconfig->max_out_queue);
1179
1180
1181 if (mconfig->formats_config.caps_size == 0)
1182 goto bind_event;
1183
1184 mconfig->formats_config.caps = (u32 *)devm_kzalloc(bus->dev,
1185 mconfig->formats_config.caps_size, GFP_KERNEL);
1186
1187 if (mconfig->formats_config.caps == NULL)
1188 return -ENOMEM;
1189
1190 memcpy(mconfig->formats_config.caps, dfw_config->caps.caps,
1191 dfw_config->caps.caps_size);
1192
1193bind_event:
1194 if (tplg_w->event_type == 0) {
1195 dev_dbg(bus->dev, "ASoC: No event handler required\n");
1196 return 0;
1197 }
1198
1199 ret = snd_soc_tplg_widget_bind_event(w, skl_tplg_widget_ops,
1200 ARRAY_SIZE(skl_tplg_widget_ops),
1201 tplg_w->event_type);
1202
1203 if (ret) {
1204 dev_err(bus->dev, "%s: No matching event handlers found for %d\n",
1205 __func__, tplg_w->event_type);
1206 return -EINVAL;
1207 }
1208
1209 return 0;
1210}
1211
1212static struct snd_soc_tplg_ops skl_tplg_ops = {
1213 .widget_load = skl_tplg_widget_load,
1214};
1215
1216
1217#define SKL_MAX_MCPS 30000000
1218#define SKL_FW_MAX_MEM 1000000
1219
1220
1221
1222
1223int skl_tplg_init(struct snd_soc_platform *platform, struct hdac_ext_bus *ebus)
1224{
1225 int ret;
1226 const struct firmware *fw;
1227 struct hdac_bus *bus = ebus_to_hbus(ebus);
1228 struct skl *skl = ebus_to_skl(ebus);
1229
1230 ret = request_firmware(&fw, "dfw_sst.bin", bus->dev);
1231 if (ret < 0) {
1232 dev_err(bus->dev, "tplg fw %s load failed with %d\n",
1233 "dfw_sst.bin", ret);
1234 return ret;
1235 }
1236
1237
1238
1239
1240
1241 ret = snd_soc_tplg_component_load(&platform->component,
1242 &skl_tplg_ops, fw, 0);
1243 if (ret < 0) {
1244 dev_err(bus->dev, "tplg component load failed%d\n", ret);
1245 return -EINVAL;
1246 }
1247
1248 skl->resource.max_mcps = SKL_MAX_MCPS;
1249 skl->resource.max_mem = SKL_FW_MAX_MEM;
1250
1251 skl->tplg = fw;
1252
1253 return 0;
1254}
1255