2 * skl-topology.c - Implements Platform component ALSA controls/widget
5 * Copyright (C) 2014-2015 Intel Corp
6 * Author: Jeeja KP <jeeja.kp@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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"
28 #include "skl-tplg-interface.h"
31 * SKL DSP driver modelling uses only few DAPM widgets so for rest we will
32 * ignore. This helpers checks if the SKL driver handles this widget type
34 static int is_skl_dsp_widget_type(struct snd_soc_dapm_widget *w)
37 case snd_soc_dapm_dai_link:
38 case snd_soc_dapm_dai_in:
39 case snd_soc_dapm_aif_in:
40 case snd_soc_dapm_aif_out:
41 case snd_soc_dapm_dai_out:
42 case snd_soc_dapm_switch:
50 * Each pipelines needs memory to be allocated. Check if we have free memory
51 * from available pool. Then only add this to pool
52 * This is freed when pipe is deleted
53 * Note: DSP does actual memory management we only keep track for complete
56 static bool skl_tplg_alloc_pipe_mem(struct skl *skl,
57 struct skl_module_cfg *mconfig)
59 struct skl_sst *ctx = skl->skl_sst;
61 if (skl->resource.mem + mconfig->pipe->memory_pages >
62 skl->resource.max_mem) {
64 "%s: module_id %d instance %d\n", __func__,
65 mconfig->id.module_id,
66 mconfig->id.instance_id);
68 "exceeds ppl memory available %d mem %d\n",
69 skl->resource.max_mem, skl->resource.mem);
73 skl->resource.mem += mconfig->pipe->memory_pages;
78 * Pipeline needs needs DSP CPU resources for computation, this is
79 * quantified in MCPS (Million Clocks Per Second) required for module/pipe
81 * Each pipelines needs mcps to be allocated. Check if we have mcps for this
82 * pipe. This adds the mcps to driver counter
83 * This is removed on pipeline delete
85 static bool skl_tplg_alloc_pipe_mcps(struct skl *skl,
86 struct skl_module_cfg *mconfig)
88 struct skl_sst *ctx = skl->skl_sst;
90 if (skl->resource.mcps + mconfig->mcps > skl->resource.max_mcps) {
92 "%s: module_id %d instance %d\n", __func__,
93 mconfig->id.module_id, mconfig->id.instance_id);
95 "exceeds ppl memory available %d > mem %d\n",
96 skl->resource.max_mcps, skl->resource.mcps);
100 skl->resource.mcps += mconfig->mcps;
105 * Free the mcps when tearing down
108 skl_tplg_free_pipe_mcps(struct skl *skl, struct skl_module_cfg *mconfig)
110 skl->resource.mcps -= mconfig->mcps;
114 * Free the memory when tearing down
117 skl_tplg_free_pipe_mem(struct skl *skl, struct skl_module_cfg *mconfig)
119 skl->resource.mem -= mconfig->pipe->memory_pages;
123 * A pipe can have multiple modules, each of them will be a DAPM widget as
124 * well. While managing a pipeline we need to get the list of all the
125 * widgets in a pipelines, so this helper - skl_tplg_get_pipe_widget() helps
126 * to get the SKL type widgets in that pipeline
128 static int skl_tplg_alloc_pipe_widget(struct device *dev,
129 struct snd_soc_dapm_widget *w, struct skl_pipe *pipe)
131 struct skl_module_cfg *src_module = NULL;
132 struct snd_soc_dapm_path *p = NULL;
133 struct skl_pipe_module *p_module = NULL;
135 p_module = devm_kzalloc(dev, sizeof(*p_module), GFP_KERNEL);
140 list_add_tail(&p_module->node, &pipe->w_list);
142 snd_soc_dapm_widget_for_each_sink_path(w, p) {
143 if ((p->sink->priv == NULL)
144 && (!is_skl_dsp_widget_type(w)))
147 if ((p->sink->priv != NULL) && p->connect
148 && is_skl_dsp_widget_type(p->sink)) {
150 src_module = p->sink->priv;
151 if (pipe->ppl_id == src_module->pipe->ppl_id)
152 skl_tplg_alloc_pipe_widget(dev,
160 * Inside a pipe instance, we can have various modules. These modules need
161 * to instantiated in DSP by invoking INIT_MODULE IPC, which is achieved by
162 * skl_init_module() routine, so invoke that for all modules in a pipeline
165 skl_tplg_init_pipe_modules(struct skl *skl, struct skl_pipe *pipe)
167 struct skl_pipe_module *w_module;
168 struct snd_soc_dapm_widget *w;
169 struct skl_module_cfg *mconfig;
170 struct skl_sst *ctx = skl->skl_sst;
173 list_for_each_entry(w_module, &pipe->w_list, node) {
177 /* check resource available */
178 if (!skl_tplg_alloc_pipe_mcps(skl, mconfig))
181 ret = skl_init_module(ctx, mconfig, NULL);