Skip to content

Commit 8d8b129

Browse files
ranj063broonie
authored andcommitted
ASoC: SOF: topology: Make src widget parsing IPC agnostic
Define the list of tokens pertaining to the src 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 src 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-12-ranjani.sridharan@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 683b54e commit 8d8b129

2 files changed

Lines changed: 60 additions & 63 deletions

File tree

sound/soc/sof/ipc3-topology.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ static const struct sof_topology_token volume_tokens[] = {
5151
offsetof(struct sof_ipc_comp_volume, initial_ramp)},
5252
};
5353

54+
/* SRC */
55+
static const struct sof_topology_token src_tokens[] = {
56+
{SOF_TKN_SRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
57+
offsetof(struct sof_ipc_comp_src, source_rate)},
58+
{SOF_TKN_SRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
59+
offsetof(struct sof_ipc_comp_src, sink_rate)},
60+
};
61+
5462
/* PCM */
5563
static const struct sof_topology_token pcm_tokens[] = {
5664
{SOF_TKN_PCM_DMAC_CONFIG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
@@ -89,6 +97,7 @@ static const struct sof_token_info ipc3_token_list[SOF_TOKEN_COUNT] = {
8997
[SOF_COMP_EXT_TOKENS] = {"AFE tokens", comp_ext_tokens, ARRAY_SIZE(comp_ext_tokens)},
9098
[SOF_BUFFER_TOKENS] = {"Buffer tokens", buffer_tokens, ARRAY_SIZE(buffer_tokens)},
9199
[SOF_VOLUME_TOKENS] = {"Volume tokens", volume_tokens, ARRAY_SIZE(volume_tokens)},
100+
[SOF_SRC_TOKENS] = {"SRC tokens", src_tokens, ARRAY_SIZE(src_tokens)},
92101
};
93102

94103
/**
@@ -324,6 +333,47 @@ static int sof_ipc3_widget_setup_comp_buffer(struct snd_sof_widget *swidget)
324333
return 0;
325334
}
326335

336+
static int sof_ipc3_widget_setup_comp_src(struct snd_sof_widget *swidget)
337+
{
338+
struct snd_soc_component *scomp = swidget->scomp;
339+
struct sof_ipc_comp_src *src;
340+
size_t ipc_size = sizeof(*src);
341+
int ret;
342+
343+
src = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
344+
if (!src)
345+
return -ENOMEM;
346+
347+
swidget->private = src;
348+
349+
/* configure src IPC message */
350+
src->comp.type = SOF_COMP_SRC;
351+
src->config.hdr.size = sizeof(src->config);
352+
353+
/* parse one set of src tokens */
354+
ret = sof_update_ipc_object(scomp, src, SOF_SRC_TOKENS, swidget->tuples,
355+
swidget->num_tuples, sizeof(*src), 1);
356+
if (ret < 0)
357+
goto err;
358+
359+
/* parse one set of comp tokens */
360+
ret = sof_update_ipc_object(scomp, &src->config, SOF_COMP_TOKENS,
361+
swidget->tuples, swidget->num_tuples, sizeof(src->config), 1);
362+
if (ret < 0)
363+
goto err;
364+
365+
dev_dbg(scomp->dev, "src %s: source rate %d sink rate %d\n",
366+
swidget->widget->name, src->source_rate, src->sink_rate);
367+
sof_dbg_comp_config(scomp, &src->config);
368+
369+
return 0;
370+
err:
371+
kfree(swidget->private);
372+
swidget->private = NULL;
373+
374+
return ret;
375+
}
376+
327377
/*
328378
* Mux topology
329379
*/
@@ -444,6 +494,13 @@ static enum sof_tokens pipeline_token_list[] = {
444494
SOF_SCHED_TOKENS,
445495
};
446496

497+
static enum sof_tokens src_token_list[] = {
498+
SOF_CORE_TOKENS,
499+
SOF_COMP_EXT_TOKENS,
500+
SOF_SRC_TOKENS,
501+
SOF_COMP_TOKENS
502+
};
503+
447504
static enum sof_tokens pga_token_list[] = {
448505
SOF_CORE_TOKENS,
449506
SOF_COMP_EXT_TOKENS,
@@ -461,6 +518,8 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc3_widget_ops[SND_SOC_DAPM_TY
461518
[snd_soc_dapm_mixer] = {sof_ipc3_widget_setup_comp_mixer, sof_ipc3_widget_free_comp,
462519
comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list),
463520
NULL},
521+
[snd_soc_dapm_src] = {sof_ipc3_widget_setup_comp_src, sof_ipc3_widget_free_comp,
522+
src_token_list, ARRAY_SIZE(src_token_list), NULL},
464523
[snd_soc_dapm_scheduler] = {sof_ipc3_widget_setup_comp_pipeline, sof_ipc3_widget_free_comp,
465524
pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL},
466525
[snd_soc_dapm_pga] = {sof_ipc3_widget_setup_comp_pga, sof_ipc3_widget_free_comp,

sound/soc/sof/topology.c

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,6 @@ static const struct sof_topology_token dai_link_tokens[] = {
629629
offsetof(struct sof_ipc_dai_config, dai_index)},
630630
};
631631

632-
/* SRC */
633-
static const struct sof_topology_token src_tokens[] = {
634-
{SOF_TKN_SRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
635-
offsetof(struct sof_ipc_comp_src, source_rate)},
636-
{SOF_TKN_SRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
637-
offsetof(struct sof_ipc_comp_src, sink_rate)},
638-
};
639-
640632
/* ASRC */
641633
static const struct sof_topology_token asrc_tokens[] = {
642634
{SOF_TKN_ASRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
@@ -1792,58 +1784,6 @@ static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_s
17921784
return ret;
17931785
}
17941786

1795-
/*
1796-
* SRC Topology
1797-
*/
1798-
1799-
static int sof_widget_load_src(struct snd_soc_component *scomp, int index,
1800-
struct snd_sof_widget *swidget,
1801-
struct snd_soc_tplg_dapm_widget *tw)
1802-
{
1803-
struct snd_soc_tplg_private *private = &tw->priv;
1804-
struct sof_ipc_comp_src *src;
1805-
size_t ipc_size = sizeof(*src);
1806-
int ret;
1807-
1808-
src = (struct sof_ipc_comp_src *)
1809-
sof_comp_alloc(swidget, &ipc_size, index);
1810-
if (!src)
1811-
return -ENOMEM;
1812-
1813-
/* configure src IPC message */
1814-
src->comp.type = SOF_COMP_SRC;
1815-
src->config.hdr.size = sizeof(src->config);
1816-
1817-
ret = sof_parse_tokens(scomp, src, src_tokens,
1818-
ARRAY_SIZE(src_tokens), private->array,
1819-
le32_to_cpu(private->size));
1820-
if (ret != 0) {
1821-
dev_err(scomp->dev, "error: parse src tokens failed %d\n",
1822-
private->size);
1823-
goto err;
1824-
}
1825-
1826-
ret = sof_parse_tokens(scomp, &src->config, comp_tokens,
1827-
ARRAY_SIZE(comp_tokens), private->array,
1828-
le32_to_cpu(private->size));
1829-
if (ret != 0) {
1830-
dev_err(scomp->dev, "error: parse src.cfg tokens failed %d\n",
1831-
le32_to_cpu(private->size));
1832-
goto err;
1833-
}
1834-
1835-
dev_dbg(scomp->dev, "src %s: source rate %d sink rate %d\n",
1836-
swidget->widget->name, src->source_rate, src->sink_rate);
1837-
sof_dbg_comp_config(scomp, &src->config);
1838-
1839-
swidget->private = src;
1840-
1841-
return 0;
1842-
err:
1843-
kfree(src);
1844-
return ret;
1845-
}
1846-
18471787
/*
18481788
* ASRC Topology
18491789
*/
@@ -2278,13 +2218,11 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
22782218
case snd_soc_dapm_scheduler:
22792219
case snd_soc_dapm_aif_out:
22802220
case snd_soc_dapm_aif_in:
2221+
case snd_soc_dapm_src:
22812222
case snd_soc_dapm_mux:
22822223
case snd_soc_dapm_demux:
22832224
ret = sof_widget_parse_tokens(scomp, swidget, tw, token_list, token_list_size);
22842225
break;
2285-
case snd_soc_dapm_src:
2286-
ret = sof_widget_load_src(scomp, index, swidget, tw);
2287-
break;
22882226
case snd_soc_dapm_asrc:
22892227
ret = sof_widget_load_asrc(scomp, index, swidget, tw);
22902228
break;

0 commit comments

Comments
 (0)