Skip to content

Commit 69222fa

Browse files
bardliaoplbossart
authored andcommitted
ASoC: SOF: ipc4-topology: add buffer type support
The corresponding IPC4 module of snd_soc_dapm_buffer widget is module -to-module copier. The module-to-module copier is a buffer-like component with demuxing capabilities. Rename the host_token_list to common_copier_token_list since it will be used by host copier and module-to-module copier. The setup callback is almost the same as sof_ipc4_widget_setup_pcm except the gtw_cfg data, and the free callback is exactly the same as sof_ipc4_widget_free_comp_pcm. To reduce the duplication, the commit reuses the setup and free callbacks. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent aab109f commit 69222fa

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ static int sof_ipc4_widget_setup_pcm(struct snd_sof_widget *swidget)
356356
goto free_available_fmt;
357357
}
358358

359+
if (!WIDGET_IS_AIF(swidget->id))
360+
goto skip_gtw_cfg;
361+
359362
ret = sof_update_ipc_object(scomp, available_fmt->dma_buffer_size,
360363
SOF_COPIER_GATEWAY_CFG_TOKENS, swidget->tuples,
361364
swidget->num_tuples, sizeof(u32),
@@ -382,7 +385,7 @@ static int sof_ipc4_widget_setup_pcm(struct snd_sof_widget *swidget)
382385
}
383386
dev_dbg(scomp->dev, "host copier '%s' node_type %u\n", swidget->widget->name, node_type);
384387

385-
ipc4_copier->data.gtw_cfg.node_id = SOF_IPC4_NODE_TYPE(node_type);
388+
skip_gtw_cfg:
386389
ipc4_copier->gtw_attr = kzalloc(sizeof(*ipc4_copier->gtw_attr), GFP_KERNEL);
387390
if (!ipc4_copier->gtw_attr) {
388391
ret = -ENOMEM;
@@ -393,6 +396,21 @@ static int sof_ipc4_widget_setup_pcm(struct snd_sof_widget *swidget)
393396
ipc4_copier->data.gtw_cfg.config_length =
394397
sizeof(struct sof_ipc4_gtw_attributes) >> 2;
395398

399+
switch (swidget->id) {
400+
case snd_soc_dapm_aif_in:
401+
case snd_soc_dapm_aif_out:
402+
ipc4_copier->data.gtw_cfg.node_id = SOF_IPC4_NODE_TYPE(node_type);
403+
break;
404+
case snd_soc_dapm_buffer:
405+
ipc4_copier->data.gtw_cfg.node_id = SOF_IPC4_INVALID_NODE_ID;
406+
ipc4_copier->ipc_config_size = 0;
407+
break;
408+
default:
409+
dev_err(scomp->dev, "invalid widget type %d\n", swidget->id);
410+
ret = -EINVAL;
411+
goto free_gtw_attr;
412+
}
413+
396414
/* set up module info and message header */
397415
ret = sof_ipc4_widget_setup_msg(swidget, &ipc4_copier->msg);
398416
if (ret)
@@ -1256,6 +1274,29 @@ sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
12561274

12571275
break;
12581276
}
1277+
case snd_soc_dapm_buffer:
1278+
{
1279+
ipc4_copier = (struct sof_ipc4_copier *)swidget->private;
1280+
copier_data = &ipc4_copier->data;
1281+
available_fmt = &ipc4_copier->available_fmt;
1282+
1283+
/*
1284+
* base_config->audio_fmt and out_audio_fmt represent the input and output audio
1285+
* formats. Use the input format as the reference to match pcm params for playback
1286+
* and the output format as reference for capture.
1287+
*/
1288+
if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
1289+
available_fmt->ref_audio_fmt = &available_fmt->base_config->audio_fmt;
1290+
ref_audio_fmt_size = sizeof(struct sof_ipc4_base_module_cfg);
1291+
} else {
1292+
available_fmt->ref_audio_fmt = available_fmt->out_audio_fmt;
1293+
ref_audio_fmt_size = sizeof(struct sof_ipc4_audio_format);
1294+
}
1295+
1296+
ref_params = pipeline_params;
1297+
1298+
break;
1299+
}
12591300
default:
12601301
dev_err(sdev->dev, "unsupported type %d for copier %s",
12611302
swidget->id, swidget->widget->name);
@@ -1679,6 +1720,7 @@ static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget
16791720
break;
16801721
case snd_soc_dapm_aif_in:
16811722
case snd_soc_dapm_aif_out:
1723+
case snd_soc_dapm_buffer:
16821724
{
16831725
struct sof_ipc4_copier *ipc4_copier = swidget->private;
16841726

@@ -2233,7 +2275,7 @@ static int sof_ipc4_link_setup(struct snd_sof_dev *sdev, struct snd_soc_dai_link
22332275
return 0;
22342276
}
22352277

2236-
static enum sof_tokens host_token_list[] = {
2278+
static enum sof_tokens common_copier_token_list[] = {
22372279
SOF_COMP_TOKENS,
22382280
SOF_AUDIO_FMT_NUM_TOKENS,
22392281
SOF_AUDIO_FORMAT_BUFFER_SIZE_TOKENS,
@@ -2298,12 +2340,12 @@ static enum sof_tokens process_token_list[] = {
22982340

22992341
static const struct sof_ipc_tplg_widget_ops tplg_ipc4_widget_ops[SND_SOC_DAPM_TYPE_COUNT] = {
23002342
[snd_soc_dapm_aif_in] = {sof_ipc4_widget_setup_pcm, sof_ipc4_widget_free_comp_pcm,
2301-
host_token_list, ARRAY_SIZE(host_token_list), NULL,
2302-
sof_ipc4_prepare_copier_module,
2343+
common_copier_token_list, ARRAY_SIZE(common_copier_token_list),
2344+
NULL, sof_ipc4_prepare_copier_module,
23032345
sof_ipc4_unprepare_copier_module},
23042346
[snd_soc_dapm_aif_out] = {sof_ipc4_widget_setup_pcm, sof_ipc4_widget_free_comp_pcm,
2305-
host_token_list, ARRAY_SIZE(host_token_list), NULL,
2306-
sof_ipc4_prepare_copier_module,
2347+
common_copier_token_list, ARRAY_SIZE(common_copier_token_list),
2348+
NULL, sof_ipc4_prepare_copier_module,
23072349
sof_ipc4_unprepare_copier_module},
23082350
[snd_soc_dapm_dai_in] = {sof_ipc4_widget_setup_comp_dai, sof_ipc4_widget_free_comp_dai,
23092351
dai_token_list, ARRAY_SIZE(dai_token_list), NULL,
@@ -2313,6 +2355,10 @@ static const struct sof_ipc_tplg_widget_ops tplg_ipc4_widget_ops[SND_SOC_DAPM_TY
23132355
dai_token_list, ARRAY_SIZE(dai_token_list), NULL,
23142356
sof_ipc4_prepare_copier_module,
23152357
sof_ipc4_unprepare_copier_module},
2358+
[snd_soc_dapm_buffer] = {sof_ipc4_widget_setup_pcm, sof_ipc4_widget_free_comp_pcm,
2359+
common_copier_token_list, ARRAY_SIZE(common_copier_token_list),
2360+
NULL, sof_ipc4_prepare_copier_module,
2361+
sof_ipc4_unprepare_copier_module},
23162362
[snd_soc_dapm_scheduler] = {sof_ipc4_widget_setup_comp_pipeline,
23172363
sof_ipc4_widget_free_comp_pipeline,
23182364
pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL,

sound/soc/sof/ipc4-topology.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353

5454
#define ALH_MAX_NUMBER_OF_GTW 16
5555

56+
#define SOF_IPC4_INVALID_NODE_ID 0xffffffff
57+
5658
/*
5759
* The base of multi-gateways. Multi-gateways addressing starts from
5860
* ALH_MULTI_GTW_BASE and there are ALH_MULTI_GTW_COUNT multi-sources

0 commit comments

Comments
 (0)