Skip to content

Commit b7f545c

Browse files
committed
ASoC: SOF: ipc4-topology: Always validate the audio format on fmt init
Even if there is a single format supported by the module on it's input or output, it must be validated that it is matching with the reference parameters. The DAI copier's DAI side reference is adjusted to the formats it supports, but modules deep within the path might have incorrect configuration in topology (single format which is not matching with the previous module's output for example). This should be reported as errors and not silently accepted. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 3fc50b3 commit b7f545c

File tree

1 file changed

+5
-50
lines changed

1 file changed

+5
-50
lines changed

sound/soc/sof/ipc4-topology.c

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,34 +1384,6 @@ static int sof_ipc4_update_hw_params(struct snd_sof_dev *sdev, struct snd_pcm_hw
13841384
return 0;
13851385
}
13861386

1387-
static bool sof_ipc4_is_single_format(struct snd_sof_dev *sdev,
1388-
struct sof_ipc4_pin_format *pin_fmts, u32 pin_fmts_size)
1389-
{
1390-
struct sof_ipc4_audio_format *fmt;
1391-
u32 rate, channels, valid_bits;
1392-
int i;
1393-
1394-
fmt = &pin_fmts[0].audio_fmt;
1395-
rate = fmt->sampling_frequency;
1396-
channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1397-
valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1398-
1399-
/* check if all output formats in topology are the same */
1400-
for (i = 1; i < pin_fmts_size; i++) {
1401-
u32 _rate, _channels, _valid_bits;
1402-
1403-
fmt = &pin_fmts[i].audio_fmt;
1404-
_rate = fmt->sampling_frequency;
1405-
_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1406-
_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1407-
1408-
if (_rate != rate || _channels != channels || _valid_bits != valid_bits)
1409-
return false;
1410-
}
1411-
1412-
return true;
1413-
}
1414-
14151387
static int sof_ipc4_init_output_audio_fmt(struct snd_sof_dev *sdev,
14161388
struct snd_sof_widget *swidget,
14171389
struct sof_ipc4_base_module_cfg *base_config,
@@ -1421,7 +1393,6 @@ static int sof_ipc4_init_output_audio_fmt(struct snd_sof_dev *sdev,
14211393
{
14221394
struct sof_ipc4_pin_format *pin_fmts = available_fmt->output_pin_fmts;
14231395
u32 pin_fmts_size = available_fmt->num_output_formats;
1424-
bool single_format;
14251396
int i = 0;
14261397

14271398
if (!pin_fmts_size) {
@@ -1430,16 +1401,6 @@ static int sof_ipc4_init_output_audio_fmt(struct snd_sof_dev *sdev,
14301401
return -EINVAL;
14311402
}
14321403

1433-
single_format = sof_ipc4_is_single_format(sdev, pin_fmts, pin_fmts_size);
1434-
1435-
/* pick the first format if there's only one available or if all formats are the same */
1436-
if (single_format)
1437-
goto out_fmt;
1438-
1439-
/*
1440-
* if there are multiple output formats, then choose the output format that matches
1441-
* the reference params
1442-
*/
14431404
for (i = 0; i < pin_fmts_size; i++) {
14441405
struct sof_ipc4_audio_format *fmt = &pin_fmts[i].audio_fmt;
14451406

@@ -1491,7 +1452,6 @@ static int sof_ipc4_init_input_audio_fmt(struct snd_sof_dev *sdev,
14911452
u32 valid_bits;
14921453
u32 channels;
14931454
u32 rate;
1494-
bool single_format;
14951455
int sample_valid_bits;
14961456
int i = 0;
14971457

@@ -1500,10 +1460,6 @@ static int sof_ipc4_init_input_audio_fmt(struct snd_sof_dev *sdev,
15001460
return -EINVAL;
15011461
}
15021462

1503-
single_format = sof_ipc4_is_single_format(sdev, pin_fmts, pin_fmts_size);
1504-
if (single_format)
1505-
goto in_fmt;
1506-
15071463
sample_valid_bits = sof_ipc4_get_valid_bits(sdev, params);
15081464
if (sample_valid_bits < 0)
15091465
return sample_valid_bits;
@@ -1523,14 +1479,13 @@ static int sof_ipc4_init_input_audio_fmt(struct snd_sof_dev *sdev,
15231479
valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
15241480
if (params_rate(params) == rate && params_channels(params) == channels &&
15251481
sample_valid_bits == valid_bits)
1526-
break;
1482+
goto in_fmt;
15271483
}
15281484

1529-
if (i == pin_fmts_size) {
1530-
dev_err(sdev->dev, "%s: Unsupported audio format: %uHz, %ubit, %u channels\n",
1531-
__func__, params_rate(params), sample_valid_bits, params_channels(params));
1532-
return -EINVAL;
1533-
}
1485+
dev_err(sdev->dev, "%s: Unsupported audio format: %uHz, %ubit, %u channels\n",
1486+
__func__, params_rate(params), sample_valid_bits, params_channels(params));
1487+
1488+
return -EINVAL;
15341489

15351490
in_fmt:
15361491
/* copy input format */

0 commit comments

Comments
 (0)