Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRC fixes #4341

Merged
merged 3 commits into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 33 additions & 41 deletions sound/soc/sof/ipc4-topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,25 +1344,6 @@ static int snd_sof_get_nhlt_endpoint_data(struct snd_sof_dev *sdev, struct snd_s
}
#endif

static int ipc4_set_fmt_mask(struct snd_mask *fmt, unsigned int bit_depth)
{
switch (bit_depth) {
case 16:
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
break;
case 24:
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
break;
case 32:
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
break;
default:
return -EINVAL;
}

return 0;
}

static int
sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
struct snd_pcm_hw_params *fe_params,
Expand All @@ -1378,8 +1359,6 @@ sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
struct snd_sof_dai *dai;
u32 gtw_cfg_config_length;
u32 dma_config_tlv_size = 0;
struct snd_mask *fmt;
int out_sample_valid_bits;
void **ipc_config_data;
int *ipc_config_size;
u32 **data;
Expand Down Expand Up @@ -1659,11 +1638,7 @@ sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
}

/* modify the input params for the next widget */
fmt = hw_param_mask(pipeline_params, SNDRV_PCM_HW_PARAM_FORMAT);
out_sample_valid_bits =
SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(copier_data->out_format.fmt_cfg);
snd_mask_none(fmt);
ret = ipc4_set_fmt_mask(fmt, out_sample_valid_bits);
ret = sof_ipc4_update_hw_params(sdev, pipeline_params, &copier_data->out_format);
plbossart marked this conversation as resolved.
Show resolved Hide resolved
if (ret)
return ret;

Expand Down Expand Up @@ -1827,37 +1802,54 @@ static int sof_ipc4_prepare_src_module(struct snd_sof_widget *swidget,
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
struct sof_ipc4_src *src = swidget->private;
struct sof_ipc4_available_audio_format *available_fmt = &src->available_fmt;
struct sof_ipc4_audio_format *in_fmt;
struct sof_ipc4_audio_format *out_audio_fmt;
ranj063 marked this conversation as resolved.
Show resolved Hide resolved
u32 out_ref_rate, out_ref_channels, out_ref_valid_bits;
struct snd_interval *rate;
int ret;
int ret, output_format_index;
plbossart marked this conversation as resolved.
Show resolved Hide resolved

ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &src->base_config,
pipeline_params, available_fmt);
if (ret < 0)
return ret;

in_fmt = &available_fmt->input_pin_fmts[ret].audio_fmt;
plbossart marked this conversation as resolved.
Show resolved Hide resolved
out_ref_rate = in_fmt->sampling_frequency;
out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
/*
* For playback, the SRC sink rate will be configured based on the requested output
* format, which is restricted to only deal with DAI's with a single format for now.
*/
if (dir == SNDRV_PCM_STREAM_PLAYBACK && available_fmt->num_output_formats > 1) {
dev_err(sdev->dev, "Invalid number of output formats: %d for SRC %s\n",
available_fmt->num_output_formats, swidget->widget->name);
return -EINVAL;
}

ret = sof_ipc4_init_output_audio_fmt(sdev, &src->base_config, available_fmt,
out_ref_rate, out_ref_channels, out_ref_valid_bits);
if (ret < 0) {
/*
* For capture, the SRC module should convert the rate to match the rate requested by the
* PCM hw_params. Set the reference params based on the fe_params unconditionally as it
* will be ignored for playback anyway.
*/
out_ref_valid_bits = sof_ipc4_get_valid_bits(sdev, fe_params);
if (out_ref_valid_bits < 0)
return out_ref_valid_bits;

out_ref_rate = params_rate(fe_params);
out_ref_channels = params_channels(fe_params);

output_format_index = sof_ipc4_init_output_audio_fmt(sdev, &src->base_config,
available_fmt, out_ref_rate,
out_ref_channels, out_ref_valid_bits);
if (output_format_index < 0) {
dev_err(sdev->dev, "Failed to initialize output format for %s",
swidget->widget->name);
return output_format_index;
}

/* update pipeline memory usage */
sof_ipc4_update_pipeline_mem_usage(sdev, swidget, &src->base_config);

/* update pipeline_params for sink widgets */
rate = hw_param_interval(pipeline_params, SNDRV_PCM_HW_PARAM_RATE);
rate->min = src->sink_rate;
rate->max = rate->min;
out_audio_fmt = &available_fmt->output_pin_fmts[output_format_index].audio_fmt;
src->sink_rate = out_audio_fmt->sampling_frequency;

return 0;
/* update pipeline_params for sink widgets */
return sof_ipc4_update_hw_params(sdev, pipeline_params, out_audio_fmt);
}

static int
Expand Down