Skip to content

Commit 53ada05

Browse files
committed
ASoC: SOF: ipc4-topology: Store the params change between input/output of a module
Based on the input and output formats we can evaluate what param might be changed by the module instance. If there is a difference between the input rate/channels/format and the output rate/channels/format it means that the module can change one or multiple of the params. Store this information during init for later use. Signed-off-by: Peter Ujfalusi <[email protected]>
1 parent c6e20f3 commit 53ada05

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,39 @@ sof_ipc4_get_input_pin_audio_fmt(struct snd_sof_widget *swidget, int pin_index)
379379
return NULL;
380380
}
381381

382+
static void
383+
sof_ipc4_evaluate_params_change(struct sof_ipc4_available_audio_format *available_fmt)
384+
{
385+
struct sof_ipc4_audio_format *fmt;
386+
u32 in_rate, in_channels, in_valid_bits;
387+
u32 out_rate, out_channels, out_valid_bits;
388+
u32 changed_params = 0;
389+
int i, j;
390+
391+
for (i = 0; i < available_fmt->num_input_formats; i++) {
392+
fmt = &available_fmt->input_pin_fmts[i].audio_fmt;
393+
in_rate = fmt->sampling_frequency;
394+
in_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
395+
in_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
396+
397+
for (j = 0; j < available_fmt->num_output_formats; j++) {
398+
fmt = &available_fmt->output_pin_fmts[j].audio_fmt;
399+
out_rate = fmt->sampling_frequency;
400+
out_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
401+
out_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
402+
403+
if (in_rate != out_rate)
404+
changed_params |= BIT(SNDRV_PCM_HW_PARAM_RATE);
405+
if (in_channels != out_channels)
406+
changed_params |= BIT(SNDRV_PCM_HW_PARAM_CHANNELS);
407+
if (in_valid_bits != out_valid_bits)
408+
changed_params |= BIT(SNDRV_PCM_HW_PARAM_FORMAT);
409+
}
410+
}
411+
412+
available_fmt->changed_params = changed_params;
413+
}
414+
382415
/**
383416
* sof_ipc4_get_audio_fmt - get available audio formats from swidget->tuples
384417
* @scomp: pointer to pointer to SOC component
@@ -470,6 +503,8 @@ static int sof_ipc4_get_audio_fmt(struct snd_soc_component *scomp,
470503
available_fmt->num_output_formats);
471504
}
472505

506+
sof_ipc4_evaluate_params_change(available_fmt);
507+
473508
return 0;
474509

475510
err_out:
@@ -632,6 +667,9 @@ static int sof_ipc4_widget_setup_pcm(struct snd_sof_widget *swidget)
632667
if (ret)
633668
goto free_copier;
634669

670+
/* Copier can only change format */
671+
available_fmt->changed_params &= BIT(SNDRV_PCM_HW_PARAM_FORMAT);
672+
635673
/*
636674
* This callback is used by host copier and module-to-module copier,
637675
* and only host copier needs to set gtw_cfg.
@@ -756,6 +794,9 @@ static int sof_ipc4_widget_setup_comp_dai(struct snd_sof_widget *swidget)
756794
if (ret)
757795
goto free_copier;
758796

797+
/* Copier can only change format */
798+
available_fmt->changed_params &= BIT(SNDRV_PCM_HW_PARAM_FORMAT);
799+
759800
ret = sof_update_ipc_object(scomp, &node_type,
760801
SOF_COPIER_TOKENS, swidget->tuples,
761802
swidget->num_tuples, sizeof(node_type), 1);

sound/soc/sof/ipc4-topology.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,15 @@ struct sof_ipc4_pin_format {
181181
* @input_pin_fmts: Available input pin formats
182182
* @num_input_formats: Number of input pin formats
183183
* @num_output_formats: Number of output pin formats
184+
* @changed_params: Mask of changed params by the module instance between it's
185+
* input and output formts (rate, channels, depth)
184186
*/
185187
struct sof_ipc4_available_audio_format {
186188
struct sof_ipc4_pin_format *output_pin_fmts;
187189
struct sof_ipc4_pin_format *input_pin_fmts;
188190
u32 num_input_formats;
189191
u32 num_output_formats;
192+
u32 changed_params;
190193
};
191194

192195
/**

0 commit comments

Comments
 (0)