ASoC: Intel: kbl_rt5663_rt5514_max98927: Fix kabylake_ssp_fixup function
Subsystems (3)
PATCH v6 1/1 ASoC: Intel: kbl_rt5663_rt5514_max98927: Fix kabylake_ssp_fixup function
From: Vamshi Krishna Gopal <[email protected]>
kabylake_ssp_fixup function uses snd_soc_dpcm to identify the codecs DAIs. The hw parameters are changed based on the codec DAI,
the stream is intended for. 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.
The snd_soc_pcm_runtime holds 2 dpcm
instances (one for playback and one for capture).
The 2 codecs on this SSP are dmic and speakers.
One is for capture and one is for playback respectively.
Based on the direction of the stream,
the snd_soc_dpcm is extracted from the snd_soc_pcm_runtime structure. Tested for all use cases of the driver.
---
v1 -> v2:
- Extract dmic from SSP0 as every BE should have own fixup function. v2 -> v3:
- Restore naming in the dapm route table to not confuse with other drivers
- Fixed indentations
v3 -> v4:
- Updated code and commit description according to solution proposed by Harsha
v4 -> v5:
- Cosmetic Changes
v5 -> v6:
- Dmic regression seen with v4 fixed
- Using available routines for obtaining dpcm information
---
--- .../intel/boards/kbl_rt5663_rt5514_max98927.c | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-)
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +17 -9
@@ -379,22 +379,30 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,struct snd_interval *chan =hw_param_interval (params,SNDRV_PCM_HW_PARAM_CHANNELS );struct snd_mask *fmt =hw_param_mask (params,SNDRV_PCM_HW_PARAM_FORMAT ); -struct snd_soc_dpcm *dpcm =container_of ( - params, struct snd_soc_dpcm, hw_params); -struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link; -struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link; +struct snd_soc_dpcm *dpcm, *rtd_dpcm; + +/* +* This macro will be called for playback stream +*/ +for_each_dpcm_fe (rtd,SNDRV_PCM_STREAM_PLAYBACK , dpcm) + rtd_dpcm = dpcm; +/* +* This macro will be called for capture stream +*/ +for_each_dpcm_fe (rtd,SNDRV_PCM_STREAM_CAPTURE , dpcm) + rtd_dpcm = dpcm;/* * The ADSP will convert the FE rate to 48k, stereo, 24 bit */ -if (!strcmp (fe_dai_link->name,"Kbl Audio Port" ) || - !strcmp (fe_dai_link->name,"Kbl Audio Headset Playback" ) || - !strcmp (fe_dai_link->name,"Kbl Audio Capture Port" )) { +if (!strcmp (rtd_dpcm->fe->dai_link->name,"Kbl Audio Port" ) || + !strcmp (rtd_dpcm->fe->dai_link->name,"Kbl Audio Headset Playback" ) || + !strcmp (rtd_dpcm->fe->dai_link->name,"Kbl Audio Capture Port" )) { rate->min = rate->max =48000 ; chan->min = chan->max =2 ;snd_mask_none (fmt);snd_mask_set_format (fmt,SNDRV_PCM_FORMAT_S24_LE ); - }else if (!strcmp (fe_dai_link->name,"Kbl Audio DMIC cap" )) { + }else if (!strcmp (rtd_dpcm->fe->dai_link->name,"Kbl Audio DMIC cap" )) {if (params_channels (params) ==2 ||DMIC_CH (dmic_constraints) ==2 ) chan->min = chan->max =2 ;
@@ -405,7 +413,7 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,* The speaker on the SSP0 supports S16_LE and not S24_LE. * thus changing the mask here */ -if (!strcmp (be_dai_link->name,"SSP0-Codec" )) +if (!strcmp (rtd_dpcm->be->dai_link->name,"SSP0-Codec" ))snd_mask_set_format (fmt,SNDRV_PCM_FORMAT_S16_LE );return 0 ;
Signature · 1 line
2.17.1
Quoted 17 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +2
-4@@ -379,22 +379,30 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,struct snd_interval *chan =hw_param_interval (params,SNDRV_PCM_HW_PARAM_CHANNELS );struct snd_mask *fmt =hw_param_mask (params,SNDRV_PCM_HW_PARAM_FORMAT ); -struct snd_soc_dpcm *dpcm =container_of ( - params, struct snd_soc_dpcm, hw_params); -struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link; -struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link; +struct snd_soc_dpcm *dpcm, *rtd_dpcm; +
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd, · line 393
Quoted 10 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +10
-0+/* +* This macro will be called for playback stream +*/ +for_each_dpcm_fe (rtd,SNDRV_PCM_STREAM_PLAYBACK , dpcm) + rtd_dpcm = dpcm; +/* +* This macro will be called for capture stream +*/ +for_each_dpcm_fe (rtd,SNDRV_PCM_STREAM_CAPTURE , dpcm) + rtd_dpcm = dpcm;
is the assumption that both of those loops return the same pointer? If yes, why not stop for the first non-NULL dpcm value?
Also wondering if you are using a loop because there's no other helper available?
Quoted 29 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +5
-5/* * The ADSP will convert the FE rate to 48k, stereo, 24 bit */ -if (!strcmp (fe_dai_link->name,"Kbl Audio Port" ) || - !strcmp (fe_dai_link->name,"Kbl Audio Headset Playback" ) || - !strcmp (fe_dai_link->name,"Kbl Audio Capture Port" )) { +if (!strcmp (rtd_dpcm->fe->dai_link->name,"Kbl Audio Port" ) || + !strcmp (rtd_dpcm->fe->dai_link->name,"Kbl Audio Headset Playback" ) || + !strcmp (rtd_dpcm->fe->dai_link->name,"Kbl Audio Capture Port" )) { rate->min = rate->max =48000 ; chan->min = chan->max =2 ;snd_mask_none (fmt);snd_mask_set_format (fmt,SNDRV_PCM_FORMAT_S24_LE ); - }else if (!strcmp (fe_dai_link->name,"Kbl Audio DMIC cap" )) { + }else if (!strcmp (rtd_dpcm->fe->dai_link->name,"Kbl Audio DMIC cap" )) {if (params_channels (params) ==2 ||DMIC_CH (dmic_constraints) ==2 ) chan->min = chan->max =2 ;@@ -405,7 +413,7 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,* The speaker on the SSP0 supports S16_LE and not S24_LE. * thus changing the mask here */ -if (!strcmp (be_dai_link->name,"SSP0-Codec" )) +if (!strcmp (rtd_dpcm->be->dai_link->name,"SSP0-Codec" ))snd_mask_set_format (fmt,SNDRV_PCM_FORMAT_S16_LE );return 0 ;
Quoted 24 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c static int kabylake_ssp_fixup(struct
Quoted 9 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +0
-0@@ -379,22 +379,30 @@ static int kabylake_ssp_fixup(struct
snd_soc_pcm_runtime*rtd,sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
Quoted 3 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +0
-0struct snd_interval *chan =hw_param_interval (params,SNDRV_PCM_HW_PARAM_CHANNELS ); struct snd_mask *fmt = hw_param_mask(params,
SNDRV_PCM_HW_PARAM_FORMAT);Quoted 10 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +6
-4-struct snd_soc_dpcm *dpcm =container_of ( - params, struct snd_soc_dpcm, hw_params); -struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link; -struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link; +struct snd_soc_dpcm *dpcm, *rtd_dpcm; + +/* +* This macro will be called for playback stream +*/ +for_each_dpcm_fe (rtd,SNDRV_PCM_STREAM_PLAYBACK , dpcm)
Quoted 8 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd, · line 393
Quoted 6 lines
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +6
-0+ rtd_dpcm = dpcm; +/* +* This macro will be called for capture stream +*/ +for_each_dpcm_fe (rtd,SNDRV_PCM_STREAM_CAPTURE , dpcm) + rtd_dpcm = dpcm;is the assumption that both of those loops return the same pointer?
no only one loop will enter based on the direction of the stream If it’s a playback stream, the dpcm[1] will be empty If it’s a capture stream, the dpcm[0] will be empty
Quoted 3 lines
If yes, why not stop for the first non-NULL dpcm value? Also wondering if you are using a loop because there's no other helper available?
yes. I did not find any other helper function so I took the loop.