Skip to content

Commit 5c5f1ba

Browse files
harshapriya-nbroonie
authored andcommitted
ASoC: Intel: kbl_rt5663_rt5514_max98927: Fix kabylake_ssp_fixup function
kabylake_ssp_fixup function uses snd_soc_dpcm to identify the codecs DAIs. The HW parameters are changed based on the codec DAI of the stream. The earlier approach to get snd_soc_dpcm was using container_of() macro on snd_pcm_hw_params. The structures have been modified over time and snd_soc_dpcm does not have snd_pcm_hw_params as a reference but as a copy. This causes the current driver to crash when used. This patch changes the way snd_soc_dpcm is extracted. snd_soc_pcm_runtime holds 2 dpcm instances (one for playback and one for capture). 2 codecs on the SSP are dmic (capture) and speakers (playback). Based on the stream direction, snd_soc_dpcm is extracted from snd_soc_pcm_runtime. Tested for all use cases of the driver. Signed-off-by: Harsha Priya <[email protected]> Signed-off-by: Vamshi Krishna Gopal <[email protected]> Tested-by: Lukasz Majczak <[email protected]> Acked-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ffc6d45 commit 5c5f1ba

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -336,22 +336,45 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
336336
struct snd_interval *chan = hw_param_interval(params,
337337
SNDRV_PCM_HW_PARAM_CHANNELS);
338338
struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
339-
struct snd_soc_dpcm *dpcm = container_of(
340-
params, struct snd_soc_dpcm, hw_params);
341-
struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
342-
struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
339+
struct snd_soc_dpcm *dpcm, *rtd_dpcm = NULL;
340+
341+
/*
342+
* The following loop will be called only for playback stream
343+
* In this platform, there is only one playback device on every SSP
344+
*/
345+
for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {
346+
rtd_dpcm = dpcm;
347+
break;
348+
}
349+
350+
/*
351+
* This following loop will be called only for capture stream
352+
* In this platform, there is only one capture device on every SSP
353+
*/
354+
for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
355+
rtd_dpcm = dpcm;
356+
break;
357+
}
358+
359+
if (!rtd_dpcm)
360+
return -EINVAL;
361+
362+
/*
363+
* The above 2 loops are mutually exclusive based on the stream direction,
364+
* thus rtd_dpcm variable will never be overwritten
365+
*/
343366

344367
/*
345368
* The ADSP will convert the FE rate to 48k, stereo, 24 bit
346369
*/
347-
if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
348-
!strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
349-
!strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
370+
if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Port") ||
371+
!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Headset Playback") ||
372+
!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio Capture Port")) {
350373
rate->min = rate->max = 48000;
351374
chan->min = chan->max = 2;
352375
snd_mask_none(fmt);
353376
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
354-
} else if (!strcmp(fe_dai_link->name, "Kbl Audio DMIC cap")) {
377+
} else if (!strcmp(rtd_dpcm->fe->dai_link->name, "Kbl Audio DMIC cap")) {
355378
if (params_channels(params) == 2 ||
356379
DMIC_CH(dmic_constraints) == 2)
357380
chan->min = chan->max = 2;
@@ -362,7 +385,7 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
362385
* The speaker on the SSP0 supports S16_LE and not S24_LE.
363386
* thus changing the mask here
364387
*/
365-
if (!strcmp(be_dai_link->name, "SSP0-Codec"))
388+
if (!strcmp(rtd_dpcm->be->dai_link->name, "SSP0-Codec"))
366389
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
367390

368391
return 0;

0 commit comments

Comments
 (0)