Skip to content

Commit b679302

Browse files
ujfalusibroonie
authored andcommitted
ASoC: SOF: ipc4-topology: Allow selective update in sof_ipc4_update_hw_params
Add a bitmask parameter to sof_ipc4_update_hw_params() to be able to select the param to be updated. This feature can be used when not all params should be updated, for example if caller only wants to update the format in the params, leaving the channels and rates untouched. Reviewed-by: Seppo Ingalsuo <[email protected]> Reviewed-by: Ranjani Sridharan <[email protected]> Signed-off-by: Peter Ujfalusi <[email protected]> Signed-off-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 5a7543d commit b679302

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,42 +1119,50 @@ static int sof_ipc4_widget_assign_instance_id(struct snd_sof_dev *sdev,
11191119

11201120
/* update hw_params based on the audio stream format */
11211121
static int sof_ipc4_update_hw_params(struct snd_sof_dev *sdev, struct snd_pcm_hw_params *params,
1122-
struct sof_ipc4_audio_format *fmt)
1122+
struct sof_ipc4_audio_format *fmt, u32 param_to_update)
11231123
{
1124-
snd_pcm_format_t snd_fmt;
11251124
struct snd_interval *i;
1126-
struct snd_mask *m;
1127-
int valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1128-
unsigned int channels, rate;
11291125

1130-
switch (valid_bits) {
1131-
case 16:
1132-
snd_fmt = SNDRV_PCM_FORMAT_S16_LE;
1133-
break;
1134-
case 24:
1135-
snd_fmt = SNDRV_PCM_FORMAT_S24_LE;
1136-
break;
1137-
case 32:
1138-
snd_fmt = SNDRV_PCM_FORMAT_S32_LE;
1139-
break;
1140-
default:
1141-
dev_err(sdev->dev, "invalid PCM valid_bits %d\n", valid_bits);
1142-
return -EINVAL;
1126+
if (param_to_update & BIT(SNDRV_PCM_HW_PARAM_FORMAT)) {
1127+
int valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1128+
snd_pcm_format_t snd_fmt;
1129+
struct snd_mask *m;
1130+
1131+
switch (valid_bits) {
1132+
case 16:
1133+
snd_fmt = SNDRV_PCM_FORMAT_S16_LE;
1134+
break;
1135+
case 24:
1136+
snd_fmt = SNDRV_PCM_FORMAT_S24_LE;
1137+
break;
1138+
case 32:
1139+
snd_fmt = SNDRV_PCM_FORMAT_S32_LE;
1140+
break;
1141+
default:
1142+
dev_err(sdev->dev, "invalid PCM valid_bits %d\n", valid_bits);
1143+
return -EINVAL;
1144+
}
1145+
1146+
m = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1147+
snd_mask_none(m);
1148+
snd_mask_set_format(m, snd_fmt);
11431149
}
11441150

1145-
m = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1146-
snd_mask_none(m);
1147-
snd_mask_set_format(m, snd_fmt);
1151+
if (param_to_update & BIT(SNDRV_PCM_HW_PARAM_RATE)) {
1152+
unsigned int rate = fmt->sampling_frequency;
11481153

1149-
rate = fmt->sampling_frequency;
1150-
i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
1151-
i->min = rate;
1152-
i->max = rate;
1154+
i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
1155+
i->min = rate;
1156+
i->max = rate;
1157+
}
11531158

1154-
channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1155-
i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
1156-
i->min = channels;
1157-
i->max = channels;
1159+
if (param_to_update & BIT(SNDRV_PCM_HW_PARAM_CHANNELS)) {
1160+
unsigned int channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1161+
1162+
i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
1163+
i->min = channels;
1164+
i->max = channels;
1165+
}
11581166

11591167
return 0;
11601168
}
@@ -1844,7 +1852,11 @@ sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
18441852
}
18451853

18461854
/* modify the input params for the next widget */
1847-
ret = sof_ipc4_update_hw_params(sdev, pipeline_params, &copier_data->out_format);
1855+
ret = sof_ipc4_update_hw_params(sdev, pipeline_params,
1856+
&copier_data->out_format,
1857+
BIT(SNDRV_PCM_HW_PARAM_FORMAT) |
1858+
BIT(SNDRV_PCM_HW_PARAM_CHANNELS) |
1859+
BIT(SNDRV_PCM_HW_PARAM_RATE));
18481860
if (ret)
18491861
return ret;
18501862

@@ -2069,7 +2081,10 @@ static int sof_ipc4_prepare_src_module(struct snd_sof_widget *swidget,
20692081
src->data.sink_rate = out_audio_fmt->sampling_frequency;
20702082

20712083
/* update pipeline_params for sink widgets */
2072-
return sof_ipc4_update_hw_params(sdev, pipeline_params, out_audio_fmt);
2084+
return sof_ipc4_update_hw_params(sdev, pipeline_params, out_audio_fmt,
2085+
BIT(SNDRV_PCM_HW_PARAM_FORMAT) |
2086+
BIT(SNDRV_PCM_HW_PARAM_CHANNELS) |
2087+
BIT(SNDRV_PCM_HW_PARAM_RATE));
20732088
}
20742089

20752090
static int
@@ -2193,7 +2208,11 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
21932208
sizeof(struct sof_ipc4_audio_format));
21942209

21952210
/* modify the pipeline params with the pin 0 output format */
2196-
ret = sof_ipc4_update_hw_params(sdev, pipeline_params, &process->output_format);
2211+
ret = sof_ipc4_update_hw_params(sdev, pipeline_params,
2212+
&process->output_format,
2213+
BIT(SNDRV_PCM_HW_PARAM_FORMAT) |
2214+
BIT(SNDRV_PCM_HW_PARAM_CHANNELS) |
2215+
BIT(SNDRV_PCM_HW_PARAM_RATE));
21972216
if (ret)
21982217
return ret;
21992218
}

0 commit comments

Comments
 (0)