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>
This commit is contained in:
Ranjani Sridharan 2022-03-14 13:05:13 -07:00 committed by Mark Brown
parent 8d8b129347
commit cb7ed49acf
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 66 additions and 71 deletions

View File

@ -59,6 +59,18 @@ static const struct sof_topology_token src_tokens[] = {
offsetof(struct sof_ipc_comp_src, sink_rate)},
};
/* ASRC */
static const struct sof_topology_token asrc_tokens[] = {
{SOF_TKN_ASRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
offsetof(struct sof_ipc_comp_asrc, source_rate)},
{SOF_TKN_ASRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
offsetof(struct sof_ipc_comp_asrc, sink_rate)},
{SOF_TKN_ASRC_ASYNCHRONOUS_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
offsetof(struct sof_ipc_comp_asrc, asynchronous_mode)},
{SOF_TKN_ASRC_OPERATION_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
offsetof(struct sof_ipc_comp_asrc, operation_mode)},
};
/* PCM */
static const struct sof_topology_token pcm_tokens[] = {
{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] = {
[SOF_BUFFER_TOKENS] = {"Buffer tokens", buffer_tokens, ARRAY_SIZE(buffer_tokens)},
[SOF_VOLUME_TOKENS] = {"Volume tokens", volume_tokens, ARRAY_SIZE(volume_tokens)},
[SOF_SRC_TOKENS] = {"SRC tokens", src_tokens, ARRAY_SIZE(src_tokens)},
[SOF_ASRC_TOKENS] = {"ASRC tokens", asrc_tokens, ARRAY_SIZE(asrc_tokens)},
};
/**
@ -374,6 +387,49 @@ err:
return ret;
}
static int sof_ipc3_widget_setup_comp_asrc(struct snd_sof_widget *swidget)
{
struct snd_soc_component *scomp = swidget->scomp;
struct sof_ipc_comp_asrc *asrc;
size_t ipc_size = sizeof(*asrc);
int ret;
asrc = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
if (!asrc)
return -ENOMEM;
swidget->private = asrc;
/* configure ASRC IPC message */
asrc->comp.type = SOF_COMP_ASRC;
asrc->config.hdr.size = sizeof(asrc->config);
/* parse one set of asrc tokens */
ret = sof_update_ipc_object(scomp, asrc, SOF_ASRC_TOKENS, swidget->tuples,
swidget->num_tuples, sizeof(*asrc), 1);
if (ret < 0)
goto err;
/* parse one set of comp tokens */
ret = sof_update_ipc_object(scomp, &asrc->config, SOF_COMP_TOKENS,
swidget->tuples, swidget->num_tuples, sizeof(asrc->config), 1);
if (ret < 0)
goto err;
dev_dbg(scomp->dev, "asrc %s: source rate %d sink rate %d asynch %d operation %d\n",
swidget->widget->name, asrc->source_rate, asrc->sink_rate,
asrc->asynchronous_mode, asrc->operation_mode);
sof_dbg_comp_config(scomp, &asrc->config);
return 0;
err:
kfree(swidget->private);
swidget->private = NULL;
return ret;
}
/*
* Mux topology
*/
@ -494,6 +550,13 @@ static enum sof_tokens pipeline_token_list[] = {
SOF_SCHED_TOKENS,
};
static enum sof_tokens asrc_token_list[] = {
SOF_CORE_TOKENS,
SOF_COMP_EXT_TOKENS,
SOF_ASRC_TOKENS,
SOF_COMP_TOKENS,
};
static enum sof_tokens src_token_list[] = {
SOF_CORE_TOKENS,
SOF_COMP_EXT_TOKENS,
@ -520,6 +583,8 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc3_widget_ops[SND_SOC_DAPM_TY
NULL},
[snd_soc_dapm_src] = {sof_ipc3_widget_setup_comp_src, sof_ipc3_widget_free_comp,
src_token_list, ARRAY_SIZE(src_token_list), NULL},
[snd_soc_dapm_asrc] = {sof_ipc3_widget_setup_comp_asrc, sof_ipc3_widget_free_comp,
asrc_token_list, ARRAY_SIZE(asrc_token_list), NULL},
[snd_soc_dapm_scheduler] = {sof_ipc3_widget_setup_comp_pipeline, sof_ipc3_widget_free_comp,
pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL},
[snd_soc_dapm_pga] = {sof_ipc3_widget_setup_comp_pga, sof_ipc3_widget_free_comp,

View File

@ -629,20 +629,6 @@ static const struct sof_topology_token dai_link_tokens[] = {
offsetof(struct sof_ipc_dai_config, dai_index)},
};
/* ASRC */
static const struct sof_topology_token asrc_tokens[] = {
{SOF_TKN_ASRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
offsetof(struct sof_ipc_comp_asrc, source_rate)},
{SOF_TKN_ASRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
offsetof(struct sof_ipc_comp_asrc, sink_rate)},
{SOF_TKN_ASRC_ASYNCHRONOUS_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
get_token_u32,
offsetof(struct sof_ipc_comp_asrc, asynchronous_mode)},
{SOF_TKN_ASRC_OPERATION_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
get_token_u32,
offsetof(struct sof_ipc_comp_asrc, operation_mode)},
};
/* Tone */
static const struct sof_topology_token tone_tokens[] = {
};
@ -1784,60 +1770,6 @@ err:
return ret;
}
/*
* ASRC Topology
*/
static int sof_widget_load_asrc(struct snd_soc_component *scomp, int index,
struct snd_sof_widget *swidget,
struct snd_soc_tplg_dapm_widget *tw)
{
struct snd_soc_tplg_private *private = &tw->priv;
struct sof_ipc_comp_asrc *asrc;
size_t ipc_size = sizeof(*asrc);
int ret;
asrc = (struct sof_ipc_comp_asrc *)
sof_comp_alloc(swidget, &ipc_size, index);
if (!asrc)
return -ENOMEM;
/* configure ASRC IPC message */
asrc->comp.type = SOF_COMP_ASRC;
asrc->config.hdr.size = sizeof(asrc->config);
ret = sof_parse_tokens(scomp, asrc, asrc_tokens,
ARRAY_SIZE(asrc_tokens), private->array,
le32_to_cpu(private->size));
if (ret != 0) {
dev_err(scomp->dev, "error: parse asrc tokens failed %d\n",
private->size);
goto err;
}
ret = sof_parse_tokens(scomp, &asrc->config, comp_tokens,
ARRAY_SIZE(comp_tokens), private->array,
le32_to_cpu(private->size));
if (ret != 0) {
dev_err(scomp->dev, "error: parse asrc.cfg tokens failed %d\n",
le32_to_cpu(private->size));
goto err;
}
dev_dbg(scomp->dev, "asrc %s: source rate %d sink rate %d "
"asynch %d operation %d\n",
swidget->widget->name, asrc->source_rate, asrc->sink_rate,
asrc->asynchronous_mode, asrc->operation_mode);
sof_dbg_comp_config(scomp, &asrc->config);
swidget->private = asrc;
return 0;
err:
kfree(asrc);
return ret;
}
/*
* Signal Generator Topology
*/
@ -2219,13 +2151,11 @@ static int sof_widget_ready(struct snd_soc_component *scomp, int index,
case snd_soc_dapm_aif_out:
case snd_soc_dapm_aif_in:
case snd_soc_dapm_src:
case snd_soc_dapm_asrc:
case snd_soc_dapm_mux:
case snd_soc_dapm_demux:
ret = sof_widget_parse_tokens(scomp, swidget, tw, token_list, token_list_size);
break;
case snd_soc_dapm_asrc:
ret = sof_widget_load_asrc(scomp, index, swidget, tw);
break;
case snd_soc_dapm_siggen:
ret = sof_widget_load_siggen(scomp, index, swidget, tw);
break;