From 2aa025e181729d526e701866b3cae1558b9dd5fa Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Thu, 26 Oct 2023 13:24:01 -0500 Subject: [PATCH] ASoC: SOF: ipc4-topology: Introduce new token for period size Add SOF_TKN_PROCESS_BUFFER_PERIOD_SIZE token, when set in topology, the tuple value of the token will be used as multiplier of process's buffer size. Signed-off-by: Ranjani Sridharan Signed-off-by: Yong Zhi --- include/uapi/sound/sof/tokens.h | 3 +++ sound/soc/sof/ipc4-topology.c | 22 ++++++++++++++++++++++ sound/soc/sof/ipc4-topology.h | 1 + 3 files changed, 26 insertions(+) diff --git a/include/uapi/sound/sof/tokens.h b/include/uapi/sound/sof/tokens.h index 453cab2a120988..b6c5e48c70443c 100644 --- a/include/uapi/sound/sof/tokens.h +++ b/include/uapi/sound/sof/tokens.h @@ -213,4 +213,7 @@ #define SOF_TKN_AMD_ACPI2S_CH 1701 #define SOF_TKN_AMD_ACPI2S_TDM_MODE 1702 +/* Process */ +#define SOF_TKN_PROCESS_BUFFER_PERIOD_SIZE 2000 + #endif diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c index 7b6f50a5972f5c..fdcd0e90a93c7a 100644 --- a/sound/soc/sof/ipc4-topology.c +++ b/sound/soc/sof/ipc4-topology.c @@ -144,6 +144,12 @@ static const struct sof_topology_token src_tokens[] = { offsetof(struct sof_ipc4_src_data, sink_rate)}, }; +/* Process tokens */ +static const struct sof_topology_token process_tokens[] = { + {SOF_TKN_PROCESS_BUFFER_PERIOD_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, + offsetof(struct sof_ipc4_process, buffer_period_size)}, +}; + static const struct sof_token_info ipc4_token_list[SOF_TOKEN_COUNT] = { [SOF_DAI_TOKENS] = {"DAI tokens", dai_tokens, ARRAY_SIZE(dai_tokens)}, [SOF_PIPELINE_TOKENS] = {"Pipeline tokens", pipeline_tokens, ARRAY_SIZE(pipeline_tokens)}, @@ -165,6 +171,7 @@ static const struct sof_token_info ipc4_token_list[SOF_TOKEN_COUNT] = { ipc4_audio_fmt_num_tokens, ARRAY_SIZE(ipc4_audio_fmt_num_tokens)}, [SOF_GAIN_TOKENS] = {"Gain tokens", gain_tokens, ARRAY_SIZE(gain_tokens)}, [SOF_SRC_TOKENS] = {"SRC tokens", src_tokens, ARRAY_SIZE(src_tokens)}, + [SOF_PROCESS_TOKENS] = {"Process tokens", process_tokens, ARRAY_SIZE(process_tokens)}, }; struct snd_sof_widget *sof_ipc4_find_swidget_by_ids(struct snd_sof_dev *sdev, @@ -906,6 +913,15 @@ static int sof_ipc4_widget_setup_comp_process(struct snd_sof_widget *swidget) if (ret) goto err; + /* set default period size to 1 and override it with the topology value if set */ + process->buffer_period_size = 1; + ret = sof_update_ipc_object(scomp, process, SOF_PROCESS_TOKENS, swidget->tuples, + swidget->num_tuples, sizeof(*process), 1); + if (ret) { + dev_err(scomp->dev, "parse process tokens failed %d\n", ret); + goto err; + } + /* parse process init module payload config type from module info */ fw_module = swidget->module_info; process->init_config = FIELD_GET(SOF_IPC4_MODULE_INIT_CONFIG_MASK, @@ -2012,6 +2028,7 @@ sof_ipc4_process_set_pin_formats(struct snd_sof_widget *swidget, int pin_type) if (pin_format_item->pin_index == i - pin_format_offset) { *pin_format = *pin_format_item; + pin_format->buffer_size *= process->buffer_period_size; break; } } @@ -2075,6 +2092,10 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget, return output_fmt_index; } + /* adjust the input/output buffer size based on the period size set in topology */ + process->base_config.ibs *= process->buffer_period_size; + process->base_config.obs *= process->buffer_period_size; + /* copy Pin 0 output format */ if (available_fmt->num_output_formats && output_fmt_index < available_fmt->num_output_formats && @@ -3042,6 +3063,7 @@ static enum sof_tokens process_token_list[] = { SOF_IN_AUDIO_FORMAT_TOKENS, SOF_OUT_AUDIO_FORMAT_TOKENS, SOF_COMP_EXT_TOKENS, + SOF_PROCESS_TOKENS, }; static const struct sof_ipc_tplg_widget_ops tplg_ipc4_widget_ops[SND_SOC_DAPM_TYPE_COUNT] = { diff --git a/sound/soc/sof/ipc4-topology.h b/sound/soc/sof/ipc4-topology.h index dce174a190ddc6..5ebb68cbb9e75e 100644 --- a/sound/soc/sof/ipc4-topology.h +++ b/sound/soc/sof/ipc4-topology.h @@ -473,6 +473,7 @@ struct sof_ipc4_process { struct sof_ipc4_msg msg; u32 base_config_ext_size; u32 init_config; + u32 buffer_period_size; }; bool sof_ipc4_copier_is_single_format(struct snd_sof_dev *sdev,