Skip to content

Commit 6bd0be1

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: topology: Make buffer widget parsing IPC agnostic
Define the list of tokens pertaining to the buffer widgets, parse and save them as part of the swidget tuples array. Once topology parsing is complete, these tokens will be applied to create the IPC structure for the buffer component based on the topology widget_setup op in ipc3_tplg_ops. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20220314200520.1233427-8-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2141b55 commit 6bd0be1

2 files changed

Lines changed: 50 additions & 52 deletions

File tree

sound/soc/sof/ipc3-topology.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
#include "sof-audio.h"
1414
#include "ops.h"
1515

16+
/* Buffers */
17+
static const struct sof_topology_token buffer_tokens[] = {
18+
{SOF_TKN_BUF_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
19+
offsetof(struct sof_ipc_buffer, size)},
20+
{SOF_TKN_BUF_CAPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
21+
offsetof(struct sof_ipc_buffer, caps)},
22+
};
23+
1624
/* scheduling */
1725
static const struct sof_topology_token sched_tokens[] = {
1826
{SOF_TKN_SCHED_PERIOD, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
@@ -71,6 +79,7 @@ static const struct sof_token_info ipc3_token_list[SOF_TOKEN_COUNT] = {
7179
[SOF_COMP_TOKENS] = {"Comp tokens", comp_tokens, ARRAY_SIZE(comp_tokens)},
7280
[SOF_CORE_TOKENS] = {"Core tokens", core_tokens, ARRAY_SIZE(core_tokens)},
7381
[SOF_COMP_EXT_TOKENS] = {"AFE tokens", comp_ext_tokens, ARRAY_SIZE(comp_ext_tokens)},
82+
[SOF_BUFFER_TOKENS] = {"Buffer tokens", buffer_tokens, ARRAY_SIZE(buffer_tokens)},
7483
};
7584

7685
/**
@@ -237,6 +246,41 @@ static int sof_ipc3_widget_setup_comp_pipeline(struct snd_sof_widget *swidget)
237246
return ret;
238247
}
239248

249+
static int sof_ipc3_widget_setup_comp_buffer(struct snd_sof_widget *swidget)
250+
{
251+
struct snd_soc_component *scomp = swidget->scomp;
252+
struct sof_ipc_buffer *buffer;
253+
int ret;
254+
255+
buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
256+
if (!buffer)
257+
return -ENOMEM;
258+
259+
swidget->private = buffer;
260+
261+
/* configure dai IPC message */
262+
buffer->comp.hdr.size = sizeof(*buffer);
263+
buffer->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_BUFFER_NEW;
264+
buffer->comp.id = swidget->comp_id;
265+
buffer->comp.type = SOF_COMP_BUFFER;
266+
buffer->comp.pipeline_id = swidget->pipeline_id;
267+
buffer->comp.core = swidget->core;
268+
269+
/* parse one set of buffer tokens */
270+
ret = sof_update_ipc_object(scomp, buffer, SOF_BUFFER_TOKENS, swidget->tuples,
271+
swidget->num_tuples, sizeof(*buffer), 1);
272+
if (ret < 0) {
273+
kfree(swidget->private);
274+
swidget->private = NULL;
275+
return ret;
276+
}
277+
278+
dev_dbg(scomp->dev, "buffer %s: size %d caps 0x%x\n",
279+
swidget->widget->name, buffer->size, buffer->caps);
280+
281+
return 0;
282+
}
283+
240284
/* token list for each topology object */
241285
static enum sof_tokens host_token_list[] = {
242286
SOF_CORE_TOKENS,
@@ -245,6 +289,10 @@ static enum sof_tokens host_token_list[] = {
245289
SOF_COMP_TOKENS,
246290
};
247291

292+
static enum sof_tokens buffer_token_list[] = {
293+
SOF_BUFFER_TOKENS,
294+
};
295+
248296
static enum sof_tokens pipeline_token_list[] = {
249297
SOF_CORE_TOKENS,
250298
SOF_COMP_EXT_TOKENS,
@@ -257,6 +305,8 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc3_widget_ops[SND_SOC_DAPM_TY
257305
host_token_list, ARRAY_SIZE(host_token_list), NULL},
258306
[snd_soc_dapm_aif_out] = {sof_ipc3_widget_setup_comp_host, sof_ipc3_widget_free_comp,
259307
host_token_list, ARRAY_SIZE(host_token_list), NULL},
308+
[snd_soc_dapm_buffer] = {sof_ipc3_widget_setup_comp_buffer, sof_ipc3_widget_free_comp,
309+
buffer_token_list, ARRAY_SIZE(buffer_token_list), NULL},
260310
[snd_soc_dapm_scheduler] = {sof_ipc3_widget_setup_comp_pipeline, sof_ipc3_widget_free_comp,
261311
pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL},
262312
};

sound/soc/sof/topology.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,6 @@ static int get_token_process_type(void *elem, void *object, u32 offset)
611611
return 0;
612612
}
613613

614-
/* Buffers */
615-
static const struct sof_topology_token buffer_tokens[] = {
616-
{SOF_TKN_BUF_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
617-
offsetof(struct sof_ipc_buffer, size)},
618-
{SOF_TKN_BUF_CAPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
619-
offsetof(struct sof_ipc_buffer, caps)},
620-
};
621-
622614
/* DAI */
623615
static const struct sof_topology_token dai_tokens[] = {
624616
{SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type,
@@ -1721,48 +1713,6 @@ static int sof_widget_load_dai(struct snd_soc_component *scomp, int index,
17211713
return ret;
17221714
}
17231715

1724-
/*
1725-
* Buffer topology
1726-
*/
1727-
1728-
static int sof_widget_load_buffer(struct snd_soc_component *scomp, int index,
1729-
struct snd_sof_widget *swidget,
1730-
struct snd_soc_tplg_dapm_widget *tw)
1731-
{
1732-
struct snd_soc_tplg_private *private = &tw->priv;
1733-
struct sof_ipc_buffer *buffer;
1734-
int ret;
1735-
1736-
buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
1737-
if (!buffer)
1738-
return -ENOMEM;
1739-
1740-
/* configure dai IPC message */
1741-
buffer->comp.hdr.size = sizeof(*buffer);
1742-
buffer->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_BUFFER_NEW;
1743-
buffer->comp.id = swidget->comp_id;
1744-
buffer->comp.type = SOF_COMP_BUFFER;
1745-
buffer->comp.pipeline_id = index;
1746-
buffer->comp.core = swidget->core;
1747-
1748-
ret = sof_parse_tokens(scomp, buffer, buffer_tokens,
1749-
ARRAY_SIZE(buffer_tokens), private->array,
1750-
le32_to_cpu(private->size));
1751-
if (ret != 0) {
1752-
dev_err(scomp->dev, "error: parse buffer tokens failed %d\n",
1753-
private->size);
1754-
kfree(buffer);
1755-
return ret;
1756-
}
1757-
1758-
dev_dbg(scomp->dev, "buffer %s: size %d caps 0x%x\n",
1759-
swidget->widget->name, buffer->size, buffer->caps);
1760-
1761-
swidget->private = buffer;
1762-
1763-
return 0;
1764-
}
1765-
17661716
/* bind PCM ID to host component ID */
17671717
static int spcm_bind(struct snd_soc_component *scomp, struct snd_sof_pcm *spcm,
17681718
int dir)
@@ -2479,8 +2429,6 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
24792429
ret = sof_widget_load_pga(scomp, index, swidget, tw);
24802430
break;
24812431
case snd_soc_dapm_buffer:
2482-
ret = sof_widget_load_buffer(scomp, index, swidget, tw);
2483-
break;
24842432
case snd_soc_dapm_scheduler:
24852433
case snd_soc_dapm_aif_out:
24862434
case snd_soc_dapm_aif_in:

0 commit comments

Comments
 (0)