Skip to content

Commit aa78d9a

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 <peter.ujfalusi@linux.intel.com>
1 parent d075847 commit aa78d9a

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

sound/soc/sof/ipc4-topology.c

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

409+
static void
410+
sof_ipc4_evaluate_params_change(struct sof_ipc4_available_audio_format *available_fmt)
411+
{
412+
struct sof_ipc4_audio_format *fmt;
413+
u32 in_rate, in_channels, in_valid_bits;
414+
u32 out_rate, out_channels, out_valid_bits;
415+
u32 changed_params = 0;
416+
int i, j;
417+
418+
for (i = 0; i < available_fmt->num_input_formats; i++) {
419+
fmt = &available_fmt->input_pin_fmts[i].audio_fmt;
420+
in_rate = fmt->sampling_frequency;
421+
in_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
422+
in_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
423+
424+
for (j = 0; j < available_fmt->num_output_formats; j++) {
425+
fmt = &available_fmt->output_pin_fmts[j].audio_fmt;
426+
out_rate = fmt->sampling_frequency;
427+
out_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
428+
out_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
429+
430+
if (in_rate != out_rate)
431+
changed_params |= BIT(SNDRV_PCM_HW_PARAM_RATE);
432+
if (in_channels != out_channels)
433+
changed_params |= BIT(SNDRV_PCM_HW_PARAM_CHANNELS);
434+
if (in_valid_bits != out_valid_bits)
435+
changed_params |= BIT(SNDRV_PCM_HW_PARAM_FORMAT);
436+
}
437+
}
438+
439+
available_fmt->changed_params = changed_params;
440+
}
441+
409442
/**
410443
* sof_ipc4_get_audio_fmt - get available audio formats from swidget->tuples
411444
* @scomp: pointer to pointer to SOC component
@@ -497,6 +530,8 @@ static int sof_ipc4_get_audio_fmt(struct snd_soc_component *scomp,
497530
available_fmt->num_output_formats);
498531
}
499532

533+
sof_ipc4_evaluate_params_change(available_fmt);
534+
500535
return 0;
501536

502537
err_out:
@@ -661,6 +696,9 @@ static int sof_ipc4_widget_setup_pcm(struct snd_sof_widget *swidget)
661696
if (ret)
662697
goto free_copier;
663698

699+
/* Copier can only change format */
700+
available_fmt->changed_params &= BIT(SNDRV_PCM_HW_PARAM_FORMAT);
701+
664702
/*
665703
* This callback is used by host copier and module-to-module copier,
666704
* and only host copier needs to set gtw_cfg.
@@ -789,6 +827,9 @@ static int sof_ipc4_widget_setup_comp_dai(struct snd_sof_widget *swidget)
789827
if (ret)
790828
goto free_copier;
791829

830+
/* Copier can only change format */
831+
available_fmt->changed_params &= BIT(SNDRV_PCM_HW_PARAM_FORMAT);
832+
792833
ret = sof_update_ipc_object(scomp, &node_type,
793834
SOF_COPIER_TOKENS, swidget->tuples,
794835
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
@@ -197,12 +197,15 @@ struct sof_ipc4_pin_format {
197197
* @input_pin_fmts: Available input pin formats
198198
* @num_input_formats: Number of input pin formats
199199
* @num_output_formats: Number of output pin formats
200+
* @changed_params: Mask of changed params by the module instance between it's
201+
* input and output formts (rate, channels, depth)
200202
*/
201203
struct sof_ipc4_available_audio_format {
202204
struct sof_ipc4_pin_format *output_pin_fmts;
203205
struct sof_ipc4_pin_format *input_pin_fmts;
204206
u32 num_input_formats;
205207
u32 num_output_formats;
208+
u32 changed_params;
206209
};
207210

208211
/**

0 commit comments

Comments
 (0)