Skip to content

Commit cb7ed49

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

File tree

2 files changed

+66
-71
lines changed

2 files changed

+66
-71
lines changed

sound/soc/sof/ipc3-topology.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ static const struct sof_topology_token src_tokens[] = {
5959
offsetof(struct sof_ipc_comp_src, sink_rate)},
6060
};
6161

62+
/* ASRC */
63+
static const struct sof_topology_token asrc_tokens[] = {
64+
{SOF_TKN_ASRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
65+
offsetof(struct sof_ipc_comp_asrc, source_rate)},
66+
{SOF_TKN_ASRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
67+
offsetof(struct sof_ipc_comp_asrc, sink_rate)},
68+
{SOF_TKN_ASRC_ASYNCHRONOUS_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
69+
offsetof(struct sof_ipc_comp_asrc, asynchronous_mode)},
70+
{SOF_TKN_ASRC_OPERATION_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
71+
offsetof(struct sof_ipc_comp_asrc, operation_mode)},
72+
};
73+
6274
/* PCM */
6375
static const struct sof_topology_token pcm_tokens[] = {
6476
{SOF_TKN_PCM_DMAC_CONFIG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
@@ -98,6 +110,7 @@ static const struct sof_token_info ipc3_token_list[SOF_TOKEN_COUNT] = {
98110
[SOF_BUFFER_TOKENS] = {"Buffer tokens", buffer_tokens, ARRAY_SIZE(buffer_tokens)},
99111
[SOF_VOLUME_TOKENS] = {"Volume tokens", volume_tokens, ARRAY_SIZE(volume_tokens)},
100112
[SOF_SRC_TOKENS] = {"SRC tokens", src_tokens, ARRAY_SIZE(src_tokens)},
113+
[SOF_ASRC_TOKENS] = {"ASRC tokens", asrc_tokens, ARRAY_SIZE(asrc_tokens)},
101114
};
102115

103116
/**
@@ -374,6 +387,49 @@ static int sof_ipc3_widget_setup_comp_src(struct snd_sof_widget *swidget)
374387
return ret;
375388
}
376389

390+
static int sof_ipc3_widget_setup_comp_asrc(struct snd_sof_widget *swidget)
391+
{
392+
struct snd_soc_component *scomp = swidget->scomp;
393+
struct sof_ipc_comp_asrc *asrc;
394+
size_t ipc_size = sizeof(*asrc);
395+
int ret;
396+
397+
asrc = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
398+
if (!asrc)
399+
return -ENOMEM;
400+
401+
swidget->private = asrc;
402+
403+
/* configure ASRC IPC message */
404+
asrc->comp.type = SOF_COMP_ASRC;
405+
asrc->config.hdr.size = sizeof(asrc->config);
406+
407+
/* parse one set of asrc tokens */
408+
ret = sof_update_ipc_object(scomp, asrc, SOF_ASRC_TOKENS, swidget->tuples,
409+
swidget->num_tuples, sizeof(*asrc), 1);
410+
if (ret < 0)
411+
goto err;
412+
413+
/* parse one set of comp tokens */
414+
ret = sof_update_ipc_object(scomp, &asrc->config, SOF_COMP_TOKENS,
415+
swidget->tuples, swidget->num_tuples, sizeof(asrc->config), 1);
416+
if (ret < 0)
417+
goto err;
418+
419+
dev_dbg(scomp->dev, "asrc %s: source rate %d sink rate %d asynch %d operation %d\n",
420+
swidget->widget->name, asrc->source_rate, asrc->sink_rate,
421+
asrc->asynchronous_mode, asrc->operation_mode);
422+
423+
sof_dbg_comp_config(scomp, &asrc->config);
424+
425+
return 0;
426+
err:
427+
kfree(swidget->private);
428+
swidget->private = NULL;
429+
430+
return ret;
431+
}
432+
377433
/*
378434
* Mux topology
379435
*/
@@ -494,6 +550,13 @@ static enum sof_tokens pipeline_token_list[] = {
494550
SOF_SCHED_TOKENS,
495551
};
496552

553+
static enum sof_tokens asrc_token_list[] = {
554+
SOF_CORE_TOKENS,
555+
SOF_COMP_EXT_TOKENS,
556+
SOF_ASRC_TOKENS,
557+
SOF_COMP_TOKENS,
558+
};
559+
497560
static enum sof_tokens src_token_list[] = {
498561
SOF_CORE_TOKENS,
499562
SOF_COMP_EXT_TOKENS,
@@ -520,6 +583,8 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc3_widget_ops[SND_SOC_DAPM_TY
520583
NULL},
521584
[snd_soc_dapm_src] = {sof_ipc3_widget_setup_comp_src, sof_ipc3_widget_free_comp,
522585
src_token_list, ARRAY_SIZE(src_token_list), NULL},
586+
[snd_soc_dapm_asrc] = {sof_ipc3_widget_setup_comp_asrc, sof_ipc3_widget_free_comp,
587+
asrc_token_list, ARRAY_SIZE(asrc_token_list), NULL},
523588
[snd_soc_dapm_scheduler] = {sof_ipc3_widget_setup_comp_pipeline, sof_ipc3_widget_free_comp,
524589
pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL},
525590
[snd_soc_dapm_pga] = {sof_ipc3_widget_setup_comp_pga, sof_ipc3_widget_free_comp,

sound/soc/sof/topology.c

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

632-
/* ASRC */
633-
static const struct sof_topology_token asrc_tokens[] = {
634-
{SOF_TKN_ASRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
635-
offsetof(struct sof_ipc_comp_asrc, source_rate)},
636-
{SOF_TKN_ASRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
637-
offsetof(struct sof_ipc_comp_asrc, sink_rate)},
638-
{SOF_TKN_ASRC_ASYNCHRONOUS_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
639-
get_token_u32,
640-
offsetof(struct sof_ipc_comp_asrc, asynchronous_mode)},
641-
{SOF_TKN_ASRC_OPERATION_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
642-
get_token_u32,
643-
offsetof(struct sof_ipc_comp_asrc, operation_mode)},
644-
};
645-
646632
/* Tone */
647633
static const struct sof_topology_token tone_tokens[] = {
648634
};
@@ -1784,60 +1770,6 @@ static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_s
17841770
return ret;
17851771
}
17861772

1787-
/*
1788-
* ASRC Topology
1789-
*/
1790-
1791-
static int sof_widget_load_asrc(struct snd_soc_component *scomp, int index,
1792-
struct snd_sof_widget *swidget,
1793-
struct snd_soc_tplg_dapm_widget *tw)
1794-
{
1795-
struct snd_soc_tplg_private *private = &tw->priv;
1796-
struct sof_ipc_comp_asrc *asrc;
1797-
size_t ipc_size = sizeof(*asrc);
1798-
int ret;
1799-
1800-
asrc = (struct sof_ipc_comp_asrc *)
1801-
sof_comp_alloc(swidget, &ipc_size, index);
1802-
if (!asrc)
1803-
return -ENOMEM;
1804-
1805-
/* configure ASRC IPC message */
1806-
asrc->comp.type = SOF_COMP_ASRC;
1807-
asrc->config.hdr.size = sizeof(asrc->config);
1808-
1809-
ret = sof_parse_tokens(scomp, asrc, asrc_tokens,
1810-
ARRAY_SIZE(asrc_tokens), private->array,
1811-
le32_to_cpu(private->size));
1812-
if (ret != 0) {
1813-
dev_err(scomp->dev, "error: parse asrc tokens failed %d\n",
1814-
private->size);
1815-
goto err;
1816-
}
1817-
1818-
ret = sof_parse_tokens(scomp, &asrc->config, comp_tokens,
1819-
ARRAY_SIZE(comp_tokens), private->array,
1820-
le32_to_cpu(private->size));
1821-
if (ret != 0) {
1822-
dev_err(scomp->dev, "error: parse asrc.cfg tokens failed %d\n",
1823-
le32_to_cpu(private->size));
1824-
goto err;
1825-
}
1826-
1827-
dev_dbg(scomp->dev, "asrc %s: source rate %d sink rate %d "
1828-
"asynch %d operation %d\n",
1829-
swidget->widget->name, asrc->source_rate, asrc->sink_rate,
1830-
asrc->asynchronous_mode, asrc->operation_mode);
1831-
sof_dbg_comp_config(scomp, &asrc->config);
1832-
1833-
swidget->private = asrc;
1834-
1835-
return 0;
1836-
err:
1837-
kfree(asrc);
1838-
return ret;
1839-
}
1840-
18411773
/*
18421774
* Signal Generator Topology
18431775
*/
@@ -2219,13 +2151,11 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
22192151
case snd_soc_dapm_aif_out:
22202152
case snd_soc_dapm_aif_in:
22212153
case snd_soc_dapm_src:
2154+
case snd_soc_dapm_asrc:
22222155
case snd_soc_dapm_mux:
22232156
case snd_soc_dapm_demux:
22242157
ret = sof_widget_parse_tokens(scomp, swidget, tw, token_list, token_list_size);
22252158
break;
2226-
case snd_soc_dapm_asrc:
2227-
ret = sof_widget_load_asrc(scomp, index, swidget, tw);
2228-
break;
22292159
case snd_soc_dapm_siggen:
22302160
ret = sof_widget_load_siggen(scomp, index, swidget, tw);
22312161
break;

0 commit comments

Comments
 (0)